Alpha code to transmit PilotAware packets, do not use it yet

pull/30/head
Pawel Jalocha 2020-11-30 14:24:22 +00:00
rodzic 2141ce87c9
commit 5f6e115fc1
3 zmienionych plików z 93 dodań i 22 usunięć

Wyświetl plik

@ -18,19 +18,20 @@ 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 if(Plan==5) { BaseFreq=433200000; ChanSepar=200000; Channels= 8; } // Europe/Africa 434MHz
else if(Plan==5) { BaseFreq=916200000; ChanSepar=200000; Channels= 1; } // Israel
else if(Plan==6) { 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)
{ setPlan(calcPlan(Latitude, Longitude)); }
const char *getPlanName(void) { return getPlanName(Plan); }
uint32_t getCenterFreq(void) { return BaseFreq + ChanSepar/2*(Channels-1); }
const char *getPlanName(void) { return getPlanName(Plan); } // get the name of the given frequency plan
uint32_t getCenterFreq(void) { return BaseFreq + ChanSepar/2*(Channels-1); } // get the center frequency for the given frequency plan
static const char *getPlanName(uint8_t Plan)
{ static const char *Name[6] = { "Default", "EU/Africa", "USA/Canada", "Australia/Chile", "New Zeeland", "EU/Africa 434MHz" } ;
if(Plan>=6) return 0;
{ static const char *Name[7] = { "Default", "EU/Africa", "USA/Canada", "Australia/Chile", "New Zeeland", "Israel", "EU/Africa 434MHz" } ;
if(Plan>=7) 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
@ -41,20 +42,10 @@ class FreqPlan
{ if(Slot) // for 2nd slot
{ uint8_t Channel2 = FreqHopHash((Time<<1)) % Channels; // use same as Flarm in the 1st slot
if(Channel2==Channel) { Channel++; if(Channel>=Channels) Channel-=2; } // but if same then Flarm in the 2nd slot
else Channel=Channel2;
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)
}
/*
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
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)
}
*/
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
@ -63,6 +54,17 @@ class FreqPlan
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
uint32_t getFreqPAW(uint32_t Time)
{ if(Plan<=1) return 869525000;
return 0; }
uint32_t getFreqFNT(uint32_t Time)
{ if(Plan<=1) return BaseFreq; // Europe and default is 868.2MHz
uint32_t Freq1 = getFrequency(Time, 0, 0);
if(Plan==5) return Freq1; // for 434MHz is same as "FLARM", which is never used there
uint32_t Freq2 = getFrequency(Time, 0, 1);
return (Freq1+Freq2)/2; } // other hopping systems is half-way between FLARM and OGN
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

Wyświetl plik

@ -15,6 +15,8 @@ static const uint8_t OGN1_SYNC[8] = { 0xAA, 0x66, 0x55, 0xA5, 0x96, 0x99, 0x96,
// OGNv2 SYNC: 0xF56D3738 encoded in Machester
static const uint8_t OGN2_SYNC[8] = { 0x55, 0x99, 0x96, 0x59, 0xA5, 0x95, 0xA5, 0x6A };
static const uint8_t PAW_SYNC [8] = { 0xB4, 0x2B, 0x00, 0x00, 0x00, 0x00, 0x18, 0x71 };
#ifdef WITH_OGN1
static const uint8_t *OGN_SYNC = OGN1_SYNC;
#endif
@ -423,6 +425,21 @@ extern "C"
TxChan = RF_FreqPlan.getChannel(RF_SlotTime, 1, 1); // transmit channel
RX_Channel = TxChan;
#ifdef WITH_PAW
{ PAW_Packet Packet; Packet.Clear();
Packet.Address = Parameters.Address;
Packet.AcftType = Parameters.AcftType;
Packet.setCRC();
TRX.WriteMode(RF_OPMODE_STANDBY);
TRX.PAW_Configure(PAW_SYNC);
TRX.WriteTxPower(Parameters.getTxPower());
TRX.WritePacketPAW(Packet.Byte, 24);
TRX.WriteMode(RF_OPMODE_TRANSMITTER);
vTaskDelay(10);
TRX.WriteMode(RF_OPMODE_STANDBY);
TRX.OGN_Configure(0, OGN_SYNC); }
#endif
#if defined(WITH_FANET) && defined(WITH_RFM95)
const FANET_Packet *FNTpkt = FNT_TxFIFO.getRead(0); // read the packet from the FANET transmitt queue
if(FNTpkt) // was there any ?

Wyświetl plik

@ -8,6 +8,7 @@
// #include "config.h"
#include "ogn.h"
#include "fanet.h"
#include "paw.h"
class RFM_LoRa_Config
{ public:
@ -292,6 +293,11 @@ class RFM_TRX
// void setFrequencyCorrection(int32_t Correction=0)
// { if(Correction<0) FrequencyCorrection = -calcSynthFrequency(-Correction);
// else FrequencyCorrection = calcSynthFrequency( Correction); }
void setFrequency(uint32_t Freq) // [Hz]
{ Freq = calcSynthFrequency(Freq);
int32_t Corr = ((int64_t)Freq*FreqCorr+5000000)/10000000;
Freq+=Corr; WriteFreq((Freq+128)>>8); }
void setChannel(int16_t newChannel)
{ Channel=newChannel;
uint32_t Freq = BaseFrequency+ChannelSpacing*Channel;
@ -350,8 +356,15 @@ class RFM_TRX
Packet[PktIdx++]=ManchesterEncode[Byte>>4]; // software manchester encode every byte
Packet[PktIdx++]=ManchesterEncode[Byte&0x0F];
}
Block_Write(Packet, 2*Len, REG_FIFO);
}
Block_Write(Packet, 2*Len, REG_FIFO); }
void WritePacketPAW(const uint8_t *Data, uint8_t Len=24)
{ uint8_t Packet[Len+1];
for(uint8_t Idx=0; Idx<Len; Idx++)
{ Packet[Idx] = Data[Idx]; }
PAW_Packet::Whiten(Packet, Len);
Packet[Len] = PAW_Packet::CRC8(Packet, Len);
Block_Write(Packet, Len+1, REG_FIFO); }
uint8_t *ReadFIFO(uint8_t Len)
{ return Block_Read(Len, REG_FIFO); }
@ -439,6 +452,19 @@ class RFM_TRX
}
Deselect(); }
void WritePacketPAW(const uint8_t *Data, uint8_t Len=24)
{ uint8_t Packet[Len+1];
for(uint8_t Idx=0; Idx<Len; Idx++)
{ Packet[Idx] = Data[Idx]; }
PAW_Packet::Whiten(Packet, Len);
Packet[Len] = PAW_Packet::CRC8(Packet, Len);
const uint8_t Addr=REG_FIFO; // write to FIFO
Select();
TransferByte(Addr | 0x80);
for(uint8_t Idx=0; Idx<=Len; Idx++)
{ TransferByte(Packet[Idx]); }
Deselect(); }
void ReadPacketOGN(uint8_t *Data, uint8_t *Err, uint8_t Len=26) const // read packet data from FIFO
{ const uint8_t Addr=REG_FIFO;
Select(); // select the RF chip: start SPI transfer
@ -695,15 +721,41 @@ class RFM_TRX
// ReadData[0], ReadData[1], ReadData[2], ReadData[3]);
return Len; }
int OGN_Configure(int16_t Channel, const uint8_t *Sync, bool PW=0)
int PAW_Configure(const uint8_t *Sync)
{ // WriteMode(RF_OPMODE_STANDBY);
WriteTxPower(0);
ClearIrqFlags();
WriteWord(0x0341, REG_BITRATEMSB); // bit rate = 0x0341 = 38.415kbps
WriteByte( 0x05, REG_BITRATEFRAC); // one should set exactly 38.400kbps for PW
WriteWord( 157, REG_FDEVMSB); // FSK deviation = 0x013B x Fstep = 19.226kHz, Fstep=32MHz/(1<<19);
setFrequency(869525000); // 869.525MHz
FSK_WriteSYNC(8, 7, Sync); // SYNC pattern
WriteWord( 10, REG_PREAMBLEMSB); // 10 preamble bytes
WriteByte( 0x85, REG_PREAMBLEDETECT); // preamble detect: 1 byte, page 92 (or 0x85 ?)
WriteByte( 0x00, REG_PACKETCONFIG1); // Fixed size packet, no DC-free encoding, no CRC, no address filtering
WriteByte( 0x40, REG_PACKETCONFIG2); // Packet mode
WriteByte( 25, REG_PAYLOADLENGTH); // Packet size = 25 bytes
WriteByte( 24, REG_FIFOTHRESH); // TxStartCondition=FifoNotEmpty, FIFO threshold = 24 bytes
WriteWord(0x3030, REG_DIOMAPPING1); // DIO signals: DIO0=00, DIO1=11, DIO2=00, DIO3=00, DIO4=00, DIO5=11, => p.64, 99
// WriteByte( 0x02, REG_RXBW); // Man=0=16 Exp=2 +/-125kHz Rx (single-side) bandwidth => p.27,67,83,90
WriteByte( 0x23, REG_RXBW); // Man=1=20 Exp=3 +/-50kHz Rx (single-side) bandwidth => p.27,67,83,90
WriteByte( 0x23, REG_AFCBW); // +/-125kHz AFC bandwidth
WriteByte( 0x49, REG_PARAMP); // BT=0.5 shaping, 40us ramp up/down
WriteByte( 0x0E, REG_RXCONFIG); // => p.90 (or 0x8E ?)
WriteByte( 0x07, REG_RSSICONFIG); // 256 samples for RSSI, no offset, => p.90,82
WriteByte( 0x20, REG_LNA); // max. LNA gain, => p.89
return 0; }
int OGN_Configure(int16_t Channel, const uint8_t *Sync)
{ // WriteMode(RF_OPMODE_STANDBY); // mode: STDBY, modulation: FSK, no LoRa
// usleep(1000);
WriteTxPower(0);
ClearIrqFlags();
WriteWord(PW?0x0341:0x0140, REG_BITRATEMSB); // bit rate = 100kbps (32MHz/100000) (0x0341 = 38.415kbps)
WriteByte(0x00, REG_BITRATEFRAC); // one should set exactly 38.400kbps for PW
WriteWord(0x0140, REG_BITRATEMSB); // bit rate = 100kbps (32MHz/100000)
WriteByte(0x00, REG_BITRATEFRAC); //
// ReadWord(REG_BITRATEMSB);
WriteWord(PW?0x013B:0x0333, REG_FDEVMSB); // FSK deviation = +/-50kHz [32MHz/(1<<19)] (0x013B = 19.226kHz)
WriteWord(0x0333, REG_FDEVMSB); // FSK deviation = +/-50kHz [32MHz/(1<<19)]
// ReadWord(REG_FDEVMSB);
setChannel(Channel); // operating channel
FSK_WriteSYNC(8, 7, Sync); // SYNC pattern (setup for reception)