diff --git a/F1-nolib/chronometer/GPS.c b/F1-nolib/chronometer/GPS.c index 65f218b..b3f44a7 100644 --- a/F1-nolib/chronometer/GPS.c +++ b/F1-nolib/chronometer/GPS.c @@ -24,6 +24,7 @@ #include "time.h" #include "usart.h" #include "str.h" +#include "usb.h" #include // memcpy #define GPS_endline() do{usart_send(GPS_USART, "\r\n"); transmit_tbuf(GPS_USART); }while(0) @@ -128,6 +129,11 @@ void GPS_send_start_seq(){ need2startseq = 0; } +// send "full cold start" command to clear all almanach & location data +void GPS_send_FullColdStart(){ + write_with_checksum("PMTK104"); +} + /** * Parse answer from GPS module * @@ -160,6 +166,10 @@ void GPS_parse_answer(const char *buf){ if(!checksum_true(buf)){ return; // wrong checksum } + if(showGPSstr){ + showGPSstr = 0; + USB_send(buf); + } buf += 7; // skip header if(*buf == ','){ // time unknown GPS_status = GPS_WAIT; diff --git a/F1-nolib/chronometer/GPS.h b/F1-nolib/chronometer/GPS.h index 8545af5..33cf025 100644 --- a/F1-nolib/chronometer/GPS.h +++ b/F1-nolib/chronometer/GPS.h @@ -38,5 +38,6 @@ extern gps_status GPS_status; void GPS_parse_answer(const char *string); void GPS_send_start_seq(); +void GPS_send_FullColdStart(); #endif // __GPS_H__ diff --git a/F1-nolib/chronometer/adc.h b/F1-nolib/chronometer/adc.h index 1cab310..08d253b 100644 --- a/F1-nolib/chronometer/adc.h +++ b/F1-nolib/chronometer/adc.h @@ -21,6 +21,10 @@ #define NUMBER_OF_ADC_CHANNELS (3) +// interval of trigger's shot (>min && // memcpy +#include "adc.h" #include "flash.h" #include "lidar.h" #ifdef EBUG #include "usart.h" #endif +#include // memcpy extern uint32_t _edata, _etext, _sdata; static int maxnum = FLASH_BLOCK_SIZE / sizeof(user_conf); @@ -52,14 +53,14 @@ typedef struct{ } flash_storage; #define USERCONF_INITIALIZER { \ - .userconf_sz = sizeof(user_conf) \ - ,.dist_min = LIDAR_MIN_DIST \ - ,.dist_max = LIDAR_MAX_DIST \ - ,.trig_pullups = 0xff \ - ,.trigstate = 0 \ - ,.trigpause = {400, 400, 400} \ - ,.ADC_min = 1024 \ - ,.ADC_max = 3072 \ + .userconf_sz = sizeof(user_conf) \ + ,.dist_min = LIDAR_MIN_DIST \ + ,.dist_max = LIDAR_MAX_DIST \ + ,.trig_pullups = 0xff \ + ,.trigstate = 0 \ + ,.trigpause = {400, 400, 400, 300, 300} \ + ,.ADC_min = ADC_MIN_VAL \ + ,.ADC_max = ADC_MAX_VAL \ } __attribute__((section(".myvars"))) static const flash_storage Flash_Storage = { diff --git a/F1-nolib/chronometer/main.c b/F1-nolib/chronometer/main.c index 1c4fef0..7723301 100644 --- a/F1-nolib/chronometer/main.c +++ b/F1-nolib/chronometer/main.c @@ -86,6 +86,10 @@ char *parse_cmd(char *buf){ btns[28] = GET_PPS() + '0'; return btns; break; + case 'c': + DBG("Send cold start"); + GPS_send_FullColdStart(); + break; case 'C': if(getnum(&buf[1], &N)){ SEND("Need a number!\n"); @@ -137,6 +141,7 @@ char *parse_cmd(char *buf){ return "0/1 - turn on/off LED1\n" "'b' - get buttons's state\n" + "'c' - send cold start\n" "'d' - dump current user conf\n" "'p' - toggle USB pullup\n" "'C' - store userconf for N times\n" @@ -179,11 +184,17 @@ void linecoding_handler(usb_LineCoding __attribute__((unused)) *lc){ // get/set DBG("linecoding_handler"); }*/ -void clstate_handler(uint16_t __attribute__((unused)) val){ // lesser bits of val: DTR|RTS +void clstate_handler(uint16_t __attribute__((unused)) val){ // lesser bits of val: RTS|DTR USB_send("Chronometer version " VERSION ".\n"); #ifdef EBUG - if(val & 1) DBG("RTS set"); - if(val & 2) DBG("DTR set"); + if(val & 2){ + DBG("RTS set"); + USB_send("RTS set\n"); + } + if(val & 1){ + DBG("DTR set"); + USB_send("DTR set\n"); + } #endif } @@ -272,10 +283,6 @@ int main(void){ r = usart_getline(GPS_USART, &txt); if(r){ txt[r] = 0; - if(showGPSstr){ - showGPSstr = 0; - USB_send(txt); - } GPS_parse_answer(txt); } } diff --git a/F1-nolib/chronometer/str.c b/F1-nolib/chronometer/str.c index 1e511ba..d48ce5e 100644 --- a/F1-nolib/chronometer/str.c +++ b/F1-nolib/chronometer/str.c @@ -18,6 +18,7 @@ #include "adc.h" #include "flash.h" +#include "GPS.h" #include "str.h" #include "time.h" #include "usart.h" @@ -107,6 +108,7 @@ int parse_USBCMD(char *cmd){ CMD_GETADCVAL " - get ADC value\n" CMD_DISTMIN " - min distance threshold (cm)\n" CMD_DISTMAX " - max distance threshold (cm)\n" + CMD_GPSRESTART " - send Full Cold Restart to GPS\n" CMD_GPSSTR " - current GPS data string\n" CMD_LEDS "S - turn leds on/off (1/0)\n" CMD_GETMCUTEMP " - MCU temperature\n" @@ -246,6 +248,9 @@ int parse_USBCMD(char *cmd){ the_conf.ADC_min = (int16_t) N; succeed = 1; } + }else if(CMP(cmd, CMD_GPSRESTART) == 0){ + USB_send("Send full cold restart to GPS\n"); + GPS_send_FullColdStart(); }else return 1; IWDG->KR = IWDG_REFRESH; if(succeed) USB_send("Success!\n"); diff --git a/F1-nolib/chronometer/str.h b/F1-nolib/chronometer/str.h index 5cc21ae..a577328 100644 --- a/F1-nolib/chronometer/str.h +++ b/F1-nolib/chronometer/str.h @@ -40,6 +40,7 @@ #define CMD_GETMCUTEMP "mcutemp" #define CMD_GETADCVAL "adcval" #define CMD_LEDS "leds" +#define CMD_GPSRESTART "gpsrestart" extern uint8_t showGPSstr; diff --git a/F1-nolib/chronometer/usb.c b/F1-nolib/chronometer/usb.c index f9ad6db..09730c5 100644 --- a/F1-nolib/chronometer/usb.c +++ b/F1-nolib/chronometer/usb.c @@ -101,13 +101,13 @@ void usb_proc(){ } } -void USB_send(char *buf){ +void USB_send(const char *buf){ if(!USB_configured()){ DBG("USB not configured"); return; } uint16_t l = 0, ctr = 0; - char *p = buf; + const char *p = buf; while(*p++) ++l; while(l){ uint16_t s = (l > USB_TXBUFSZ) ? USB_TXBUFSZ : l; diff --git a/F1-nolib/chronometer/usb.h b/F1-nolib/chronometer/usb.h index 0d5831a..75d22b4 100644 --- a/F1-nolib/chronometer/usb.h +++ b/F1-nolib/chronometer/usb.h @@ -30,7 +30,7 @@ void USB_setup(); void usb_proc(); -void USB_send(char *buf); +void USB_send(const char *buf); int USB_receive(char *buf, int bufsize); int USB_configured(); diff --git a/F1-nolib/chronometer/usb_lib.c b/F1-nolib/chronometer/usb_lib.c index c45f3f2..0597aed 100644 --- a/F1-nolib/chronometer/usb_lib.c +++ b/F1-nolib/chronometer/usb_lib.c @@ -296,7 +296,10 @@ static uint16_t EP0_Handler(ep_t ep){ default: break; } - if(!dev2host) EP_WriteIRQ(0, (uint8_t *)0, 0); // write acknowledgement + // SET_CONTROL_LINE_STATE don't work! Need something to fix the BUG! + //if(!dev2host) + if(setup_packet.bRequest != GET_LINE_CODING) + EP_WriteIRQ(0, (uint8_t *)0, 0); // write acknowledgement epstatus = SET_VALID_RX(epstatus); epstatus = SET_VALID_TX(epstatus); break;