@@ -122,7 +122,7 @@ public class RadioAudioService extends Service {
122122 private int mode = MODE_STARTUP ;
123123 private int messageNumber = 0 ;
124124
125- public static final byte SILENT_BYTE = - 128 ;
125+ public static final byte SILENT_BYTE = 0 ;
126126
127127 // Callbacks to the Activity that started us
128128 private RadioAudioServiceCallbacks callbacks = null ;
@@ -151,9 +151,14 @@ public class RadioAudioService extends Service {
151151
152152 // Delimiter must match ESP32 code
153153 static final byte [] COMMAND_DELIMITER = new byte [] {(byte )0xDE , (byte )0xAD , (byte )0xBE , (byte )0xEF , (byte )0xDE , (byte )0xAD , (byte )0xBE , (byte )0xEF };
154- private static final byte COMMAND_SMETER_REPORT = 0x53 ; // Ascii "S"
155- private static final byte COMMAND_PHYS_PTT_DOWN = 0x44 ; // Ascii "D"
156- private static final byte COMMAND_PHYS_PTT_UP = 0x55 ; // Ascii "U"
154+ private static final byte COMMAND_SMETER_REPORT = 0x53 ; // Ascii "S"
155+ private static final byte COMMAND_PHYS_PTT_DOWN = 0x44 ; // Ascii "D"
156+ private static final byte COMMAND_PHYS_PTT_UP = 0x55 ; // Ascii "U"
157+ private static final byte COMMAND_DEBUG_INFO = 0x01 ;
158+ private static final byte COMMAND_DEBUG_ERROR = 0x02 ;
159+ private static final byte COMMAND_DEBUG_WARN = 0x03 ;
160+ private static final byte COMMAND_DEBUG_DEBUG = 0x04 ;
161+ private static final byte COMMAND_DEBUG_TRACE = 0x05 ;
157162
158163 private final ESP32DataStreamParser esp32DataStreamParser = new ESP32DataStreamParser (this ::handleParsedCommand );
159164
@@ -602,8 +607,10 @@ public void tuneToFreq(String frequencyStr, int squelchLevel, boolean forceTune)
602607
603608 try {
604609 Float freq = Float .parseFloat (makeSafeHamFreq (activeFrequencyStr ));
605- Float offsetMaxFreq = maxHamFreq - (bandwidth .equals ("W" ) ? 0.025f : 0.0125f );
606- if (freq < minHamFreq || freq > offsetMaxFreq ) {
610+ Float halfBandwidth = (bandwidth .equals ("Wide" ) ? 0.025f : 0.0125f ) / 2 ;
611+ Float offsetMaxFreq = maxHamFreq - halfBandwidth ;
612+ Float offsetMinFreq = minHamFreq + halfBandwidth ;
613+ if (freq < offsetMinFreq || freq > offsetMaxFreq ) {
607614 txAllowed = false ;
608615 } else {
609616 txAllowed = true ;
@@ -693,8 +700,10 @@ public void tuneToMemory(ChannelMemory memory, int squelchLevel, boolean forceTu
693700
694701 try {
695702 Float txFreq = Float .parseFloat (getTxFreq (memory .frequency , memory .offset , memory .offsetKhz ));
696- Float offsetMaxFreq = maxHamFreq - (bandwidth .equals ("W" ) ? 0.025f : 0.0125f );
697- if (txFreq < minHamFreq || txFreq > offsetMaxFreq ) {
703+ Float halfBandwidth = (bandwidth .equals ("Wide" ) ? 0.025f : 0.0125f ) / 2 ;
704+ Float offsetMaxFreq = maxHamFreq - halfBandwidth ;
705+ Float offsetMinFreq = minHamFreq + halfBandwidth ;
706+ if (txFreq < offsetMinFreq || txFreq > offsetMaxFreq ) {
698707 txAllowed = false ;
699708 } else {
700709 txAllowed = true ;
@@ -945,8 +954,8 @@ public void onRunError(Exception e) {
945954 }
946955 });
947956 usbIoManager .setWriteBufferSize (90000 ); // Must be large enough that ESP32 can take its time accepting our bytes without overrun.
948- usbIoManager .setReadBufferSize (1024 / 4 ); // Must not be 0 (infinite) or it may block on read() until a write() occurs.
949- usbIoManager .setReadBufferCount (16 *4 );
957+ usbIoManager .setReadBufferSize (1024 ); // Must not be 0 (infinite) or it may block on read() until a write() occurs.
958+ usbIoManager .setReadBufferCount (16 *2 );
950959 usbIoManager .start ();
951960 checkedFirmwareVersion = false ;
952961
@@ -1097,8 +1106,14 @@ public void nextScan() {
10971106 do {
10981107 ChannelMemory candidate = channelMemories .get (nextIndex );
10991108
1100- // If not marked as skipped, we tune to it and return.
1101- if (!candidate .skipDuringScan ) {
1109+ // If not marked as skipped, and it's in the active band, we tune to it and return.
1110+ float memoryFreqFloat = 0.0f ;
1111+ try {
1112+ memoryFreqFloat = Float .parseFloat (candidate .frequency );
1113+ } catch (Exception e ) {
1114+ Log .d ("DEBUG" , "Memory with id " + candidate .memoryId + " had invalid frequency." );
1115+ }
1116+ if (!candidate .skipDuringScan && memoryFreqFloat >= minRadioFreq && memoryFreqFloat <= maxRadioFreq ) {
11021117 // Reset silence since we found an active memory.
11031118 consecutiveSilenceBytes = 0 ;
11041119
@@ -1434,6 +1449,16 @@ private void handleParsedCommand(byte cmd, byte[] param) {
14341449 endPtt ();
14351450 callbacks .forcedPttEnd ();
14361451 }
1452+ } else if (cmd == COMMAND_DEBUG_INFO ) {
1453+ Log .i ("firmware" , new String (param ));
1454+ } else if (cmd == COMMAND_DEBUG_DEBUG ) {
1455+ Log .d ("firmware" , new String (param ));
1456+ } else if (cmd == COMMAND_DEBUG_ERROR ) {
1457+ Log .e ("firmware" , new String (param ));
1458+ } else if (cmd == COMMAND_DEBUG_WARN ) {
1459+ Log .w ("firmware" , new String (param ));
1460+ } else if (cmd == COMMAND_DEBUG_TRACE ) {
1461+ Log .v ("firmware" , new String (param ));
14371462 } else {
14381463 Log .d ("DEBUG" , "Unknown cmd received from ESP32: 0x" + Integer .toHexString (cmd & 0xFF ) +
14391464 " paramLen=" + param .length );
0 commit comments