@@ -97,7 +97,7 @@ PacketType identifyPacketType()
9797 return (PROCESS_TRAINING_CONTROL_PACKET);
9898 }
9999
100- // If this packet is marked as a remote command, it's either an ack or a ping
100+ // If this packet is marked as a remote command, it's either an ack or a zero length packet (not known)
101101 else if (receiveTrailer.remoteCommand == 1 )
102102 {
103103 if (receiveTrailer.ack == 1 )
@@ -106,22 +106,15 @@ PacketType identifyPacketType()
106106 return (PACKET_COMMAND_ACK);
107107 }
108108
109- LRS_DEBUG_PRINTLN (F (" RX: Command Ping " ));
110- return (PACKET_COMMAND_PING );
109+ LRS_DEBUG_PRINTLN (F (" RX: Unknown Command " ));
110+ return (PROCESS_BAD_PACKET );
111111 }
112112
113113 // Not training, not command packet, just a ping
114114 LRS_DEBUG_PRINTLN (F (" RX: Control Packet" ));
115115 return (PROCESS_CONTROL_PACKET);
116116 }
117117
118- // If we have one byte, and remote command, we are being asked for our settings
119- if (receivedBytes == 1 && receiveTrailer.remoteCommand == 1 )
120- {
121- LRS_DEBUG_PRINTLN (F (" RX: Command Request Settings" ));
122- return (PACKET_COMMAND_REQUEST_SETTINGS);
123- }
124-
125118 // Update lastPacket details with current packet
126119 memcpy (lastPacket, incomingBuffer, receivedBytes);
127120 lastPacketSize = receivedBytes;
@@ -136,15 +129,9 @@ PacketType identifyPacketType()
136129
137130 else if (receiveTrailer.remoteCommand == 1 )
138131 {
139- if (receiveTrailer.ack == 1 )
140- {
141- // Remote is giving us their settings
142- LRS_DEBUG_PRINTLN (F (" RX: Command Current Settings" ));
143- return (PACKET_COMMAND_CURRENT_SETTINGS);
144- }
145- // New settings from remote
146- LRS_DEBUG_PRINTLN (F (" RX: Command New Settings" ));
147- return (PACKET_COMMAND_NEW_SETTINGS);
132+ // New data from remote
133+ LRS_DEBUG_PRINTLN (F (" RX: Command Data" ));
134+ return (PACKET_COMMAND_DATA);
148135 }
149136
150137 LRS_DEBUG_PRINTLN (F (" RX: Data packet" ));
@@ -490,110 +477,19 @@ void sendCommandAckPacket()
490477 sendPacket ();
491478}
492479
493- // Create short packet of 2 control bytes - query remote radio for proof of life (ack)
494- void sendCommandPingPacket ()
495- {
496- LRS_DEBUG_PRINT (F (" TX: Command Ping " ));
497- responseTrailer.ack = 0 ; // This is not an ACK to a previous transmission
498- responseTrailer.resend = 0 ; // This is not a resend
499- responseTrailer.train = 0 ; // This is not a training packet
500- responseTrailer.remoteCommand = 1 ; // This is a remote command packet
501-
502- packetSize = 2 ;
503- packetSent = 0 ; // Reset the number of times we've sent this packet
504-
505- // SF6 requires an implicit header which means there is no dataLength in the header
506- // Because we cannot predict when a ping packet will be received, the receiver will always
507- // expecting 255 bytes. Pings must be increased to 255 bytes. ACKs are still 2 bytes.
508- if (settings.radioSpreadFactor == 6 )
509- {
510- // Manually store actual data length 3 bytes from the end (before NetID)
511- // Manual packet size is whatever has been processed + 1 for the manual packetSize byte
512- outgoingPacket[255 - 3 ] = packetSize + 1 ;
513- packetSize = 255 ; // We're now going to transmit 255 bytes
514- }
515-
516- expectingAck = true ; // We expect destination to ack
517- sendPacket ();
518- }
519-
520- // Create short packet of 2 control bytes, 1 dummy byte, with remoteSetting = 1
521- void sendCommandRequestSettingsPacket ()
522- {
523- LRS_DEBUG_PRINT (F (" TX: Settings Request " ));
524- responseTrailer.ack = 0 ; // This is not an ACK to a previous transmission
525- responseTrailer.resend = 0 ; // This is not a resend
526- responseTrailer.train = 0 ; // This is not a training packet
527- responseTrailer.remoteCommand = 1 ; // This is a remote command packet
528-
529- outgoingPacket[0 ] = 0xAA ; // Avoid DC bias
530-
531- packetSize = 3 ;
532- packetSent = 0 ; // Reset the number of times we've sent this packet
533-
534- // SF6 requires an implicit header which means there is no dataLength in the header
535- // Because we cannot predict when a ping packet will be received, the receiver will always
536- // expecting 255 bytes. Pings must be increased to 255 bytes. ACKs are still 2 bytes.
537- if (settings.radioSpreadFactor == 6 )
538- {
539- // Manually store actual data length 3 bytes from the end (before NetID)
540- // Manual packet size is whatever has been processed + 1 for the manual packetSize byte
541- outgoingPacket[255 - 3 ] = packetSize + 1 ;
542- packetSize = 255 ; // We're now going to transmit 255 bytes
543- }
544-
545- expectingAck = true ; // We expect destination to ack
546- sendPacket ();
547- }
548-
549- // Create packet of unit's settings with remote command = 1, ack = 0
550- void sendCommandCurrentSettingsPacket ()
480+ // Create packet of serial command with remote command = 1, ack = 0
481+ void sendCommandDataPacket ()
551482{
552- LRS_DEBUG_PRINT (F (" TX: Settings Data " ));
483+ LRS_DEBUG_PRINT (F (" TX: Command Data " ));
553484 responseTrailer.ack = 0 ; // This is not an ACK to a previous transmission.
554485 responseTrailer.resend = 0 ; // This is not a resend
555486 responseTrailer.train = 0 ; // This is not training packet
556487 responseTrailer.remoteCommand = 1 ; // This is a remote control packet
557488
558- moveSettingsToPacket (settings, outgoingPacket); // Copy settings to outgoingPacket
559- packetSize = sizeof (settings);
560-
561- packetSize += 2 ;
562- packetSent = 0 ; // Reset the number of times we've sent this packet
563-
564- // SF6 requires an implicit header which means there is no dataLength in the header
565- // Because we cannot predict when a ping packet will be received, the receiver will always
566- // expecting 255 bytes. Pings must be increased to 255 bytes. ACKs are still 2 bytes.
567- if (settings.radioSpreadFactor == 6 )
568- {
569- // Manually store actual data length 3 bytes from the end (before NetID)
570- // Manual packet size is whatever has been processed + 1 for the manual packetSize byte
571- outgoingPacket[255 - 3 ] = packetSize + 1 ;
572- packetSize = 255 ; // We're now going to transmit 255 bytes
573- }
574-
575- expectingAck = true ; // We do expect destination to ack
576- sendPacket ();
577- }
578-
579- // Create packet of unit's settings with remote command = 1
580- void sendCommandNewSettingsPacket ()
581- {
582- LRS_DEBUG_PRINT (F (" TX: Settings Data " ));
583- responseTrailer.ack = 0 ; // This is not a normal ping packet.
584- responseTrailer.resend = 0 ; // This is not a resend
585- responseTrailer.train = 0 ; // This is not training packet
586- responseTrailer.remoteCommand = 1 ; // This is a remote command packet
587-
588- moveSettingsToPacket (settings, outgoingPacket); // Copy settings to outgoingPacket
589- packetSize = sizeof (settings);
590-
591- packetSize += 2 ;
489+ packetSize += 2 ; // Make room for control bytes
592490 packetSent = 0 ; // Reset the number of times we've sent this packet
593491
594492 // SF6 requires an implicit header which means there is no dataLength in the header
595- // Because we cannot predict when a ping packet will be received, the receiver will always
596- // expecting 255 bytes. Pings must be increased to 255 bytes. ACKs are still 2 bytes.
597493 if (settings.radioSpreadFactor == 6 )
598494 {
599495 // Manually store actual data length 3 bytes from the end (before NetID)
@@ -602,24 +498,7 @@ void sendCommandNewSettingsPacket()
602498 packetSize = 255 ; // We're now going to transmit 255 bytes
603499 }
604500
605- expectingAck = false ; // We do not expect destination to ack
606- sendPacket ();
607- }
608-
609- // Create short packet of 2 control bytes - do not expect ack, remoteCommand = 1
610- void sendCommandDataPacketAck ()
611- {
612- LRS_DEBUG_PRINT (F (" TX: Ack " ));
613- responseTrailer.ack = 0 ; // This is not a normal packet, no ack
614- responseTrailer.resend = 0 ; // This is not a resend
615- responseTrailer.train = 0 ; // This is not a training packet
616- responseTrailer.remoteCommand = 1 ; // This is a remote control packet
617- responseTrailer.remoteCommandAck = 1 ; // ACK the reception of the remote command data packet
618-
619- packetSize = 2 ;
620- packetSent = 0 ; // Reset the number of times we've sent this packet
621-
622- expectingAck = false ; // We do not expect destination to ack
501+ expectingAck = true ; // We expect destination to ack
623502 sendPacket ();
624503}
625504
0 commit comments