diff --git a/CMakeLists.txt b/CMakeLists.txt index 759e9f5a..b84b193e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,9 +26,9 @@ set(C2A_CORE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) set(C2A_SRCS c2a_core_main.c - component_driver/common_tlm_cmd_packet_for_driver_super.c - component_driver/eb90_frame_for_driver_super.c - component_driver/eb90_packet_for_driver_super.c + component_driver/cdrv_common_tlm_cmd_packet.c + component_driver/cdrv_eb90_frame.c + component_driver/cdrv_eb90_packet.c component_driver/driver_super.c hal/i2c_common.c system/application_manager/app_info.c diff --git a/code-generator/my_mod/tlm_buffer.py b/code-generator/my_mod/tlm_buffer.py index cc314570..69a048db 100644 --- a/code-generator/my_mod/tlm_buffer.py +++ b/code-generator/my_mod/tlm_buffer.py @@ -146,7 +146,7 @@ def GenerateTlmBuffer(settings, other_obc_dbs): body_c += " {_obc_name_upper}_TLM_CODE tlm_id;\n" body_c += " CDS_ERR_CODE ret;\n" body_c += "\n" - body_c += " ret = CTP_get_ctp_from_cdssc(p_stream_config, &{_obc_name_upper}_ctp_);\n" + body_c += " ret = CDRV_CTP_get_ctp(p_stream_config, &{_obc_name_upper}_ctp_);\n" body_c += " if (ret != CDS_ERR_CODE_OK) return ret;\n" body_c += "\n" body_c += " tlm_id = ({_obc_name_upper}_TLM_CODE)CTP_get_id(&{_obc_name_upper}_ctp_);\n" @@ -368,7 +368,7 @@ def OutputTlmBufferC_(file_path, name, body, settings): * @brief テレメトリバッファー(テレメ中継) * @note このコードは自動生成されています! */ -#include +#include #include "./{_obc_name_lower}_telemetry_definitions.h" #include "./{_obc_name_lower}_telemetry_buffer.h" #include "./{_obc_name_lower}.h" diff --git a/component_driver/common_tlm_cmd_packet_for_driver_super.c b/component_driver/cdrv_common_tlm_cmd_packet.c similarity index 60% rename from component_driver/common_tlm_cmd_packet_for_driver_super.c rename to component_driver/cdrv_common_tlm_cmd_packet.c index 845488fc..6969f60a 100644 --- a/component_driver/common_tlm_cmd_packet_for_driver_super.c +++ b/component_driver/cdrv_common_tlm_cmd_packet.c @@ -6,34 +6,34 @@ * @note データリンク層は CDS_StreamConfig.data_link_layer_ で規定する * @note packet 構造 などは tlm_cmd/common_tlm_cmd_packet.h を参照のこと */ -#include "common_tlm_cmd_packet_for_driver_super.h" -#include "eb90_frame_for_driver_super.h" +#include "cdrv_common_tlm_cmd_packet.h" +#include "cdrv_eb90_frame.h" #include // FIXME: CDS_StreamConfig.data_link_layer_ をちゃんと見る! -CDS_ERR_CODE CTCP_get_ctcp_from_cdssc(const CDS_StreamConfig* p_stream_config, CommonTlmCmdPacket* received_packet) +CDS_ERR_CODE CDRV_CTCP_get_ctcp(const CDS_StreamConfig* p_stream_config, CommonTlmCmdPacket* received_packet) { - const uint16_t packet_len = EB90_FRAME_get_packet_length_from_cdssc(p_stream_config); + const uint16_t packet_len = CDRV_EB90_FRAME_get_packet_length(p_stream_config); if (packet_len > CTCP_MAX_LEN) return CDS_ERR_CODE_ERR; // まず, 受信データ長だけコピーしてしまってから,アサーションする(効率のため) - memcpy(&received_packet->packet, EB90_FRAME_get_packet_head_from_cdssc(p_stream_config), (size_t)packet_len); + memcpy(&received_packet->packet, CDRV_EB90_FRAME_get_packet_head(p_stream_config), (size_t)packet_len); if (CTCP_get_packet_len(received_packet) != packet_len) return CDS_ERR_CODE_ERR; if (!CTCP_is_valid_packet(received_packet)) return CDS_ERR_CODE_ERR; return CDS_ERR_CODE_OK; } -CDS_ERR_CODE CTP_get_ctp_from_cdssc(const CDS_StreamConfig* p_stream_config, CommonTlmPacket* received_packet) +CDS_ERR_CODE CDRV_CTP_get_ctp(const CDS_StreamConfig* p_stream_config, CommonTlmPacket* received_packet) { - const uint16_t packet_len = EB90_FRAME_get_packet_length_from_cdssc(p_stream_config); + const uint16_t packet_len = CDRV_EB90_FRAME_get_packet_length(p_stream_config); if (packet_len > CTP_MAX_LEN) return CDS_ERR_CODE_ERR; // まず, 受信データ長だけコピーしてしまってから,アサーションする(効率のため) - memcpy(&received_packet->packet, EB90_FRAME_get_packet_head_from_cdssc(p_stream_config), (size_t)packet_len); + memcpy(&received_packet->packet, CDRV_EB90_FRAME_get_packet_head(p_stream_config), (size_t)packet_len); if (CTP_get_packet_len(received_packet) != packet_len) return CDS_ERR_CODE_ERR; if (!CTP_is_valid_packet(received_packet)) return CDS_ERR_CODE_ERR; @@ -49,28 +49,28 @@ CDS_ERR_CODE CTP_get_ctp_from_cdssc(const CDS_StreamConfig* p_stream_config, Com } -CDS_ERR_CODE CCP_get_ccp_from_cdssc(const CDS_StreamConfig* p_stream_config, CommonCmdPacket* received_packet) +CDS_ERR_CODE CDRV_CCP_get_ccp(const CDS_StreamConfig* p_stream_config, CommonCmdPacket* received_packet) { - const uint16_t packet_len = EB90_FRAME_get_packet_length_from_cdssc(p_stream_config); + const uint16_t packet_len = CDRV_EB90_FRAME_get_packet_length(p_stream_config); if (packet_len > CCP_MAX_LEN) return CDS_ERR_CODE_ERR; // まず, 受信データ長だけコピーしてしまってから,アサーションする(効率のため) - memcpy(&received_packet->packet, EB90_FRAME_get_packet_head_from_cdssc(p_stream_config), (size_t)packet_len); + memcpy(&received_packet->packet, CDRV_EB90_FRAME_get_packet_head(p_stream_config), (size_t)packet_len); if (CCP_get_packet_len(received_packet) != packet_len) return CDS_ERR_CODE_ERR; if (!CCP_is_valid_packet(received_packet)) return CDS_ERR_CODE_ERR; return CDS_ERR_CODE_OK; } -CDS_ERR_CODE CTCP_init_cdssc(CDS_StreamConfig* p_stream_config, - uint8_t* tx_frame_buffer, - int16_t tx_frame_buffer_size, - CDS_ERR_CODE (*data_analyzer)(CDS_StreamConfig* p_stream_config, void* p_driver)) +CDS_ERR_CODE CDRV_CTCP_init_stream_config(CDS_StreamConfig* p_stream_config, + uint8_t* tx_frame_buffer, + int16_t tx_frame_buffer_size, + CDS_ERR_CODE (*data_analyzer)(CDS_StreamConfig* p_stream_config, void* p_driver)) { // MOBC か sub OBC かによって,送信側 (tx 側) が CTP になるか CCP になるかは不明なため,ひとまず CTCP に // メモリが苦しい OBC もあるので,考えてもいいかも - const uint16_t max_frame_size = EB90_FRAME_HEADER_SIZE + CTCP_MAX_LEN + EB90_FRAME_FOOTER_SIZE; + const uint16_t max_frame_size = CDRV_EB90_FRAME_HEADER_SIZE + CTCP_MAX_LEN + CDRV_EB90_FRAME_FOOTER_SIZE; if (tx_frame_buffer_size < max_frame_size) { return CDS_ERR_CODE_ERR; @@ -82,14 +82,14 @@ CDS_ERR_CODE CTCP_init_cdssc(CDS_StreamConfig* p_stream_config, CDSSC_set_tx_frame_size(p_stream_config, 0); // 送る直前に値をセットする // 定期的な受信はする - CDSSC_set_rx_header(p_stream_config, EB90_FRAME_kStx, EB90_FRAME_STX_SIZE); - CDSSC_set_rx_footer(p_stream_config, EB90_FRAME_kEtx, EB90_FRAME_ETX_SIZE); + CDSSC_set_rx_header(p_stream_config, CDRV_EB90_FRAME_kStx, CDRV_EB90_FRAME_STX_SIZE); + CDSSC_set_rx_footer(p_stream_config, CDRV_EB90_FRAME_kEtx, CDRV_EB90_FRAME_ETX_SIZE); CDSSC_set_rx_frame_size(p_stream_config, -1); // 可変 CDSSC_set_max_rx_frame_size(p_stream_config, max_frame_size); - CDSSC_set_rx_framelength_pos(p_stream_config, EB90_FRAME_STX_SIZE); + CDSSC_set_rx_framelength_pos(p_stream_config, CDRV_EB90_FRAME_STX_SIZE); CDSSC_set_rx_framelength_type_size(p_stream_config, 2); CDSSC_set_rx_framelength_offset(p_stream_config, - EB90_FRAME_HEADER_SIZE + EB90_FRAME_FOOTER_SIZE); + CDRV_EB90_FRAME_HEADER_SIZE + CDRV_EB90_FRAME_FOOTER_SIZE); CDSSC_set_data_analyzer(p_stream_config, data_analyzer); // 定期 TLM の監視機能の有効化はここではしないので, ComponentDriver 側でやる @@ -99,14 +99,14 @@ CDS_ERR_CODE CTCP_init_cdssc(CDS_StreamConfig* p_stream_config, } -CDS_ERR_CODE CTCP_set_tx_frame_to_cdssc(CDS_StreamConfig* p_stream_config, - const CommonTlmCmdPacket* send_packet) +CDS_ERR_CODE CDRV_CTCP_set_tx_frame(CDS_StreamConfig* p_stream_config, + const CommonTlmCmdPacket* send_packet) { size_t pos; size_t size; uint16_t crc; uint16_t packet_len = CTCP_get_packet_len(send_packet); - uint16_t frame_len = (uint16_t)(packet_len + EB90_FRAME_HEADER_SIZE + EB90_FRAME_FOOTER_SIZE); + uint16_t frame_len = (uint16_t)(packet_len + CDRV_EB90_FRAME_HEADER_SIZE + CDRV_EB90_FRAME_FOOTER_SIZE); uint8_t* tx_frame = CDSSC_get_tx_frame_as_non_const_pointer(p_stream_config); if (frame_len > CDSSC_get_tx_frame_buffer_size(p_stream_config)) return CDS_ERR_CODE_ERR; @@ -114,10 +114,10 @@ CDS_ERR_CODE CTCP_set_tx_frame_to_cdssc(CDS_StreamConfig* p_stream_config, CDSSC_set_tx_frame_size(p_stream_config, frame_len); pos = 0; - size = EB90_FRAME_STX_SIZE; - memcpy(&(tx_frame[pos]), EB90_FRAME_kStx, size); + size = CDRV_EB90_FRAME_STX_SIZE; + memcpy(&(tx_frame[pos]), CDRV_EB90_FRAME_kStx, size); pos += size; - size = EB90_FRAME_LEN_SIZE; + size = CDRV_EB90_FRAME_LEN_SIZE; ENDIAN_memcpy(&(tx_frame[pos]), &packet_len, size); // ここはエンディアンを気にする! pos += size; @@ -125,32 +125,32 @@ CDS_ERR_CODE CTCP_set_tx_frame_to_cdssc(CDS_StreamConfig* p_stream_config, memcpy(&(tx_frame[pos]), send_packet->packet, size); pos += size; - crc = EB90_FRAME_calc_crc(tx_frame + EB90_FRAME_HEADER_SIZE, pos - EB90_FRAME_HEADER_SIZE); - size = EB90_FRAME_CRC_SIZE; + crc = EB90_FRAME_calc_crc(tx_frame + CDRV_EB90_FRAME_HEADER_SIZE, pos - CDRV_EB90_FRAME_HEADER_SIZE); + size = CDRV_EB90_FRAME_CRC_SIZE; ENDIAN_memcpy(&(tx_frame[pos]), &crc, size); // ここはエンディアンを気にする! pos += size; - size = EB90_FRAME_ETX_SIZE; - memcpy(&(tx_frame[pos]), EB90_FRAME_kEtx, size); + size = CDRV_EB90_FRAME_ETX_SIZE; + memcpy(&(tx_frame[pos]), CDRV_EB90_FRAME_kEtx, size); return CDS_ERR_CODE_OK; } -CDS_ERR_CODE CTP_set_tx_frame_to_cdssc(CDS_StreamConfig* p_stream_config, - const CommonTlmPacket* send_packet) +CDS_ERR_CODE CDRV_CTP_set_tx_frame(CDS_StreamConfig* p_stream_config, + const CommonTlmPacket* send_packet) { const CommonTlmCmdPacket* ctcp = CTCP_convert_from_ctp(send_packet); if (ctcp == NULL) return CDS_ERR_CODE_ERR; - return CTCP_set_tx_frame_to_cdssc(p_stream_config, ctcp); + return CDRV_CTCP_set_tx_frame(p_stream_config, ctcp); } -CDS_ERR_CODE CCP_set_tx_frame_to_cdssc(CDS_StreamConfig* p_stream_config, - const CommonCmdPacket* send_packet) +CDS_ERR_CODE CDRV_CCP_set_tx_frame(CDS_StreamConfig* p_stream_config, + const CommonCmdPacket* send_packet) { const CommonTlmCmdPacket* ctcp = CTCP_convert_from_ccp(send_packet); if (ctcp == NULL) return CDS_ERR_CODE_ERR; - return CTCP_set_tx_frame_to_cdssc(p_stream_config, ctcp); + return CDRV_CTCP_set_tx_frame(p_stream_config, ctcp); } #pragma section diff --git a/component_driver/common_tlm_cmd_packet_for_driver_super.h b/component_driver/cdrv_common_tlm_cmd_packet.h similarity index 76% rename from component_driver/common_tlm_cmd_packet_for_driver_super.h rename to component_driver/cdrv_common_tlm_cmd_packet.h index e17466ed..83fb4b18 100644 --- a/component_driver/common_tlm_cmd_packet_for_driver_super.h +++ b/component_driver/cdrv_common_tlm_cmd_packet.h @@ -5,8 +5,8 @@ * @note データリンク層は CDS_StreamConfig.data_link_layer_ で規定する * @note packet 構造 などは tlm_cmd/common_tlm_cmd_packet.h を参照のこと */ -#ifndef COMMON_TLM_CMD_PACKET_FOR_DRIVER_SUPER_H_ -#define COMMON_TLM_CMD_PACKET_FOR_DRIVER_SUPER_H_ +#ifndef CDRV_COMMON_TLM_CMD_PACKET_H_ +#define CDRV_COMMON_TLM_CMD_PACKET_H_ #include #include "driver_super.h" @@ -20,7 +20,7 @@ * @retval CDS_ERR_CODE_OK: 正常終了 * @retval CDS_ERR_CODE_ERR: パケット長が異常など,エラーでコピーできない */ -CDS_ERR_CODE CTCP_get_ctcp_from_cdssc(const CDS_StreamConfig* p_stream_config, CommonTlmCmdPacket* received_packet); +CDS_ERR_CODE CDRV_CTCP_get_ctcp(const CDS_StreamConfig* p_stream_config, CommonTlmCmdPacket* received_packet); /** * @brief CommonTlmPacket を受信データからコピーして取得する @@ -30,7 +30,7 @@ CDS_ERR_CODE CTCP_get_ctcp_from_cdssc(const CDS_StreamConfig* p_stream_config, C * @retval CDS_ERR_CODE_OK: 正常終了 * @retval CDS_ERR_CODE_ERR: パケット長が異常など,エラーでコピーできない */ -CDS_ERR_CODE CTP_get_ctp_from_cdssc(const CDS_StreamConfig* p_stream_config, CommonTlmPacket* received_packet); +CDS_ERR_CODE CDRV_CTP_get_ctp(const CDS_StreamConfig* p_stream_config, CommonTlmPacket* received_packet); /** * @brief CommonCmdPacket を受信データからコピーして取得する @@ -40,7 +40,7 @@ CDS_ERR_CODE CTP_get_ctp_from_cdssc(const CDS_StreamConfig* p_stream_config, Com * @retval CDS_ERR_CODE_OK: 正常終了 * @retval CDS_ERR_CODE_ERR: パケット長が異常など,エラーでコピーできない */ -CDS_ERR_CODE CCP_get_ccp_from_cdssc(const CDS_StreamConfig* p_stream_config, CommonCmdPacket* received_packet); +CDS_ERR_CODE CDRV_CCP_get_ccp(const CDS_StreamConfig* p_stream_config, CommonCmdPacket* received_packet); /** * @brief C2A 間通信など, CTCP をコンポ間通信に用いるとき,CDS_init で渡す初期化関数内部用の Init Util @@ -54,10 +54,10 @@ CDS_ERR_CODE CCP_get_ccp_from_cdssc(const CDS_StreamConfig* p_stream_config, Com * @retval CDS_ERR_CODE_OK: 正常終了 * @retval CDS_ERR_CODE_ERR: フレームバッファのサイズ不足などのエラー */ -CDS_ERR_CODE CTCP_init_cdssc(CDS_StreamConfig* p_stream_config, - uint8_t* tx_frame_buffer, - int16_t tx_frame_buffer_size, - CDS_ERR_CODE (*data_analyzer)(CDS_StreamConfig* p_stream_config, void* p_driver)); +CDS_ERR_CODE CDRV_CTCP_init_stream_config(CDS_StreamConfig* p_stream_config, + uint8_t* tx_frame_buffer, + int16_t tx_frame_buffer_size, + CDS_ERR_CODE (*data_analyzer)(CDS_StreamConfig* p_stream_config, void* p_driver)); /** * @brief C2A 間通信など, CTCP をコンポ間通信に用いるときの tx_frame のセット @@ -66,8 +66,8 @@ CDS_ERR_CODE CTCP_init_cdssc(CDS_StreamConfig* p_stream_config, * @retval CDS_ERR_CODE_OK: 正常終了 * @retval CDS_ERR_CODE_ERR: DSSC 内部の設定不足などのエラー */ -CDS_ERR_CODE CTCP_set_tx_frame_to_cdssc(CDS_StreamConfig* p_stream_config, - const CommonTlmCmdPacket* send_packet); +CDS_ERR_CODE CDRV_CTCP_set_tx_frame(CDS_StreamConfig* p_stream_config, + const CommonTlmCmdPacket* send_packet); /** * @brief C2A 間通信など, CTP をコンポ間通信に用いるときの tx_frame のセット @@ -76,8 +76,8 @@ CDS_ERR_CODE CTCP_set_tx_frame_to_cdssc(CDS_StreamConfig* p_stream_config, * @retval CDS_ERR_CODE_OK: 正常終了 * @retval CDS_ERR_CODE_ERR: DSSC 内部の設定不足などのエラー */ -CDS_ERR_CODE CTP_set_tx_frame_to_cdssc(CDS_StreamConfig* p_stream_config, - const CommonTlmPacket* send_packet); +CDS_ERR_CODE CDRV_CTP_set_tx_frame(CDS_StreamConfig* p_stream_config, + const CommonTlmPacket* send_packet); /** * @brief C2A 間通信など, CCP をコンポ間通信に用いるときの tx_frame のセット @@ -86,7 +86,7 @@ CDS_ERR_CODE CTP_set_tx_frame_to_cdssc(CDS_StreamConfig* p_stream_config, * @retval CDS_ERR_CODE_OK: 正常終了 * @retval CDS_ERR_CODE_ERR: DSSC 内部の設定不足などのエラー */ -CDS_ERR_CODE CCP_set_tx_frame_to_cdssc(CDS_StreamConfig* p_stream_config, - const CommonCmdPacket* send_packet); +CDS_ERR_CODE CDRV_CCP_set_tx_frame(CDS_StreamConfig* p_stream_config, + const CommonCmdPacket* send_packet); #endif diff --git a/component_driver/cdrv_eb90_frame.c b/component_driver/cdrv_eb90_frame.c new file mode 100644 index 00000000..f2dd5a76 --- /dev/null +++ b/component_driver/cdrv_eb90_frame.c @@ -0,0 +1,52 @@ +#pragma section REPRO +/** + * @file + * @brief コンポ間通信などで標準的に使う データリンク層 の EB90 Frame + */ +#include "cdrv_eb90_frame.h" +#include "../library/endian.h" +#include "../library/crc.h" + +const uint8_t CDRV_EB90_FRAME_kStx[CDRV_EB90_FRAME_STX_SIZE] = {CDRV_EB90_FRAME_STX_1ST_BYTE, CDRV_EB90_FRAME_STX_2ND_BYTE}; +const uint8_t CDRV_EB90_FRAME_kEtx[CDRV_EB90_FRAME_ETX_SIZE] = {CDRV_EB90_FRAME_ETX_1ST_BYTE, CDRV_EB90_FRAME_ETX_2ND_BYTE}; + + +uint16_t CDRV_EB90_FRAME_get_packet_length(const CDS_StreamConfig* p_stream_config) +{ + uint16_t length; + ENDIAN_memcpy(&length, &(CDSSC_get_rx_frame(p_stream_config)[2]), CDRV_EB90_FRAME_LEN_SIZE); + return length; +} + + +const uint8_t* CDRV_EB90_FRAME_get_packet_head(const CDS_StreamConfig* p_stream_config) +{ + return &(CDSSC_get_rx_frame(p_stream_config)[CDRV_EB90_FRAME_HEADER_SIZE]); +} + + +uint16_t CDRV_EB90_FRAME_get_crc(const CDS_StreamConfig* p_stream_config) +{ + uint16_t crc; + uint16_t offset = CDRV_EB90_FRAME_HEADER_SIZE + CDRV_EB90_FRAME_get_packet_length(p_stream_config); + ENDIAN_memcpy(&crc, &(CDSSC_get_rx_frame(p_stream_config)[offset]), CDRV_EB90_FRAME_CRC_SIZE); + return crc; +} + + +uint8_t CDRV_EB90_FRAME_is_valid_crc(const CDS_StreamConfig* p_stream_config) +{ + uint16_t len = CDRV_EB90_FRAME_get_packet_length(p_stream_config); + const uint8_t* head = CDRV_EB90_FRAME_get_packet_head(p_stream_config); + return (EB90_FRAME_calc_crc(head, len + CDRV_EB90_FRAME_CRC_SIZE) == 0) ? 1 : 0; +} + + +uint16_t EB90_FRAME_calc_crc(const uint8_t* data, size_t len) +{ + // CRC-16/CCITT-FALSE (CRC-16/AUTOSAR, CRC-16/IBM-3740 とも) + // https://reveng.sourceforge.io/crc-catalogue/16.htm + return CRC_calc_crc_16_ccitt_left(0xffff, data, len, 0); +} + +#pragma section diff --git a/component_driver/eb90_frame_for_driver_super.h b/component_driver/cdrv_eb90_frame.h similarity index 65% rename from component_driver/eb90_frame_for_driver_super.h rename to component_driver/cdrv_eb90_frame.h index 42ae5c78..26c0f7a8 100644 --- a/component_driver/eb90_frame_for_driver_super.h +++ b/component_driver/cdrv_eb90_frame.h @@ -31,26 +31,26 @@ * Packet Field の CRC * Header は含めない */ -#ifndef EB90_FRAME_FOR_DRIVER_SUPER_H_ -#define EB90_FRAME_FOR_DRIVER_SUPER_H_ +#ifndef CDRV_EB90_FRAME_H_ +#define CDRV_EB90_FRAME_H_ #include #include "driver_super.h" -#define EB90_FRAME_STX_SIZE (2) //!< EB90 Frame の STX のサイズ -#define EB90_FRAME_ETX_SIZE (2) //!< EB90 Frame の ETX のサイズ -#define EB90_FRAME_LEN_SIZE (2) //!< EB90 Frame の LEN のサイズ -#define EB90_FRAME_CRC_SIZE (2) //!< EB90 Frame の CRC のサイズ -#define EB90_FRAME_HEADER_SIZE (EB90_FRAME_STX_SIZE + EB90_FRAME_LEN_SIZE) //!< EB90 Frame のヘッダサイズ -#define EB90_FRAME_FOOTER_SIZE (EB90_FRAME_ETX_SIZE + EB90_FRAME_CRC_SIZE) //!< EB90 Frame のフッタサイズ +#define CDRV_EB90_FRAME_STX_SIZE (2) //!< EB90 Frame の STX のサイズ +#define CDRV_EB90_FRAME_ETX_SIZE (2) //!< EB90 Frame の ETX のサイズ +#define CDRV_EB90_FRAME_LEN_SIZE (2) //!< EB90 Frame の LEN のサイズ +#define CDRV_EB90_FRAME_CRC_SIZE (2) //!< EB90 Frame の CRC のサイズ +#define CDRV_EB90_FRAME_HEADER_SIZE (CDRV_EB90_FRAME_STX_SIZE + CDRV_EB90_FRAME_LEN_SIZE) //!< EB90 Frame のヘッダサイズ +#define CDRV_EB90_FRAME_FOOTER_SIZE (CDRV_EB90_FRAME_ETX_SIZE + CDRV_EB90_FRAME_CRC_SIZE) //!< EB90 Frame のフッタサイズ -#define EB90_FRAME_STX_1ST_BYTE (0xEB) //!< EB90 Frame の STX 1st byte -#define EB90_FRAME_STX_2ND_BYTE (0x90) //!< EB90 Frame の STX 2nd byte -#define EB90_FRAME_ETX_1ST_BYTE (0xC5) //!< EB90 Frame の ETX 1st byte -#define EB90_FRAME_ETX_2ND_BYTE (0x79) //!< EB90 Frame の ETX 2nd byte +#define CDRV_EB90_FRAME_STX_1ST_BYTE (0xEB) //!< EB90 Frame の STX 1st byte +#define CDRV_EB90_FRAME_STX_2ND_BYTE (0x90) //!< EB90 Frame の STX 2nd byte +#define CDRV_EB90_FRAME_ETX_1ST_BYTE (0xC5) //!< EB90 Frame の ETX 1st byte +#define CDRV_EB90_FRAME_ETX_2ND_BYTE (0x79) //!< EB90 Frame の ETX 2nd byte -extern const uint8_t EB90_FRAME_kStx[EB90_FRAME_STX_SIZE]; -extern const uint8_t EB90_FRAME_kEtx[EB90_FRAME_ETX_SIZE]; +extern const uint8_t CDRV_EB90_FRAME_kStx[CDRV_EB90_FRAME_STX_SIZE]; +extern const uint8_t CDRV_EB90_FRAME_kEtx[CDRV_EB90_FRAME_ETX_SIZE]; /** * @brief Packet Length の取得 @@ -58,7 +58,7 @@ extern const uint8_t EB90_FRAME_kEtx[EB90_FRAME_ETX_SIZE]; * @param p_stream_config: ComponentDriverSuper 構造体の CDS_StreamConfig * @return Packet Length */ -uint16_t EB90_FRAME_get_packet_length_from_cdssc(const CDS_StreamConfig* p_stream_config); +uint16_t CDRV_EB90_FRAME_get_packet_length(const CDS_StreamConfig* p_stream_config); /** * @brief 受信フレームから Packet Field の先頭ポインタを取得する @@ -66,7 +66,7 @@ uint16_t EB90_FRAME_get_packet_length_from_cdssc(const CDS_StreamConfig* p_strea * @param p_stream_config: ComponentDriverSuper 構造体の CDS_StreamConfig * @return Packet Field の先頭ポインタ */ -const uint8_t* EB90_FRAME_get_packet_head_from_cdssc(const CDS_StreamConfig* p_stream_config); +const uint8_t* CDRV_EB90_FRAME_get_packet_head(const CDS_StreamConfig* p_stream_config); /** * @brief CRC の取得 @@ -74,7 +74,7 @@ const uint8_t* EB90_FRAME_get_packet_head_from_cdssc(const CDS_StreamConfig* p_s * @param p_stream_config: ComponentDriverSuper 構造体の CDS_StreamConfig * @return CRC */ -uint16_t EB90_FRAME_get_crc_from_cdssc(const CDS_StreamConfig* p_stream_config); +uint16_t CDRV_EB90_FRAME_get_crc(const CDS_StreamConfig* p_stream_config); /** * @brief EB90 Frame に付与された CRC が正しいかチェック @@ -82,7 +82,7 @@ uint16_t EB90_FRAME_get_crc_from_cdssc(const CDS_StreamConfig* p_stream_config); * @retval 1: 正しい * @retval 0: 正しくない */ -uint8_t EB90_FRAME_is_valid_crc_of_cdssc(const CDS_StreamConfig* p_stream_config); +uint8_t CDRV_EB90_FRAME_is_valid_crc(const CDS_StreamConfig* p_stream_config); /** * @brief EB90 Frame の CRC の計算 diff --git a/component_driver/cdrv_eb90_packet.c b/component_driver/cdrv_eb90_packet.c new file mode 100644 index 00000000..9bae51fa --- /dev/null +++ b/component_driver/cdrv_eb90_packet.c @@ -0,0 +1,68 @@ +#pragma section REPRO +/** + * @file + * @brief コンポ間通信などで標準的に使う ネットワーク層 の EB90 Packet + * @note 一般的には,データリンク層は EB90 Frame を使うことを想定 + * @note Tlm か Cmd かはコンテキストで読み替える + * @note データリンク層は CDS_StreamConfig.data_link_layer_ で規定する + */ +#include "cdrv_eb90_packet.h" +#include "cdrv_eb90_frame.h" +#include "../library/endian.h" + +// FIXME: CDS_StreamConfig.data_link_layer_ をちゃんと見る! + +uint32_t CDRV_EB90_PACKET_get_version(const CDS_StreamConfig* p_stream_config) +{ + // TODO: 現状は Version 番号が 8bit のもののみしか対応していない + return (uint32_t)(CDRV_EB90_FRAME_get_packet_head(p_stream_config)[0]); +} + + +uint32_t CDRV_EB90_PACKET_get_count(const CDS_StreamConfig* p_stream_config) +{ + const uint32_t version = CDRV_EB90_PACKET_get_version(p_stream_config); + + if (version == 1) + { + return (uint32_t)(CDRV_EB90_FRAME_get_packet_head(p_stream_config)[1]); + } + else + { + return 0; + } +} + + +uint32_t CDRV_EB90_PACKET_get_id(const CDS_StreamConfig* p_stream_config) +{ + const uint32_t version = CDRV_EB90_PACKET_get_version(p_stream_config); + + if (version == 1) + { + uint16_t id; + ENDIAN_memcpy(&id, &(CDRV_EB90_FRAME_get_packet_head(p_stream_config)[2]), sizeof(uint16_t)); + return (uint32_t)id; + } + else + { + return 0; + } +} + + +const uint8_t* CDRV_EB90_PACKET_get_user_data_head(const CDS_StreamConfig* p_stream_config) +{ + const uint32_t version = CDRV_EB90_PACKET_get_version(p_stream_config); + + if (version == 1) + { + return &(CDRV_EB90_FRAME_get_packet_head(p_stream_config)[4]); + } + else + { + return NULL; + } +} + +#pragma section diff --git a/component_driver/eb90_packet_for_driver_super.h b/component_driver/cdrv_eb90_packet.h similarity index 85% rename from component_driver/eb90_packet_for_driver_super.h rename to component_driver/cdrv_eb90_packet.h index b689d511..6bc6e2a6 100644 --- a/component_driver/eb90_packet_for_driver_super.h +++ b/component_driver/cdrv_eb90_packet.h @@ -23,13 +23,13 @@ * | * | 0 | * | ... | * |---------+-------+-------+------------------| */ -#ifndef EB90_PACKET_FOR_DRIVER_SUPER_H_ -#define EB90_PACKET_FOR_DRIVER_SUPER_H_ +#ifndef CDRV_EB90_PACKET_H_ +#define CDRV_EB90_PACKET_H_ #include #include "driver_super.h" -#define EB90_PACKET_HEADER_SIZE (4) //!< EB90 Packet のヘッダサイズ +#define CDRV_EB90_PACKET_HEADER_SIZE (4) //!< EB90 Packet のヘッダサイズ /** * @brief Version ID の取得 @@ -37,7 +37,7 @@ * @param p_stream_config: ComponentDriverSuper 構造体の CDS_StreamConfig * @return Version ID (バージョン 0x01 では uint8_t だが将来性のために uint32_t で返す) */ -uint32_t EB90_PACKET_get_version_from_cdssc(const CDS_StreamConfig* p_stream_config); +uint32_t CDRV_EB90_PACKET_get_version(const CDS_StreamConfig* p_stream_config); /** * @brief Tlm / Cmd Count の取得 @@ -46,7 +46,7 @@ uint32_t EB90_PACKET_get_version_from_cdssc(const CDS_StreamConfig* p_stream_con * @retval Tlm / Cmd Count (バージョン 0x01 では uint8_t だが将来性のために uint32_t で返す) * @retval 0 (入力が不正な場合) */ -uint32_t EB90_PACKET_get_count_from_cdssc(const CDS_StreamConfig* p_stream_config); +uint32_t CDRV_EB90_PACKET_get_count(const CDS_StreamConfig* p_stream_config); /** * @brief Tlm / Cmd ID の取得 @@ -56,7 +56,7 @@ uint32_t EB90_PACKET_get_count_from_cdssc(const CDS_StreamConfig* p_stream_confi * @retval Tlm / Cmd ID (バージョン 0x01 では uint16_t だが将来性のために uint32_t で返す) * @retval 0 (入力が不正な場合) */ -uint32_t EB90_PACKET_get_id_from_cdssc(const CDS_StreamConfig* p_stream_config); +uint32_t CDRV_EB90_PACKET_get_id(const CDS_StreamConfig* p_stream_config); /** * @brief 受信フレームからPacket Field の先頭ポインタを取得する @@ -65,7 +65,7 @@ uint32_t EB90_PACKET_get_id_from_cdssc(const CDS_StreamConfig* p_stream_config); * @retval Packet Field の先頭ポインタ * @retval NULL (入力が不正な場合) */ -const uint8_t* EB90_PACKET_get_user_data_head_from_cdssc(const CDS_StreamConfig* p_stream_config); +const uint8_t* CDRV_EB90_PACKET_get_user_data_head(const CDS_StreamConfig* p_stream_config); // TODO: cdssc の tx_frame に packet を EB90 frame につめてから挿入する関数を作る // CTCP_set_tx_frame_to_cdssc の EB90 packet 用 diff --git a/component_driver/eb90_frame_for_driver_super.c b/component_driver/eb90_frame_for_driver_super.c deleted file mode 100644 index ee5584c0..00000000 --- a/component_driver/eb90_frame_for_driver_super.c +++ /dev/null @@ -1,52 +0,0 @@ -#pragma section REPRO -/** - * @file - * @brief コンポ間通信などで標準的に使う データリンク層 の EB90 Frame - */ -#include "eb90_frame_for_driver_super.h" -#include "../library/endian.h" -#include "../library/crc.h" - -const uint8_t EB90_FRAME_kStx[EB90_FRAME_STX_SIZE] = {EB90_FRAME_STX_1ST_BYTE, EB90_FRAME_STX_2ND_BYTE}; -const uint8_t EB90_FRAME_kEtx[EB90_FRAME_ETX_SIZE] = {EB90_FRAME_ETX_1ST_BYTE, EB90_FRAME_ETX_2ND_BYTE}; - - -uint16_t EB90_FRAME_get_packet_length_from_cdssc(const CDS_StreamConfig* p_stream_config) -{ - uint16_t length; - ENDIAN_memcpy(&length, &(CDSSC_get_rx_frame(p_stream_config)[2]), EB90_FRAME_LEN_SIZE); - return length; -} - - -const uint8_t* EB90_FRAME_get_packet_head_from_cdssc(const CDS_StreamConfig* p_stream_config) -{ - return &(CDSSC_get_rx_frame(p_stream_config)[EB90_FRAME_HEADER_SIZE]); -} - - -uint16_t EB90_FRAME_get_crc_from_cdssc(const CDS_StreamConfig* p_stream_config) -{ - uint16_t crc; - uint16_t offset = EB90_FRAME_HEADER_SIZE + EB90_FRAME_get_packet_length_from_cdssc(p_stream_config); - ENDIAN_memcpy(&crc, &(CDSSC_get_rx_frame(p_stream_config)[offset]), EB90_FRAME_CRC_SIZE); - return crc; -} - - -uint8_t EB90_FRAME_is_valid_crc_of_cdssc(const CDS_StreamConfig* p_stream_config) -{ - uint16_t len = EB90_FRAME_get_packet_length_from_cdssc(p_stream_config); - const uint8_t* head = EB90_FRAME_get_packet_head_from_cdssc(p_stream_config); - return (EB90_FRAME_calc_crc(head, len + EB90_FRAME_CRC_SIZE) == 0) ? 1 : 0; -} - - -uint16_t EB90_FRAME_calc_crc(const uint8_t* data, size_t len) -{ - // CRC-16/CCITT-FALSE (CRC-16/AUTOSAR, CRC-16/IBM-3740 とも) - // https://reveng.sourceforge.io/crc-catalogue/16.htm - return CRC_calc_crc_16_ccitt_left(0xffff, data, len, 0); -} - -#pragma section diff --git a/component_driver/eb90_packet_for_driver_super.c b/component_driver/eb90_packet_for_driver_super.c deleted file mode 100644 index 789f31f4..00000000 --- a/component_driver/eb90_packet_for_driver_super.c +++ /dev/null @@ -1,68 +0,0 @@ -#pragma section REPRO -/** - * @file - * @brief コンポ間通信などで標準的に使う ネットワーク層 の EB90 Packet - * @note 一般的には,データリンク層は EB90 Frame を使うことを想定 - * @note Tlm か Cmd かはコンテキストで読み替える - * @note データリンク層は CDS_StreamConfig.data_link_layer_ で規定する - */ -#include "eb90_packet_for_driver_super.h" -#include "eb90_frame_for_driver_super.h" -#include "../library/endian.h" - -// FIXME: CDS_StreamConfig.data_link_layer_ をちゃんと見る! - -uint32_t EB90_PACKET_get_version_from_cdssc(const CDS_StreamConfig* p_stream_config) -{ - // TODO: 現状は Version 番号が 8bit のもののみしか対応していない - return (uint32_t)(EB90_FRAME_get_packet_head_from_cdssc(p_stream_config)[0]); -} - - -uint32_t EB90_PACKET_get_count_from_cdssc(const CDS_StreamConfig* p_stream_config) -{ - const uint32_t version = EB90_PACKET_get_version_from_cdssc(p_stream_config); - - if (version == 1) - { - return (uint32_t)(EB90_FRAME_get_packet_head_from_cdssc(p_stream_config)[1]); - } - else - { - return 0; - } -} - - -uint32_t EB90_PACKET_get_id_from_cdssc(const CDS_StreamConfig* p_stream_config) -{ - const uint32_t version = EB90_PACKET_get_version_from_cdssc(p_stream_config); - - if (version == 1) - { - uint16_t id; - ENDIAN_memcpy(&id, &(EB90_FRAME_get_packet_head_from_cdssc(p_stream_config)[2]), sizeof(uint16_t)); - return (uint32_t)id; - } - else - { - return 0; - } -} - - -const uint8_t* EB90_PACKET_get_user_data_head_from_cdssc(const CDS_StreamConfig* p_stream_config) -{ - const uint32_t version = EB90_PACKET_get_version_from_cdssc(p_stream_config); - - if (version == 1) - { - return &(EB90_FRAME_get_packet_head_from_cdssc(p_stream_config)[4]); - } - else - { - return NULL; - } -} - -#pragma section diff --git a/script/migration/v4-rename-component-driver-prefix.sh b/script/migration/v4-rename-component-driver-prefix.sh new file mode 100755 index 00000000..a7938def --- /dev/null +++ b/script/migration/v4-rename-component-driver-prefix.sh @@ -0,0 +1,49 @@ +#!/bin/bash +# driver instances -> Component Service + +## c2a-core ref +header_org=("common_tlm_cmd_packet_for_driver_super.h" "eb90_frame_for_driver_super.h" "eb90_packet_for_driver_super.h") +header_new=("cdrv_common_tlm_cmd_packet.h" "cdrv_eb90_frame.h" "cdrv_eb90_packet.h") + +echo "rename c2a-core header file name prefix & remove _for_driver_super suffix" +for i in ${!header_org[@]}; do + echo " ${header_org[$i]} -> ${header_new[$i]}" + find . -name "*" -not -path "*/.git/*" -type f -print0 | xargs -0 sed -i -e "s#${header_org[$i]}#${header_new[$i]}#g" +done + +echo "rename init func" +find . -name "*" -not -path "*/.git/*" -type f -print0 | xargs -0 sed -i -e "s#CTCP_init_cdssc(#CDRV_CTCP_init_stream_config(#g" + +remove_suffix=("_from_cdssc" "_to_cdssc" "_of_cdssc" "_cdssc") +prefix_org=("CTCP_" "CTP_" "CCP_" "EB90_PACKET_" "EB90_FRAME_") + +for i in ${!remove_suffix[@]}; do + echo "remove suffix: ${remove_suffix[$i]}" + for k in ${!prefix_org[@]}; do + echo " rename function: ${prefix_org[$k]}***${remove_suffix[$i]}(*** -> CDRV_${prefix_org[$k]}***(***" + find . -name "*" -not -path "*/.git/*" -type f -print0 \ + | xargs -0 sed -i -E "s#${prefix_org[$k]}([0-9a-zA-Z_]*)${remove_suffix[$i]}\((.*)#CDRV_${prefix_org[$k]}\1\(\2#g" + done +done + +echo "rename constants" +constants=("EB90_PACKET_HEADER_SIZE" "EB90_FRAME_(MACRO_ANY)_SIZE" "EB90_FRAME_(MACRO_ANY)_BYTE") +for i in ${!constants[@]}; do + match_org=$(echo "${constants[$i]}" | sed -e "s#(MACRO_ANY)#(\[0-9A-Z_\]\*)#g") + match_new=$(echo "${constants[$i]}" | sed -e "s#(MACRO_ANY)#\\\1#g") + + echo " ${match_org} -> CDRV_${match_new}" + find . -name "*" -not -path "*/.git/*" -type f -print0 \ + | xargs -0 sed -i -E "s#${match_org}#CDRV_${match_new}#g" +done + +echo "rename globals" +global=("EB90_FRAME_kStx" "EB90_FRAME_kEtx") +for i in ${!global[@]}; do + echo " ${global[$i]} -> CDRV_${global[$i]}" + find . -name "*" -not -path "*/.git/*" -type f -print0 \ + | xargs -0 sed -i -E "s#${global[$i]}#CDRV_${global[$i]}#g" +done + +git restore src/src_user/Settings/tlm_cmd/data_base/CMD_DB/*.xlsm +git restore src/src_user/Settings/tlm_cmd/data_base/TLM_DB/*.xlsm