Initalizaion Alpha Two

master
Jay 3 years ago
parent 84d1886469
commit b25debc4e0

@ -1,5 +1,5 @@
/* /*
HamHead CI-V Alpha Module - Initialization HamHead CI-V Alpha Module
This is a test of multiple things, an initialization routine This is a test of multiple things, an initialization routine
as well as working with pointers. Pointers was easy; getting as well as working with pointers. Pointers was easy; getting
@ -8,15 +8,13 @@ variables and such. Pointers are used so that we can just work
on one VFO variable that's mapped to whatever the current one on one VFO variable that's mapped to whatever the current one
is. is.
Echo and ACK data are simply dropped right now. I have some This now gets the current VFO mode, writes it to a variable, then
plans of maybe using echos to keep VFO in sync. But I will switch cases it to set a string. I may do something similar to
determine this as I actually build functions. automatically handle "valid" CI-V frames. I need to anyway for
transcieve data.
We now automatically drop the Echo and ACK ($FB), but you
MUST call getdata() to do so.
*/ */
#define DEBUG 0 #define DEBUG 0 //enables or disables debug(), debug2(), and debugln() debugging output
#if DEBUG == 1 #if DEBUG == 1
#define debug(x) Serial.print(x) #define debug(x) Serial.print(x)
#define debug2(x,y) Serial.print(x,y) #define debug2(x,y) Serial.print(x,y)
@ -33,16 +31,18 @@ MUST call getdata() to do so.
const byte numBytes = 32; const byte numBytes = 32;
long dec[6]; long dec[6];
byte rxbytes[numBytes]; byte rxbytes[numBytes];
unsigned long vfoa; unsigned long vfoa; // VFO A
unsigned long vfob; unsigned long vfob; // VFO B
unsigned long vfos; unsigned long vfos; // starting VFO
//byte civ[9]; byte civ[9] = {0xFE, 0xFE, 0x88, 0xE0}; // civ array with preamble
byte civ[9] = {0xFE, 0xFE, 0x88, 0xE0, 0xFF, 0xFF}; byte endbyte = 0xFD; // I'm not keeping the endbyte in the array.
byte endbyte = 0xFD; unsigned long *v; // pointer for whatever VFO we're in
unsigned long *v; String *m; // pointer for current VFO's mode
boolean newdata = false; boolean newdata = false;
int bc; int bc;
long bcd[6]; long bcd[6];
String vam;
String vbm;
void setup() { void setup() {
Serial1.begin(19200); Serial1.begin(19200);
@ -53,17 +53,24 @@ debugln("Getting Starting VFO...");
v = &vfos; v = &vfos;
getvfo(); getvfo();
v = &vfoa; v = &vfoa;
m = &vam;
setvfo(0x00); setvfo(0x00);
getvfo(); getvfo();
//debugln(); getmode();
v = &vfob; v = &vfob;
m = &vbm;
setvfo(0x01); setvfo(0x01);
getvfo(); getvfo();
getmode();
Serial.print("VFO A: "); Serial.print("VFO A: ");
Serial.print(vfoa, DEC); Serial.print(vfoa, DEC);
Serial.print(" - ");
Serial.print(vam);
Serial.println(); Serial.println();
Serial.print("VFO B: "); Serial.print("VFO B: ");
Serial.print(vfob, DEC); Serial.print(vfob, DEC);
Serial.print(" - ");
Serial.print(vbm);
debugln(); debugln();
debugln("Reverting to initial VFO."); debugln("Reverting to initial VFO.");
setstartvfo(); setstartvfo();
@ -84,7 +91,7 @@ void getdata() {
bc = 0; // i don't trust myself bc = 0; // i don't trust myself
} else if (rb == 0xFD) { // end of the frame } else if (rb == 0xFD) { // end of the frame
rxbytes[bc] = '\0'; // terminate the string rxbytes[bc] = '\0'; // terminate the string
if (rxbytes[0]==0x88 || rxbytes[2] == 0xFB) { if (rxbytes[0]==0x88 || rxbytes[2] == 0xFB) { // check the array for echo at index 0 or ACK at index 3
newdata = false; // auto-echo ditch&ack newdata = false; // auto-echo ditch&ack
bc = 0; bc = 0;
} }
@ -101,10 +108,10 @@ void getdata() {
long gogovfo() { long gogovfo() {
int i = 0; int i = 0;
long ggv; long ggv;
#ifdef MODE731 #ifdef MODE731 // The IC-731/735, and I assume the 765/CI-IV, only send 4 bytes for frequency. We only need to account for index starting at 0.
bc--; bc--;
#else #else
bc -=2; bc -=2; // Everything after the 735 sends 5 bytes (unless you put the radio in 731 mode). We're HF only; this ditches the extra byte and index adjustment.
#endif #endif
for (int x = bc; x > 2; x--) { for (int x = bc; x > 2; x--) {
bcd[i] = (((rxbytes[x] >> 4) *10) + (rxbytes[x]&0xF)); bcd[i] = (((rxbytes[x] >> 4) *10) + (rxbytes[x]&0xF));
@ -113,20 +120,31 @@ long gogovfo() {
newdata = false; newdata = false;
return ggv; return ggv;
} }
void swapvfo() {
debugln("Sending VFO Swap");
send7(0x07, 0xB0); // VFO, SWAP A/B
Serial1.flush();
delay(50); // I'm assuming this is needed to wait for the radio to send data
getdata(); // I might be able to avoid all delay() if I do something with my loop.
}
void setvfo(byte vfo) { void setvfo(byte vfo) {
//byte zz;
if (vfo == 0x00) debugln ("Setting VFO A"); if (vfo == 0x00) debugln ("Setting VFO A");
else debugln("Setting VFO B"); else debugln("Setting VFO B");
send7(0x07, vfo); send7(0x07, vfo); // VFO, A or B (0x00 or 0x01)
Serial1.flush(); Serial1.flush();
delay(50); delay(50);
getdata(); // drop the echo getdata(); // drop the echo
// newdata=false;
// getdata(); // drop the ack
// newdata=false;
} }
/*
the send# functions just replace the appropiate array index with whatever
was passed to it. It'd be nice if I could have one function with an additional
value of bytes; but something something "expects 2, sends 1" arguement error.
*/
void send6(byte cmd) { void send6(byte cmd) {
civ[4]=cmd; civ[4]=cmd;
Serial1.write(civ,5); Serial1.write(civ,5);
@ -146,19 +164,58 @@ void send7(byte cmd, byte data) {
void getvfo() { void getvfo() {
debugln("Sending VFO Read"); debugln("Sending VFO Read");
send6(0x03); send6(0x03); // 03 is VFO read
Serial1.flush(); Serial1.flush();
delay(50); delay(50);
// getdata(); // drop the echo
// newdata=false;
getdata(); // preload the vfo getdata(); // preload the vfo
*v = gogovfo(); // process and update *v = gogovfo(); // process and update
} }
void getmode() {
int mode;
debugln("Getting Mode.");
send6(0x04); // 04 is mode read
getdata();
mode = (int) rxbytes[3]; // it's easy enough to just deal with mode as integer
switch (mode) {
case 0:
*m = "LSB";
break;
case 1:
*m = "USB";
break;
case 2:
*m = "AM";
break;
case 3:
*m = "CW";
break;
case 4:
*m = "RTTY";
break;
case 5:
*m = "FM";
break;
case 7:
*m = "CW-R";
break;
case 8:
*m = "RTTY-R";
break;
case 23:
*m = "D-Star DV";
break;
default:
*m = "INVALID";
break;
}
newdata = false;
}
void setstartvfo() { void setstartvfo() {
Serial.println(); Serial.println();
if (vfos == vfoa) { if (vfos == vfoa) {
Serial.println("Started on A"); Serial.println("Started on A");
setvfo(0x00);} setvfo(0x00);}
else Serial.println("Staying on B"); else Serial.println("Staying on B");
} }
Loading…
Cancel
Save