车规MCU开发之E2E协议

发布时间:2024年01月12日

啥是E2E?

E2E的原理:
1. 发送端:发送数据包添加E2E保护头
2. 接收端:接收数据包校验E2E保护头

E2E例子 - profile 11为例

?? ?E2E_P11ConfigType wk_stP11Cfg = {
?? ??? ?.CounterOffset = 8,
?? ??? ?.CRCOffset = 0,
?? ??? ?.DataID = 0x666,
?? ??? ?.DataIDNibbleOffset = 12,
?? ??? ?.DataIDMode = 0,
?? ??? ?.DataLength = 40,
?? ??? ?.MaxDeltaCounter = 14
?? ?};
?? ?/* E2E_P11ProtectInit */
?? ?E2E_P11ProtectStateType wk_stP11State = {
?? ??? ?.Counter = 0
?? ?};
?? ?/* E2E_P11CheckInit */
?? ?E2E_P11CheckStateType wk_stP11ChkState = {
?? ??? ?.Counter = 0x0E,
?? ??? ?.Status = E2E_P11STATUS_ERROR
?? ?};
?? ?/* P11: CRC[8bit] + DataIDNibble[4bit] + Counter[4bit] */
?? ?uint8 wk_Data[2 + 5] = {0, 0, 1, 2, 3, 4, 5};
?? ?Std_ReturnType wk_ucRetVal = E_OK;

?? ?wk_ucRetVal = E2E_P11Protect(&wk_stP11Cfg, &wk_stP11State, wk_Data, sizeof(wk_Data) - 2);
?? ?printf("E2E_P11Protect=%d\n", wk_ucRetVal);
?? ?show_data(wk_Data);

?? ?wk_ucRetVal = E2E_P11Check(&wk_stP11Cfg, &wk_stP11ChkState, wk_Data, sizeof(wk_Data) - 2);
?? ?printf("E2E_P11Check=%d,Status=%d\n", wk_ucRetVal, wk_stP11ChkState.Status);
?? ?show_data(wk_Data);

?? ?// trigger repeate wk_stP11State.Counter = 0;
?? ?wk_ucRetVal = E2E_P11Protect(&wk_stP11Cfg, &wk_stP11State, wk_Data, sizeof(wk_Data) - 2);
?? ?printf("E2E_P11Protect=%d\n", wk_ucRetVal);
?? ?show_data(wk_Data);

?? ?wk_ucRetVal = E2E_P11Check(&wk_stP11Cfg, &wk_stP11ChkState, wk_Data, sizeof(wk_Data) - 2);
?? ?printf("E2E_P11Check=%d,Status=%d\n", wk_ucRetVal, wk_stP11ChkState.Status);
?? ?show_data(wk_Data);
?

运行效果

$ ./_build/e2e_exe
E2E_P11Protect=0
Data=a0 00 01 02 03 04 05
E2E_P11Check=0,Status=0
Data=a0 00 01 02 03 04 05
E2E_P11Protect=0
Data=3d 01 01 02 03 04 05
E2E_P11Check=0,Status=0
Data=3d 01 01 02 03 04 05
?

<完>?

文章来源:https://blog.csdn.net/m0_37132481/article/details/134172602
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。