Skip to content

Commit

Permalink
add TLCD_insert_tl_cmd_asap
Browse files Browse the repository at this point in the history
  • Loading branch information
yngyu committed Mar 22, 2022
1 parent 8f91e97 commit 8acd53e
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 17 deletions.
104 changes: 104 additions & 0 deletions Applications/timeline_command_dispatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,110 @@ static void tlc_dispatcher_(int line_no)
}
}

PL_ACK TLCD_insert_tl_cmd_strictly(PacketList* pl, const CommonCmdPacket* packet, cycle_t now)
{
cycle_t head, tail;
cycle_t planed = CCP_get_ti(packet);

if (PL_get_packet_type(pl)) return PL_PACKET_TYPE_ERR;
if (now > planed) return PL_TLC_PAST_TIME;
if (PL_is_full(pl)) return PL_LIST_FULL;

if (PL_is_empty(pl)) return PL_push_back(pl, packet);

head = CCP_get_ti((const CommonCmdPacket*)(PL_get_head(pl)->packet));
tail = CCP_get_ti((const CommonCmdPacket*)(PL_get_tail(pl)->packet));

if (tail < planed)
{
return PL_push_back(pl, packet);
}
else if (head > planed)
{
return PL_push_front(pl, packet);
}
else if (head == planed || tail == planed) // 時刻指定が等しい
{
return PL_TLC_ALREADY_EXISTS;
}
else
{
uint16_t i;
PL_Node* previous = (PL_Node*)PL_get_head(pl)->next;
PL_Node* current = previous->next; // const_cast

for (i = 0; i < pl->active_nodes_; ++i)
{
cycle_t current_ti = CCP_get_ti((const CommonCmdPacket*)(current->packet));
if (planed > current_ti)
{
previous = current;
current = previous->next;
}
else if (current_ti > planed)
{
PL_insert_after(pl, previous, packet);
return PL_SUCCESS;
}
else
{
return PL_TLC_ALREADY_EXISTS;
}
}
}

// NOT REACED
return PL_NO_SUCH_NODE;
}

PL_ACK TLCD_insert_tl_cmd_asap(PacketList* pl, const CommonCmdPacket* packet, cycle_t now)
{
cycle_t head, tail;
cycle_t planed = CCP_get_ti(packet);

if (PL_get_packet_type(pl)) return PL_PACKET_TYPE_ERR;
if (now > planed) return PL_TLC_PAST_TIME;
if (PL_is_full(pl)) return PL_LIST_FULL;

if (PL_is_empty(pl)) return PL_push_back(pl, packet);

head = CCP_get_ti((const CommonCmdPacket*)(PL_get_head(pl)->packet));
tail = CCP_get_ti((const CommonCmdPacket*)(PL_get_tail(pl)->packet));

if (tail < planed)
{
return PL_push_back(pl, packet);
}
else if (head > planed)
{
return PL_push_front(pl, packet);
}
else
{
uint16_t i;
PL_Node* previous = (PL_Node*)PL_get_head(pl)->next;
PL_Node* current = previous->next; // const_cast

for (i = 0; i < pl->active_nodes_; ++i)
{
cycle_t current_ti = CCP_get_ti((const CommonCmdPacket*)(current->packet));
if (planed > current_ti)
{
previous = current;
current = previous->next;
}
else if (current_ti > planed)
{
PL_insert_after(pl, previous, packet);
return PL_SUCCESS;
}
}
}

// NOT REACED
return PL_NO_SUCH_NODE;
}

uint8_t TLCD_update_tl_list_for_tlm(uint8_t line_no)
{
PL_Node* pos;
Expand Down
22 changes: 22 additions & 0 deletions Applications/timeline_command_dispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,28 @@ AppInfo TLCD0_create_app(void);
AppInfo TLCD1_create_app(void);
AppInfo TLCD2_create_app(void);


/**
* @brief CCP が時系列に並ぶように CCP を挿入する
* @note TimeLine だけでなく TaskList もこれを使い,その場合, now は step_t になることに注意
* @note asap と違うのは,そこに挿入出来なければ挿入しない
* @param[in,out] pl: CCP を挿入する PacketList
* @param[in] packet: 挿入する CCP
* @param[in] now: 基準時刻 (TimeLine なら現在時刻, TaskList なら現在 step)
* @return PL_ACK
*/
PL_ACK TLCD_insert_tl_cmd_strictly(PacketList* pl, const CommonCmdPacket* packet, cycle_t now);

/**
* @brief CCP が時系列に並ぶように CCP を挿入する
* @note strictly と違うのは同時刻に既に入ってもいてもそこ以降に最速で入れる
* @param[in,out] pl: CCP を挿入する PacketList
* @param[in] packet: 挿入する CCP
* @param[in] now: 基準時刻 (TimeLine なら現在時刻, TaskList なら現在 step)
* @return PL_ACK
*/
PL_ACK TLCD_insert_tl_cmd_asap(PacketList* pl, const CommonCmdPacket* packet, cycle_t now);

/**
* @brief TLM の内容を自動更新する.
* @param[in] line_no TLCD_line_no_for_tlm が入ることを想定している
Expand Down
2 changes: 1 addition & 1 deletion TlmCmd/packet_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ static PH_ACK PH_add_tl_cmd_(int line_no,
const CommonCmdPacket* packet,
cycle_t now)
{
PL_ACK ack = PL_insert_tl_cmd(&(PH_tl_cmd_list[line_no]), packet, now);
PL_ACK ack = TLCD_insert_tl_cmd_strictly(&(PH_tl_cmd_list[line_no]), packet, now);

switch (ack)
{
Expand Down
3 changes: 2 additions & 1 deletion TlmCmd/packet_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "block_command_table.h"
#include <src_user/Library/stdint.h>
#include <string.h>
#include "../Applications/timeline_command_dispatcher.h"


/**
Expand Down Expand Up @@ -375,7 +376,7 @@ PL_ACK PL_deploy_block_cmd(PacketList* pl, const bct_id_t block, cycle_t start_a
for (j = 0; j <= pl->active_nodes_; ++j)
{
// コマンドをTLCに登録を試みる
ack = PL_insert_tl_cmd(pl, &temp_, start_at);
ack = TLCD_insert_tl_cmd_strictly(pl, &temp_, start_at);
if (ack != PL_TLC_ALREADY_EXISTS) break; // PL_SUCCESS なはず. TODO: 一応 event 発行しておく?

// 同一時刻で既に登録されていた場合は時刻をずらして再登録
Expand Down
15 changes: 0 additions & 15 deletions TlmCmd/packet_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,21 +242,6 @@ PL_ACK PL_drop_node(PacketList* pl, PL_Node* prev, PL_Node* current);

// 以下,特定の packet を想定した PacketList の関数

/**
* @brief CCP が時系列に並ぶように CCP を挿入する
* @note TimeLine だけでなく TaskList もこれを使い,その場合, now は step_t になることに注意
* @param[in,out] pl: CCP を挿入する PacketList
* @param[in] packet: 挿入する CCP
* @param[in] now: 基準時刻 (TimeLine なら現在時刻, TaskList なら現在 step)
* @retval PL_SUCCESS: 成功
* @retval PL_LIST_FULL: PacketList が満杯
* @retval PL_TLC_PAST_TIME: 実行時間がすでに過ぎている
* @retval PL_TLC_ALREADY_EXISTS: 指定した実行時間にはすでにコマンドが登録されている
* @retval PL_NO_SUCH_NODE: 何かがおかしい
* @retval PL_PACKET_TYPE_ERR: 指定した PacketList の packet が CCP ではない
*/
PL_ACK PL_insert_tl_cmd(PacketList* pl, const CommonCmdPacket* packet, cycle_t now);

/**
* @brief PacketList 上に BC を展開する
* @note TimeLine だけでなく TaskList もこれを使い,その場合, start_at は step_t になることに注意
Expand Down

0 comments on commit 8acd53e

Please sign in to comment.