Not working. No Matching Function to call to...

This commit is contained in:
Wolfgang Bachschwell 2020-05-08 22:00:26 +02:00
parent 032e8cc126
commit ffb8885771

View File

@ -1,21 +1,20 @@
#include <Arduino.h> #include <Arduino.h>
#include <SoftwareSerial.h> #include <SoftwareSerial.h>
#include <FT817_NBS.h>
#define SET_FREQ 4 #define SET_FREQ 4
#define SWITCH_AB 5 #define SWITCH_AB 5
SoftwareSerial ft817 = SoftwareSerial(2, 3); SoftwareSerial radio = SoftwareSerial(2, 3);
FT817_NBS ft817(radio);
String getMode(uint8_t byte);
unsigned long bcdToInt(uint8_t bcd);
void setFreq(); void setFreq();
void switchAB();
void convertFromValueToBCD(uint8_t *buffer, unsigned long actualValue);
void setup() { void setup() {
// put your setup code here, to run once: // put your setup code here, to run once:
ft817.begin(9600); radio.begin(9600);
ft817 = FT817_NBS(radio);
Serial.begin(9600); Serial.begin(9600);
pinMode(SET_FREQ, INPUT_PULLUP); pinMode(SET_FREQ, INPUT_PULLUP);
pinMode(SWITCH_AB, INPUT_PULLUP); pinMode(SWITCH_AB, INPUT_PULLUP);
@ -36,7 +35,7 @@ void loop() {
} }
if (digitalRead(SWITCH_AB) == LOW && !pressBlockSwitchAB){ if (digitalRead(SWITCH_AB) == LOW && !pressBlockSwitchAB){
switchAB(); ft817.toggleAB();
pressBlockSwitchAB = true; pressBlockSwitchAB = true;
} }
@ -48,162 +47,22 @@ void loop() {
} }
void sendCommand(uint8_t *bytes, size_t len){
for (unsigned int i = 0; i < len; i++){
ft817.write(bytes[i]);
Serial.print(String(bytes[i], HEX));
delay(1);
}
}
void switchAB(){
Serial.println(ft817.available());
if(ft817.available() != 0){ //Emptying ft817.available()
uint8_t throwAwayBuffer[ft817.available()];
ft817.readBytes(&throwAwayBuffer[0], ft817.available());
}
uint8_t bytes[] = {0x00,0x00,0x00,0x00,0x81};
sendCommand(&bytes[0], sizeof(bytes));
Serial.println();
}
void setFreq(){ void setFreq(){
Serial.println(ft817.available()); unsigned long frequency = ft817.getFrequency().frequency;
if(ft817.available() != 0){ //Emptying ft817.available()
uint8_t throwAwayBuffer[ft817.available()];
ft817.readBytes(&throwAwayBuffer[0], ft817.available());
}
uint8_t bytes[] = {0x00,0x00,0x00,0x00,0x03}; if(frequency < 28850000){
sendCommand(&bytes[0], sizeof(bytes)); Serial.println("Please go into the 70 cm Band!");
//return;
Serial.println();
uint8_t buffer[5];
ft817.readBytes(&buffer[0], sizeof(buffer));
String mode = getMode(buffer[4]);
Serial.print(String(buffer[0], HEX) + " ");
Serial.print(String(buffer[1], HEX) + " ");
Serial.print(String(buffer[2], HEX) + " ");
Serial.print(String(buffer[3], HEX) + " ");
Serial.println(String(buffer[4], HEX));
unsigned long receiveFrequency = 0;
receiveFrequency = bcdToInt(buffer[0]) * 1000000;
receiveFrequency += (bcdToInt(buffer[1]) * 10000);
receiveFrequency += (bcdToInt(buffer[2]) * 100);
receiveFrequency += bcdToInt(buffer[3]);
if (receiveFrequency < 28850000){
Serial.println("Please go into the 70cm Band! Data: " + String(receiveFrequency));
return; return;
} }
delay(300);
unsigned long newFrequency = frequency - 28850000;
unsigned long txFrequency = receiveFrequency - 28850000; ft817.toggleAB();
delay(300);
uint8_t sendBuffer[5]; ft817.setFrequency(newFrequency);
convertFromValueToBCD(&sendBuffer[0], txFrequency);
delay(300);
Serial.print(receiveFrequency); ft817.toggleAB();
Serial.write(0x20);
Serial.println(mode);
Serial.println(txFrequency);
Serial.print(String(sendBuffer[0], HEX) + " ");
Serial.print(String(sendBuffer[1], HEX) + " ");
Serial.print(String(sendBuffer[2], HEX) + " ");
Serial.println(String(sendBuffer[3], HEX));
bytes[4] = 0x81;
sendCommand(&bytes[0], sizeof(bytes));
Serial.println();
delay(100);
sendBuffer[4] = 0x01;
sendCommand(&sendBuffer[0], sizeof(sendBuffer));
Serial.println();
delay(100);
sendCommand(&bytes[0], sizeof(bytes));
Serial.println();
} }
String getMode(uint8_t byte){
switch (byte)
{
case 0x00:
return "LSB";
break;
case 0x01:
return "USB";
break;
case 0x02:
return "CW";
case 0x03:
return "CWR";
case 0x04:
return "AM";
case 0x06:
return "WFM";
case 0x08:
return "FM";
case 0x0A:
return "DIG";
case 0x0C:
return "PKT";
default:
return "IDENTIFICATION FAILURE";
break;
}
}
unsigned long bcdToInt(uint8_t bcd){
int byte = (bcd & 0xF0) >> 4;
byte *= 10;
byte += bcd & 0x0F;
return byte;
}
unsigned long getDevicer(int step){
switch (step) {
case 0:
return 1000000;
break;
case 1:
return 10000;
break;
case 2:
return 100;
break;
case 3:
return 1;
break;
default:
Serial.println("SHIT"); //CAN'T HAPPEN
return 1;
break;
}
}
uint8_t intToBcd(unsigned long value){
unsigned long tens = value / 10;
value -= tens * 10;
unsigned long singles = value;
uint8_t returnValue = (tens & 0xF) << 4;
returnValue = returnValue | (singles & 0xF);
return returnValue;
}
void convertFromValueToBCD(uint8_t *buffer, unsigned long actualValue){
for(int partsLeft = 0;partsLeft < 4; partsLeft++){
unsigned long part = actualValue / getDevicer(partsLeft);
actualValue -= part * getDevicer(partsLeft);
uint8_t bcd = intToBcd(part);
buffer[partsLeft] = bcd;
}
}