diff --git a/F1-nolib/chronometer/GPS.c b/F1-nolib/chronometer/GPS.c index 1080c11..279baa7 100644 --- a/F1-nolib/chronometer/GPS.c +++ b/F1-nolib/chronometer/GPS.c @@ -58,9 +58,9 @@ static int checksum_true(const char *buf){ static void send_chksum(uint8_t chs){ usart_putchar(GPS_USART, hex(chs >> 4)); - usart_putchar(1, hex(chs >> 4)); + //usart_putchar(1, hex(chs >> 4)); usart_putchar(GPS_USART, hex(chs & 0x0f)); - usart_putchar(1, hex(chs & 0x0f)); + //usart_putchar(1, hex(chs & 0x0f)); } /** * Calculate checksum & write message to port @@ -78,19 +78,19 @@ static void write_with_checksum(const char *buf){ break; } } - DBG("Send:"); + //DBG("Send:"); uint8_t checksum = 0; usart_putchar(GPS_USART, '$'); - usart_putchar(1, '$'); + //usart_putchar(1, '$'); GPS_send_string(buf); - SEND(buf); + //SEND(buf); do{ checksum ^= *buf++; }while(*buf); usart_putchar(GPS_USART, '*'); - usart_putchar(1, '*'); + //usart_putchar(1, '*'); send_chksum(checksum); - newline(); + //newline(); GPS_endline(); } @@ -155,9 +155,6 @@ void GPS_send_FullColdStart(){ */ void GPS_parse_answer(const char *buf){ char *ptr; -#if defined USART1PROXY - usart_send(1, buf); newline(); -#endif if(buf[1] == 'P') return; // answers to proprietary messages if(cmpstr(buf+3, "RMC", 3)){ // not RMC message need2startseq = 1; diff --git a/F1-nolib/chronometer/Makefile b/F1-nolib/chronometer/Makefile index 2836837..acfcfa0 100644 --- a/F1-nolib/chronometer/Makefile +++ b/F1-nolib/chronometer/Makefile @@ -12,8 +12,6 @@ LDSCRIPT ?= stm32F103xB.ld DEFS = -DVERSION=\"0.1.0\" # debug #DEFS += -DEBUG -# proxy GPS output over USART1 -DEFS += -DUSART1PROXY INDEPENDENT_HEADERS= diff --git a/F1-nolib/chronometer/adc.c b/F1-nolib/chronometer/adc.c index 80a98e2..9871ce6 100644 --- a/F1-nolib/chronometer/adc.c +++ b/F1-nolib/chronometer/adc.c @@ -86,7 +86,7 @@ uint8_t chkADCtrigger(){ }else{ // check if thigger shot if(val > (int16_t)the_conf.ADC_min + ADC_THRESHOLD && val < (int16_t)the_conf.ADC_max - ADC_THRESHOLD){ triggered = 1; - fillshotms(4); + fillshotms(ADC_TRIGGER); } } return triggered; diff --git a/F1-nolib/chronometer/chrono.bin b/F1-nolib/chronometer/chrono.bin index dd4dc4c..6e6c786 100755 Binary files a/F1-nolib/chronometer/chrono.bin and b/F1-nolib/chronometer/chrono.bin differ diff --git a/F1-nolib/chronometer/flash.h b/F1-nolib/chronometer/flash.h index 7933eca..fd9b057 100644 --- a/F1-nolib/chronometer/flash.h +++ b/F1-nolib/chronometer/flash.h @@ -52,6 +52,9 @@ typedef struct __attribute__((packed, aligned(4))){ #define FLAG_SAVE_EVENTS (1 << 0) // strings ends with "\r\n" instead of normal "\n" #define FLAG_STRENDRN (1 << 1) +// proxy GPS messages over USART1 +#define FLAG_GPSPROXY (1 << 2) + /* * struct to save events logs diff --git a/F1-nolib/chronometer/hardware.c b/F1-nolib/chronometer/hardware.c index 258235f..9245f4f 100644 --- a/F1-nolib/chronometer/hardware.c +++ b/F1-nolib/chronometer/hardware.c @@ -42,7 +42,7 @@ static uint8_t trigstate[DIGTRIG_AMOUNT]; // time of triggers shot trigtime shottime[TRIGGERS_AMOUNT]; // Tms value when they shot -static uint32_t shotms[TRIGGERS_AMOUNT]; +uint32_t shotms[TRIGGERS_AMOUNT]; // trigger length (-1 if > MAX_TRIG_LEN) int16_t triglen[TRIGGERS_AMOUNT]; // if trigger[N] shots, the bit N will be 1 @@ -187,7 +187,7 @@ void fillunshotms(){ if(pinval != trigstate[i]) rdy = 1; // trigger is OFF } if(rdy){ - shotms[i] = Tms; + if(i != LIDAR_TRIGGER) shotms[i] = Tms; show_trigger_shot(X); trigger_shot &= ~X; } diff --git a/F1-nolib/chronometer/hardware.h b/F1-nolib/chronometer/hardware.h index 441c2b5..d53524e 100644 --- a/F1-nolib/chronometer/hardware.h +++ b/F1-nolib/chronometer/hardware.h @@ -41,7 +41,7 @@ extern uint8_t buzzer_on; #define BUZZER_OFF() pin_clear(BUZZER_port, BUZZER_pin) #define BUZZER_GET() (pin_read(BUZZER_port, BUZZER_pin)) // minimal time to buzzer to cheep (ms) -#define BUZZER_CHEEP_TIME (500) +#define BUZZER_CHEEP_TIME 500 // PPS pin - PA1 #define PPS_port GPIOA @@ -49,15 +49,15 @@ extern uint8_t buzzer_on; // PPS and triggers state // amount of triggers, should be less than 9; 5 - 0..2 - switches, 3 - LIDAR, 4 - ADC -#define TRIGGERS_AMOUNT (5) +#define TRIGGERS_AMOUNT 5 // number of LIDAR trigger -#define LIDAR_TRIGGER (3) +#define LIDAR_TRIGGER 3 // number of ADC trigger -#define ADC_TRIGGER (4) +#define ADC_TRIGGER 4 // amount of digital triggers (on interrupts) -#define DIGTRIG_AMOUNT (3) +#define DIGTRIG_AMOUNT 3 // max length of trigger event (ms) -#define MAX_TRIG_LEN (1000) +#define MAX_TRIG_LEN 1000 #ifdef EBUG uint8_t gettrig(uint8_t N); diff --git a/F1-nolib/chronometer/lidar.c b/F1-nolib/chronometer/lidar.c index 156890d..7bd2400 100644 --- a/F1-nolib/chronometer/lidar.c +++ b/F1-nolib/chronometer/lidar.c @@ -24,6 +24,8 @@ uint16_t last_lidar_dist = 0; uint16_t last_lidar_stren = 0; uint16_t lidar_triggered_dist = 0; +extern uint32_t shotms[]; + /** * @brief parse_lidar_data - parsing of string from lidar * @param txt - the string or NULL (if you want just check trigger state) @@ -31,7 +33,16 @@ uint16_t lidar_triggered_dist = 0; */ uint8_t parse_lidar_data(char *txt){ static uint8_t triggered = 0; - if(!txt) return triggered; + if(!txt){ + // clear trigger state after timeout -> need to monitor lidar + uint32_t len = Tms - shotms[LIDAR_TRIGGER]; + //if(len > MAX_TRIG_LEN || len > (uint32_t)the_conf.trigpause[LIDAR_TRIGGER]){ + if(len > MAX_TRIG_LEN){ + triggered = 0; + DBG("MAX time gone, untrigger!"); + } + return triggered; + } last_lidar_dist = txt[2] | (txt[3] << 8); last_lidar_stren = txt[4] | (txt[5] << 8); if(last_lidar_stren < LIDAR_LOWER_STREN) return 0; // weak signal diff --git a/F1-nolib/chronometer/main.c b/F1-nolib/chronometer/main.c index 22cd5af..e140fb0 100644 --- a/F1-nolib/chronometer/main.c +++ b/F1-nolib/chronometer/main.c @@ -266,7 +266,7 @@ int main(void){ } // check if triggers that was recently shot are off now fillunshotms(); - if(lastT > Tms || Tms - lastT > 499){ + if(Tms - lastT > 499){ if(need2startseq) GPS_send_start_seq(); IWDG->KR = IWDG_REFRESH; switch(GPS_status){ @@ -280,17 +280,15 @@ int main(void){ LED1_off(); // turn off LED1 if GPS not found or time unknown } lastT = Tms; - if(usartrx(LIDAR_USART)){ + /*if(usartrx(LIDAR_USART)){ char *txt; if(usart_getline(LIDAR_USART, &txt)){ DBG("LIDAR:"); DBG(txt); } - } + }*/ IWDG->KR = IWDG_REFRESH; -#if defined EBUG || defined USART1PROXY transmit_tbuf(1); // non-blocking transmission of data from UART buffer every 0.5s -#endif transmit_tbuf(GPS_USART); transmit_tbuf(LIDAR_USART); #ifdef EBUG @@ -333,7 +331,6 @@ int main(void){ } IWDG->KR = IWDG_REFRESH; } -#if defined EBUG || defined USART1PROXY if(usartrx(1)){ // usart1 received data, store in in buffer r = usart_getline(1, &txt); if(r){ @@ -348,18 +345,19 @@ int main(void){ transmit_tbuf(1); IWDG->KR = IWDG_REFRESH; } -#else // USART1PROXY - send received data to GPS - usart_send(GPS_USART, txt); - IWDG->KR = IWDG_REFRESH; #endif + if(the_conf.defflags & FLAG_GPSPROXY){ + usart_send(GPS_USART, txt); + IWDG->KR = IWDG_REFRESH; + } } } -#endif if(usartrx(GPS_USART)){ IWDG->KR = IWDG_REFRESH; r = usart_getline(GPS_USART, &txt); if(r){ txt[r] = 0; + if(the_conf.defflags & FLAG_GPSPROXY) usart_send(1, txt); GPS_parse_answer(txt); } } diff --git a/F1-nolib/chronometer/str.c b/F1-nolib/chronometer/str.c index ff75f2a..7b34468 100644 --- a/F1-nolib/chronometer/str.c +++ b/F1-nolib/chronometer/str.c @@ -92,6 +92,9 @@ static void showuserconf(){ USB_send("\nSAVE_EVENTS="); if(f & FLAG_SAVE_EVENTS) USB_send("1"); else USB_send("0"); + USB_send("\nGPSPROXY="); + if(f & FLAG_GPSPROXY) USB_send("1"); + else USB_send("0"); USB_send("\nNFREE="); sendu(the_conf.NLfreeWarn); USB_send("\n"); @@ -121,6 +124,7 @@ int parse_USBCMD(char *cmd){ CMD_DISTMAX " - max distance threshold (cm)\n" CMD_DUMP "N - dump 20 last stored events (no x), all (x<1) or x\n" CMD_FLASH " - FLASH info\n" + CMD_GPSPROXY "S - GPS proxy over USART1 on/off\n" CMD_GPSRESTART " - send Full Cold Restart to GPS\n" CMD_GPSSTAT " - get GPS status\n" CMD_GPSSTR " - current GPS data string\n" @@ -149,8 +153,8 @@ int parse_USBCMD(char *cmd){ if(the_conf.dist_min != (uint16_t)N){ conf_modified = 1; the_conf.dist_min = (uint16_t) N; - succeed = 1; } + succeed = 1; }else if(CMP(cmd, CMD_DISTMAX) == 0){ // set low limit DBG("CMD_DISTMAX"); GETNUM(CMD_DISTMAX); @@ -158,8 +162,8 @@ int parse_USBCMD(char *cmd){ if(the_conf.dist_max != (uint16_t)N){ conf_modified = 1; the_conf.dist_max = (uint16_t) N; - succeed = 1; } + succeed = 1; }else if(CMP(cmd, CMD_STORECONF) == 0){ // store everything DBG("Store"); if(conf_modified){ @@ -193,8 +197,10 @@ int parse_USBCMD(char *cmd){ if(Nt > TRIGGERS_AMOUNT - 1) goto bad_number; if(getnum(cmd, &N)) goto bad_number; if(N < 0 || N > 10000) goto bad_number; - if(the_conf.trigpause[Nt] != N) conf_modified = 1; - the_conf.trigpause[Nt] = N; + if(the_conf.trigpause[Nt] != N){ + conf_modified = 1; + the_conf.trigpause[Nt] = N; + } succeed = 1; }else if(CMP(cmd, CMD_TRGTIME) == 0){ DBG("Trigger time"); @@ -245,16 +251,16 @@ int parse_USBCMD(char *cmd){ if(the_conf.ADC_max != (int16_t)N){ conf_modified = 1; the_conf.ADC_max = (int16_t) N; - succeed = 1; } + succeed = 1; }else if(CMP(cmd, CMD_ADCMIN) == 0){ // set low limit GETNUM(CMD_ADCMIN); if(N < -4096 || N > 4096) goto bad_number; if(the_conf.ADC_min != (int16_t)N){ conf_modified = 1; the_conf.ADC_min = (int16_t) N; - succeed = 1; } + succeed = 1; }else if(CMP(cmd, CMD_GPSRESTART) == 0){ USB_send("Send full cold restart to GPS\n"); GPS_send_FullColdStart(); @@ -297,17 +303,25 @@ int parse_USBCMD(char *cmd){ if(the_conf.USART_speed != (uint32_t)N){ the_conf.USART_speed = (uint32_t)N; conf_modified = 1; - succeed = 1; } + succeed = 1; }else if(CMP(cmd, CMD_RESET) == 0){ USB_send("Soft reset\n"); NVIC_SystemReset(); }else if(CMP(cmd, CMD_STREND) == 0){ char c = cmd[sizeof(CMD_STREND) - 1]; succeed = 1; - if(c == 'n' || c == 'N') the_conf.defflags &= ~FLAG_STRENDRN; - else if(c == 'r' || c == 'R') the_conf.defflags |= FLAG_STRENDRN; - else{ + if(c == 'n' || c == 'N'){ + if(the_conf.defflags & FLAG_STRENDRN){ + conf_modified = 1; + the_conf.defflags &= ~FLAG_STRENDRN; + } + }else if(c == 'r' || c == 'R'){ + if(!(the_conf.defflags & FLAG_STRENDRN)){ + conf_modified = 1; + the_conf.defflags |= FLAG_STRENDRN; + } + }else{ succeed = 0; USB_send("Bad letter, should be 'n' or 'r'\n"); } @@ -332,8 +346,17 @@ int parse_USBCMD(char *cmd){ sendu(maxLnum - 1); USB_send("\n"); }else if(CMP(cmd, CMD_SAVEEVTS) == 0){ - if('0' == cmd[sizeof(CMD_SAVEEVTS) - 1]) the_conf.defflags &= ~FLAG_SAVE_EVENTS; - else the_conf.defflags |= FLAG_SAVE_EVENTS; + if('0' == cmd[sizeof(CMD_SAVEEVTS) - 1]){ + if(the_conf.defflags & FLAG_SAVE_EVENTS){ + conf_modified = 1; + the_conf.defflags &= ~FLAG_SAVE_EVENTS; + } + }else{ + if(!(the_conf.defflags & FLAG_SAVE_EVENTS)){ + conf_modified = 1; + the_conf.defflags |= FLAG_SAVE_EVENTS; + } + } succeed = 1; }else if(CMP(cmd, CMD_DUMP) == 0){ if(getnum(cmd+sizeof(CMD_DUMP)-1, &N)) N = -20; // default - without N @@ -343,11 +366,27 @@ int parse_USBCMD(char *cmd){ }else if(CMP(cmd, CMD_NFREE) == 0){ GETNUM(CMD_NFREE); if(N < 0 || N > 0xffff) goto bad_number; - the_conf.NLfreeWarn = (uint16_t)N; + if(the_conf.NLfreeWarn != (uint16_t)N){ + conf_modified = 1; + the_conf.NLfreeWarn = (uint16_t)N; + } succeed = 1; }else if(CMP(cmd, CMD_DELLOGS) == 0){ if(store_log(NULL)) USB_send("Error during erasing flash\n"); else USB_send("All logs erased\n"); + }else if(CMP(cmd, CMD_GPSPROXY) == 0){ + if(cmd[sizeof(CMD_GPSPROXY) - 1] == '0'){ + if(the_conf.defflags & FLAG_GPSPROXY){ + conf_modified = 1; + the_conf.defflags &= ~FLAG_GPSPROXY; + } + }else{ + if(!(the_conf.defflags & FLAG_GPSPROXY)){ + conf_modified = 1; + the_conf.defflags |= FLAG_GPSPROXY; + } + } + succeed = 1; }else return 1; /*else if(CMP(cmd, CMD_) == 0){ ; @@ -377,7 +416,7 @@ char *get_trigger_shot(int number, const event_log *logdata){ if(logdata->trigno == LIDAR_TRIGGER){ bptr = strcp(bptr, "LIDAR, dist="); bptr = strcp(bptr, u2str(logdata->lidar_dist)); - bptr = strcp(bptr, ", TRIG" STR(LIDAR_TRIGGER) "="); + bptr = strcp(bptr, ", TRIG" STR(LIDAR_TRIGGER)); }else{ bptr = strcp(bptr, "TRIG"); *bptr++ = '0' + logdata->trigno; diff --git a/F1-nolib/chronometer/str.h b/F1-nolib/chronometer/str.h index 7e9780f..f4f1d3b 100644 --- a/F1-nolib/chronometer/str.h +++ b/F1-nolib/chronometer/str.h @@ -51,6 +51,7 @@ #define CMD_DUMP "dump" #define CMD_NFREE "nfree" #define CMD_DELLOGS "deletelogs" +#define CMD_GPSPROXY "gpsproxy" extern uint8_t showGPSstr; diff --git a/F1-nolib/chronometer/time.c b/F1-nolib/chronometer/time.c index d10ed81..bb0778e 100644 --- a/F1-nolib/chronometer/time.c +++ b/F1-nolib/chronometer/time.c @@ -62,10 +62,12 @@ void time_increment(){ current_time.H = 0; } } + /* #ifdef EBUG SEND("time_increment(): "); SEND(get_time(¤t_time, 0)); #endif + */ } static char *puttwo(uint8_t N, char *buf){ diff --git a/F1-nolib/chronometer/usart.c b/F1-nolib/chronometer/usart.c index 101f657..ce4241e 100644 --- a/F1-nolib/chronometer/usart.c +++ b/F1-nolib/chronometer/usart.c @@ -96,7 +96,7 @@ void usart_send(int n, const char *str){ tbuf[n][tbufno[n]][odatalen[n][tbufno[n]]++] = *str++; } } -#if defined EBUG || defined USART1PROXY +#if defined EBUG // only for USART1 void newline(){ usart_putchar(1, '\n'); @@ -170,9 +170,7 @@ static void usart_setup(int n, uint32_t BRR){ void usarts_setup(){ RCC->AHBENR |= RCC_AHBENR_DMA1EN; -#if defined EBUG || defined USART1PROXY usart_setup(1, 72000000 / the_conf.USART_speed); // debug console or GPS proxy -#endif usart_setup(2, 36000000 / 9600); // GPS usart_setup(3, 36000000 / 115200); // LIDAR } @@ -217,11 +215,9 @@ void usart_isr(int n, USART_TypeDef *USART){ } } -#if defined EBUG || defined USART1PROXY void usart1_isr(){ usart_isr(1, USART1); } -#endif // GPS_USART void usart2_isr(){ @@ -279,14 +275,12 @@ void hexdump(uint8_t *arr, uint16_t len){ } #endif -#if defined EBUG || defined USART1PROXY void dma1_channel4_isr(){ // USART1 if(DMA1->ISR & DMA_ISR_TCIF4){ // Tx DMA1->IFCR = DMA_IFCR_CTCIF4; // clear TC flag txrdy[1] = 1; } } -#endif void dma1_channel7_isr(){ // USART2 if(DMA1->ISR & DMA_ISR_TCIF7){ // Tx