From a161b1c69b1df6a55b18bab83e79c68608504f95 Mon Sep 17 00:00:00 2001 From: SA5NTK <84469214+SA5NTK@users.noreply.github.com> Date: Wed, 19 May 2021 20:31:49 +0200 Subject: [PATCH 1/2] Update ML_TRX.ino https://github.com/lofturj/loopController/issues/2#issue-895719498 --- ML_v4/ML_TRX.ino | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/ML_v4/ML_TRX.ino b/ML_v4/ML_TRX.ino index 82127a2..7d6cb98 100644 --- a/ML_v4/ML_TRX.ino +++ b/ML_v4/ML_TRX.ino @@ -561,6 +561,23 @@ int8_t transceiver_async_read(void) return Incoming; } +// +//--------------------------------------------------------------------------------- +// Conversion to and from BCD helpers +// Used to pass and parse values to ICOMs. Added /NoMe +//--------------------------------------------------------------------------------- +// +// +uint8_t bcdToBin(uint8_t val) +{ + return ( 10*(val >> 4) + (val & 0x0f) ); +} + +uint8_t binToBcd(uint8_t val) +{ + return ( ((val/10) << 4) + val%10 ); +} + uint8_t icom_filter; // RX Filter setting, specific to ICOM //--------------------------------------------------------------------------------- @@ -612,8 +629,8 @@ void icom_parse_serial_input(void) // Check if this is an incoming Power Level Indication message else if ((transceiver_in_string[4] == 0x14) && (transceiver_in_string[5] == 0x0a)) { - trx_pwr = 100 * transceiver_in_string[6]; - trx_pwr += transceiver_in_string[7]; + trx_pwr = 100 * transceiver_in_string[6]; // MSB can be only 0,1 or 2. No conversion needed + trx_pwr += bcdToBin(transceiver_in_string[7]); radio.pwr = true; // Indicate that we have successfully read power control level radio.ack = true; } @@ -703,7 +720,7 @@ void icom_set_pwr(uint16_t pwr) trx_write(0x14); // Set Level trx_write(0x0a); // level type = RF power trx_write(pwr/100); // High byte (bcd) - trx_write(pwr%100); // Low byte (bcd) + trx_write(binToBcd(pwr%100)); // Low byte (bcd) trx_writeln(0xfd); delayloop(9); } From 2c34bce131423c64ceb89db8455c94d1b9cc6ac9 Mon Sep 17 00:00:00 2001 From: SA5NTK <84469214+SA5NTK@users.noreply.github.com> Date: Mon, 24 May 2021 15:53:52 +0200 Subject: [PATCH 2/2] Update ML_TRX.ino --- ML_v4/ML_TRX.ino | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ML_v4/ML_TRX.ino b/ML_v4/ML_TRX.ino index 7d6cb98..2ebf375 100644 --- a/ML_v4/ML_TRX.ino +++ b/ML_v4/ML_TRX.ino @@ -611,8 +611,10 @@ void icom_parse_serial_input(void) civ_value += (uint32_t) 1000000 * (transceiver_in_string[8] & 0x0f); // MHz civ_value += (uint32_t) 10000000 * ((transceiver_in_string[8] & 0xf0) >> 4); // 10 x MHz - civ_value += (uint32_t) 100000000 * (transceiver_in_string[9] & 0x0f); // 100 x MHz - civ_value += (uint32_t) 1000000000 * ((transceiver_in_string[9] & 0xf0) >> 4); // GHz + if ( transceiver_in_string[9] != 0xfd ) { // some older ICOM rigs report current VFO frequency in 4 bytes insted of 5. Watch for End Of Message (0xfd) + civ_value += (uint32_t) 100000000 * (transceiver_in_string[9] & 0x0f); // 100 x MHz + civ_value += (uint32_t) 1000000000 * ((transceiver_in_string[9] & 0xf0) >> 4); // GHz + } // // Update running frequency of the application