@@ -31,7 +31,7 @@ PacketType identifyPacketType()
3131 if (receivedBytes < 2 )
3232 {
3333 LRS_DEBUG_PRINTLN (F (" Bad packet" ));
34- return (PROCESS_BAD_PACKET );
34+ return (PACKET_BAD );
3535 }
3636
3737 // Pull out control header
@@ -58,13 +58,13 @@ PacketType identifyPacketType()
5858 {
5959 LRS_DEBUG_PRINT (F (" NetID mismatch: " ));
6060 LRS_DEBUG_PRINTLN (receivedNetID);
61- return (PROCESS_NETID_MISMATCH );
61+ return (PACKET_NETID_MISMATCH );
6262 }
6363
64- if (receiveTrailer.ack == 1 && receiveTrailer.remoteCommand == 0 )
64+ if (receiveTrailer.ack == 1 && receiveTrailer.remoteCommand == 0 && receiveTrailer. remoteCommandResponse == 0 )
6565 {
6666 LRS_DEBUG_PRINTLN (F (" RX: Ack packet" ));
67- return (PROCESS_ACK_PACKET );
67+ return (PACKET_ACK );
6868 }
6969
7070 if (receiveTrailer.resend == 1 )
@@ -77,7 +77,7 @@ PacketType identifyPacketType()
7777 if (memcmp (lastPacket, incomingBuffer, lastPacketSize) == 0 )
7878 {
7979 LRS_DEBUG_PRINTLN (F (" Duplicate received. Acking again." ));
80- return (PROCESS_DUPLICATE_PACKET ); // It's a duplicate. Ack then ignore
80+ return (PACKET_DUPLICATE ); // It's a duplicate. Ack then ignore
8181 }
8282 }
8383 else
@@ -94,7 +94,7 @@ PacketType identifyPacketType()
9494 if (receiveTrailer.train == 1 )
9595 {
9696 LRS_DEBUG_PRINTLN (F (" RX: Training Control Packet" ));
97- return (PROCESS_TRAINING_CONTROL_PACKET );
97+ return (PACKET_TRAINING_PING );
9898 }
9999
100100 // If this packet is marked as a remote command, it's either an ack or a zero length packet (not known)
@@ -107,12 +107,25 @@ PacketType identifyPacketType()
107107 }
108108
109109 LRS_DEBUG_PRINTLN (F (" RX: Unknown Command" ));
110- return (PROCESS_BAD_PACKET);
110+ return (PACKET_BAD);
111+ }
112+
113+ // If this packet is marked as a remote command response, it's either an ack or a zero length packet (not known)
114+ else if (receiveTrailer.remoteCommandResponse == 1 )
115+ {
116+ if (receiveTrailer.ack == 1 )
117+ {
118+ LRS_DEBUG_PRINTLN (F (" RX: Command Response Ack" ));
119+ return (PACKET_COMMAND_RESPONSE_ACK);
120+ }
121+
122+ LRS_DEBUG_PRINTLN (F (" RX: Unknown Response Command" ));
123+ return (PACKET_BAD);
111124 }
112125
113126 // Not training, not command packet, just a ping
114127 LRS_DEBUG_PRINTLN (F (" RX: Control Packet" ));
115- return (PROCESS_CONTROL_PACKET );
128+ return (PACKET_PING );
116129 }
117130
118131 // Update lastPacket details with current packet
@@ -123,8 +136,8 @@ PacketType identifyPacketType()
123136 // payload contains new AES key and netID which will be processed externally
124137 if (receiveTrailer.train == 1 )
125138 {
126- LRS_DEBUG_PRINTLN (F (" RX: Training data packet " ));
127- return (PROCESS_TRAINING_DATA_PACKET );
139+ LRS_DEBUG_PRINTLN (F (" RX: Training Data " ));
140+ return (PACKET_TRAINING_DATA );
128141 }
129142
130143 else if (receiveTrailer.remoteCommand == 1 )
@@ -134,8 +147,15 @@ PacketType identifyPacketType()
134147 return (PACKET_COMMAND_DATA);
135148 }
136149
137- LRS_DEBUG_PRINTLN (F (" RX: Data packet" ));
138- return (PROCESS_DATA_PACKET);
150+ else if (receiveTrailer.remoteCommandResponse == 1 )
151+ {
152+ // New response data from remote
153+ LRS_DEBUG_PRINTLN (F (" RX: Command Response Data" ));
154+ return (PACKET_COMMAND_RESPONSE_DATA);
155+ }
156+
157+ LRS_DEBUG_PRINTLN (F (" RX: Data" ));
158+ return (PACKET_DATA);
139159}
140160
141161// Apply settings to radio
@@ -205,7 +225,7 @@ void configureRadio()
205225 default :
206226 if (settings.debug == true )
207227 {
208- systemPrint (F ( " Unknown airSpeed: " ) );
228+ systemPrint (" Unknown airSpeed: " );
209229 systemPrintln (settings.airSpeed );
210230 }
211231 break ;
@@ -268,23 +288,23 @@ void configureRadio()
268288
269289 if (settings.debug == true )
270290 {
271- systemPrint (F ( " Freq: " ) );
291+ systemPrint (" Freq: " );
272292 systemPrintln (channels[0 ], 3 );
273- systemPrint (F ( " radioBandwidth: " ) );
293+ systemPrint (" radioBandwidth: " );
274294 systemPrintln (settings.radioBandwidth );
275- systemPrint (F ( " radioSpreadFactor: " ) );
295+ systemPrint (" radioSpreadFactor: " );
276296 systemPrintln (settings.radioSpreadFactor );
277- systemPrint (F ( " radioCodingRate: " ) );
297+ systemPrint (" radioCodingRate: " );
278298 systemPrintln (settings.radioCodingRate );
279- systemPrint (F ( " radioSyncWord: " ) );
299+ systemPrint (" radioSyncWord: " );
280300 systemPrintln (settings.radioSyncWord );
281- systemPrint (F ( " radioPreambleLength: " ) );
301+ systemPrint (" radioPreambleLength: " );
282302 systemPrintln (settings.radioPreambleLength );
283- systemPrint (F ( " calcSymbolTime: " ) );
303+ systemPrint (" calcSymbolTime: " );
284304 systemPrintln (calcSymbolTime ());
285- systemPrint (F ( " HoppingPeriod: " ) );
305+ systemPrint (" HoppingPeriod: " );
286306 systemPrintln (hoppingPeriod);
287- systemPrint (F ( " controlPacketAirTime: " ) );
307+ systemPrint (" controlPacketAirTime: " );
288308 systemPrintln (controlPacketAirTime);
289309 }
290310
@@ -293,10 +313,10 @@ void configureRadio()
293313 reportERROR ();
294314 if (settings.debug == true )
295315 {
296- systemPrintln (F ( " Radio init failed. Check settings." ) );
316+ systemPrintln (" Radio init failed. Check settings." );
297317 }
298318 }
299- LRS_DEBUG_PRINTLN (F ( " Radio online" ) );
319+ LRS_DEBUG_PRINTLN (" Radio online" );
300320}
301321
302322void returnToReceiving ()
@@ -346,6 +366,7 @@ void sendPingPacket()
346366 responseTrailer.resend = 0 ; // This is not a resend
347367 responseTrailer.train = 0 ; // This is not a training packet
348368 responseTrailer.remoteCommand = 0 ; // This is not a remote command packet
369+ responseTrailer.remoteCommandResponse = 0 ; // This is not a response to a previous remote command
349370
350371 packetSize = 2 ;
351372 packetSent = 0 ; // Reset the number of times we've sent this packet
@@ -373,6 +394,7 @@ void sendDataPacket()
373394 responseTrailer.resend = 0 ; // This is not a resend
374395 responseTrailer.train = 0 ; // This is not a training packet
375396 responseTrailer.remoteCommand = 0 ; // This is not a remote command packet
397+ responseTrailer.remoteCommandResponse = 0 ; // This is not a response to a previous remote command
376398
377399 packetSize += 2 ; // Make room for control bytes
378400 packetSent = 0 ; // Reset the number of times we've sent this packet
@@ -398,6 +420,7 @@ void sendResendPacket()
398420 responseTrailer.resend = 1 ; // This is a resend
399421 responseTrailer.train = 0 ; // This is not a training packet
400422 // responseTrailer.remoteCommand = ; //Don't modify the remoteCommand bit; we may be resending a command packet
423+ // responseTrailer.remoteCommandResponse = ; //Don't modify the remoteCommand bit; we may be resending a command packet
401424
402425 // packetSize += 2; //Don't adjust the packet size
403426 // packetSent = 0; //Don't reset
@@ -413,6 +436,7 @@ void sendAckPacket()
413436 responseTrailer.resend = 0 ; // This is not a resend
414437 responseTrailer.train = 0 ; // This is not a training packet
415438 responseTrailer.remoteCommand = 0 ; // This is not a remote command packet
439+ responseTrailer.remoteCommandResponse = 0 ; // This is not a response to a previous remote command
416440
417441 packetSize = 2 ;
418442 packetSent = 0 ; // Reset the number of times we've sent this packet
@@ -428,6 +452,7 @@ void sendTrainingPingPacket()
428452 responseTrailer.resend = 0 ; // This is not a resend
429453 responseTrailer.train = 1 ; // This is a training packet
430454 responseTrailer.remoteCommand = 0 ; // This is not a remote command packet
455+ responseTrailer.remoteCommandResponse = 0 ; // This is not a response to a previous remote command
431456
432457 packetSize = 2 ;
433458 packetSent = 0 ; // Reset the number of times we've sent this packet
@@ -446,6 +471,7 @@ void sendTrainingDataPacket()
446471 responseTrailer.resend = 0 ; // This is not a resend
447472 responseTrailer.train = 1 ; // This is training packet
448473 responseTrailer.remoteCommand = 0 ; // This is not a remote command packet
474+ responseTrailer.remoteCommandResponse = 0 ; // This is not a response to a previous remote command
449475
450476 packetSize = sizeof (trainEncryptionKey) + sizeof (trainNetID);
451477
@@ -470,6 +496,7 @@ void sendCommandAckPacket()
470496 responseTrailer.resend = 0 ; // This is not a resend
471497 responseTrailer.train = 0 ; // This is not a training packet
472498 responseTrailer.remoteCommand = 1 ; // This is a remote command packet
499+ responseTrailer.remoteCommandResponse = 0 ; // This is not a response to a previous command
473500
474501 packetSize = 2 ;
475502 packetSent = 0 ; // Reset the number of times we've sent this packet
@@ -485,6 +512,49 @@ void sendCommandDataPacket()
485512 responseTrailer.resend = 0 ; // This is not a resend
486513 responseTrailer.train = 0 ; // This is not training packet
487514 responseTrailer.remoteCommand = 1 ; // This is a remote control packet
515+ responseTrailer.remoteCommandResponse = 0 ; // This is not a response to a previous command
516+
517+ packetSize += 2 ; // Make room for control bytes
518+ packetSent = 0 ; // Reset the number of times we've sent this packet
519+
520+ // SF6 requires an implicit header which means there is no dataLength in the header
521+ if (settings.radioSpreadFactor == 6 )
522+ {
523+ // Manually store actual data length 3 bytes from the end (before NetID)
524+ // Manual packet size is whatever has been processed + 1 for the manual packetSize byte
525+ outgoingPacket[255 - 3 ] = packetSize + 1 ;
526+ packetSize = 255 ; // We're now going to transmit 255 bytes
527+ }
528+
529+ expectingAck = true ; // We expect destination to ack
530+ sendPacket ();
531+ }
532+
533+ // Create short packet of 2 control bytes - do not expect ack
534+ void sendCommandResponseAckPacket ()
535+ {
536+ LRS_DEBUG_PRINT (F (" TX: Command Response Ack " ));
537+ responseTrailer.ack = 1 ; // This is an ACK to a previous reception
538+ responseTrailer.resend = 0 ; // This is not a resend
539+ responseTrailer.train = 0 ; // This is not a training packet
540+ responseTrailer.remoteCommand = 0 ; // This is not a remote command packet
541+ responseTrailer.remoteCommandResponse = 1 ; // This is a response to a previous command
542+
543+ packetSize = 2 ;
544+ packetSent = 0 ; // Reset the number of times we've sent this packet
545+ expectingAck = false ; // We do not expect destination to ack
546+ sendPacket ();
547+ }
548+
549+ // Create packet of serial command with remote command = 1, ack = 0
550+ void sendCommandResponseDataPacket ()
551+ {
552+ LRS_DEBUG_PRINT (F (" TX: Command Response Data " ));
553+ responseTrailer.ack = 0 ; // This is not an ACK to a previous transmission.
554+ responseTrailer.resend = 0 ; // This is not a resend
555+ responseTrailer.train = 0 ; // This is not training packet
556+ responseTrailer.remoteCommand = 0 ; // This is a remote control packet
557+ responseTrailer.remoteCommandResponse = 1 ; // This is a response to a previous command
488558
489559 packetSize += 2 ; // Make room for control bytes
490560 packetSent = 0 ; // Reset the number of times we've sent this packet
@@ -643,23 +713,22 @@ void generateHopTable()
643713
644714 if (settings.debug == true )
645715 {
646- systemPrint (F ( " channelSpacing: " ) );
716+ systemPrint (" channelSpacing: " );
647717 systemPrintln (channelSpacing, 3 );
648718
649- systemPrintln (F ( " Channel table:" ) );
719+ systemPrintln (" Channel table:" );
650720 for (int x = 0 ; x < settings.numberOfChannels ; x++)
651721 {
652722 systemPrint (x);
653- systemPrint (F ( " : " ) );
723+ systemPrint (" : " );
654724 systemPrint (channels[x], 3 );
655725 systemPrintln ();
656726 }
657727
658- systemPrint (F ( " AES IV:" ) );
728+ systemPrint (" AES IV:" );
659729 for (uint8_t i = 0 ; i < 12 ; i++)
660730 {
661731 systemPrint (" 0x" );
662- if (AESiv[i] < 0x10 ) systemPrint (" 0" );
663732 systemPrint (AESiv[i], HEX);
664733 }
665734 systemPrintln ();
0 commit comments