From 82aefc2a10c537ba9c7fd94a396b10743e2cc93f Mon Sep 17 00:00:00 2001 From: Gregor Riepl Date: Tue, 19 Jan 2021 19:30:56 +0100 Subject: [PATCH] Use symbolic message constants in firmware --- feedback/firmware/main.c | 14 +++++++------- poweriface/firmware/main.c | 16 ++++++++-------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/feedback/firmware/main.c b/feedback/firmware/main.c index b28fdfa..f7f2c68 100644 --- a/feedback/firmware/main.c +++ b/feedback/firmware/main.c @@ -21,8 +21,8 @@ static void init() { // Filter for messages addressed to us (RTR on) can_filter_t us = { - .id = 0x000, - .mask = 0x00f, + .id = CAN_HOSTID_FEEDBACK, + .mask = CAN_HOSTID_MASK, .flags = { .rtr = 1, .extended = 0, @@ -31,8 +31,8 @@ static void init() { can_set_filter(0, &us); // Filter for public messages (RTR off) can_filter_t pub = { - .id = 0x00f, - .mask = 0x00f, + .id = CAN_HOSTID_BROADCAST, + .mask = CAN_HOSTID_MASK, .flags = { .rtr = 0, .extended = 0, @@ -61,7 +61,7 @@ static uint16_t get_status() { static void send_status(uint16_t status) { if (can_check_free_buffer()) { can_t msg = { - .id = 0x10, + .id = CAN_MSG_FEEDBACK_STATUS, .flags = { .rtr = 0, }, @@ -85,10 +85,10 @@ static void loop() { uint8_t status = can_get_message(&msg); if (status != 0) { switch (msg.id) { - case 0x10: + case CAN_MSG_FEEDBACK_STATUS: send_status(get_status()); break; - case 0x4f: + case CAN_MSG_AUTO_STATUS: if (msg.length == 1) { report_change = msg.data[0] ? true : false; } diff --git a/poweriface/firmware/main.c b/poweriface/firmware/main.c index 7f61573..8022922 100644 --- a/poweriface/firmware/main.c +++ b/poweriface/firmware/main.c @@ -20,8 +20,8 @@ static void init() { // Filter for messages addressed to us (RTR on) can_filter_t us = { - .id = 0x001, - .mask = 0x00f, + .id = CAN_HOSTID_POWER, + .mask = CAN_HOSTID_MASK, .flags = { .rtr = 1, .extended = 0, @@ -30,8 +30,8 @@ static void init() { can_set_filter(0, &us); // Filter for public messages (RTR off) can_filter_t pub = { - .id = 0x00f, - .mask = 0x00f, + .id = CAN_HOSTID_BROADCAST, + .mask = CAN_HOSTID_MASK, .flags = { .rtr = 0, .extended = 0, @@ -108,7 +108,7 @@ static void send_status() { if (can_check_free_buffer()) { can_t msg = { - .id = 0x11, + .id = CAN_MSG_POWER_STATUS, .flags = { .rtr = 0, }, @@ -137,10 +137,10 @@ static void loop() { uint8_t status = can_get_message(&msg); if (status != 0) { switch (msg.id) { - case 0x11: + case CAN_MSG_POWER_STATUS: send_status(); break; - case 0x21: + case CAN_MSG_POWER_DISPENSE: if (msg.length == 1) { // stop (d0 = 0) or fire relay (d0 = 1..5) fire_relay(msg.data[0]); @@ -148,7 +148,7 @@ static void loop() { send_status(); } break; - case 0x4f: + case CAN_MSG_AUTO_STATUS: if (msg.length == 1) { report_change = msg.data[0] ? true : false; }