Use enums instead of hardcoded numbers

This commit is contained in:
Reed Nightingale 2020-05-03 17:45:43 -07:00
parent 8e4adbff72
commit c6d83beff0

View File

@ -57,7 +57,7 @@ enum OperatingMode_e : uint8_t {
LSB = 0x00, LSB = 0x00,
USB = 0x01, USB = 0x01,
CW = 0x02, CW = 0x02,
CWR = 0x03, CWR = 0x03,//CW-reverse aka LSB CW
AM = 0x04, AM = 0x04,
FM = 0x08, FM = 0x08,
DIG = 0x0A, DIG = 0x0A,
@ -79,7 +79,7 @@ enum CtcssDcsMode_e : uint8_t {
struct ReadRxStatus_t { struct ReadRxStatus_t {
//Bitfields are not defined by the standard to be portable, which is unfortunate //Bitfields are not defined by the standard to be portable, which is unfortunate
uint8_t Smeter : 4; uint8_t Smeter : 4;//0x00 = S0, 0x09 = S9, etc.
uint8_t Dummy : 1; uint8_t Dummy : 1;
uint8_t DiscriminatorCenteringOff : 1; uint8_t DiscriminatorCenteringOff : 1;
uint8_t CodeUnmatched : 1; uint8_t CodeUnmatched : 1;
@ -87,6 +87,7 @@ struct ReadRxStatus_t {
}; };
struct ReadTxStatus_t { struct ReadTxStatus_t {
//Bitfields are not defined by the standard to be portable, which is unfortunate
uint8_t PowerOutputMeter : 4; uint8_t PowerOutputMeter : 4;
uint8_t Dummy : 1; uint8_t Dummy : 1;
uint8_t SplitOff : 1; uint8_t SplitOff : 1;
@ -157,7 +158,7 @@ void writeFreq(unsigned long freq, uint8_t* cmd) {
// //
// [12][34][56][78] = 123.45678? Mhz // [12][34][56][78] = 123.45678? Mhz
// //
unsigned long readFreq(uint8_t* cmd) { uint32_t readFreq(uint8_t* cmd) {
// Pull off each of the digits // Pull off each of the digits
unsigned long ret = 0; unsigned long ret = 0;
for(uint8_t i = 0; i < 4; ++i){ for(uint8_t i = 0; i < 4; ++i){
@ -312,82 +313,82 @@ void catReadEEPRom(uint8_t* cat)
} }
void processCatCommand(uint8_t* cmd) { void processCatCommand(uint8_t* cmd) {
uint8_t response[5]; uint8_t response[FT817_MESSAGE_SIZE];
unsigned long f;
switch(cmd[CMD]){ switch(cmd[CMD]){
/* case 0x00: /* case Ft817Command_e::LockOn:
response[0]=0; response[0]=0;
Serial.write(response, 1); Serial.write(response, 1);
break; break;
*/ */
case 0x01: case Ft817Command_e::SetFrequency:
//set frequency {
f = readFreq(cmd); uint32_t f = readFreq(cmd);
setFrequency(f); setFrequency(f);
updateDisplay(); updateDisplay();
response[0]=0; response[0]=0;
Serial.write(response, 1); Serial.write(response, 1);
//sprintf(b, "set:%ld", f); break;
//printLine2(b); }
case Ft817Command_e::SplitOn:
globalSettings.splitOn = true;
break;
case Ft817Command_e::SplitOff:
globalSettings.splitOn = false;
break; break;
case 0x02: case Ft817Command_e::ReadFreqAndMode:
//split on //First 4 bytes are the frequency
globalSettings.splitOn = 1; writeFreq(GetActiveVfoFreq(),response);//bytes 0-3
break; //Last byte is the mode
case 0x82: if (VfoMode_e::VFO_MODE_USB == GetActiveVfoMode()){
//split off response[4] = OperatingMode_e::USB;
globalSettings.splitOn = 0; }
break; else{
response[4] = OperatingMode_e::LSB;
case 0x03: }
writeFreq(GetActiveVfoFreq(),response); // Put the frequency into the buffer
if (VfoMode_e::VFO_MODE_USB == GetActiveVfoMode())
response[4] = 0x01; //USB
else
response[4] = 0x00; //LSB
Serial.write(response,5); Serial.write(response,5);
//printLine2("cat:getfreq");
break; break;
case 0x07: // set mode case Ft817Command_e::OperatingMode:
if (cmd[P1] == 0x00 || cmd[P1] == 0x03) if(OperatingMode_e::LSB == cmd[P1] || OperatingMode_e::CWR == cmd[P1]){
SetActiveVfoMode(VfoMode_e::VFO_MODE_LSB); SetActiveVfoMode(VfoMode_e::VFO_MODE_LSB);
else }
else{
SetActiveVfoMode(VfoMode_e::VFO_MODE_USB); SetActiveVfoMode(VfoMode_e::VFO_MODE_USB);
}
response[0] = 0x00; response[0] = 0x00;
Serial.write(response, 1); Serial.write(response, 1);
setFrequency(GetActiveVfoFreq());
//printLine2("cat: mode changed"); setFrequency(GetActiveVfoFreq());//Refresh frequency to get new mode to take effect
//updateDisplay(); updateDisplay();
break; break;
case 0x08: // PTT On case Ft817Command_e::PttOn:
if (!globalSettings.txActive) { if (!globalSettings.txActive) {
response[0] = 0; response[0] = 0;
globalSettings.txCatActive = true; globalSettings.txCatActive = true;
startTx(TuningMode_e::TUNE_SSB); startTx(globalSettings.tuningMode);
updateDisplay(); }
} else { else {
response[0] = 0xf0; response[0] = 0xf0;
} }
Serial.write(response,1); Serial.write(response,1);
updateDisplay(); updateDisplay();
break; break;
case 0x88 : //PTT OFF case Ft817Command_e::PttOff:
if (globalSettings.txActive) { if (globalSettings.txActive) {
stopTx(); stopTx();
globalSettings.txCatActive = false;
} }
globalSettings.txCatActive = false;
response[0] = 0; response[0] = 0;
Serial.write(response,1); Serial.write(response,1);
updateDisplay(); updateDisplay();
break; break;
case 0x81: case Ft817Command_e::VfoToggle:
//toggle the VFOs
response[0] = 0; response[0] = 0;
if (Vfo_e::VFO_A == globalSettings.activeVfo){ if (Vfo_e::VFO_A == globalSettings.activeVfo){
globalSettings.activeVfo = Vfo_e::VFO_B; globalSettings.activeVfo = Vfo_e::VFO_B;
@ -399,38 +400,39 @@ void processCatCommand(uint8_t* cmd) {
updateDisplay(); updateDisplay();
break; break;
case 0xBB: //Read FT-817 EEPROM Data (for comfirtable) case 0xBB: //Read FT-817 EEPROM Data (for comfirtable)
catReadEEPRom(cmd); catReadEEPRom(cmd);
break; break;
case 0xe7 : case Ft817Command_e::ReadRxStatus:
// get receiver status, we have hardcoded this as //We don't have visibility into these values, so just hard code stuff
//as we dont' support ctcss, etc. ReadRxStatus_t reply_status;
response[0] = 0x09; reply_status.Dummy = 0;
reply_status.Smeter = 9;//S9
reply_status.SquelchSuppressionActive = 0;
reply_status.DiscriminatorCenteringOff = 1;
reply_status.CodeUnmatched = 0;
response[0] = *(uint8_t*)&reply_status;
Serial.write(response,1); Serial.write(response,1);
break; break;
case 0xf7: case Ft817Command_e::ReadTxStatus:
{ {
boolean isHighSWR = false; //We don't have visibility into some of these values, so just hard code stuff
boolean issplitOn = false; ReadTxStatus_t reply_status;
reply_status.Dummy = 0;
reply_status.HighSwrDetected = 0;
reply_status.PowerOutputMeter = 0xF;
reply_status.PttOff = !globalSettings.txActive;
reply_status.SplitOff = !globalSettings.splitOn;
/* response[0] = *(uint8_t*)&reply_status;
Inverted -> *ptt = ((p->tx_status & 0x80) == 0); <-- souce code in ft817.c (hamlib)
*/
response[0] = ((globalSettings.txActive ? 0 : 1) << 7) +
((isHighSWR ? 1 : 0) << 6) + //hi swr off / on
((issplitOn ? 1 : 0) << 5) + //Split on / off
(0 << 4) + //dummy data
0x08; //P0 meter data
Serial.write(response, 1); Serial.write(response, 1);
}
break; break;
}
default: default:
//somehow, get this to print the four uint8_ts
ultoa(*((unsigned long *)cmd), c, 16);
response[0] = 0x00; response[0] = 0x00;
Serial.write(response[0]); Serial.write(response[0]);
} }