Skip to content

Commit

Permalink
Relay encrypted packets
Browse files Browse the repository at this point in the history
  • Loading branch information
pjalocha committed Aug 11, 2021
1 parent a35802e commit 9a335da
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
10 changes: 7 additions & 3 deletions main/ogn.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ template <class OGNx_Packet=OGN1_Packet>
if(Packet.Header.Relay) return; // no rank for relayed packets (only single relay)
if(RxRSSI>128) // [-0.5dB] weaker signal => higher rank
Rank += (RxRSSI-128)>>2; // 1point/2dB less signal
if(Packet.Header.Encrypted) return; // for exncrypted packets we only take signal strength
RxAltitude -= 10*Packet.DecodeAltitude(); // [0.1m] lower altitude => higher rank
if(RxAltitude>0)
Rank += RxAltitude>>9; // 2points/100m of altitude below
Expand Down Expand Up @@ -643,7 +644,10 @@ template<class OGNx_Packet, uint8_t Size=8>
Out[Len++]=' '; Len+=Format_Hex(Out+Len, Rank); // print the slot Rank
if(Rank) // if Rank is none-zero
{ Out[Len++]='/'; Len+=Format_Hex(Out+Len, Packet[Idx].Packet.getAddressAndType() ); // print address-type and address
Out[Len++]=':'; Len+=Format_UnsDec(Out+Len, Packet[Idx].Packet.Position.Time, 2 ); } // [sec] print time
Out[Len++]=':';
if(Packet[Idx].Header.Encrypted) Len+=Format_String(Out+Len, "ee");
else Len+=Format_UnsDec(Out+Len, Packet[Idx].Packet.Position.Time, 2); // [sec] print time
}
}
Out[Len++]=' '; Len+=Format_Hex(Out+Len, Sum); // sum of all Ranks
Out[Len++]='/'; Len+=Format_Hex(Out+Len, LowIdx); // index of the lowest Rank or a free slot
Expand Down Expand Up @@ -798,9 +802,9 @@ class GPS_Time
return Same; } // return 1 when time did not change (both RMC and GGA were for same time)

int8_t ReadDate(const char *Param) // read the field DDMMYY
{ Day=Read_Dec2(Param); if(Day<0) return -1; // read calendar year (two digits - thus need to be extended to four)
{ Day=Read_Dec2(Param); if(Day<0) return -1; // read calendar day
Month=Read_Dec2(Param+2); if(Month<0) return -1; // read calendar month
Year=Read_Dec2(Param+4); if(Year<0) return -1; // read calendar day
Year=Read_Dec2(Param+4); if(Year<0) return -1; // read calendar year (two digits - thus need to be extended to four)
return 0; } // return 0 when field valid and was read correctly

private:
Expand Down
9 changes: 7 additions & 2 deletions main/proc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ static bool GetRelayPacket(OGN_TxPacket<OGN_Packet> *Packet) // prepare a p
memcpy(Packet->Packet.Byte(), RelayQueue[Idx]->Byte(), OGN_Packet::Bytes); // copy the packet
Packet->Packet.Header.Relay=1; // increment the relay count (in fact we only do single relay)
// Packet->Packet.calcAddrParity();
Packet->Packet.Whiten(); Packet->calcFEC(); // whiten and calc. the FEC code => packet ready for transmission
if(!Packet->Packet.Header.Encrypted) Packet->Packet.Whiten(); // whiten but only for non-encrypted packets
Packet->calcFEC(); // Calc. the FEC code => packet ready for transmission
// PrintRelayQueue(Idx); // for debug
RelayQueue.decrRank(Idx); // reduce the rank of the packet selected for relay
return 1; }
Expand Down Expand Up @@ -330,10 +331,14 @@ static uint8_t WritePFLAU(char *NMEA, uint8_t GPS=1) // produce the (mostly d

static void ProcessRxPacket(OGN_RxPacket<OGN_Packet> *RxPacket, uint8_t RxPacketIdx, uint32_t RxTime) // process every (correctly) received packet
{ int32_t LatDist=0, LonDist=0; uint8_t Warn=0;
if( RxPacket->Packet.Header.NonPos || RxPacket->Packet.Header.Encrypted ) return ; // status packet or encrypted: ignore
if( RxPacket->Packet.Header.NonPos /* || RxPacket->Packet.Header.Encrypted */ ) return ; // status packet or encrypted: ignore
uint8_t MyOwnPacket = ( RxPacket->Packet.Header.Address == Parameters.Address )
&& ( RxPacket->Packet.Header.AddrType == Parameters.AddrType );
if(MyOwnPacket) return; // don't process my own (relayed) packets
if(RxPacket->Packet.Header.Encrypted && RxPacket->RxErr<10) // here we attempt to relay encrypted packets
{ RxPacket->calcRelayRank(GPS_Altitude/10);
OGN_RxPacket<OGN_Packet> *PrevRxPacket = RelayQueue.addNew(RxPacketIdx);
return; }
bool DistOK = RxPacket->Packet.calcDistanceVector(LatDist, LonDist, GPS_Latitude, GPS_Longitude, GPS_LatCosine)>=0;
if(DistOK)
{ RxPacket->calcRelayRank(GPS_Altitude/10); // calculate the relay-rank (priority for relay)
Expand Down

0 comments on commit 9a335da

Please sign in to comment.