啥是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
?
<完>?