feat(protocan): добавь общий ABI для GUI
This commit is contained in:
43
c/protocan-transport/tests/test_abi.c
Normal file
43
c/protocan-transport/tests/test_abi.c
Normal file
@@ -0,0 +1,43 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "pcan_abi.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
uint32_t raw = pcan_abi_id_pack(1U, 0U, 7U, 14U, 3U, 0x1234U);
|
||||
if (raw != 0x17E31234UL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint8_t data[] = { 0xAAU, 0xBBU };
|
||||
uint8_t encoded[32];
|
||||
size_t encoded_size = pcan_abi_frame_encode(
|
||||
1U, 0x05U, raw, data, 2U, encoded, sizeof encoded);
|
||||
if (encoded_size == 0U) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
size_t parser_size = pcan_abi_parser_size();
|
||||
void *parser = malloc(parser_size);
|
||||
if ((parser == NULL) || !pcan_abi_parser_init(parser, parser_size)) {
|
||||
free(parser);
|
||||
return 3;
|
||||
}
|
||||
|
||||
pcan_abi_frame_t frame;
|
||||
memset(&frame, 0, sizeof frame);
|
||||
int found = 0;
|
||||
for (size_t i = 0U; i < encoded_size; ++i) {
|
||||
found += pcan_abi_parser_push(parser, encoded[i], &frame) > 0;
|
||||
}
|
||||
free(parser);
|
||||
|
||||
if ((found != 1) || (frame.can_id != raw) || (frame.dlc != 2U) ||
|
||||
(frame.data[0] != 0xAAU) || (frame.data[1] != 0xBBU)) {
|
||||
return 4;
|
||||
}
|
||||
puts("ABI tests passed");
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user