#ifndef __PARAMETERS_H__ #define __PARAMETERS_H__ #include #include #if defined(WITH_STM32) || defined(WITH_ESP32) #include "hal.h" #endif #include "ogn.h" #ifdef WITH_ESP32 #include "nvs.h" #endif #ifdef WITH_STM32 #include "stm32f10x_flash.h" #include "flashsize.h" #endif #include "nmea.h" #include "format.h" // Parameters stored in Flash class FlashParameters { public: union { uint32_t AcftID; // identification: Private:AcftType:AddrType:Address - must be different for every tracker struct { uint32_t Address:24; // address (ID) uint8_t AddrType:2; uint8_t AcftType:4; bool NoTrack:1; // unused bool Stealth:1; // unused } ; } ; int16_t RFchipFreqCorr; // [0.1ppm] frequency correction for crystal frequency offset int8_t RFchipTxPower; // [dBm] highest bit set => HW module (up to +20dBm Tx power) int8_t RFchipTempCorr; // [degC] correction to the temperature measured in the RF chip uint32_t CONbaud; // [bps] Console baud rate int16_t PressCorr; // [0.25Pa] pressure correction for the baro union { uint8_t Flags; struct { bool SaveToFlash:1; // Save parameters from the config file to Flash bool hasBT:1; // has BT interface on the console bool BT_ON:1; // BT on after power up bool manGeoidSepar:1; // GeoidSepar is manually configured as the GPS or MAVlink are not able to deliver it } ; } ; // int8_t TimeCorr; // [sec] it appears for ArduPilot you need to correct time by 3 seconds int16_t GeoidSepar; // [0.1m] Geoid-Separation, apparently ArduPilot MAVlink does not give this value (although present in the format) // or it could be a problem of some GPSes uint8_t PPSdelay; // [ms] delay between the PPS and the data burst starts on the GPS UART (used when PPS failed or is not there) uint8_t FreqPlan; // force given frequency hopping plan static const uint8_t InfoParmLen = 16; // [char] max. size of an infp-parameter static const uint8_t InfoParmNum = 12; // [int] number of info-parameters char *InfoParmValue(uint8_t Idx) { return Idx>16)); Format_Hex(Call+5, (uint16_t)Address); Call[9]=0; return 9; } public: void setDefault(void) { setDefault(getUniqueAddress()); } void setDefault(uint32_t UniqueAddr) { AcftID = ((uint32_t)DEFAULT_AcftType<<26) | 0x03000000 | (UniqueAddr&0x00FFFFFF); RFchipFreqCorr = 0; // [0.1ppm] #ifdef WITH_RFM69W RFchipTxPower = 13; // [dBm] for RFM69W #else RFchipTxPower = 0x80 | 14; // [dBm] for RFM69HW #endif RFchipTempCorr = 0; // [degC] CONbaud = DEFAULT_CONbaud; // [bps] PressCorr = 0; // [0.25Pa] TimeCorr = 0; // [sec] GeoidSepar = 10*DEFAULT_GeoidSepar; // [0.1m] FreqPlan = DEFAULT_FreqPlan; // [0..5] PPSdelay = DEFAULT_PPSdelay; // [ms] for(uint8_t Idx=0; Idx='0') && (ch<='9') ) return 1; // numbers if( (ch>='A') && (ch<='Z') ) return 1; // uppercase letters if( (ch>='a') && (ch<='z') ) return 1; // lowercase letters if(strchr(".@-+_/#", ch)) return 1; // any of the listed special characters return 0; } static int8_t Read_String(char *Value, const char *Inp, uint8_t MaxLen) { const char *Val = SkipBlanks(Inp); uint8_t Idx; for(Idx=0; Idx' ') break; Inp++; } return Inp; } bool ReadParam(const char *Name, const char *Value) // interprete "Name = Value" line { if(strcmp(Name, "Address")==0) { uint32_t Addr=0; if(Read_Int(Addr, Value)<=0) return 0; Address=Addr; return 1; } if(strcmp(Name, "AddrType")==0) { uint32_t Type=0; if(Read_Int(Type, Value)<=0) return 0; AddrType=Type; return 1; } if(strcmp(Name, "AcftType")==0) { uint32_t Type=0; if(Read_Int(Type, Value)<=0) return 0; AcftType=Type; return 1; } if(strcmp(Name, "Console")==0) { uint32_t Baud=0; if(Read_Int(Baud, Value)<=0) return 0; CONbaud=Baud; return 1; } if(strcmp(Name, "TxHW")==0) { int32_t HW=1; if(Read_Int(HW, Value)<=0) return 0; if(HW) setTxTypeHW(); else clrTxTypeHW(); } if(strcmp(Name, "TxPower")==0) { int32_t TxPower=0; if(Read_Int(TxPower, Value)<=0) return 0; setTxPower(TxPower); return 1; } if(strcmp(Name, "PPSdelay")==0) { uint32_t Delay=0; if(Read_Int(Delay, Value)<=0) return 0; if(Delay>0xFF) Delay=0xFF; PPSdelay=Delay; return 1; } if(strcmp(Name, "FreqPlan")==0) { uint32_t Plan=0; if(Read_Int(Plan, Value)<=0) return 0; if(Plan>5) Plan=5; FreqPlan=Plan; return 1; } if(strcmp(Name, "FreqCorr")==0) { int32_t Corr=0; if(Read_Float1(Corr, Value)<=0) return 0; RFchipFreqCorr=Corr; return 1; } if(strcmp(Name, "PressCorr")==0) { int32_t Corr=0; if(Read_Float1(Corr, Value)<=0) return 0; PressCorr=4*Corr/10; return 1; } if(strcmp(Name, "TimeCorr")==0) { int32_t Corr=0; if(Read_Int(Corr, Value)<=0) return 0; TimeCorr=Corr; return 1; } if(strcmp(Name, "GeoidSepar")==0) { return Read_Float1(GeoidSepar, Value)<=0; } if(strcmp(Name, "manGeoidSepar")==0) { int32_t Man=0; if(Read_Int(Man, Value)<=0) return 0; manGeoidSepar=Man; } #ifdef WITH_BT_PWR if(strcmp(Name, "Bluetooth")==0) { int32_t bton=0; if(Read_Int(bton, Value)<=0) return 0; // if (bton==2) //WAR: disable usart1 in order to be able to configure BT over 2nd USB // { USART1_Disable(); // bton=1; } BT_ON=bton; return 1; } #endif for(uint8_t Idx=0; Idx=0) && (Idx=0) && (Idx