add GPS full cold start command

This commit is contained in:
eddyem 2019-07-20 20:20:40 +03:00
parent 926e8d2037
commit 57ad234091
11 changed files with 52 additions and 20 deletions

View File

@ -24,6 +24,7 @@
#include "time.h" #include "time.h"
#include "usart.h" #include "usart.h"
#include "str.h" #include "str.h"
#include "usb.h"
#include <string.h> // memcpy #include <string.h> // memcpy
#define GPS_endline() do{usart_send(GPS_USART, "\r\n"); transmit_tbuf(GPS_USART); }while(0) #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; 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 * Parse answer from GPS module
* *
@ -160,6 +166,10 @@ void GPS_parse_answer(const char *buf){
if(!checksum_true(buf)){ if(!checksum_true(buf)){
return; // wrong checksum return; // wrong checksum
} }
if(showGPSstr){
showGPSstr = 0;
USB_send(buf);
}
buf += 7; // skip header buf += 7; // skip header
if(*buf == ','){ // time unknown if(*buf == ','){ // time unknown
GPS_status = GPS_WAIT; GPS_status = GPS_WAIT;

View File

@ -38,5 +38,6 @@ extern gps_status GPS_status;
void GPS_parse_answer(const char *string); void GPS_parse_answer(const char *string);
void GPS_send_start_seq(); void GPS_send_start_seq();
void GPS_send_FullColdStart();
#endif // __GPS_H__ #endif // __GPS_H__

View File

@ -21,6 +21,10 @@
#define NUMBER_OF_ADC_CHANNELS (3) #define NUMBER_OF_ADC_CHANNELS (3)
// interval of trigger's shot (>min && <max), maybe negative
#define ADC_MIN_VAL (1024)
#define ADC_MAX_VAL (3072)
extern uint16_t ADC_array[]; extern uint16_t ADC_array[];
int32_t getMCUtemp(); int32_t getMCUtemp();
uint32_t getVdd(); uint32_t getVdd();

Binary file not shown.

View File

@ -35,13 +35,14 @@
*/ */
#include "stm32f1.h" #include "stm32f1.h"
#include <string.h> // memcpy
#include "adc.h"
#include "flash.h" #include "flash.h"
#include "lidar.h" #include "lidar.h"
#ifdef EBUG #ifdef EBUG
#include "usart.h" #include "usart.h"
#endif #endif
#include <string.h> // memcpy
extern uint32_t _edata, _etext, _sdata; extern uint32_t _edata, _etext, _sdata;
static int maxnum = FLASH_BLOCK_SIZE / sizeof(user_conf); static int maxnum = FLASH_BLOCK_SIZE / sizeof(user_conf);
@ -57,9 +58,9 @@ typedef struct{
,.dist_max = LIDAR_MAX_DIST \ ,.dist_max = LIDAR_MAX_DIST \
,.trig_pullups = 0xff \ ,.trig_pullups = 0xff \
,.trigstate = 0 \ ,.trigstate = 0 \
,.trigpause = {400, 400, 400} \ ,.trigpause = {400, 400, 400, 300, 300} \
,.ADC_min = 1024 \ ,.ADC_min = ADC_MIN_VAL \
,.ADC_max = 3072 \ ,.ADC_max = ADC_MAX_VAL \
} }
__attribute__((section(".myvars"))) static const flash_storage Flash_Storage = { __attribute__((section(".myvars"))) static const flash_storage Flash_Storage = {

View File

@ -86,6 +86,10 @@ char *parse_cmd(char *buf){
btns[28] = GET_PPS() + '0'; btns[28] = GET_PPS() + '0';
return btns; return btns;
break; break;
case 'c':
DBG("Send cold start");
GPS_send_FullColdStart();
break;
case 'C': case 'C':
if(getnum(&buf[1], &N)){ if(getnum(&buf[1], &N)){
SEND("Need a number!\n"); SEND("Need a number!\n");
@ -137,6 +141,7 @@ char *parse_cmd(char *buf){
return return
"0/1 - turn on/off LED1\n" "0/1 - turn on/off LED1\n"
"'b' - get buttons's state\n" "'b' - get buttons's state\n"
"'c' - send cold start\n"
"'d' - dump current user conf\n" "'d' - dump current user conf\n"
"'p' - toggle USB pullup\n" "'p' - toggle USB pullup\n"
"'C' - store userconf for N times\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"); 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"); USB_send("Chronometer version " VERSION ".\n");
#ifdef EBUG #ifdef EBUG
if(val & 1) DBG("RTS set"); if(val & 2){
if(val & 2) DBG("DTR set"); DBG("RTS set");
USB_send("RTS set\n");
}
if(val & 1){
DBG("DTR set");
USB_send("DTR set\n");
}
#endif #endif
} }
@ -272,10 +283,6 @@ int main(void){
r = usart_getline(GPS_USART, &txt); r = usart_getline(GPS_USART, &txt);
if(r){ if(r){
txt[r] = 0; txt[r] = 0;
if(showGPSstr){
showGPSstr = 0;
USB_send(txt);
}
GPS_parse_answer(txt); GPS_parse_answer(txt);
} }
} }

View File

@ -18,6 +18,7 @@
#include "adc.h" #include "adc.h"
#include "flash.h" #include "flash.h"
#include "GPS.h"
#include "str.h" #include "str.h"
#include "time.h" #include "time.h"
#include "usart.h" #include "usart.h"
@ -107,6 +108,7 @@ int parse_USBCMD(char *cmd){
CMD_GETADCVAL " - get ADC value\n" CMD_GETADCVAL " - get ADC value\n"
CMD_DISTMIN " - min distance threshold (cm)\n" CMD_DISTMIN " - min distance threshold (cm)\n"
CMD_DISTMAX " - max 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_GPSSTR " - current GPS data string\n"
CMD_LEDS "S - turn leds on/off (1/0)\n" CMD_LEDS "S - turn leds on/off (1/0)\n"
CMD_GETMCUTEMP " - MCU temperature\n" CMD_GETMCUTEMP " - MCU temperature\n"
@ -246,6 +248,9 @@ int parse_USBCMD(char *cmd){
the_conf.ADC_min = (int16_t) N; 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();
}else return 1; }else return 1;
IWDG->KR = IWDG_REFRESH; IWDG->KR = IWDG_REFRESH;
if(succeed) USB_send("Success!\n"); if(succeed) USB_send("Success!\n");

View File

@ -40,6 +40,7 @@
#define CMD_GETMCUTEMP "mcutemp" #define CMD_GETMCUTEMP "mcutemp"
#define CMD_GETADCVAL "adcval" #define CMD_GETADCVAL "adcval"
#define CMD_LEDS "leds" #define CMD_LEDS "leds"
#define CMD_GPSRESTART "gpsrestart"
extern uint8_t showGPSstr; extern uint8_t showGPSstr;

View File

@ -101,13 +101,13 @@ void usb_proc(){
} }
} }
void USB_send(char *buf){ void USB_send(const char *buf){
if(!USB_configured()){ if(!USB_configured()){
DBG("USB not configured"); DBG("USB not configured");
return; return;
} }
uint16_t l = 0, ctr = 0; uint16_t l = 0, ctr = 0;
char *p = buf; const char *p = buf;
while(*p++) ++l; while(*p++) ++l;
while(l){ while(l){
uint16_t s = (l > USB_TXBUFSZ) ? USB_TXBUFSZ : l; uint16_t s = (l > USB_TXBUFSZ) ? USB_TXBUFSZ : l;

View File

@ -30,7 +30,7 @@
void USB_setup(); void USB_setup();
void usb_proc(); void usb_proc();
void USB_send(char *buf); void USB_send(const char *buf);
int USB_receive(char *buf, int bufsize); int USB_receive(char *buf, int bufsize);
int USB_configured(); int USB_configured();

View File

@ -296,7 +296,10 @@ static uint16_t EP0_Handler(ep_t ep){
default: default:
break; 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_RX(epstatus);
epstatus = SET_VALID_TX(epstatus); epstatus = SET_VALID_TX(epstatus);
break; break;