Skip to content

Commit

Permalink
add crc check to driver
Browse files Browse the repository at this point in the history
  • Loading branch information
meltingrabbit committed Aug 28, 2022
1 parent 210ccb3 commit 4f8156d
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 10 deletions.
5 changes: 3 additions & 2 deletions Drivers/Protocol/eb90_frame_for_driver_super.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ uint16_t EB90_FRAME_get_crc_from_dssc(const DS_StreamConfig* p_stream_config)

uint8_t EB90_FRAME_is_valid_crc_of_dssc(const DS_StreamConfig* p_stream_config)
{
// TODO: CRC を IBM から CCITT に変えてから実装する
return 1;
uint16_t len = EB90_FRAME_get_packet_length_from_dssc(p_stream_config);
const uint8_t* head = EB90_FRAME_get_packet_head_from_dssc(p_stream_config);
return (EB90_FRAME_calc_crc(head, len + EB90_FRAME_CRC_SIZE) == 0) ? 1 : 0;
}


Expand Down
2 changes: 2 additions & 0 deletions Drivers/Protocol/eb90_frame_for_driver_super.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
* | N - 2 | 0 | 16 | ETX |
* |---------+-------+-------+------------------|
*
* Packet Length:
* Packet Field の長さ
* CRC
* CRC-16/CCITT-FALSE (CRC-16/AUTOSAR, CRC-16/IBM-3740 とも)
* Packet Field の CRC
Expand Down
7 changes: 5 additions & 2 deletions Examples/2nd_obc_user/src/src_user/Drivers/Etc/mobc.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,11 @@ static DS_ERR_CODE MOBC_analyze_rec_data_(DS_StreamConfig* p_stream_config, void

mobc_driver->info.comm.rx_err_code = MOBC_RX_ERR_CODE_OK;

// TODO: ここに CRC チェックをいれる
// MOBC_RX_ERR_CODE_CRC_ERR を入れる
if (!EB90_FRAME_is_valid_crc_of_dssc(p_stream_config))
{
mobc_driver->info.comm.rx_err_code = MOBC_RX_ERR_CODE_CRC_ERR;
return DS_ERR_CODE_ERR;
}

// MOBC からのコマンドは以下のパターン
// APID:
Expand Down
4 changes: 2 additions & 2 deletions Examples/2nd_obc_user/src/src_user/Drivers/Etc/mobc.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
typedef enum
{
MOBC_TX_ERR_CODE_OK = 0
MOBC_TX_ERR_CODE_OK = 0
// MOBC_TX_ERR_CODE_CMD_NOT_FOUND,
} MOBC_TX_ERR_CODE;

Expand All @@ -31,7 +31,7 @@ typedef enum
*/
typedef enum
{
MOBC_RX_ERR_CODE_OK = 0,
MOBC_RX_ERR_CODE_OK = 0,
// MOBC_RX_ERR_CODE_TLM_NOT_FOUND,
MOBC_RX_ERR_CODE_CRC_ERR,
MOBC_RX_ERR_CODE_INVALID_PACKET
Expand Down
7 changes: 5 additions & 2 deletions Examples/minimum_user/src/src_user/Drivers/Aocs/aobc.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,11 @@ static DS_ERR_CODE AOBC_analyze_rec_data_(DS_StreamConfig* p_stream_config,

aobc_driver->info.comm.rx_err_code = AOBC_RX_ERR_CODE_OK;

// [TODO] ここに CRC チェックをいれる
// AOBC_RX_ERR_CODE_CRC_ERR を入れる
if (!EB90_FRAME_is_valid_crc_of_dssc(p_stream_config))
{
aobc_driver->info.comm.rx_err_code = AOBC_RX_ERR_CODE_CRC_ERR;
return DS_ERR_CODE_ERR;
}

return AOBC_buffer_tlm_packet(p_stream_config, aobc_driver);
}
Expand Down
4 changes: 2 additions & 2 deletions Examples/minimum_user/src/src_user/Drivers/Aocs/aobc.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
typedef enum
{
AOBC_TX_ERR_CODE_OK = 0,
AOBC_TX_ERR_CODE_OK = 0,
AOBC_TX_ERR_CODE_CMD_NOT_FOUND
} AOBC_TX_ERR_CODE;

Expand All @@ -30,7 +30,7 @@ typedef enum
*/
typedef enum
{
AOBC_RX_ERR_CODE_OK = 0,
AOBC_RX_ERR_CODE_OK = 0,
AOBC_RX_ERR_CODE_TLM_NOT_FOUND,
AOBC_RX_ERR_CODE_CRC_ERR
} AOBC_RX_ERR_CODE;
Expand Down

0 comments on commit 4f8156d

Please sign in to comment.