Skip to content

Commit 4f8156d

Browse files
committed
add crc check to driver
1 parent 210ccb3 commit 4f8156d

File tree

6 files changed

+19
-10
lines changed

6 files changed

+19
-10
lines changed

Drivers/Protocol/eb90_frame_for_driver_super.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ uint16_t EB90_FRAME_get_crc_from_dssc(const DS_StreamConfig* p_stream_config)
3636

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

4344

Drivers/Protocol/eb90_frame_for_driver_super.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
* | N - 2 | 0 | 16 | ETX |
2525
* |---------+-------+-------+------------------|
2626
*
27+
* Packet Length:
28+
* Packet Field の長さ
2729
* CRC
2830
* CRC-16/CCITT-FALSE (CRC-16/AUTOSAR, CRC-16/IBM-3740 とも)
2931
* Packet Field の CRC

Examples/2nd_obc_user/src/src_user/Drivers/Etc/mobc.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,11 @@ static DS_ERR_CODE MOBC_analyze_rec_data_(DS_StreamConfig* p_stream_config, void
108108

109109
mobc_driver->info.comm.rx_err_code = MOBC_RX_ERR_CODE_OK;
110110

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

114117
// MOBC からのコマンドは以下のパターン
115118
// APID:

Examples/2nd_obc_user/src/src_user/Drivers/Etc/mobc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*/
2020
typedef enum
2121
{
22-
MOBC_TX_ERR_CODE_OK = 0
22+
MOBC_TX_ERR_CODE_OK = 0
2323
// MOBC_TX_ERR_CODE_CMD_NOT_FOUND,
2424
} MOBC_TX_ERR_CODE;
2525

@@ -31,7 +31,7 @@ typedef enum
3131
*/
3232
typedef enum
3333
{
34-
MOBC_RX_ERR_CODE_OK = 0,
34+
MOBC_RX_ERR_CODE_OK = 0,
3535
// MOBC_RX_ERR_CODE_TLM_NOT_FOUND,
3636
MOBC_RX_ERR_CODE_CRC_ERR,
3737
MOBC_RX_ERR_CODE_INVALID_PACKET

Examples/minimum_user/src/src_user/Drivers/Aocs/aobc.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,11 @@ static DS_ERR_CODE AOBC_analyze_rec_data_(DS_StreamConfig* p_stream_config,
103103

104104
aobc_driver->info.comm.rx_err_code = AOBC_RX_ERR_CODE_OK;
105105

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

109112
return AOBC_buffer_tlm_packet(p_stream_config, aobc_driver);
110113
}

Examples/minimum_user/src/src_user/Drivers/Aocs/aobc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*/
2020
typedef enum
2121
{
22-
AOBC_TX_ERR_CODE_OK = 0,
22+
AOBC_TX_ERR_CODE_OK = 0,
2323
AOBC_TX_ERR_CODE_CMD_NOT_FOUND
2424
} AOBC_TX_ERR_CODE;
2525

@@ -30,7 +30,7 @@ typedef enum
3030
*/
3131
typedef enum
3232
{
33-
AOBC_RX_ERR_CODE_OK = 0,
33+
AOBC_RX_ERR_CODE_OK = 0,
3434
AOBC_RX_ERR_CODE_TLM_NOT_FOUND,
3535
AOBC_RX_ERR_CODE_CRC_ERR
3636
} AOBC_RX_ERR_CODE;

0 commit comments

Comments
 (0)