Skip to content

Commit

Permalink
add CTCP_set_tx_frane_to_dssc
Browse files Browse the repository at this point in the history
  • Loading branch information
meltingrabbit committed Aug 28, 2022
1 parent 2c8cd9b commit 71b59ff
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 57 deletions.
55 changes: 55 additions & 0 deletions Drivers/Protocol/common_tlm_cmd_packet_for_driver_super.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,59 @@ DS_ERR_CODE CTCP_init_dssc(DS_StreamConfig* p_stream_config,
return DS_ERR_CODE_OK;
}


DS_ERR_CODE CTCP_set_tx_frane_to_dssc(DS_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);
uint8_t* tx_frame = DSSC_get_tx_frame_as_non_const_pointer(p_stream_config);

if (frame_len > DSSC_get_tx_frame_buffer_size(p_stream_config)) return DS_ERR_CODE_ERR;

DSSC_set_tx_frame_size(p_stream_config, frame_len);

pos = 0;
size = EB90_FRAME_STX_SIZE;
memcpy(&(tx_frame[pos]), EB90_FRAME_kStx, size);
pos += size;
size = EB90_FRAME_LEN_SIZE;
endian_memcpy(&(tx_frame[pos]), &packet_len, size); // ここはエンディアンを気にする!
pos += size;

size = (size_t)packet_len;
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;
endian_memcpy(&(tx_frame[pos]), &crc, size); // ここはエンディアンを気にする!
pos += size;
size = EB90_FRAME_ETX_SIZE;
memcpy(&(tx_frame[pos]), EB90_FRAME_kEtx, size);

return DS_ERR_CODE_OK;
}


DS_ERR_CODE CTP_set_tx_frane_to_dssc(DS_StreamConfig* p_stream_config,
const CommonTlmPacket* send_packet)
{
const CommonTlmCmdPacket* ctcp = CTCP_convert_from_ctp(send_packet);
if (ctcp == NULL) return DS_ERR_CODE_ERR;
return CTCP_set_tx_frane_to_dssc(p_stream_config, ctcp);
}


DS_ERR_CODE CCP_set_tx_frane_to_dssc(DS_StreamConfig* p_stream_config,
const CommonCmdPacket* send_packet)
{
const CommonTlmCmdPacket* ctcp = CTCP_convert_from_ccp(send_packet);
if (ctcp == NULL) return DS_ERR_CODE_ERR;
return CTCP_set_tx_frane_to_dssc(p_stream_config, ctcp);
}

#pragma section
32 changes: 29 additions & 3 deletions Drivers/Protocol/common_tlm_cmd_packet_for_driver_super.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,34 @@ DS_ERR_CODE CTCP_init_dssc(DS_StreamConfig* p_stream_config,
int16_t tx_frame_buffer_size,
DS_ERR_CODE (*data_analyzer)(DS_StreamConfig* p_stream_config, void* p_driver));

// TODO: aobc.c の TODO 時に実装(標準処理の共通化)
// DS_ERR_CODE CTCP_set_tx_frane_to_dssc(const DS_StreamConfig* p_stream_config,
// const CommonTlmCmdPacket* send_packet);
/**
* @brief C2A 間通信など, CTCP をコンポ間通信に用いるときの tx_frame のセット
* @param[in] p_stream_config: DriverSuper 構造体の DS_StreamConfig
* @param[in] send_packet: 送信するパケット
* @retval DS_ERR_CODE_OK: 正常終了
* @retval DS_ERR_CODE_ERR: DSSC 内部の設定不足などのエラー
*/
DS_ERR_CODE CTCP_set_tx_frane_to_dssc(DS_StreamConfig* p_stream_config,
const CommonTlmCmdPacket* send_packet);

/**
* @brief C2A 間通信など, CTP をコンポ間通信に用いるときの tx_frame のセット
* @param[in] p_stream_config: DriverSuper 構造体の DS_StreamConfig
* @param[in] send_packet: 送信するパケット
* @retval DS_ERR_CODE_OK: 正常終了
* @retval DS_ERR_CODE_ERR: DSSC 内部の設定不足などのエラー
*/
DS_ERR_CODE CTP_set_tx_frane_to_dssc(DS_StreamConfig* p_stream_config,
const CommonTlmPacket* send_packet);

/**
* @brief C2A 間通信など, CCP をコンポ間通信に用いるときの tx_frame のセット
* @param[in] p_stream_config: DriverSuper 構造体の DS_StreamConfig
* @param[in] send_packet: 送信するパケット
* @retval DS_ERR_CODE_OK: 正常終了
* @retval DS_ERR_CODE_ERR: DSSC 内部の設定不足などのエラー
*/
DS_ERR_CODE CCP_set_tx_frane_to_dssc(DS_StreamConfig* p_stream_config,
const CommonCmdPacket* send_packet);

#endif
29 changes: 2 additions & 27 deletions Examples/2nd_obc_user/src/src_user/Drivers/Etc/mobc.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,36 +128,11 @@ DS_CMD_ERR_CODE MOBC_send(MOBC_Driver* mobc_driver, const CommonTlmPacket* packe
{
DS_ERR_CODE ret;
DS_StreamConfig* p_stream_config;
uint16_t ctp_len;
uint16_t crc;
size_t pos;
size_t size;

p_stream_config = &(mobc_driver->driver.super.stream_config[MOBC_STREAM_TLM_CMD]);

// tx_frame の設定
ctp_len = CTP_get_packet_len(packet);
DSSC_set_tx_frame_size(p_stream_config,
(uint16_t)(ctp_len + EB90_FRAME_HEADER_SIZE + EB90_FRAME_FOOTER_SIZE));

pos = 0;
size = EB90_FRAME_STX_SIZE;
memcpy(&(MOBC_tx_frame_[pos]), EB90_FRAME_kStx, size);
pos += size;
size = EB90_FRAME_LEN_SIZE;
endian_memcpy(&(MOBC_tx_frame_[pos]), &ctp_len, size); // ここはエンディアンを気にする!
pos += size;
size = (size_t)ctp_len;
memcpy(&(MOBC_tx_frame_[pos]), packet->packet, size);
pos += size;

crc = EB90_FRAME_calc_crc(MOBC_tx_frame_ + EB90_FRAME_HEADER_SIZE, pos - EB90_FRAME_HEADER_SIZE);

size = EB90_FRAME_CRC_SIZE;
endian_memcpy(&(MOBC_tx_frame_[pos]), &crc, size); // ここはエンディアンを気にする!
pos += size;
size = EB90_FRAME_ETX_SIZE;
memcpy(&(MOBC_tx_frame_[pos]), EB90_FRAME_kEtx, size);
// tx_frameの設定
CTP_set_tx_frane_to_dssc(p_stream_config, packet);

ret = DS_send_general_cmd(&(mobc_driver->driver.super), MOBC_STREAM_TLM_CMD);

Expand Down
28 changes: 1 addition & 27 deletions Examples/minimum_user/src/src_user/Drivers/Aocs/aobc.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,37 +131,11 @@ DS_CMD_ERR_CODE AOBC_send_cmd(AOBC_Driver* aobc_driver, const CommonCmdPacket* p
DS_ERR_CODE ret;
DS_StreamConfig* p_stream_config;
AOBC_CMD_CODE cmd_code;
uint16_t ccp_len;
uint16_t crc;
size_t pos;
size_t size;

p_stream_config = &(aobc_driver->driver.super.stream_config[AOBC_STREAM_TLM_CMD]);

// TODO: 標準なので, Util を common_tlm_cmd_packet_for_driver_super.c で整備
// tx_frameの設定
ccp_len = CCP_get_packet_len(packet);
DSSC_set_tx_frame_size(p_stream_config,
(uint16_t)(ccp_len + EB90_FRAME_HEADER_SIZE + EB90_FRAME_FOOTER_SIZE));

pos = 0;
size = EB90_FRAME_STX_SIZE;
memcpy(&(AOBC_tx_frame_[pos]), EB90_FRAME_kStx, size);
pos += size;
size = EB90_FRAME_LEN_SIZE;
endian_memcpy(&(AOBC_tx_frame_[pos]), &ccp_len, size); // ここはエンディアンを気にする!
pos += size;
size = (size_t)ccp_len;
memcpy(&(AOBC_tx_frame_[pos]), packet->packet, size);
pos += size;

crc = EB90_FRAME_calc_crc(AOBC_tx_frame_ + EB90_FRAME_HEADER_SIZE, pos - EB90_FRAME_HEADER_SIZE);

size = EB90_FRAME_CRC_SIZE;
endian_memcpy(&(AOBC_tx_frame_[pos]), &crc, size); // ここはエンディアンを気にする!
pos += size;
size = EB90_FRAME_ETX_SIZE;
memcpy(&(AOBC_tx_frame_[pos]), EB90_FRAME_kEtx, size);
CCP_set_tx_frane_to_dssc(p_stream_config, packet);

cmd_code = (AOBC_CMD_CODE)CCP_get_id(packet);

Expand Down

0 comments on commit 71b59ff

Please sign in to comment.