Implement firmware support for auto-report

This commit is contained in:
Gregor Riepl 2021-01-18 20:25:01 +01:00
parent 318eb18e50
commit 395be23d74
2 changed files with 39 additions and 14 deletions

View file

@ -4,6 +4,8 @@
#include <util/delay.h> #include <util/delay.h>
#include <can.h> #include <can.h>
static bool report_change = false;
static void init() { static void init() {
// Set PB as input, pull-up off // Set PB as input, pull-up off
DDRB = 0; DDRB = 0;
@ -15,16 +17,26 @@ static void init() {
// Regular receive/transmit mode // Regular receive/transmit mode
can_set_mode(NORMAL_MODE); can_set_mode(NORMAL_MODE);
// Filter for status requests // Filter for messages addressed to us (RTR on)
can_filter_t filter = { can_filter_t us = {
.id = 0x10, .id = 0x000,
.mask = 0x7ff, .mask = 0x00f,
.flags = { .flags = {
.rtr = 1, .rtr = 1,
.extended = 0, .extended = 0,
}, },
}; };
can_set_filter(0, &filter); can_set_filter(0, &us);
// Filter for public messages (RTR off)
can_filter_t pub = {
.id = 0x00f,
.mask = 0x00f,
.flags = {
.rtr = 0,
.extended = 0,
},
};
can_set_filter(1, &pub);
// Enable interrupts to start reception // Enable interrupts to start reception
sei(); sei();
@ -65,6 +77,11 @@ static void loop() {
if (msg.flags.rtr) { if (msg.flags.rtr) {
send_status(); send_status();
} }
case 0x4f:
if (msg.length == 1) {
report_change = msg.data[0] ? true : false;
}
break;
} }
} }
} }

View file

@ -4,6 +4,8 @@
#include <util/delay.h> #include <util/delay.h>
#include <can.h> #include <can.h>
static bool report_change = false;
static void init() { static void init() {
// Enable GPIO: PB2, PB3, PB4 output, low; PB5 input, pull-up on // Enable GPIO: PB2, PB3, PB4 output, low; PB5 input, pull-up on
PORTB = (PORTB & ~(_BV(PB2) | _BV(PB3) | _BV(PB4))) | _BV(PB5); PORTB = (PORTB & ~(_BV(PB2) | _BV(PB3) | _BV(PB4))) | _BV(PB5);
@ -14,25 +16,26 @@ static void init() {
// Regular receive/transmit mode // Regular receive/transmit mode
can_set_mode(NORMAL_MODE); can_set_mode(NORMAL_MODE);
// Filter for status requests and dispense commands // Filter for messages addressed to us (RTR on)
can_filter_t filter = { can_filter_t us = {
.id = 0x11, .id = 0x001,
.mask = 0x7ff, .mask = 0x00f,
.flags = { .flags = {
.rtr = 1, .rtr = 1,
.extended = 0, .extended = 0,
}, },
}; };
can_set_filter(0, &filter); can_set_filter(0, &us);
can_filter_t disp = { // Filter for public messages (RTR off)
.id = 0x21, can_filter_t pub = {
.mask = 0x7ff, .id = 0x00f,
.mask = 0x00f,
.flags = { .flags = {
.rtr = 0, .rtr = 0,
.extended = 0, .extended = 0,
}, },
}; };
can_set_filter(1, &disp); can_set_filter(1, &pub);
// Enable interrupts to start reception // Enable interrupts to start reception
sei(); sei();
@ -141,6 +144,11 @@ static void loop() {
// also send out the current status // also send out the current status
send_status(); send_status();
} }
case 0x4f:
if (msg.length == 1) {
report_change = msg.data[0] ? true : false;
}
break;
} }
} }
} }