mirror of
https://github.com/eddyem/stm32samples.git
synced 2025-12-06 02:35:23 +03:00
add "megaflooding" to CANusb F303 (and incremental flooding)
This commit is contained in:
parent
7fb3d5ac59
commit
17eec9bf6f
@ -30,7 +30,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){ // flood every ~5ms
|
||||
lastFloodTime = Tms;
|
||||
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;
|
||||
}
|
||||
|
||||
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{
|
||||
memcpy(&loc_flood_msg, msg, sizeof(CAN_message));
|
||||
|
||||
@ -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);
|
||||
|
||||
Binary file not shown.
@ -63,7 +63,7 @@ int main(void){
|
||||
LED_on(LED0);
|
||||
lastT = Tms;
|
||||
if(!lastT) lastT = 1;
|
||||
if(ShowMsgs){ // new data in buff
|
||||
if(ShowMsgs){ // display message content
|
||||
IWDG->KR = IWDG_REFRESH;
|
||||
uint8_t len = can_mesg->length;
|
||||
printu(Tms);
|
||||
|
||||
@ -199,11 +199,11 @@ TRUE_INLINE void setfloodt(const char *s){
|
||||
uint32_t N;
|
||||
s = omit_spaces(s);
|
||||
const 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;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -307,6 +307,7 @@ const char *helpstring =
|
||||
"'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"
|
||||
@ -315,7 +316,7 @@ const char *helpstring =
|
||||
"'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"
|
||||
;
|
||||
|
||||
@ -356,7 +357,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':
|
||||
@ -380,6 +381,10 @@ void cmd_parser(char *txt){
|
||||
case 'e':
|
||||
printCANerr();
|
||||
break;
|
||||
case 'i':
|
||||
set_flood(NULL, 1);
|
||||
USB_sendstr("Incremental flooding is ON ('F' to off)\n");
|
||||
break;
|
||||
case 'I':
|
||||
CAN_reinit(0);
|
||||
break;
|
||||
|
||||
@ -1,2 +1,2 @@
|
||||
#define BUILD_NUMBER "15"
|
||||
#define BUILD_NUMBER "18"
|
||||
#define BUILD_DATE "2023-01-30"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user