mirror of
https://github.com/eddyem/stm32samples.git
synced 2025-12-06 10:45:11 +03:00
add GPS full cold start command
This commit is contained in:
parent
926e8d2037
commit
57ad234091
@ -24,6 +24,7 @@
|
||||
#include "time.h"
|
||||
#include "usart.h"
|
||||
#include "str.h"
|
||||
#include "usb.h"
|
||||
#include <string.h> // 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;
|
||||
|
||||
@ -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__
|
||||
|
||||
@ -21,6 +21,10 @@
|
||||
|
||||
#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[];
|
||||
int32_t getMCUtemp();
|
||||
uint32_t getVdd();
|
||||
|
||||
Binary file not shown.
@ -35,13 +35,14 @@
|
||||
*/
|
||||
|
||||
#include "stm32f1.h"
|
||||
#include <string.h> // memcpy
|
||||
|
||||
#include "adc.h"
|
||||
#include "flash.h"
|
||||
#include "lidar.h"
|
||||
#ifdef EBUG
|
||||
#include "usart.h"
|
||||
#endif
|
||||
#include <string.h> // 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 = {
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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");
|
||||
|
||||
@ -40,6 +40,7 @@
|
||||
#define CMD_GETMCUTEMP "mcutemp"
|
||||
#define CMD_GETADCVAL "adcval"
|
||||
#define CMD_LEDS "leds"
|
||||
#define CMD_GPSRESTART "gpsrestart"
|
||||
|
||||
extern uint8_t showGPSstr;
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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();
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user