Добавить общий API старого CAN terminal

This commit is contained in:
2026-09-04 18:19:07 +03:00
parent d9eb7dd9ad
commit 3c4ac9963d
20 changed files with 941 additions and 1 deletions

View File

@@ -0,0 +1,30 @@
#include <stdio.h>
#include <string.h>
#include "balsam_can.h"
#define CHECK(x) do { if (!(x)) { \
fprintf(stderr, "FAIL %s:%d: %s\n", __FILE__, __LINE__, #x); return 1; \
} } while (0)
int main(void)
{
const uint8_t packet[8] = { 0xE0, 0x18, 0x00, 0x29, 0xFF, 0xFE, 0x12, 0x34 };
balsam_can_frame_t frame;
char name[64];
CHECK(balsam_can_is_id(0x00BA0010UL));
CHECK(balsam_can_is_id(0x00BA001CUL));
CHECK(!balsam_can_is_id(0x00BA001DUL));
CHECK(balsam_can_decode(0x00BA0010UL, packet, sizeof packet, &frame) == 1);
CHECK(frame.device == 1U);
CHECK(frame.direction == BALSAM_CAN_FROM_NODE);
CHECK(frame.present_mask == 7U);
CHECK(frame.start_address == 0x18U);
CHECK(frame.values[0] == 41U && frame.values[1] == 0xFFFEU
&& frame.values[2] == 0x1234U);
CHECK(balsam_can_register_name(1U, 0x18U, name, sizeof name) > 0U);
CHECK(strstr(name, "T° 1") != NULL);
CHECK(balsam_can_decode(0x00BA0010UL, packet, 7U, &frame) == -2);
return 0;
}