add "megaflooding" to CANusb F303 (and incremental flooding)

This commit is contained in:
Edward Emelianov 2023-01-30 23:33:03 +03:00
parent 7fb3d5ac59
commit 17eec9bf6f
6 changed files with 22 additions and 10 deletions

View File

@ -30,7 +30,8 @@ static CAN_message messages[CAN_INMESSAGE_SIZE];
static uint8_t first_free_idx = 0; // index of first empty cell 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 int8_t first_nonfree_idx = -1; // index of first data cell
static uint16_t oldspeed = 100; // speed of last init 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 uint32_t last_err_code = 0;
static CAN_status can_status = CAN_STOP; static CAN_status can_status = CAN_STOP;
@ -227,9 +228,13 @@ void can_proc(){
CAN_setup(0); CAN_setup(0);
} }
static uint32_t lastFloodTime = 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){ // flood every ~5ms
lastFloodTime = Tms; lastFloodTime = Tms;
can_send(flood_msg->data, flood_msg->length, flood_msg->ID); can_send(flood_msg->data, flood_msg->length, flood_msg->ID);
}else if(incrflood && (Tms - lastFloodTime) >= floodT){
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; 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; if(!msg) flood_msg = NULL;
else{ else{
memcpy(&loc_flood_msg, msg, sizeof(CAN_message)); memcpy(&loc_flood_msg, msg, sizeof(CAN_message));

View File

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

Binary file not shown.

View File

@ -63,7 +63,7 @@ int main(void){
LED_on(LED0); LED_on(LED0);
lastT = Tms; lastT = Tms;
if(!lastT) lastT = 1; if(!lastT) lastT = 1;
if(ShowMsgs){ // new data in buff if(ShowMsgs){ // display message content
IWDG->KR = IWDG_REFRESH; IWDG->KR = IWDG_REFRESH;
uint8_t len = can_mesg->length; uint8_t len = can_mesg->length;
printu(Tms); printu(Tms);

View File

@ -199,11 +199,11 @@ TRUE_INLINE void setfloodt(const char *s){
uint32_t N; uint32_t N;
s = omit_spaces(s); s = omit_spaces(s);
const char *n = getnum(s, &N); const char *n = getnum(s, &N);
if(s == n || N == 0){ if(s == n){
USB_sendstr("t="); printu(floodT); USB_putbyte('\n'); USB_sendstr("t="); printu(floodT); USB_putbyte('\n');
return; return;
} }
floodT = N - 1; floodT = N;
} }
/** /**
@ -307,6 +307,7 @@ const char *helpstring =
"'e' - get CAN errcodes\n" "'e' - get CAN errcodes\n"
"'f' - add/delete filter, format: bank# FIFO# mode(M/I) num0 [num1 [num2 [num3]]]\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" "'F' - send/clear flood message: F ID byte0 ... byteN\n"
"'i' - send incremental flood message (ID == ID for `F`)\n"
"'I' - reinit CAN\n" "'I' - reinit CAN\n"
"'l' - list all active filters\n" "'l' - list all active filters\n"
"'o' - turn LEDs OFF\n" "'o' - turn LEDs OFF\n"
@ -315,7 +316,7 @@ const char *helpstring =
"'P' - pause/resume in packets displaying\n" "'P' - pause/resume in packets displaying\n"
"'R' - software reset\n" "'R' - software reset\n"
"'s/S' - send data over CAN: s ID byte0 .. byteN\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" "'T' - get time from start (ms)\n"
; ;
@ -356,7 +357,7 @@ void cmd_parser(char *txt){
goto eof; goto eof;
break; break;
case 'F': case 'F':
set_flood(parseCANmsg(txt)); set_flood(parseCANmsg(txt), 0);
goto eof; goto eof;
break; break;
case 's': case 's':
@ -380,6 +381,10 @@ void cmd_parser(char *txt){
case 'e': case 'e':
printCANerr(); printCANerr();
break; break;
case 'i':
set_flood(NULL, 1);
USB_sendstr("Incremental flooding is ON ('F' to off)\n");
break;
case 'I': case 'I':
CAN_reinit(0); CAN_reinit(0);
break; break;

View File

@ -1,2 +1,2 @@
#define BUILD_NUMBER "15" #define BUILD_NUMBER "18"
#define BUILD_DATE "2023-01-30" #define BUILD_DATE "2023-01-30"