add "incremental flooding" to CAN-USB based on STM32F0x2

This commit is contained in:
Edward Emelianov 2023-01-31 20:09:57 +03:00
parent 17eec9bf6f
commit fecadc71f7
5 changed files with 23 additions and 11 deletions

View File

@ -26,7 +26,8 @@ static CAN_message messages[CAN_INMESSAGE_SIZE];
static uint8_t first_free_idx = 0; // index of first empty cell
static int8_t first_nonfree_idx = -1; // index of first data cell
static uint16_t oldspeed = 100; // speed of last init
uint32_t floodT = FLOOD_PERIOD_MS-1; // flood period in ms
uint32_t floodT = FLOOD_PERIOD_MS; // flood period in ms
static uint8_t incrflood = 0; // ==1 for incremental flooding
static uint32_t last_err_code = 0;
static CAN_status can_status = CAN_STOP;
@ -227,9 +228,13 @@ void can_proc(){
CAN_setup(0);
}
static uint32_t lastFloodTime = 0;
if(flood_msg && (Tms - lastFloodTime) > (floodT)){ // flood every ~5ms
static uint32_t incrmessagectr = 0;
if(flood_msg && (Tms - lastFloodTime) >= (floodT)){ // send message every floodT ms
lastFloodTime = Tms;
can_send(flood_msg->data, flood_msg->length, flood_msg->ID);
}else if(incrflood && (Tms - lastFloodTime) >= floodT){ // incremental flood message
lastFloodTime = Tms;
if(CAN_OK == can_send((uint8_t*)&incrmessagectr, 4, flood_msg->ID)) ++incrmessagectr;
}
}
@ -287,7 +292,9 @@ CAN_status can_send(uint8_t *msg, uint8_t len, uint16_t target_id){
return CAN_OK;
}
void set_flood(CAN_message *msg){
void set_flood(CAN_message *msg, int incr){
if(incr){ incrflood = 1; return; }
incrflood = 0;
if(!msg) flood_msg = NULL;
else{
#ifdef EBUG

View File

@ -56,4 +56,4 @@ void printCANerr();
CAN_message *CAN_messagebuf_pop();
void set_flood(CAN_message *msg);
void set_flood(CAN_message *msg, int incr);

View File

@ -24,7 +24,7 @@
extern volatile uint8_t canerror;
uint8_t ShowMsgs = 0;
uint8_t ShowMsgs = 1;
uint16_t Ignore_IDs[IGN_SIZE];
uint8_t IgnSz = 0;
@ -325,11 +325,11 @@ TRUE_INLINE void setfloodt(char *s){
uint32_t N;
s = omit_spaces(s);
char *n = getnum(s, &N);
if(s == n || N == 0){
if(s == n){
USB_sendstr("t="); printu(floodT); USB_putbyte('\n');
return;
}
floodT = N - 1;
floodT = N;
}
/**
@ -434,6 +434,7 @@ const char *helpmsg =
"'e' - get CAN errcodes\n"
"'f' - add/delete filter, format: bank# FIFO# mode(M/I) num0 [num1 [num2 [num3]]]\n"
"'F' - send/clear flood message: F ID byte0 ... byteN\n"
"'i' - send incremental flood message (ID == ID for `F`)\n"
"'I' - reinit CAN\n"
"'l' - list all active filters\n"
"'o' - turn LEDs OFF\n"
@ -442,7 +443,7 @@ const char *helpmsg =
"'P' - pause/resume in packets displaying\n"
"'R' - software reset\n"
"'s/S' - send data over CAN: s ID byte0 .. byteN\n"
"'t' - change flood period (>=1ms)\n"
"'t' - change flood period (>=0ms)\n"
"'T' - get time from start (ms)\n"
;
@ -482,7 +483,7 @@ void cmd_parser(char *txt){
goto eof;
break;
case 'F':
set_flood(parseCANmsg(txt));
set_flood(parseCANmsg(txt), 0);
goto eof;
break;
case 's':
@ -511,6 +512,10 @@ void cmd_parser(char *txt){
USB_sendall();
Jump2Boot();
break;
case 'i':
set_flood(NULL, 1);
USB_sendstr("Incremental flooding is ON ('F' to off)\n");
break;
case 'I':
CAN_reinit(0);
break;

View File

@ -1,2 +1,2 @@
#define BUILD_NUMBER "23"
#define BUILD_DATE "2022-12-05"
#define BUILD_NUMBER "26"
#define BUILD_DATE "2023-01-31"