From 83eaf08534f461a14f95cf96c9e0d3251dabd724 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Fri, 28 Jan 2022 14:03:04 +0900 Subject: [PATCH] fix to be build --- Applications/divided_cmd_utility.c | 2 +- Applications/memory_dump.c | 12 +++++ Applications/memory_dump.h | 4 ++ Applications/telemetry_manager.c | 4 +- .../src/src_user/Drivers/Com/gs.c | 14 +++-- .../src/src_user/Drivers/Com/gs_validate.c | 40 +++++++------- .../src/src_user/Drivers/Com/gs_validate.h | 1 + .../TlmCmd/common_tlm_cmd_packet_params.h | 8 --- .../src/src_user/TlmCmd/Ccsds/TCSegment.h | 6 ++- .../src/src_user/TlmCmd/Ccsds/m_pdu.c | 2 - .../src/src_user/TlmCmd/Ccsds/tcp_to_m_pdu.c | 12 +++-- .../src/src_user/TlmCmd/Ccsds/tcp_to_m_pdu.h | 2 + .../src/src_user/TlmCmd/common_cmd_packet.c | 6 +++ .../src_user/TlmCmd/common_tlm_cmd_packet.c | 2 + .../src/src_user/TlmCmd/common_tlm_packet.c | 10 +++- .../src/src_user/TlmCmd/user_packet_handler.c | 4 +- Library/endian_memcpy.h | 8 ++- TlmCmd/Ccsds/cmd_space_packet.c | 20 +++---- TlmCmd/Ccsds/space_packet.c | 9 ++-- TlmCmd/Ccsds/space_packet.h | 7 +-- TlmCmd/Ccsds/space_packet_typedef.h | 2 +- TlmCmd/Ccsds/tlm_space_packet.c | 24 +++++---- TlmCmd/Ccsds/tlm_space_packet.h | 3 +- TlmCmd/block_command_table.c | 8 ++- TlmCmd/common_cmd_packet.h | 9 ++++ TlmCmd/common_cmd_packet_util.c | 4 +- TlmCmd/common_tlm_cmd_packet.h | 3 +- TlmCmd/common_tlm_packet.h | 9 ++++ TlmCmd/packet_handler.c | 23 ++++---- TlmCmd/packet_handler.h | 5 +- TlmCmd/telemetry_frame.c | 3 +- TlmCmd/telemetry_frame.h | 3 +- TlmCmd/telemetry_generator.c | 53 ++++++++++++------- 33 files changed, 200 insertions(+), 122 deletions(-) delete mode 100644 Examples/minimum_user_for_s2e/src/src_user/Settings/TlmCmd/common_tlm_cmd_packet_params.h diff --git a/Applications/divided_cmd_utility.c b/Applications/divided_cmd_utility.c index f69d59ba1..6feb768d5 100644 --- a/Applications/divided_cmd_utility.c +++ b/Applications/divided_cmd_utility.c @@ -213,7 +213,7 @@ DCU_ACK DCU_register_next(CMD_CODE cmd_code, const uint8_t* param, uint16_t len) ret = CCP_form_rtc(&DCU_packet_, cmd_code, param, len); if (ret != CCP_UTIL_ACK_OK) return DCU_ACK_ERR; - if (PH_analyze_packet(&DCU_packet_) != PH_REGISTERED) // FIXME: CTCP, SpacePacket 整理で直す + if (PH_analyze_cmd_packet(&DCU_packet_) != PH_REGISTERED) { return DCU_ACK_ERR; } diff --git a/Applications/memory_dump.c b/Applications/memory_dump.c index 71b2aafa9..9bebe3cb2 100644 --- a/Applications/memory_dump.c +++ b/Applications/memory_dump.c @@ -16,6 +16,9 @@ static void MEM_init_(void); static uint8_t MEM_get_next_adu_counter_(void); +// FIXME: CTCP 大改修が終わったら直す +// https://github.com/ut-issl/c2a-core/pull/217 +#if 0 static CCP_EXEC_STS MEM_dump_region_(uint8_t category, uint8_t num_dumps); @@ -35,6 +38,7 @@ static void MEM_setup_header_(TCP* packet, static void MEM_send_packet_(const CommonTlmPacket* packet, uint8_t num_dumps); +#endif AppInfo MEM_create_app(void) { @@ -84,6 +88,9 @@ CCP_EXEC_STS Cmd_MEM_SET_REGION(const CommonCmdPacket* packet) return CCP_EXEC_SUCCESS; } +// FIXME: CTCP 大改修が終わったら直す +// https://github.com/ut-issl/c2a-core/pull/217 +#if 0 CCP_EXEC_STS Cmd_MEM_DUMP_REGION_SEQ(const CommonCmdPacket* packet) { const uint8_t* param = CCP_get_param_head(packet); @@ -188,6 +195,7 @@ CCP_EXEC_STS Cmd_MEM_DUMP_SINGLE(const CommonCmdPacket* packet) return CCP_EXEC_SUCCESS; } +#endif CCP_EXEC_STS Cmd_MEM_LOAD(const CommonCmdPacket* packet) { @@ -266,6 +274,9 @@ static uint8_t MEM_get_next_adu_counter_(void) return ++adu_counter_; } +// FIXME: CTCP 大改修が終わったら直す +// https://github.com/ut-issl/c2a-core/pull/217 +#if 0 static CCP_EXEC_STS MEM_dump_region_(uint8_t category, uint8_t num_dumps) { @@ -406,5 +417,6 @@ static void MEM_send_packet_(const CommonTlmPacket* packet, PH_analyze_packet(packet); // FIXME: CTCP, SpacePacket 整理で直す } } +#endif #pragma section diff --git a/Applications/memory_dump.h b/Applications/memory_dump.h index 786ba3d2e..640081655 100644 --- a/Applications/memory_dump.h +++ b/Applications/memory_dump.h @@ -34,6 +34,9 @@ AppInfo MEM_create_app(void); // 自分の解釈をコメントとして追加 CCP_EXEC_STS Cmd_MEM_SET_REGION(const CommonCmdPacket* packet); +// FIXME: CTCP 大改修が終わったら直す +// https://github.com/ut-issl/c2a-core/pull/217 +#if 0 CCP_EXEC_STS Cmd_MEM_DUMP_REGION_SEQ(const CommonCmdPacket* packet); // 1パケットに入り切らない場合は,最初のADU分割された最初のパケットのみダンプ // もう一度送ると,その次のパケットがダンプ @@ -45,6 +48,7 @@ CCP_EXEC_STS Cmd_MEM_DUMP_REGION_RND(const CommonCmdPacket* packet); CCP_EXEC_STS Cmd_MEM_DUMP_SINGLE(const CommonCmdPacket* packet); // アドレスを指定して,ダンプ? // Cmd_MEM_SET_REGION は無視? +#endif CCP_EXEC_STS Cmd_MEM_LOAD(const CommonCmdPacket* packet); // MEMにアップリンクして書き込み diff --git a/Applications/telemetry_manager.c b/Applications/telemetry_manager.c index bbf332a4d..bc72d7031 100644 --- a/Applications/telemetry_manager.c +++ b/Applications/telemetry_manager.c @@ -567,7 +567,7 @@ CCP_EXEC_STS Cmd_TLM_MGR_START_TLM(const CommonCmdPacket* packet) // master bc 展開 CCP_form_block_deploy_cmd(&TLM_MGR_packet_, TL_ID_DEPLOY_TLM, master_bc_id); - PH_analyze_packet(&TLM_MGR_packet_); // FIXME: CTCP, SpacePacket 整理で直す + PH_analyze_cmd_packet(&TLM_MGR_packet_); return CCP_EXEC_SUCCESS; } @@ -614,7 +614,7 @@ CCP_EXEC_STS Cmd_TLM_MGR_CLEAR_TLM_TL(const CommonCmdPacket* packet) param[0] = TL_ID_DEPLOY_TLM; CCP_form_rtc(&TLM_MGR_packet_, Cmd_CODE_TLCD_CLEAR_ALL_TIMELINE, param, 1); - PH_analyze_packet(&TLM_MGR_packet_); // FIXME: CTCP, SpacePacket 整理で直す + PH_analyze_cmd_packet(&TLM_MGR_packet_); return CCP_EXEC_SUCCESS; } diff --git a/Examples/minimum_user_for_s2e/src/src_user/Drivers/Com/gs.c b/Examples/minimum_user_for_s2e/src/src_user/Drivers/Com/gs.c index f948bf921..fc3694294 100644 --- a/Examples/minimum_user_for_s2e/src/src_user/Drivers/Com/gs.c +++ b/Examples/minimum_user_for_s2e/src/src_user/Drivers/Com/gs.c @@ -213,11 +213,17 @@ static DS_ERR_CODE GS_analyze_rec_data_(DS_StreamConfig* p_stream_config, void* const uint8_t* gs_rx_data = DSSC_get_rx_frame(p_stream_config); const TCF* tc_frame = (const TCF*)gs_rx_data; // 非自明なcast GS_Driver* gs_driver = (GS_Driver*)p_driver; - int driver_index; + GS_PORT_TYPE driver_index; // アドレス計算で CCSDS か UART か判別 - if ((uint32_t)p_stream_config < (uint32_t)&gs_driver->driver_uart) driver_index = GS_PORT_TYPE_CCSDS; - else driver_index = GS_PORT_TYPE_UART; + if ((uint32_t)p_stream_config < (uint32_t)&gs_driver->driver_uart) + { + driver_index = GS_PORT_TYPE_CCSDS; + } + else + { + driver_index = GS_PORT_TYPE_UART; + } gs_driver->info[driver_index].tc_frame_validate_status = GS_validate_tc_frame(tc_frame); if (gs_driver->info[driver_index].tc_frame_validate_status != GS_VALIDATE_ERR_OK) @@ -225,7 +231,7 @@ static DS_ERR_CODE GS_analyze_rec_data_(DS_StreamConfig* p_stream_config, void* return DS_ERR_CODE_ERR; } - gs_driver->info[driver_index].cmd_ack = PH_analyze_packet(&tc_frame->tcs.tcp); // 受信コマンドパケット解析 + gs_driver->info[driver_index].cmd_ack = PH_analyze_cmd_packet(&tc_frame->tcs.tcp); // 受信コマンドパケット解析 return DS_ERR_CODE_OK; } diff --git a/Examples/minimum_user_for_s2e/src/src_user/Drivers/Com/gs_validate.c b/Examples/minimum_user_for_s2e/src/src_user/Drivers/Com/gs_validate.c index d21501098..9ce5834cc 100644 --- a/Examples/minimum_user_for_s2e/src/src_user/Drivers/Com/gs_validate.c +++ b/Examples/minimum_user_for_s2e/src/src_user/Drivers/Com/gs_validate.c @@ -12,7 +12,7 @@ static GS_VALIDATE_ERR GS_check_tcf_header_(const TCF* tc_frame); static GS_VALIDATE_ERR GS_check_tcf_contents_(const TCF* tc_frame); static GS_VALIDATE_ERR GS_check_tcs_headers_(const TCS* tc_segment); -static GS_VALIDATE_ERR GS_check_tcp_headers_(const TCP* tc_packet); +static GS_VALIDATE_ERR GS_check_cmd_space_packet_headers_(const CmdSpacePacket* csp); static GS_VALIDATE_ERR GS_check_fecw_(const uint8_t* data, size_t len); static GS_VALIDATE_ERR GS_check_ad_cmd_(const TCF* tc_frame); @@ -77,26 +77,14 @@ static GS_VALIDATE_ERR GS_check_tcf_contents_(const TCF* tc_frame) { GS_VALIDATE_ERR ack; - // TCSegment Headerの固定値部分が妥当か確認する + // TCSegment Header の固定値部分が妥当か確認する ack = GS_check_tcs_headers_(&tc_frame->tcs); if (ack != GS_VALIDATE_ERR_OK) return ack; - // TCPacektのヘッダのうちTLM/CMD共通部分が妥当か確認する - ack = GS_check_tcp_headers_(&tc_frame->tcs.tcp); + // CmdSpacePacket のヘッダのうち共通部分が妥当か確認する + ack = GS_check_cmd_space_packet_headers_(&tc_frame->tcs.tcp); if (ack != GS_VALIDATE_ERR_OK) return ack; - // TCPacketのPackte TypeがCommandかどうか確認する - if (TCP_get_type(&tc_frame->tcs.tcp) != TCP_TYPE_CMD) - { - return GS_VALIDATE_ERR_TCP_TYPE_IS_NOT_CMD; - } - - // TCPacketのSequence Flagが単パケットか確認する - if (TCP_get_seq_flag(&tc_frame->tcs.tcp) != TCP_SEQ_SINGLE) - { - return GS_VALIDATE_ERR_TCP_SEQ_IS_NOT_SINGLE; - } - return GS_VALIDATE_ERR_OK; } @@ -115,18 +103,24 @@ static GS_VALIDATE_ERR GS_check_tcs_headers_(const TCS* tc_segment) return GS_VALIDATE_ERR_OK; } -static GS_VALIDATE_ERR GS_check_tcp_headers_(const TCP* tc_packet) +static GS_VALIDATE_ERR GS_check_cmd_space_packet_headers_(const CmdSpacePacket* csp) { APID apid; + // FIXME: 他の部分のチェックも入れる - if (TCP_get_ver(tc_packet) != TCP_VER_1) return GS_VALIDATE_ERR_TCP_VER; - if (TCP_get_2nd_hdr_flag(tc_packet) != TCP_2ND_HDR_PRESENT) + if (CSP_get_ver(csp) != SP_VER_1) return GS_VALIDATE_ERR_TCP_VER; + if (CSP_get_2nd_hdr_flag(csp) != SP_2ND_HDR_FLAG_PRESENT) { // ここではSecondary Headerが必須。 return GS_VALIDATE_ERR_TCP_2ND_HDR_FLAG; } - apid = TCP_get_apid(tc_packet); + if (CSP_get_type(csp) != SP_TYPE_CMD) + { + return GS_VALIDATE_ERR_TCP_TYPE_IS_NOT_CMD; + } + + apid = CSP_get_apid(csp); if ( !( apid == APID_MOBC_CMD || apid == APID_AOBC_CMD || apid == APID_TOBC_CMD ) ) @@ -134,6 +128,12 @@ static GS_VALIDATE_ERR GS_check_tcp_headers_(const TCP* tc_packet) return GS_VALIDATE_ERR_APID; } + // Sequence Flag が単パケットか確認する + if (CSP_get_seq_flag(csp) != SP_SEQ_FLAG_SINGLE) + { + return GS_VALIDATE_ERR_TCP_SEQ_IS_NOT_SINGLE; + } + return GS_VALIDATE_ERR_OK; } diff --git a/Examples/minimum_user_for_s2e/src/src_user/Drivers/Com/gs_validate.h b/Examples/minimum_user_for_s2e/src/src_user/Drivers/Com/gs_validate.h index e76a0e172..a07ce236d 100644 --- a/Examples/minimum_user_for_s2e/src/src_user/Drivers/Com/gs_validate.h +++ b/Examples/minimum_user_for_s2e/src/src_user/Drivers/Com/gs_validate.h @@ -34,6 +34,7 @@ typedef enum GS_VALIDATE_ERR_FARM1_SAME_NUMBER, GS_VALIDATE_ERR_INVALID_BC_CMD } GS_VALIDATE_ERR; +// FIXME: TCP → SpacePacket 大工事後に TCP を直す /** * @struct GS_ValidateInfo diff --git a/Examples/minimum_user_for_s2e/src/src_user/Settings/TlmCmd/common_tlm_cmd_packet_params.h b/Examples/minimum_user_for_s2e/src/src_user/Settings/TlmCmd/common_tlm_cmd_packet_params.h deleted file mode 100644 index e4ac35aee..000000000 --- a/Examples/minimum_user_for_s2e/src/src_user/Settings/TlmCmd/common_tlm_cmd_packet_params.h +++ /dev/null @@ -1,8 +0,0 @@ -/** - * @file - * @brief CTCP パラメタのオーバーライド用ヘッダー - */ -#ifndef COMMON_TLM_CMD_PACKET_PARAMS_H_ -#define COMMON_TLM_CMD_PACKET_PARAMS_H_ - -#endif diff --git a/Examples/minimum_user_for_s2e/src/src_user/TlmCmd/Ccsds/TCSegment.h b/Examples/minimum_user_for_s2e/src/src_user/TlmCmd/Ccsds/TCSegment.h index b3876d102..683618a10 100644 --- a/Examples/minimum_user_for_s2e/src/src_user/TlmCmd/Ccsds/TCSegment.h +++ b/Examples/minimum_user_for_s2e/src/src_user/TlmCmd/Ccsds/TCSegment.h @@ -4,14 +4,16 @@ #include // for size_t #include "../../Library/stdint.h" -#include +#include + +// FIXME: TCP から CmdSpacePacket にしたことによる整理をする!!! #define TCS_HEADER_SIZE (1u) typedef struct { uint8_t header[TCS_HEADER_SIZE]; - TCP tcp; + CmdSpacePacket tcp; // FIXME: TCP から CSP に諸々直す! } TCS; typedef enum diff --git a/Examples/minimum_user_for_s2e/src/src_user/TlmCmd/Ccsds/m_pdu.c b/Examples/minimum_user_for_s2e/src/src_user/TlmCmd/Ccsds/m_pdu.c index aa59a0a18..2d809741f 100644 --- a/Examples/minimum_user_for_s2e/src/src_user/TlmCmd/Ccsds/m_pdu.c +++ b/Examples/minimum_user_for_s2e/src/src_user/TlmCmd/Ccsds/m_pdu.c @@ -3,8 +3,6 @@ #include "string.h" // for memcpy -#include - static void M_PDU_clear_spare_(M_PDU* m_pdu); void M_PDU_generate_byte_stream(const M_PDU* m_pdu, diff --git a/Examples/minimum_user_for_s2e/src/src_user/TlmCmd/Ccsds/tcp_to_m_pdu.c b/Examples/minimum_user_for_s2e/src/src_user/TlmCmd/Ccsds/tcp_to_m_pdu.c index 1f1fc4353..4a74199b3 100644 --- a/Examples/minimum_user_for_s2e/src/src_user/TlmCmd/Ccsds/tcp_to_m_pdu.c +++ b/Examples/minimum_user_for_s2e/src/src_user/TlmCmd/Ccsds/tcp_to_m_pdu.c @@ -5,6 +5,8 @@ */ #include "tcp_to_m_pdu.h" +// FIXME: CTP ではなく TSP を使ってしまっている.できれば抽象化するべき +#include void T2M_initialize(TcpToMPdu* tcp_to_m_pdu) { @@ -26,7 +28,7 @@ T2M_ACK T2M_form_m_pdu(TcpToMPdu* tcp_to_m_pdu, PacketList* pl, M_PDU* m_pdu) // M_PDUが完成する or TC Packetがなくなるまで実施 while (tcp_to_m_pdu->m_pdu_wp != M_PDU_DATA_SIZE) { - const TCP* packet; + const TlmSpacePacket* packet; size_t tcp_len, tcp_left, m_pdu_left, write_len; if (PL_is_empty(pl)) @@ -58,19 +60,19 @@ T2M_ACK T2M_form_m_pdu(TcpToMPdu* tcp_to_m_pdu, PacketList* pl, M_PDU* m_pdu) // この場合、生成されたFill Packetは次M_PDUにまたがる。 // この状態で追加のテレメトリが生成されない場合は、Fill // Packetのみで構成されたM_PDUが一度送出されることになる。 - static TCP fill_; // サイズが大きいため静的確保(スタック保護) + static TlmSpacePacket fill_; // サイズが大きいため静的確保(スタック保護) size_t fill_size = M_PDU_DATA_SIZE - tcp_to_m_pdu->m_pdu_wp; - TCP_TLM_setup_fill_packet(&fill_, (uint16_t)fill_size); + TSP_setup_fill_packet(&fill_, (uint16_t)fill_size); PL_push_back(pl, &fill_); } } // Queue先頭のTC Packetを取得 // 有効パケットまたはFillパケットが必ず入っている。 - packet = (const TCP*)(PL_get_head(pl)->packet); // FIXME: Space Packet 実装でなおす + packet = (const TlmSpacePacket*)(PL_get_head(pl)->packet); // FIXME: Space Packet 実装でなおす // 書き込むデータ長を計算 - tcp_len = TCP_TLM_get_packet_len(packet); + tcp_len = TSP_get_packet_len(packet); tcp_left = tcp_len - tcp_to_m_pdu->tcp_rp; m_pdu_left = M_PDU_DATA_SIZE - tcp_to_m_pdu->m_pdu_wp; write_len = (tcp_left > m_pdu_left) ? m_pdu_left : tcp_left; diff --git a/Examples/minimum_user_for_s2e/src/src_user/TlmCmd/Ccsds/tcp_to_m_pdu.h b/Examples/minimum_user_for_s2e/src/src_user/TlmCmd/Ccsds/tcp_to_m_pdu.h index a93854e44..bd2aafaea 100644 --- a/Examples/minimum_user_for_s2e/src/src_user/TlmCmd/Ccsds/tcp_to_m_pdu.h +++ b/Examples/minimum_user_for_s2e/src/src_user/TlmCmd/Ccsds/tcp_to_m_pdu.h @@ -5,6 +5,8 @@ #ifndef TCP_TO_M_PDU_H_ #define TCP_TO_M_PDU_H_ +// FIXME: TCP から TlmSpacePacket に直す!!! + #include // for size_t #include diff --git a/Examples/minimum_user_for_s2e/src/src_user/TlmCmd/common_cmd_packet.c b/Examples/minimum_user_for_s2e/src/src_user/TlmCmd/common_cmd_packet.c index 1bdd6f5ae..154985a3b 100644 --- a/Examples/minimum_user_for_s2e/src/src_user/TlmCmd/common_cmd_packet.c +++ b/Examples/minimum_user_for_s2e/src/src_user/TlmCmd/common_cmd_packet.c @@ -5,6 +5,7 @@ * @note CCP: CommonCmdPacket */ #include +#include #include @@ -96,4 +97,9 @@ void CCP_set_common_hdr(CommonCmdPacket* packet) CSP_set_common_hdr(packet); } +void CCP_copy_packet(CommonCmdPacket* dest, const CommonCmdPacket* src) +{ + CSP_copy_packet(dest, src); +} + #pragma section diff --git a/Examples/minimum_user_for_s2e/src/src_user/TlmCmd/common_tlm_cmd_packet.c b/Examples/minimum_user_for_s2e/src/src_user/TlmCmd/common_tlm_cmd_packet.c index 0fd8dc24c..314f1dfe4 100644 --- a/Examples/minimum_user_for_s2e/src/src_user/TlmCmd/common_tlm_cmd_packet.c +++ b/Examples/minimum_user_for_s2e/src/src_user/TlmCmd/common_tlm_cmd_packet.c @@ -7,6 +7,8 @@ * @note CCP: CommonCmdPacket */ #include +#include +#include int CTCP_is_valid_packet(const CommonTlmCmdPacket* packet) diff --git a/Examples/minimum_user_for_s2e/src/src_user/TlmCmd/common_tlm_packet.c b/Examples/minimum_user_for_s2e/src/src_user/TlmCmd/common_tlm_packet.c index d080c6f8d..5c3265738 100644 --- a/Examples/minimum_user_for_s2e/src/src_user/TlmCmd/common_tlm_packet.c +++ b/Examples/minimum_user_for_s2e/src/src_user/TlmCmd/common_tlm_packet.c @@ -5,6 +5,7 @@ * @note CTP: CommonTlmPacket */ #include +#include #include @@ -16,12 +17,12 @@ int CTP_is_valid_packet(const CommonTlmPacket* packet) return 1; } -CTP_DEST_FLAG CTP_get_dest_flags(const CommonTlmPacket* packet) +ctp_dest_flags_t CTP_get_dest_flags(const CommonTlmPacket* packet) { return TSP_get_dest_flgas(packet); } -void CTP_set_dest_flags(CommonTlmPacket* packet, CTP_DEST_FLAG flags) +void CTP_set_dest_flags(CommonTlmPacket* packet, ctp_dest_flags_t flags) { TSP_set_dest_flgas(packet, flags); } @@ -36,4 +37,9 @@ uint8_t* CTP_get_user_data_head(CommonTlmPacket* packet) return TSP_get_user_data_head(packet); } +void CTP_copy_packet(CommonTlmPacket* dest, const CommonTlmPacket* src) +{ + TSP_copy_packet(dest, src); +} + #pragma section diff --git a/Examples/minimum_user_for_s2e/src/src_user/TlmCmd/user_packet_handler.c b/Examples/minimum_user_for_s2e/src/src_user/TlmCmd/user_packet_handler.c index 7c93a3de3..aec84aaf0 100644 --- a/Examples/minimum_user_for_s2e/src/src_user/TlmCmd/user_packet_handler.c +++ b/Examples/minimum_user_for_s2e/src/src_user/TlmCmd/user_packet_handler.c @@ -34,9 +34,9 @@ PH_ACK PH_user_analyze_cmd(const CommonCmdPacket* packet) { switch (CCP_get_dest_type(packet)) { - case TCP_CMD_DEST_TYPE_TO_AOBC: + case CCP_DEST_TYPE_TO_AOBC: return (PH_add_aobc_cmd_(packet) == PH_SUCCESS) ? PH_FORWARDED : PH_PL_LIST_FULL; - case TCP_CMD_DEST_TYPE_TO_TOBC: + case CCP_DEST_TYPE_TO_TOBC: return (PH_add_tobc_cmd_(packet) == PH_SUCCESS) ? PH_FORWARDED : PH_PL_LIST_FULL; default: // TCP_CMD_DEST_TYPE_TO_ME diff --git a/Library/endian_memcpy.h b/Library/endian_memcpy.h index d64ad4fb5..77e3bfb25 100644 --- a/Library/endian_memcpy.h +++ b/Library/endian_memcpy.h @@ -2,7 +2,6 @@ * @file * @brief memcpyのエンディアン対策 */ - /* memcpyでエンディアンのせいで死ぬことがあるので, OBCではmemcpy,SLIS環境ではendian convが入るようにスイッチさせる. @@ -11,9 +10,8 @@ memcpy(&sci_.sib_rev, CCP_get_param_head(packet), 2); ↓ endina_memcpy(&sci_.sib_rev, CCP_get_param_head(packet), 2); */ - -#ifndef ENDIAN_MEMCPY_INCLUDE_ -#define ENDIAN_MEMCPY_INCLUDE_ +#ifndef ENDIAN_MEMCPY_H_ +#define ENDIAN_MEMCPY_H_ #include // for size_t @@ -21,4 +19,4 @@ endina_memcpy(&sci_.sib_rev, CCP_get_param_head(packet), 2); // #pragma inline endian_memcpy void* endian_memcpy(void* dest, const void* src, size_t count); -#endif // ENDIAN_MEMCPY_INCLUDE_ +#endif diff --git a/TlmCmd/Ccsds/cmd_space_packet.c b/TlmCmd/Ccsds/cmd_space_packet.c index 6b54fe35d..6383f26e9 100644 --- a/TlmCmd/Ccsds/cmd_space_packet.c +++ b/TlmCmd/Ccsds/cmd_space_packet.c @@ -7,6 +7,7 @@ */ #include "cmd_space_packet.h" #include +#include #define CSP_CAST_TO_SP(csp) ((const SpacePacket*)(csp)) //!< SPへのキャスト. SPのほうが広いので,これは可能 #define CSP_CAST_TO_NON_CONSTSP(csp) ((SpacePacket*)(csp)) //!< SPへのキャスト. SPのほうが広いので,これは可能 @@ -133,7 +134,7 @@ CSP_2ND_HDR_VER CSP_get_2nd_hdr_ver(const CmdSpacePacket* csp) void CSP_set_2nd_hdr_ver(CmdSpacePacket* csp, CSP_2ND_HDR_VER ver) { uint8_t tmp = (uint8_t)ver; - SP_insert_param_from_packet(CSP_CAST_TO_SP(csp), &CSP_pei_2nd_hdr_ver_, &tmp); + SP_insert_param_from_packet(CSP_CAST_TO_NON_CONSTSP(csp), &CSP_pei_2nd_hdr_ver_, &tmp); } @@ -148,7 +149,7 @@ CSP_CMD_TYPE CSP_get_cmd_type(const CmdSpacePacket* csp) void CSP_set_cmd_type(CmdSpacePacket* csp, CSP_CMD_TYPE cmd_type) { uint8_t tmp = (uint8_t)cmd_type; - SP_insert_param_from_packet(CSP_CAST_TO_SP(csp), &CSP_pei_cmd_type_, &tmp); + SP_insert_param_from_packet(CSP_CAST_TO_NON_CONSTSP(csp), &CSP_pei_cmd_type_, &tmp); } @@ -164,7 +165,7 @@ CMD_CODE CSP_get_cmd_id(const CmdSpacePacket* csp) void CSP_set_cmd_id(CmdSpacePacket* csp, CMD_CODE id) { uint16_t tmp = (uint16_t)id; - SP_insert_param_from_packet(CSP_CAST_TO_SP(csp), &CSP_pei_cmd_id_, &tmp); + SP_insert_param_from_packet(CSP_CAST_TO_NON_CONSTSP(csp), &CSP_pei_cmd_id_, &tmp); } @@ -192,7 +193,7 @@ CCP_DEST_TYPE CSP_get_dest_type(const CmdSpacePacket* csp) void CSP_set_dest_type(CmdSpacePacket* csp, CCP_DEST_TYPE dest_type) { uint8_t tmp = (uint8_t)dest_type; - SP_insert_param_from_packet(CSP_CAST_TO_SP(csp), &CSP_pei_dest_type_, &tmp); + SP_insert_param_from_packet(CSP_CAST_TO_NON_CONSTSP(csp), &CSP_pei_dest_type_, &tmp); } @@ -223,7 +224,7 @@ CCP_EXEC_TYPE CSP_get_exec_type(const CmdSpacePacket* csp) void CSP_set_exec_type(CmdSpacePacket* csp, CCP_EXEC_TYPE exec_type) { uint8_t tmp = (uint8_t)exec_type; - SP_insert_param_from_packet(CSP_CAST_TO_SP(csp), &CSP_pei_exec_type_, &tmp); + SP_insert_param_from_packet(CSP_CAST_TO_NON_CONSTSP(csp), &CSP_pei_exec_type_, &tmp); } @@ -238,7 +239,7 @@ uint32_t CSP_get_ti(const CmdSpacePacket* csp) void CSP_set_ti(CmdSpacePacket* csp, uint32_t ti) { - SP_insert_param_from_packet(CSP_CAST_TO_SP(csp), &CSP_pei_ti_, &ti); + SP_insert_param_from_packet(CSP_CAST_TO_NON_CONSTSP(csp), &CSP_pei_ti_, &ti); } @@ -280,15 +281,16 @@ void CSP_set_param(CmdSpacePacket* csp, const uint8_t* param, uint16_t len) { // パラメータをパケットにコピー // paramは既に成形されているのでここは endian_memcpy ではなく memcpy (paramの数, 種類などがこの関数からは不明) - memcpy(CSP_get_param_head(csp), param, (size_t)len); + // const ではダメなので, CSP_get_param_head が使えない + memcpy(&(csp->packet[SP_PRM_HDR_LEN + CSP_SND_HDR_LEN]), param, (size_t)len); // パラメータ長に合わせパケット長を設定 // パケット長はヘッダ分が加算される - SP_set_packet_len(csp, (uint16_t)(SP_PRM_HDR_LEN + CSP_SND_HDR_LEN + len)); + CSP_set_packet_len(csp, (uint16_t)(SP_PRM_HDR_LEN + CSP_SND_HDR_LEN + len)); } -void TCP_CMD_set_common_hdr(CmdSpacePacket* csp) +void CSP_set_common_hdr(CmdSpacePacket* csp) { // ここでは Version Number は Version-1 固定 CSP_set_ver(csp, SP_VER_1); diff --git a/TlmCmd/Ccsds/space_packet.c b/TlmCmd/Ccsds/space_packet.c index cd410f12c..127ce67ee 100644 --- a/TlmCmd/Ccsds/space_packet.c +++ b/TlmCmd/Ccsds/space_packet.c @@ -5,7 +5,8 @@ * @note 詳細は space_packet.h を参照 */ #include "space_packet.h" -#include +#include "../../Library/endian_memcpy.h" +#include static const SP_ParamExtractionInfo SP_pei_ver_ = { 0, 0xe0, 5, 1}; // 11100000b @@ -46,7 +47,7 @@ void SP_set_ver(SpacePacket* sp, SP_VER ver) } -SP_TYPE TCP_get_type(const SpacePacket* sp) +SP_TYPE SP_get_type(const SpacePacket* sp) { uint8_t type; @@ -55,7 +56,7 @@ SP_TYPE TCP_get_type(const SpacePacket* sp) } -void TCP_set_type(SpacePacket* sp, SP_TYPE type) +void SP_set_type(SpacePacket* sp, SP_TYPE type) { uint8_t tmp = (uint8_t)type; SP_insert_param_from_packet(sp, &SP_pei_type_, &tmp); @@ -81,7 +82,7 @@ void SP_set_2nd_hdr_flag(SpacePacket* sp, SP_2ND_HDR_FLAG flag) APID SP_get_apid(const SpacePacket* sp) { uint16_t tmp; - SP_VER apid; + APID apid; SP_extract_param_from_packet(sp, &SP_pei_apid_, &tmp); apid = (APID)tmp; diff --git a/TlmCmd/Ccsds/space_packet.h b/TlmCmd/Ccsds/space_packet.h index 0374f5645..d25090e5a 100644 --- a/TlmCmd/Ccsds/space_packet.h +++ b/TlmCmd/Ccsds/space_packet.h @@ -3,9 +3,10 @@ * @brief CCSDS で規定される Space Packet の実装 * @note 資料: https://sma.jaxa.jp/TechDoc/Docs/JAXA-JERG-2-403.pdf * @note C2A においては, CommonHogePacket の実体として,以下のように Space Packet を標準とする - * CommonTlmCmdPacket -> SpacePacket - * CommonTlmPacket -> TlmSpacePacket - * CommonCmdPacket -> CmdSpacePacket + * CommonTlmCmdPacket -> SpacePacket + * CommonTlmPacket -> TlmSpacePacket + * CommonCmdPacket -> CmdSpacePacket + * つまり, C2A Core 実装においては, Space Packet に依存したコードを書いてはならない!(これを include してはならない) FIXME: 完全にできてないので直す * @note Packet Secondary Header は C2A 独自定義. いくつかのバージョンを用意している * @note /Docs/Core/communication.md などを参照 * @note packet 構造 diff --git a/TlmCmd/Ccsds/space_packet_typedef.h b/TlmCmd/Ccsds/space_packet_typedef.h index f827775e9..8a38132ec 100644 --- a/TlmCmd/Ccsds/space_packet_typedef.h +++ b/TlmCmd/Ccsds/space_packet_typedef.h @@ -1,7 +1,7 @@ /** * @file * @brief SpacePacket 類 と CommonTlmCmdPacket 類が相互参照するのを回避するためのヘッダ - * @note C2A Core 部が知って良い情報はこれだけ + * @note C2A Core のヘッダが知って良い情報はこれだけ */ #ifndef SPACE_PACKET_TYPEDEF_H_ #define SPACE_PACKET_TYPEDEF_H_ diff --git a/TlmCmd/Ccsds/tlm_space_packet.c b/TlmCmd/Ccsds/tlm_space_packet.c index 0d6683112..9a905e8d5 100644 --- a/TlmCmd/Ccsds/tlm_space_packet.c +++ b/TlmCmd/Ccsds/tlm_space_packet.c @@ -7,6 +7,7 @@ */ #include "tlm_space_packet.h" #include +#include #define TSP_CAST_TO_SP(tsp) ((const SpacePacket*)(tsp)) //!< SPへのキャスト. SPのほうが広いので,これは可能 #define TSP_CAST_TO_NON_CONSTSP(tsp) ((SpacePacket*)(tsp)) //!< SPへのキャスト. SPのほうが広いので,これは可能 @@ -134,7 +135,7 @@ TSP_2ND_HDR_VER TSP_get_2nd_hdr_ver(const TlmSpacePacket* tsp) void TSP_set_2nd_hdr_ver(TlmSpacePacket* tsp, TSP_2ND_HDR_VER ver) { uint8_t tmp = (uint8_t)ver; - SP_insert_param_from_packet(TSP_CAST_TO_SP(tsp), &TSP_pei_2nd_hdr_ver_, &tmp); + SP_insert_param_from_packet(TSP_CAST_TO_NON_CONSTSP(tsp), &TSP_pei_2nd_hdr_ver_, &tmp); } @@ -149,7 +150,7 @@ uint32_t TSP_get_board_time(const TlmSpacePacket* tsp) void TSP_set_board_time(TlmSpacePacket* tsp, uint32_t time) { - SP_insert_param_from_packet(TSP_CAST_TO_SP(tsp), &TSP_pei_board_time_, &time); + SP_insert_param_from_packet(TSP_CAST_TO_NON_CONSTSP(tsp), &TSP_pei_board_time_, &time); } @@ -164,7 +165,7 @@ double TSP_get_global_time(const TlmSpacePacket* tsp) void TSP_set_global_time(TlmSpacePacket* tsp, double time) { - SP_insert_param_from_packet(TSP_CAST_TO_SP(tsp), &TSP_pei_global_time_, &time); + SP_insert_param_from_packet(TSP_CAST_TO_NON_CONSTSP(tsp), &TSP_pei_global_time_, &time); } @@ -179,7 +180,7 @@ uint32_t TSP_get_on_board_subnet_time(const TlmSpacePacket* tsp) void TSP_set_on_board_subnet_time(TlmSpacePacket* tsp, uint32_t time) { - SP_insert_param_from_packet(TSP_CAST_TO_SP(tsp), &TSP_pei_ob_sn_time_, &time); + SP_insert_param_from_packet(TSP_CAST_TO_NON_CONSTSP(tsp), &TSP_pei_ob_sn_time_, &time); } @@ -195,7 +196,7 @@ TLM_CODE TSP_get_tlm_id(const TlmSpacePacket* tsp) void TSP_set_tlm_id(TlmSpacePacket* tsp, TLM_CODE id) { uint8_t tmp = (uint8_t)id; - SP_insert_param_from_packet(TSP_CAST_TO_SP(tsp), &TSP_pei_tlm_id_, &tmp); + SP_insert_param_from_packet(TSP_CAST_TO_NON_CONSTSP(tsp), &TSP_pei_tlm_id_, &tmp); } @@ -210,7 +211,7 @@ ctp_dest_flags_t TSP_get_dest_flgas(const TlmSpacePacket* tsp) void TSP_set_dest_flgas(TlmSpacePacket* tsp, ctp_dest_flags_t flags) { - SP_insert_param_from_packet(TSP_CAST_TO_SP(tsp), &TSP_pei_dest_flags_, &flags); + SP_insert_param_from_packet(TSP_CAST_TO_NON_CONSTSP(tsp), &TSP_pei_dest_flags_, &flags); } @@ -225,7 +226,7 @@ uint8_t TSP_get_dr_partition(const TlmSpacePacket* tsp) void TSP_set_dr_partition(TlmSpacePacket* tsp, uint8_t ptn) { - SP_insert_param_from_packet(TSP_CAST_TO_SP(tsp), &TSP_pei_dr_ptn_, &ptn); + SP_insert_param_from_packet(TSP_CAST_TO_NON_CONSTSP(tsp), &TSP_pei_dr_ptn_, &ptn); } @@ -253,13 +254,13 @@ void TSP_copy_packet(TlmSpacePacket* dest, const TlmSpacePacket* src) uint8_t* TSP_get_user_data_head(const TlmSpacePacket* tsp) { - return &(tsp->packet[SP_PRM_HDR_LEN + TSP_SND_HDR_LEN]); // const_cast + return (uint8_t*)&(tsp->packet[SP_PRM_HDR_LEN + TSP_SND_HDR_LEN]); // const_cast } // FIXME: TCP 時代の len と変わってることに注意!!!!!! // これを呼ぶ関数でなおす!!!! -void TSP_setup_primary_hdr(const TlmSpacePacket* tsp, APID apid, uint16_t packet_data_len) +void TSP_setup_primary_hdr(TlmSpacePacket* tsp, APID apid, uint16_t packet_data_len) { TSP_set_common_hdr(tsp); TSP_set_apid(tsp, apid); @@ -277,8 +278,9 @@ void TSP_set_common_hdr(TlmSpacePacket* tsp) TSP_set_2nd_hdr_flag(tsp, SP_2ND_HDR_FLAG_PRESENT); // ここでは Sequence Flag は Standalone Packet に固定 // FIXME: きちんとやる TSP_set_seq_flag(tsp, SP_SEQ_FLAG_SINGLE); - // ここでは Sequence Count は 0 固定 // FIXME: きちんとやる - TSP_set_seq_count(tsp, 0); + // FIXME: 一時的に Cmd_GENERATE_TLM で適当にやってるので,後で直す + // // ここでは Sequence Count は 0 固定 // FIXME: きちんとやる + // TSP_set_seq_count(tsp, 0); } diff --git a/TlmCmd/Ccsds/tlm_space_packet.h b/TlmCmd/Ccsds/tlm_space_packet.h index 97b012794..4ec556c41 100644 --- a/TlmCmd/Ccsds/tlm_space_packet.h +++ b/TlmCmd/Ccsds/tlm_space_packet.h @@ -337,6 +337,7 @@ void TSP_copy_packet(TlmSpacePacket* dest, const TlmSpacePacket* src); * @param tsp: TlmSpacePacket * @return *user_data_head * @note FIXME: この関数で取得したポインタ経由で tlm のデータをセットする事があるため, const をつけていない + * 引数の const を外しても良いかも? */ uint8_t* TSP_get_user_data_head(const TlmSpacePacket* tsp); @@ -347,7 +348,7 @@ uint8_t* TSP_get_user_data_head(const TlmSpacePacket* tsp); * @param[in] packet_data_len: Packet Data Length * @return void */ -void TSP_setup_primary_hdr(const TlmSpacePacket* tsp, APID apid, uint16_t packet_data_len); +void TSP_setup_primary_hdr(TlmSpacePacket* tsp, APID apid, uint16_t packet_data_len); /** * @brief 共通部分の Header を構築 diff --git a/TlmCmd/block_command_table.c b/TlmCmd/block_command_table.c index 7a7ff9479..a1ebaa7fa 100644 --- a/TlmCmd/block_command_table.c +++ b/TlmCmd/block_command_table.c @@ -20,6 +20,10 @@ #include "../System/WatchdogTimer/watchdog_timer.h" #include "common_cmd_packet_util.h" +// FIXME: この include は依存的にダメなので, TCP → Space Packet 大工事が終わったら直す +#include "./Ccsds/space_packet.h" +#include "./Ccsds/cmd_space_packet.h" + static BlockCommandTable block_command_table_; const BlockCommandTable* const block_command_table = &block_command_table_; @@ -486,7 +490,9 @@ CCP_EXEC_STS Cmd_BCT_OVERWRITE_CMD(const CommonCmdPacket* packet) BCT_Pos pos; BCT_CmdData new_bct_cmddata; // FIXME: BCT_CmdData <-> CTCP - uint8_t new_cmd_param[sizeof(BCT_CmdData) - TCP_PRM_HDR_LEN - TCP_CMD_2ND_HDR_LEN - TCP_CMD_USER_HDR_LEN]; // いったんここにparamをコピーする, FIXME: TCPに依存させないように + // FIXME: TCP → SpacePacket 大工事が終わったら直す + // CCP ならまだしも CSP 依存はやばい + uint8_t new_cmd_param[BCT_CMD_MAX_LENGTH - SP_PRM_HDR_LEN - CSP_SND_HDR_LEN]; // いったんここにparamをコピーする, FIXME: TCPに依存させないように uint16_t real_param_len = CCP_get_param_len(packet); uint16_t min_cmd_param_len = CA_get_cmd_param_min_len(Cmd_CODE_BCT_OVERWRITE_CMD); uint16_t max_cmd_param_len = min_cmd_param_len + sizeof(new_cmd_param); diff --git a/TlmCmd/common_cmd_packet.h b/TlmCmd/common_cmd_packet.h index ef7aecbab..54a173429 100644 --- a/TlmCmd/common_cmd_packet.h +++ b/TlmCmd/common_cmd_packet.h @@ -194,4 +194,13 @@ void CCP_set_param(CommonCmdPacket* packet, const uint8_t* param, uint16_t len); */ void CCP_set_common_hdr(CommonCmdPacket* packet); +/** + * @brief CommonCmdPacket をコピー + * @note user 実装次第だが,高速化のためすすべてではなく必要最低限しかコピーしない場合もある + * @param[in,out] dest: コピー先 CCP + * @param[in] src: コピー元 CCP + * @return void + */ +void CCP_copy_packet(CommonCmdPacket* dest, const CommonCmdPacket* src); + #endif diff --git a/TlmCmd/common_cmd_packet_util.c b/TlmCmd/common_cmd_packet_util.c index 4b82479f0..93ffe531b 100644 --- a/TlmCmd/common_cmd_packet_util.c +++ b/TlmCmd/common_cmd_packet_util.c @@ -63,7 +63,7 @@ CCP_UTIL_ACK CCP_form_rtc(CommonCmdPacket* packet, CMD_CODE cmd_id, const uint8_ CCP_set_common_hdr(packet); CCP_set_id(packet, cmd_id); CCP_set_exec_type(packet, CCP_EXEC_TYPE_RT); - CCP_set_dest_type(packet, TCP_CMD_DEST_TYPE_TO_ME); + CCP_set_dest_type(packet, CCP_DEST_TYPE_TO_ME); CCP_set_ti(packet, 0); // RTの場合、TIは0固定。 CCP_set_param(packet, param, len); @@ -89,7 +89,7 @@ CCP_UTIL_ACK CCP_form_tlc(CommonCmdPacket* packet, cycle_t ti, CMD_CODE cmd_id, CCP_set_common_hdr(packet); CCP_set_id(packet, cmd_id); CCP_set_exec_type(packet, CCP_EXEC_TYPE_TL0); - CCP_set_dest_type(packet, TCP_CMD_DEST_TYPE_TO_ME); + CCP_set_dest_type(packet, CCP_DEST_TYPE_TO_ME); CCP_set_ti(packet, ti); CCP_set_param(packet, param, len); diff --git a/TlmCmd/common_tlm_cmd_packet.h b/TlmCmd/common_tlm_cmd_packet.h index e46e5b1c5..fe4576d21 100644 --- a/TlmCmd/common_tlm_cmd_packet.h +++ b/TlmCmd/common_tlm_cmd_packet.h @@ -11,7 +11,6 @@ #include // ここで, CTCP_MAX_LEN, CommonTlmCmdPacket として使うパケット型を指定する #include -#include #include "./common_tlm_packet.h" #include "./common_cmd_packet.h" @@ -87,7 +86,7 @@ void CTCP_set_apid(CommonTlmCmdPacket* packet, APID apid); /** * @brief CommonTlmCmdPacket をコピー - * @note user実装次第だが,高速化のためすすべてではなく必要最低限しかコピーしない場合もある + * @note user 実装次第だが,高速化のためすすべてではなく必要最低限しかコピーしない場合もある * @param[in,out] dest: コピー先 CTCP * @param[in] src: コピー元 CTCP * @return void diff --git a/TlmCmd/common_tlm_packet.h b/TlmCmd/common_tlm_packet.h index e1a77a443..0efd0bda3 100644 --- a/TlmCmd/common_tlm_packet.h +++ b/TlmCmd/common_tlm_packet.h @@ -73,8 +73,17 @@ uint16_t CTP_get_packet_len(const CommonTlmPacket* packet); * @brief ADU 分割なしの場合の User Data 先頭のポインタを取得 * @param packet: CTP * @note FIXME: この関数で取得したポインタ経由で tlm のデータをセットする事があるため, const をつけていない + * 引数の const を外しても良いかも? */ uint8_t* CTP_get_user_data_head(CommonTlmPacket* packet); +/** + * @brief CommonTlmPacket をコピー + * @note user 実装次第だが,高速化のためすすべてではなく必要最低限しかコピーしない場合もある + * @param[in,out] dest: コピー先 CTP + * @param[in] src: コピー元 CTP + * @return void + */ +void CTP_copy_packet(CommonTlmPacket* dest, const CommonTlmPacket* src); #endif diff --git a/TlmCmd/packet_handler.c b/TlmCmd/packet_handler.c index 09d75089f..35ecef8eb 100644 --- a/TlmCmd/packet_handler.c +++ b/TlmCmd/packet_handler.c @@ -72,6 +72,7 @@ void PH_init(void) // パケット解析関数 // GSTOSからのパケット以外もすべてここで処理される // Cmd_GENERATE_TLMとかも. +// FIXME: 外の OBC からコマンドが飛んでくることもあるので,長さが足りているかのチェックを入れる! PH_analyze_tlm_packet, PH_analyze_cmd_packet でも PH_ACK PH_analyze_packet(const CommonTlmCmdPacket* packet) { if (packet == NULL) return PH_UNKNOWN; // FIXME: 返り値変えたい @@ -93,9 +94,10 @@ PH_ACK PH_analyze_packet(const CommonTlmCmdPacket* packet) return PH_UNKNOWN; } -static PH_ACK PH_analyze_cmd_packet(const CommonCmdPacket* packet) +PH_ACK PH_analyze_cmd_packet(const CommonCmdPacket* packet) { PH_ACK ack; + // FIXME: CommonCmdPacket としての妥当性チェックを入れる!!! if (packet == NULL) return PH_UNKNOWN; // FIXME: 返り値変えたい // ユーザー定義部 @@ -159,24 +161,25 @@ static PH_ACK PH_analyze_block_cmd_(const CommonCmdPacket* packet) } } -static PH_ACK PH_analyze_tlm_packet(const CommonTlmPacket* packet) +PH_ACK PH_analyze_tlm_packet(const CommonTlmPacket* packet) { - CTP_DEST_FLAG flag; + ctp_dest_flags_t flags; + // FIXME: CommonTlmPacket としての妥当性チェックを入れる!!! if (packet == NULL) return PH_UNKNOWN; // FIXME: 返り値変えたい - flag = CTP_get_dest_flag(packet); + flags = CTP_get_dest_flags(packet); // Housekeeping Telemetry - if (flag & CTP_DEST_FLAG_HK) PH_add_ms_tlm_(packet); // hk_tlm のフラグが立っていても,MS_TLMとして処理する方針にした + if (flags & CTP_DEST_FLAG_HK) PH_add_ms_tlm_(packet); // hk_tlm のフラグが立っていても,MS_TLMとして処理する方針にした // Mission Telemetry - if (flag & CTP_DEST_FLAG_MS) PH_add_ms_tlm_(packet); + if (flags & CTP_DEST_FLAG_MS) PH_add_ms_tlm_(packet); // Stored Telemetry - if (flag & CTP_DEST_FLAG_ST) PH_add_st_tlm_(packet); + if (flags & CTP_DEST_FLAG_ST) PH_add_st_tlm_(packet); // Replay Telemetry - if (flag & CTP_DEST_FLAG_RP) PH_add_rp_tlm_(packet); + if (flags & CTP_DEST_FLAG_RP) PH_add_rp_tlm_(packet); // [TODO] 要検討:各Queue毎の登録エラー判定は未実装 return PH_SUCCESS; @@ -194,7 +197,7 @@ CCP_EXEC_STS PH_dispatch_command(const CommonCmdPacket* packet) // } // FIXME: CTCP, SpacePacket 整理で直す - if (CCP_get_apid(packet) == CTCP_MY_DST_ID) + if (CCP_get_apid(packet) == CCP_APID_TO_ME) { // 自分宛てのコマンドの場合は対応処理を呼び出し。 return CA_execute_cmd(packet); @@ -259,7 +262,7 @@ static PH_ACK PH_add_utl_cmd_(const CommonCmdPacket* packet) cycle_t ti = TMGR_get_ti_from_utl_unixtime(utl_unixtime); // TL_cmd に変換して tl_cmd_list に追加する - CTCP_copy_packet(&temp_, packet); // FIXME: CTCP, SpacePacket 整理で直す + CCP_copy_packet(&temp_, packet); CCP_set_ti(&temp_, ti); CCP_set_exec_type(&temp_, CCP_EXEC_TYPE_TL0); // UTL -> TL0 diff --git a/TlmCmd/packet_handler.h b/TlmCmd/packet_handler.h index 52b88eb6a..cdc95af52 100644 --- a/TlmCmd/packet_handler.h +++ b/TlmCmd/packet_handler.h @@ -62,9 +62,10 @@ extern PacketList PH_rp_tlm_list; void PH_init(void); +// FIXME: CTCP大改修がおわったらコメント入れる! PH_ACK PH_analyze_packet(const CommonTlmCmdPacket* packet); -static PH_ACK PH_analyze_tlm_packet(const CommonTlmPacket* packet); -static PH_ACK PH_analyze_cmd_packet(const CommonCmdPacket* packet); +PH_ACK PH_analyze_tlm_packet(const CommonTlmPacket* packet); +PH_ACK PH_analyze_cmd_packet(const CommonCmdPacket* packet); CCP_EXEC_STS PH_dispatch_command(const CommonCmdPacket* packet); diff --git a/TlmCmd/telemetry_frame.c b/TlmCmd/telemetry_frame.c index 77d9f27fc..37d4d413d 100644 --- a/TlmCmd/telemetry_frame.c +++ b/TlmCmd/telemetry_frame.c @@ -6,7 +6,6 @@ #include "telemetry_frame.h" #include -#include #include "../Library/print.h" #include "../Library/endian_memcpy.h" #include @@ -17,7 +16,7 @@ static TelemetryFrame telemetry_frame_; const TelemetryFrame* const telemetry_frame = &telemetry_frame_; -int TF_generate_contents(int packet_id, +int TF_generate_contents(TLM_CODE packet_id, unsigned char* contents, int max_len) { diff --git a/TlmCmd/telemetry_frame.h b/TlmCmd/telemetry_frame.h index 785a4c746..813a7873f 100644 --- a/TlmCmd/telemetry_frame.h +++ b/TlmCmd/telemetry_frame.h @@ -6,6 +6,7 @@ #define TELEMETRY_FRAME_H_ #include "./common_tlm_cmd_packet.h" +#include #define TF_TLM_PAGE_SIZE (64) //!< テレメテーブルの1テレメトリパケット(=1ページ)に格納されるテレメ数 #define TF_TLM_PAGE_MAX (4) //!< テレメテーブルページ数(ページネーション用) @@ -63,7 +64,7 @@ void TF_initialize(void); * @param max_len: テレメの body として使える最大長 * @return 成功時はテレメ長,失敗時は TF_ACK */ -int TF_generate_contents(int packet_id, +int TF_generate_contents(TLM_CODE packet_id, unsigned char* contents, int max_len); diff --git a/TlmCmd/telemetry_generator.c b/TlmCmd/telemetry_generator.c index 005afff57..0cc2a729d 100644 --- a/TlmCmd/telemetry_generator.c +++ b/TlmCmd/telemetry_generator.c @@ -6,23 +6,23 @@ #include "telemetry_frame.h" #include "packet_handler.h" #include "../System/TimeManager/time_manager.h" +#include "common_cmd_packet_util.h" #include +#include "./Ccsds/tlm_space_packet.h" // FIXME: TSP 依存性はNGなので, TCP → SP 大工事終わったら直す static uint8_t TG_get_next_adu_counter_(void); CCP_EXEC_STS Cmd_GENERATE_TLM(const CommonCmdPacket* packet) { - static TCP tcp_; - const uint8_t* param = CCP_get_param_head(packet); - uint8_t category; - uint8_t id; - uint8_t num_dumps; + static CommonTlmPacket ctp_; + uint8_t category = CCP_get_param_from_packet(packet, 0, uint8_t); + TLM_CODE id = (TLM_CODE)CCP_get_param_from_packet(packet, 1, uint8_t); + uint8_t num_dumps = CCP_get_param_from_packet(packet, 2, uint8_t); int len; - - // パラメータ読み出し - category = param[0]; - id = param[1]; - num_dumps = param[2]; + uint8_t dr_partition_mask = 0x1f; // 00011111b // FIXME: 一時的な対応 + uint8_t dest_flags_mask = 0xe0; // 11100000b // FIXME: 一時的な対応 + uint8_t dr_partition; + ctp_dest_flags_t dest_flags; if (num_dumps >= 8) { @@ -35,32 +35,45 @@ CCP_EXEC_STS Cmd_GENERATE_TLM(const CommonCmdPacket* packet) // ADU生成 // ADU分割が発生しない場合に限定したコードになっている。 // TLM定義シート上で定義するADUはADU長をADU分割が発生しない長さに制限する。 - len = TF_generate_contents((int)id, - TCP_TLM_get_user_data_head(&tcp_), - TCP_MAX_LEN - TCP_PRM_HDR_LEN - TCP_TLM_2ND_HDR_LEN); + len = TF_generate_contents(id, + CTP_get_user_data_head(&ctp_), + TSP_MAX_LEN - SP_PRM_HDR_LEN - TSP_SND_HDR_LEN); // FIXME: Space Packet 依存を直す // 範囲外のTLM IDを除外 if (len == TF_NOT_DEFINED) return CCP_EXEC_ILLEGAL_PARAMETER; if (len < 0) return CCP_EXEC_ILLEGAL_CONTEXT; // TODO: lenがマイナスの値たちをどうするか? // TCPacketヘッダ設定 - TCP_TLM_setup_primary_hdr(&tcp_, APID_MIS_TLM, (uint16_t)(len + 7)); - TCP_TLM_set_ti(&tcp_, (uint32_t)(TMGR_get_master_total_cycle())); - TCP_TLM_set_category(&tcp_, category); // パラメータによる指定 - TCP_TLM_set_packet_id(&tcp_, id); - TCP_TLM_set_adu_seq_flag(&tcp_, TCP_SEQ_SINGLE); - TCP_TLM_set_adu_cnt(&tcp_, TG_get_next_adu_counter_()); + // FIXME: Space Packet 依存を直す + TSP_setup_primary_hdr(&ctp_, APID_MIS_TLM, (uint16_t)(len + TSP_SND_HDR_LEN)); + TSP_set_board_time(&ctp_, (uint32_t)(TMGR_get_master_total_cycle())); + // FIXME: 他の時刻も入れる + TSP_set_board_time(&ctp_, 0.0); + TSP_set_on_board_subnet_time(&ctp_, 0); + // FIXME: 他 OBC からのパケットは別処理する + // FIXME: 一旦雑に category を処理してるが後でちゃんと直す + dr_partition = (uint8_t)(category & dr_partition_mask); + dest_flags = (uint8_t)( (category & dest_flags_mask) >> 5 ); + if (dest_flags == 0) + { + dest_flags = CTP_DEST_FLAG_RP; + } + TSP_set_dest_flgas(&ctp_, dest_flags); + TSP_set_dr_partition(&ctp_, dr_partition); + TSP_set_tlm_id(&ctp_, id); + TSP_set_seq_count(&ctp_, TG_get_next_adu_counter_()); // 生成したパケットを指定された回数配送処理へ渡す while (num_dumps != 0) { - PH_analyze_packet(&tcp_); + PH_analyze_tlm_packet(&ctp_); --num_dumps; } return CCP_EXEC_SUCCESS; } +// FIXME: space packet 大工事でビット幅が変わってるので直す! static uint8_t TG_get_next_adu_counter_(void) { // インクリメントした値を返すため初期値は0xffとする