Updated ports to the new numbers for the actual board, added FreqSync Warning light

This commit is contained in:
Wolfgang Bachschwell 2020-08-15 17:19:38 +02:00
parent 1d28ce58d9
commit 903e4d2add
4 changed files with 168 additions and 119 deletions

View File

@ -1,17 +1,15 @@
#include <FT817_NBS.h> #include <FT817_NBS.h>
FT817_NBS::FT817_NBS(SoftwareSerial *connection){ FT817_NBS::FT817_NBS(SoftwareSerial *connection) { serial = connection; }
serial = connection;
}
unsigned long FT817_NBS::bcdToInt(uint8_t bcd){ unsigned long FT817_NBS::bcdToInt(uint8_t bcd) {
int byte = (bcd & 0xF0) >> 4; int byte = (bcd & 0xF0) >> 4;
byte *= 10; byte *= 10;
byte += bcd & 0x0F; byte += bcd & 0x0F;
return byte; return byte;
} }
uint8_t FT817_NBS::intToBcd(unsigned long value){ uint8_t FT817_NBS::intToBcd(unsigned long value) {
unsigned long tens = value / 10; unsigned long tens = value / 10;
value -= tens * 10; value -= tens * 10;
unsigned long singles = value; unsigned long singles = value;
@ -20,7 +18,7 @@ uint8_t FT817_NBS::intToBcd(unsigned long value){
return returnValue; return returnValue;
} }
unsigned long FT817_NBS::getDevicer(int step){ unsigned long FT817_NBS::getDevicer(int step) {
switch (step) { switch (step) {
case 0: case 0:
return 1000000; return 1000000;
@ -35,49 +33,50 @@ unsigned long FT817_NBS::getDevicer(int step){
return 1; return 1;
break; break;
default: default:
//Serial.println("SHIT"); //CAN'T HAPPEN // Serial.println("SHIT"); //CAN'T HAPPEN
return 1; return 1;
break; break;
} }
} }
FT817_NBS::SignalMode FT817_NBS::getSignalMode(uint8_t numericValue){ FT817_NBS::SignalMode FT817_NBS::getSignalMode(uint8_t numericValue) {
switch (numericValue){ switch (numericValue) {
case 0x0: case 0x0:
return FT817_NBS::SignalMode::LSB; return FT817_NBS::SignalMode::LSB;
break; break;
case 0x01: case 0x01:
return FT817_NBS::SignalMode::USB; return FT817_NBS::SignalMode::USB;
break; break;
case 0x02: case 0x02:
return FT817_NBS::SignalMode::CW; return FT817_NBS::SignalMode::CW;
break; break;
case 0x03: case 0x03:
return FT817_NBS::SignalMode::CWR; return FT817_NBS::SignalMode::CWR;
break; break;
case 0x4: case 0x4:
return FT817_NBS::SignalMode::AM; return FT817_NBS::SignalMode::AM;
break; break;
case 0x6: case 0x6:
return FT817_NBS::SignalMode::WFM; return FT817_NBS::SignalMode::WFM;
break; break;
case 0x8: case 0x8:
return FT817_NBS::SignalMode::FM; return FT817_NBS::SignalMode::FM;
break; break;
case 0xA: case 0xA:
return FT817_NBS::SignalMode::DIG; return FT817_NBS::SignalMode::DIG;
break; break;
case 0xC: case 0xC:
return FT817_NBS::SignalMode::PKT; return FT817_NBS::SignalMode::PKT;
break; break;
default: default:
return FT817_NBS::SignalMode::UNKNOWN; return FT817_NBS::SignalMode::UNKNOWN;
break; break;
} }
} }
void FT817_NBS::convertFromValueToBcd(uint8_t *buffer, unsigned long actualValue){ void FT817_NBS::convertFromValueToBcd(uint8_t *buffer,
for(int partsLeft = 0;partsLeft < 4; partsLeft++){ unsigned long actualValue) {
for (int partsLeft = 0; partsLeft < 4; partsLeft++) {
unsigned long part = actualValue / getDevicer(partsLeft); unsigned long part = actualValue / getDevicer(partsLeft);
actualValue -= part * getDevicer(partsLeft); actualValue -= part * getDevicer(partsLeft);
uint8_t bcd = intToBcd(part); uint8_t bcd = intToBcd(part);
@ -85,9 +84,9 @@ void FT817_NBS::convertFromValueToBcd(uint8_t *buffer, unsigned long actualValue
} }
} }
unsigned long FT817_NBS::convertFromBcdToValue(uint8_t *buffer){ unsigned long FT817_NBS::convertFromBcdToValue(uint8_t *buffer) {
unsigned long actualValue = 0; unsigned long actualValue = 0;
for(int partsleft = 0; partsleft < 4; partsleft++){ for (int partsleft = 0; partsleft < 4; partsleft++) {
unsigned long multiplier = getDevicer(partsleft); unsigned long multiplier = getDevicer(partsleft);
unsigned long partValue = bcdToInt(buffer[partsleft]); unsigned long partValue = bcdToInt(buffer[partsleft]);
actualValue += (partValue * multiplier); actualValue += (partValue * multiplier);
@ -95,34 +94,34 @@ unsigned long FT817_NBS::convertFromBcdToValue(uint8_t *buffer){
return actualValue; return actualValue;
} }
void FT817_NBS::clearAvailableBytes(){ void FT817_NBS::clearAvailableBytes() {
if(serial->available() != 0){ //Emptying ft817.available() if (serial->available() != 0) { // Emptying ft817.available()
uint8_t throwAwayBuffer[serial->available()]; uint8_t throwAwayBuffer[serial->available()];
serial->readBytes(&throwAwayBuffer[0], serial->available()); serial->readBytes(&throwAwayBuffer[0], serial->available());
} }
} }
void FT817_NBS::sendCommand(uint8_t *bytes, size_t len){ void FT817_NBS::sendCommand(uint8_t *bytes, size_t len) {
for (unsigned int i = 0; i < len; i++){ for (unsigned int i = 0; i < len; i++) {
serial->write(bytes[i]); serial->write(bytes[i]);
//Serial.print(String(bytes[i], HEX)); // Serial.print(String(bytes[i], HEX));
delay(1); delay(1);
} }
} }
void FT817_NBS::toggleAB(){ void FT817_NBS::toggleAB() {
clearAvailableBytes(); clearAvailableBytes();
uint8_t data[] = {0x0,0x0,0x0,0x0,0x81}; uint8_t data[] = {0x0, 0x0, 0x0, 0x0, 0x81};
sendCommand(&data[0], sizeof(data)); sendCommand(&data[0], sizeof(data));
} }
FT817_NBS::Frequency FT817_NBS::getFrequency(){ FT817_NBS::Frequency FT817_NBS::getFrequency() {
clearAvailableBytes(); clearAvailableBytes();
uint8_t data[] = {0x0,0x0,0x0,0x0,0x3}; uint8_t data[] = {0x0, 0x0, 0x0, 0x0, 0x3};
sendCommand(&data[0], sizeof(data)); sendCommand(&data[0], sizeof(data));
delay(10); delay(10);
uint8_t buffer[5]; uint8_t buffer[5];
serial->readBytes(&buffer[0], sizeof(buffer)); serial->readBytes(&buffer[0], sizeof(buffer));
FT817_NBS::Frequency frequency; FT817_NBS::Frequency frequency;
@ -131,7 +130,7 @@ FT817_NBS::Frequency FT817_NBS::getFrequency(){
return frequency; return frequency;
} }
void FT817_NBS::setFrequency(unsigned long frequency){ void FT817_NBS::setFrequency(unsigned long frequency) {
clearAvailableBytes(); clearAvailableBytes();
uint8_t data[5]; uint8_t data[5];
convertFromValueToBcd(&data[0], frequency); convertFromValueToBcd(&data[0], frequency);
@ -139,21 +138,20 @@ void FT817_NBS::setFrequency(unsigned long frequency){
sendCommand(&data[0], sizeof(data)); sendCommand(&data[0], sizeof(data));
} }
void FT817_NBS::setMode(FT817_NBS::SignalMode mode){ void FT817_NBS::setMode(FT817_NBS::SignalMode mode) {
if(mode == SignalMode::UNKNOWN || mode == SignalMode::WFM){ if (mode == SignalMode::UNKNOWN || mode == SignalMode::WFM) {
return; return;
} }
uint8_t value = (uint8_t) mode; uint8_t value = (uint8_t)mode;
uint8_t data[5] = {value, 0x0, 0x0, 0x0, 0x7}; uint8_t data[5] = {value, 0x0, 0x0, 0x0, 0x7};
sendCommand(&data[0], sizeof(data)); sendCommand(&data[0], sizeof(data));
} }
void FT817_NBS::setSplit(bool on){ void FT817_NBS::setSplit(bool on) {
uint8_t data[5] = {0x0, 0x0, 0x0, 0x0}; uint8_t data[5] = {0x0, 0x0, 0x0, 0x0};
if(on){ if (on) {
data[4] = 0x2; data[4] = 0x2;
} } else {
else{
data[4] = 0x82; data[4] = 0x82;
} }
sendCommand(&data[0], sizeof(data)); sendCommand(&data[0], sizeof(data));

View File

@ -6,7 +6,18 @@
class FT817_NBS { class FT817_NBS {
public: public:
enum SignalMode {LSB = 0x0, USB = 0x1, CW = 0x2, CWR = 0x3, AM = 0x4, WFM = 0x6, FM = 0x8, DIG = 0xA, PKT = 0xC, UNKNOWN}; enum SignalMode {
LSB = 0x0,
USB = 0x1,
CW = 0x2,
CWR = 0x3,
AM = 0x4,
WFM = 0x6,
FM = 0x8,
DIG = 0xA,
PKT = 0xC,
UNKNOWN
};
private: private:
SoftwareSerial *serial; SoftwareSerial *serial;
@ -26,7 +37,7 @@ public:
unsigned long frequency; unsigned long frequency;
FT817_NBS::SignalMode mode; FT817_NBS::SignalMode mode;
}; };
FT817_NBS::Frequency getFrequency(); FT817_NBS::Frequency getFrequency();
void setFrequency(unsigned long frequency); void setFrequency(unsigned long frequency);
void toggleAB(); void toggleAB();

View File

@ -12,3 +12,14 @@
platform = atmelavr platform = atmelavr
board = uno board = uno
framework = arduino framework = arduino
; upload_protocol = stk500v2
upload_protocol = stk500v1
; edit these lines
upload_port = /dev/tty.usbmodem14101
upload_speed = 19200
; each flag in a new line
upload_flags =
-P$UPLOAD_PORT
-b$UPLOAD_SPEED

View File

@ -1,13 +1,20 @@
#include <Arduino.h> #include <Arduino.h>
#include <SoftwareSerial.h>
#include <FT817_NBS.h> #include <FT817_NBS.h>
#include <SoftwareSerial.h>
#define SET_FREQ 4 #define LOWER_FREQ_BEACON A0
#define SWITCH_AB 5 #define INIT A1
#define SWITCH_USB_CW 7 #define HIGHER_FREQ_BEACON A2
#define INIT 9 #define SWITCH_USB_CW A3
#define LOWER_FREQ_BEACON 6 #define SET_FREQ A4
#define HIGHER_FREQ_BEACON 8 #define SWITCH_AB A5
#define LED_LOWER_FREQ_BEACON 4
#define LED_INIT 5
#define LED_HIGHER_FREQ_BEACON 6
#define LED_SWITCH_USB_CW 7
#define LED_SET_FREQ 8
#define LED_SWITCH_AB 9
SoftwareSerial radio = SoftwareSerial(2, 3); SoftwareSerial radio = SoftwareSerial(2, 3);
FT817_NBS ft817(&radio); FT817_NBS ft817(&radio);
@ -17,6 +24,8 @@ void switchUsbCw();
void initRadio(); void initRadio();
bool setBeaconHigh(); bool setBeaconHigh();
bool setBeaconLow(); bool setBeaconLow();
void checkSync();
void slowBlinkerClock();
void setup() { void setup() {
// put your setup code here, to run once: // put your setup code here, to run once:
@ -28,6 +37,15 @@ void setup() {
pinMode(INIT, INPUT_PULLUP); pinMode(INIT, INPUT_PULLUP);
pinMode(HIGHER_FREQ_BEACON, INPUT_PULLUP); pinMode(HIGHER_FREQ_BEACON, INPUT_PULLUP);
pinMode(LOWER_FREQ_BEACON, INPUT_PULLUP); pinMode(LOWER_FREQ_BEACON, INPUT_PULLUP);
pinMode(LED_INIT, OUTPUT);
pinMode(LED_SET_FREQ, OUTPUT);
digitalWrite(LED_INIT, HIGH);
delay(500);
digitalWrite(LED_INIT, LOW);
digitalWrite(LED_SET_FREQ, HIGH);
delay(500);
digitalWrite(LED_SET_FREQ, LOW);
} }
bool pressBlockSetFreq = false; bool pressBlockSetFreq = false;
@ -36,123 +54,118 @@ bool pressBlockSwitchUsbCW = false;
bool pressBlockInit = false; bool pressBlockInit = false;
bool pressBlockLowerFreqBeacon = false; bool pressBlockLowerFreqBeacon = false;
bool pressBlockHigherFreqBeacon = false; bool pressBlockHigherFreqBeacon = false;
bool slowBlinker = false;
unsigned long pressLengthInit = 0; unsigned long pressLengthInit = 0;
unsigned long lastSyncFrequency = 0;
unsigned long lastBlinkToggle = 0;
void loop() { void loop() {
// put your main code here, to run repeatedly: // put your main code here, to run repeatedly:
if (digitalRead(SET_FREQ) == LOW && !pressBlockSetFreq){ if (digitalRead(SET_FREQ) == LOW && !pressBlockSetFreq) {
pressBlockSetFreq = true; pressBlockSetFreq = true;
setFreq(); setFreq();
} } else if (digitalRead(SET_FREQ) != LOW) {
else if(digitalRead(SET_FREQ) != LOW){
pressBlockSetFreq = false; pressBlockSetFreq = false;
delay(20); delay(20);
} }
if (digitalRead(SWITCH_AB) == LOW && !pressBlockSwitchAB){ if (digitalRead(SWITCH_AB) == LOW && !pressBlockSwitchAB) {
ft817.toggleAB(); ft817.toggleAB();
pressBlockSwitchAB = true; pressBlockSwitchAB = true;
} else if (digitalRead(SWITCH_AB) != LOW) {
}
else if(digitalRead(SWITCH_AB) != LOW){
pressBlockSwitchAB = false; pressBlockSwitchAB = false;
delay(20); delay(20);
} }
if (digitalRead(SWITCH_USB_CW) == LOW && !pressBlockSwitchUsbCW){ if (digitalRead(SWITCH_USB_CW) == LOW && !pressBlockSwitchUsbCW) {
switchUsbCw(); switchUsbCw();
pressBlockSwitchUsbCW = true; pressBlockSwitchUsbCW = true;
} else if (digitalRead(SWITCH_USB_CW) != LOW) {
}
else if(digitalRead(SWITCH_USB_CW) != LOW){
pressBlockSwitchUsbCW = false; pressBlockSwitchUsbCW = false;
delay(20); delay(20);
} }
if(digitalRead(INIT) == LOW && !pressBlockInit){ if (digitalRead(INIT) == LOW && !pressBlockInit) {
pressLengthInit = millis() + 1000; pressLengthInit = millis() + 1000;
pressBlockInit = true; pressBlockInit = true;
} } else if (digitalRead(INIT) == LOW) {
else if(digitalRead(INIT) == LOW) { if (pressLengthInit != 0 && pressLengthInit <= millis()) {
if(pressLengthInit != 0 && pressLengthInit <= millis()){
pressLengthInit = 0; pressLengthInit = 0;
initRadio(); initRadio();
} }
} } else {
else{
pressLengthInit = 0; pressLengthInit = 0;
pressBlockInit = false; pressBlockInit = false;
delay(20); delay(20);
} }
if (digitalRead(HIGHER_FREQ_BEACON) == LOW && !pressBlockHigherFreqBeacon){ if (digitalRead(HIGHER_FREQ_BEACON) == LOW && !pressBlockHigherFreqBeacon) {
setBeaconHigh(); setBeaconHigh();
pressBlockHigherFreqBeacon = true; pressBlockHigherFreqBeacon = true;
} else if (digitalRead(HIGHER_FREQ_BEACON) != LOW) {
}
else if(digitalRead(HIGHER_FREQ_BEACON) != LOW){
pressBlockHigherFreqBeacon = false; pressBlockHigherFreqBeacon = false;
delay(20); delay(20);
} }
if (digitalRead(LOWER_FREQ_BEACON) == LOW && !pressBlockLowerFreqBeacon){ if (digitalRead(LOWER_FREQ_BEACON) == LOW && !pressBlockLowerFreqBeacon) {
setBeaconLow(); setBeaconLow();
pressBlockLowerFreqBeacon = true; pressBlockLowerFreqBeacon = true;
} else if (digitalRead(LOWER_FREQ_BEACON) != LOW) {
}
else if(digitalRead(LOWER_FREQ_BEACON) != LOW){
pressBlockLowerFreqBeacon = false; pressBlockLowerFreqBeacon = false;
delay(20); delay(20);
} }
checkSync();
slowBlinkerClock();
} }
void setFreq(){ void setFreq() {
unsigned long frequency = ft817.getFrequency().frequency; unsigned long rxFrequency = ft817.getFrequency().frequency;
if(frequency < 28850000){ if (rxFrequency < 28850000) {
Serial.println("Please go into the 70 cm Band!"); Serial.println("Please go into the 70 cm Band!");
return; return;
} }
delay(300); delay(300);
unsigned long newFrequency = frequency - 28850000; unsigned long txFrequency = rxFrequency - 28850000;
lastSyncFrequency = rxFrequency;
ft817.toggleAB(); ft817.toggleAB();
delay(300); delay(300);
ft817.setFrequency(newFrequency); ft817.setFrequency(txFrequency);
delay(300); delay(300);
ft817.toggleAB(); ft817.toggleAB();
} }
void switchUsbCw(){ void switchUsbCw() {
FT817_NBS::SignalMode mode = ft817.getFrequency().mode; FT817_NBS::SignalMode mode = ft817.getFrequency().mode;
FT817_NBS::SignalMode newMode; FT817_NBS::SignalMode newMode;
if (mode == FT817_NBS::SignalMode::USB){ if (mode == FT817_NBS::SignalMode::USB) {
newMode = FT817_NBS::SignalMode::CW; newMode = FT817_NBS::SignalMode::CW;
} } else {
else{
newMode = FT817_NBS::SignalMode::USB; newMode = FT817_NBS::SignalMode::USB;
} }
delay(300); delay(300);
ft817.setMode(newMode); ft817.setMode(newMode);
delay(300); delay(300);
ft817.toggleAB(); ft817.toggleAB();
delay(300); delay(300);
ft817.setMode(newMode); ft817.setMode(newMode);
delay(300); delay(300);
ft817.toggleAB(); ft817.toggleAB();
} }
void initRadio(){ void initRadio() {
ft817.setMode(FT817_NBS::SignalMode::USB); ft817.setMode(FT817_NBS::SignalMode::USB);
delay(300); delay(300);
ft817.setFrequency(14420000); ft817.setFrequency(14420000);
@ -161,40 +174,56 @@ void initRadio(){
delay(300); delay(300);
ft817.setMode(FT817_NBS::SignalMode::USB); ft817.setMode(FT817_NBS::SignalMode::USB);
delay(300); delay(300);
ft817.setFrequency(43250000); //43274500, 43250000 ft817.setFrequency(43250000); // 43274500, 43250000
delay(300); delay(300);
ft817.setSplit(true); ft817.setSplit(true);
} }
bool setBeacon(unsigned long frequency, FT817_NBS::SignalMode mode, bool firstVFO){ bool setBeacon(unsigned long frequency, FT817_NBS::SignalMode mode,
bool firstVFO) {
unsigned long result = ft817.getFrequency().frequency; unsigned long result = ft817.getFrequency().frequency;
if(result >= 43000000 && result <= 44000000){ if (result >= 43000000 && result <= 44000000) {
delay(300); delay(300);
ft817.setMode(mode); ft817.setMode(mode);
delay(300); delay(300);
ft817.setFrequency(frequency); ft817.setFrequency(frequency);
return true; return true;
} } else {
else{
delay(300); delay(300);
ft817.toggleAB(); ft817.toggleAB();
if(firstVFO){ if (firstVFO) {
delay(300); delay(300);
return setBeacon(frequency, mode, false); return setBeacon(frequency, mode, false);
} } else {
else{ Serial.println(
Serial.println("Could not set beacon. Please initialise the radio first."); "Could not set beacon. Please initialise the radio first.");
return false; return false;
} }
} }
} }
bool setBeaconHigh(){ bool setBeaconHigh() {
return setBeacon(43274500, FT817_NBS::SignalMode::USB, true); return setBeacon(43274500, FT817_NBS::SignalMode::USB, true);
} }
bool setBeaconLow(){ bool setBeaconLow() {
return setBeacon(43250000, FT817_NBS::SignalMode::CW, true); return setBeacon(43250000, FT817_NBS::SignalMode::CW, true);
} }
void checkSync() {
unsigned long latest_rxFrequency = ft817.getFrequency().frequency;
if (abs(latest_rxFrequency - lastSyncFrequency) >= 250) {
digitalWrite(LED_SET_FREQ, HIGH);
} else if (abs(latest_rxFrequency - lastSyncFrequency) == 0) {
digitalWrite(LED_SET_FREQ, LOW);
} else if (abs(latest_rxFrequency - lastSyncFrequency) < 250) {
digitalWrite(LED_SET_FREQ, slowBlinker);
}
}
void slowBlinkerClock() {
if ((millis() - lastBlinkToggle) >= 1000) {
lastBlinkToggle = millis();
slowBlinker = !slowBlinker;
}
}