diff --git a/main/freqplan.h b/main/freqplan.h index e0bf5c8..87274aa 100644 --- a/main/freqplan.h +++ b/main/freqplan.h @@ -5,10 +5,11 @@ class FreqPlan { public: - uint8_t Plan; // 1=Europe, 2=USA/Canada, 3=Australia/Chile, 4=New Zeeland - uint8_t Channels; // number of channels - uint32_t BaseFreq; // [Hz] base channel (#0) frequency - uint32_t ChanSepar; // [Hz] channel spacing + uint8_t Plan; // 1=Europe, 2=USA/Canada, 3=Australia/Chile, 4=New Zeeland + // char Name[16]; + uint8_t Channels; // number of channels + uint32_t BaseFreq; // [Hz] base channel (#0) frequency + uint32_t ChanSepar; // [Hz] channel spacing static const uint8_t MaxChannels=65; public: @@ -17,7 +18,8 @@ class FreqPlan if(Plan==2) { BaseFreq=902200000; ChanSepar=400000; Channels=65; } // USA else if(Plan==3) { BaseFreq=917000000; ChanSepar=400000; Channels=24; } // Australia and South America else if(Plan==4) { BaseFreq=869250000; ChanSepar=200000; Channels= 1; } // New Zeeland - else { BaseFreq=868200000; ChanSepar=200000; Channels= 2; } // Europe + else if(Plan==5) { BaseFreq=433200000; ChanSepar=200000; Channels= 8; } // Europe/Africa 434MHz + else { BaseFreq=868200000; ChanSepar=200000; Channels= 2; } // Europe/Africa 868MHz } void setPlan(int32_t Latitude, int32_t Longitude) @@ -26,31 +28,31 @@ class FreqPlan const char *getPlanName(void) { return getPlanName(Plan); } static const char *getPlanName(uint8_t Plan) - { static const char *Name[5] = { "Default", "Europe/Africa", "USA/Canada", "Australia/South America", "New Zeeland" } ; - if(Plan>4) return 0; + { static const char *Name[6] = { "Default", "Europe/Africa", "USA/Canada", "Australia/South America", "New Zeeland", "Europe/Africa 434MHz" } ; + if(Plan>=6) return 0; return Name[Plan]; } uint8_t getChannel (uint32_t Time, uint8_t Slot=0, uint8_t OGN=1) const // OGN-tracker or FLARM, UTC time, slot: 0 or 1 - { if(Channels<=1) return 0; // if single channel (New Zeeland) return channel #0 - if(Plan>=2) // if USA/Canada or Australia/South America - { uint8_t Channel = FreqHopHash((Time<<1)+Slot) % Channels; // Flarm hopping channel - if(OGN) // for OGN tracker - { if(Slot) { uint8_t Channel1=FreqHopHash((Time<<1)) % Channels; // for 2nd slot choose a channel close to the 1st slot - Channel1++; if(Channel1>=Channels) Channel1-=2; // + { if(Channels<=1) return 0; // if single channel (New Zeeland) return channel #0 + if(Plan>=2) // if USA/Canada or Australia/South America + { uint8_t Channel = FreqHopHash((Time<<1)+Slot) % Channels; // Flarm hopping channel + if(OGN) // for OGN tracker + { if(Slot) { uint8_t Channel1=FreqHopHash((Time<<1)) % Channels; // for 2nd slot choose a channel close to the 1st slot + Channel1++; if(Channel1>=Channels) Channel1-=2; // uint8_t Channel2=Channel1+1; if(Channel2>=Channels) Channel2-=2; - if(Channel2==Channel) Channel=Channel1; // avoid being on same chanel as Flarm + if(Channel2==Channel) Channel=Channel1; // avoid being on same chanel as Flarm else Channel=Channel2; } - else { Channel++; if(Channel>=Channels) Channel-=2; } // for 1st slot choose a higher channel (unless already highest, then choose a lower one) + else { Channel++; if(Channel>=Channels) Channel-=2; } // for 1st slot choose a higher channel (unless already highest, then choose a lower one) } - return Channel; } // return 0..Channels-1 for USA/CA or Australia. - return Slot^OGN; } // if Europe/South Africa: return 0 or 1 for EU freq. plan + return Channel; } // return 0..Channels-1 for USA/CA or Australia. + return Slot^OGN; } // if Europe/South Africa: return 0 or 1 for EU freq. plan uint32_t getChanFrequency(int Channel) const { return BaseFreq+ChanSepar*Channel; } uint32_t getFrequency(uint32_t Time, uint8_t Slot=0, uint8_t OGN=1) const { uint8_t Channel=getChannel(Time, Slot, OGN); return BaseFreq+ChanSepar*Channel; } // return frequency [Hz] for given UTC time and slot - uint8_t static calcPlan(int32_t Latitude, int32_t Longitude) // get the frequency plan from Lat/Lon: 1 = Europe + Africa, 2 = USA/CAnada, 3 = Australia + South America, 4$ + uint8_t static calcPlan(int32_t Latitude, int32_t Longitude) // get the frequency plan from Lat/Lon: 1 = Europe + Africa, 2 = USA/CAnada, 3 = Australia + South America, 4 = New Zeeland { if( (Longitude>=(-20*600000)) && (Longitude<=(60*600000)) ) return 1; // between -20 and 60 deg Lat => Europe + Africa: 868MHz band if( Latitude<(20*600000) ) // below 20deg latitude { if( ( Longitude>(164*600000)) && (Latitude<(-30*600000)) && (Latitude>(-48*600000)) ) return 4; // => New Zeeland diff --git a/main/gps.cpp b/main/gps.cpp index a6cbb5f..1c7acc7 100644 --- a/main/gps.cpp +++ b/main/gps.cpp @@ -67,7 +67,7 @@ static union } ; } GPS_Burst; // for the autobaud on the GPS port -const int GPS_BurstTimeout = 250; // [ms] +const int GPS_BurstTimeout = 200; // [ms] static const uint8_t BaudRates=7; // number of possible baudrates choices static uint8_t BaudRateIdx=0; // actual choice @@ -157,8 +157,6 @@ static void GPS_LockEnd(void) // called when GPS looses a // ---------------------------------------------------------------------------- -const uint8_t GPS_BurstDelay=70; // [ms] time after the PPS when the data burst starts on the UART - static void GPS_BurstStart(void) // when GPS starts sending the data on the serial port { Burst_TickCount=xTaskGetTickCount(); #ifdef DEBUG_PRINT @@ -249,7 +247,7 @@ static void GPS_BurstComplete(void) // wh { uint32_t UnixTime=Position[PosIdx].getUnixTime(); GPS_FatTime=Position[PosIdx].getFatTime(); #ifndef WITH_MAVLINK // with MAVlink we sync. with the SYSTEM_TIME message - TimeSync_SoftPPS(Burst_TickCount, UnixTime, GPS_BurstDelay); + TimeSync_SoftPPS(Burst_TickCount, UnixTime, Parameters.PPSdelay); #endif } } @@ -381,7 +379,7 @@ static void GPS_NMEA(void) // wh Format_String(CONS_UART_Write, " -> "); Format_Bytes(CONS_UART_Write, NMEA.Data, 6); CONS_UART_Write(' '); Format_Hex(CONS_UART_Write, GPS_Burst.Flags); - CONS_UART_Write('\n'); + Format_String(CONS_UART_Write, "\n"); xSemaphoreGive(CONS_Mutex); #endif if( NMEA.isP() || NMEA.isGxRMC() || NMEA.isGxGGA() || NMEA.isGxGSA() || NMEA.isGPTXT() ) @@ -389,7 +387,7 @@ static void GPS_NMEA(void) // wh // if(CONS_UART_Free()>=128) { xSemaphoreTake(CONS_Mutex, portMAX_DELAY); Format_String(CONS_UART_Write, (const char *)NMEA.Data, 0, NMEA.Len); - CONS_UART_Write('\n'); + Format_String(CONS_UART_Write, "\n"); // Format_Bytes(CONS_UART_Write, NMEA.Data, NMEA.Len); // Format_Bytes(CONS_UART_Write, (const uint8_t *)CRNL, 2); xSemaphoreGive(CONS_Mutex); } diff --git a/main/parameters.h b/main/parameters.h index a102e85..f2c84cd 100644 --- a/main/parameters.h +++ b/main/parameters.h @@ -29,8 +29,8 @@ class FlashParameters { uint32_t Address:24; // address (ID) uint8_t AddrType:2; uint8_t AcftType:4; - bool NoTrack:1; - bool Stealth:1; + bool NoTrack:1; // unused + bool Stealth:1; // unused } ; } ; @@ -52,7 +52,8 @@ class FlashParameters 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) - uint16_t SoftPPSdelay; // [ms] + 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 = 11; // [int] number of info-parameters @@ -78,6 +79,22 @@ class FlashParameters // char Copilot[16] // char Category[16] +#ifdef WITH_WIFI + static const uint8_t WIFInameLen = 32; + static const uint8_t WIFIpassLen = 64; + static const uint8_t WIFIsets = 10; + char *getWIFIname(uint8_t Idx) { return Idx>16)); + Format_Hex(Call+5, (uint16_t)Address); + Call[9]=0; return 9; } + public: // void setDefault(void) { setDefaults(UniqueID[0] ^ UniqueID[1] ^ UniqueID[2]); } @@ -110,9 +134,16 @@ class FlashParameters TimeCorr = 0; // [sec] GeoidSepar = 470; // [0.1m] + FreqPlan = 0; // [0..5] + PPSdelay = 100; // [ms] + for(uint8_t Idx=0; Idx=0) && (Val<16) ) AcftType=Val; } - Parm = (const char *)NMEA.ParmPtr(1); // [0..3] addr-type: 1=ICAO, 2=FLARM, 3=OGN - if(Parm) - { Val=Read_Hex1(Parm[0]); - if( (Val>=0) && (Val<4) ) AddrType=Val; } - Parm = (const char *)NMEA.ParmPtr(2); // [HHHHHH] Address (ID): 6 hex digits, 24-bit - uint32_t Addr; - int8_t Len=Read_Hex(Addr, Parm); - if( (Len==6) && (Addr<0x01000000) ) Address=Addr; - Parm = (const char *)NMEA.ParmPtr(3); // [0..1] RFM69HW (up to +20dBm) or W (up to +13dBm) - if(Parm) - { Val=Read_Dec1(Parm[0]); - if(Val==0) clrTxTypeHW(); - else if(Val==1) setTxTypeHW(); } - Parm = (const char *)NMEA.ParmPtr(4); // [dBm] Tx power - int32_t TxPwr; - Len=Read_SignDec(TxPwr, Parm); - if( (Len>0) && (TxPwr>=(-10)) && (TxPwr<=20) ) setTxPower(TxPwr); - Parm = (const char *)NMEA.ParmPtr(5); // [kHz] Tx/Rx frequency correction - int32_t FreqCorr; - Len=Read_Float1(FreqCorr, Parm); - if( (Len>0) && (FreqCorr>=(-1000)) && (FreqCorr<=1000) ) RFchipFreqCorr = 10*FreqCorr; - Parm = (const char *)NMEA.ParmPtr(6); // [bps] Console baud rate - uint32_t BaudRate; - Len=Read_UnsDec(BaudRate, Parm); - if( (Len>0) && (BaudRate<=230400) ) CONbaud = BaudRate; - return 0; } -*/ + static bool isStringChar (char ch) // characters accepted as part of the string values { if( (ch>='0') && (ch<='9') ) return 1; // numbers if( (ch>='A') && (ch<='Z') ) return 1; // uppercase letters @@ -299,9 +297,18 @@ class FlashParameters 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=10*Corr; return 1; } @@ -316,6 +323,14 @@ class FlashParameters for(uint8_t Idx=0; Idx=0) && (Idx=0) && (IdxisReady && (!Position->Sent) && Position->isReady && Position->isValid() ) { AverSpeed=GPS_AverageSpeed(); // [0.1m/s] average speed, including the vertical speed isMoving = AverSpeed>10; - RF_FreqPlan.setPlan(Position->Latitude, Position->Longitude); // set the frequency plan according to the GPS position + if(Parameters.FreqPlan==0) + RF_FreqPlan.setPlan(Position->Latitude, Position->Longitude); // set the frequency plan according to the GPS position + else RF_FreqPlan.setPlan(Parameters.FreqPlan); /* #ifdef DEBUG_PRINT xSemaphoreTake(CONS_Mutex, portMAX_DELAY); diff --git a/main/rf.cpp b/main/rf.cpp index 0886000..071224f 100644 --- a/main/rf.cpp +++ b/main/rf.cpp @@ -166,7 +166,7 @@ extern "C" TRX.DIO0_isOn = RFM_IRQ_isOn; TRX.RESET = RFM_RESET; - RF_FreqPlan.setPlan(0); // 1 = Europe/Africa, 2 = USA/CA, 3 = Australia and South America + RF_FreqPlan.setPlan(Parameters.FreqPlan); // 1 = Europe/Africa, 2 = USA/CA, 3 = Australia and South America vTaskDelay(5); diff --git a/sdkconfig b/sdkconfig index dbdb087..eb95d09 100644 --- a/sdkconfig +++ b/sdkconfig @@ -83,9 +83,8 @@ CONFIG_PARTITION_TABLE_SINGLE_APP= CONFIG_PARTITION_TABLE_TWO_OTA= CONFIG_PARTITION_TABLE_CUSTOM=y CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv" -CONFIG_PARTITION_TABLE_CUSTOM_APP_BIN_OFFSET=0x10000 CONFIG_PARTITION_TABLE_FILENAME="partitions.csv" -CONFIG_APP_OFFSET=0x10000 +CONFIG_PARTITION_TABLE_OFFSET=0x8000 CONFIG_PARTITION_TABLE_MD5=y # @@ -124,12 +123,22 @@ CONFIG_BT_ENABLED= CONFIG_BTDM_CONTROLLER_PINNED_TO_CORE=0 CONFIG_BT_RESERVE_DRAM=0 +# +# Driver configurations +# + # # ADC configuration # CONFIG_ADC_FORCE_XPD_FSM= CONFIG_ADC2_DISABLE_DAC=y +# +# SPI master configuration +# +CONFIG_SPI_MASTER_IN_IRAM= +CONFIG_SPI_MASTER_ISR_IN_IRAM=y + # # ESP32-specific # @@ -487,6 +496,11 @@ CONFIG_MBEDTLS_ECP_DP_BP512R1_ENABLED=y CONFIG_MBEDTLS_ECP_DP_CURVE25519_ENABLED=y CONFIG_MBEDTLS_ECP_NIST_OPTIM=y +# +# mDNS +# +CONFIG_MDNS_MAX_SERVICES=10 + # # OpenSSL #