From 8acd53e07ede1233eba168517e70d6df28d8fd81 Mon Sep 17 00:00:00 2001 From: Yoshinari Gyu <50069930+yngyu@users.noreply.github.com> Date: Tue, 22 Mar 2022 16:27:22 +0900 Subject: [PATCH] add TLCD_insert_tl_cmd_asap --- Applications/timeline_command_dispatcher.c | 104 +++++++++++++++++++++ Applications/timeline_command_dispatcher.h | 22 +++++ TlmCmd/packet_handler.c | 2 +- TlmCmd/packet_list.c | 3 +- TlmCmd/packet_list.h | 15 --- 5 files changed, 129 insertions(+), 17 deletions(-) diff --git a/Applications/timeline_command_dispatcher.c b/Applications/timeline_command_dispatcher.c index 0c50469fa..b6c54b4a5 100644 --- a/Applications/timeline_command_dispatcher.c +++ b/Applications/timeline_command_dispatcher.c @@ -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; diff --git a/Applications/timeline_command_dispatcher.h b/Applications/timeline_command_dispatcher.h index bdfc2d355..e34d2b155 100644 --- a/Applications/timeline_command_dispatcher.h +++ b/Applications/timeline_command_dispatcher.h @@ -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 が入ることを想定している diff --git a/TlmCmd/packet_handler.c b/TlmCmd/packet_handler.c index e0019a5bf..623d0f034 100644 --- a/TlmCmd/packet_handler.c +++ b/TlmCmd/packet_handler.c @@ -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) { diff --git a/TlmCmd/packet_list.c b/TlmCmd/packet_list.c index b86d1a2f8..c5e05cce9 100644 --- a/TlmCmd/packet_list.c +++ b/TlmCmd/packet_list.c @@ -11,6 +11,7 @@ #include "block_command_table.h" #include #include +#include "../Applications/timeline_command_dispatcher.h" /** @@ -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 発行しておく? // 同一時刻で既に登録されていた場合は時刻をずらして再登録 diff --git a/TlmCmd/packet_list.h b/TlmCmd/packet_list.h index 3515b1275..a470d91dd 100644 --- a/TlmCmd/packet_list.h +++ b/TlmCmd/packet_list.h @@ -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 になることに注意