Got basic 3-way comm (CAT-Teensy-Raduino) working. CAT commands are received via Serial by the Teensy. Data is passed on to the Raduino via I2C. Had to add an intermediate step in the protocol in order for the Raduino to request a byte as a flag for whether or not any changed data was coming, and then if so, request the changed data. There are certainly some optimizations that could be made on this number. Currently, the Raduino code is very clunky. In addition, the Rig and RigState classes have deteriorated somewhat.

This commit is contained in:
Rob French 2021-02-10 00:10:24 -06:00
parent aeeec69daf
commit c3cc9a7cf7
5 changed files with 69 additions and 19 deletions

View File

@ -1006,6 +1006,13 @@ void idle_process()
rigState.flags |= UBITX_VFOB_FLAG; rigState.flags |= UBITX_VFOB_FLAG;
} }
doRaduinoToTeensy(&rigState); doRaduinoToTeensy(&rigState);
if (vfoActive == VFO_A) {
if (rigState.vfo[0] != frequency) {
setFrequency(rigState.vfo[0]);
} else if (vfoActive == VFO_B) {
setFrequency(rigState.vfo[1]);
}
}
//S-Meter Display //S-Meter Display
if (((displayOption1 & 0x08) == 0x08 && (sdrModeOn == 0)) && (++checkCountSMeter > SMeterLatency)) if (((displayOption1 & 0x08) == 0x08 && (sdrModeOn == 0)) && (++checkCountSMeter > SMeterLatency))

View File

@ -312,6 +312,7 @@ void doRaduinoToTeensy(UBitxRigState* r) {
Wire.write(ptr, sizeof(UBitxRigState)); Wire.write(ptr, sizeof(UBitxRigState));
Wire.endTransmission(); Wire.endTransmission();
Serial.println("BEFORE:");
Serial.print("VFO A: "); Serial.print("VFO A: ");
Serial.print(r->vfo[0]); Serial.print(r->vfo[0]);
Serial.print(", VFO B: "); Serial.print(", VFO B: ");
@ -320,17 +321,32 @@ void doRaduinoToTeensy(UBitxRigState* r) {
Serial.print(sizeof(UBitxRigState)); Serial.print(sizeof(UBitxRigState));
Serial.println(); Serial.println();
Wire.requestFrom(I2CMETER_ADDR, sizeof(UBitxRigState)); // First we need to see if there's any updated state.
Wire.requestFrom(I2CMETER_ADDR, sizeof(uint8_t));
UBitxRigState tmp;
int len = 0; int len = 0;
ptr = (uint8_t*)&tmp; int readflag = Wire.read();
if (readflag != 0) {
Wire.requestFrom(I2CMETER_ADDR, sizeof(UBitxRigState));
while (Wire.available() > 0) { UBitxRigState tmp;
uint8_t b = Wire.read();
if (len < sizeof(UBitxRigState)) { //int len = 0;
ptr[len++] = b; //ptr = (uint8_t*)&tmp;
while (Wire.available() > 0) {
uint8_t b = Wire.read();
if (len < sizeof(UBitxRigState)) {
ptr[len++] = b;
}
} }
} }
Serial.println("AFTER:");
Serial.print("VFO A: ");
Serial.print(r->vfo[0]);
Serial.print(", VFO B: ");
Serial.print(r->vfo[1]);
Serial.print(", Data Size: ");
Serial.print(len);
Serial.println();
} }

View File

@ -123,6 +123,19 @@ class UBitxRig {
uint8_t* const stateAsBytes() const { return (uint8_t* const)&state; } uint8_t* const stateAsBytes() const { return (uint8_t* const)&state; }
inline void updateState(UBitxRigState& r, bool isCAT = false) {
if ((r.vfo[0] == state.vfo[0]) &&
(r.vfo[1] == state.vfo[1]) &&
(r.rit == state.rit) &&
(r.xit == state.xit) &&
(r.flags == state.flags)) {
return;
} else {
state = r;
lastUpdatedBy = isCAT ? CATSource : RaduinoSource;
}
}
private: private:
bool autoInfo = false; bool autoInfo = false;
UpdateSource lastUpdatedBy = NoSource; UpdateSource lastUpdatedBy = NoSource;

View File

@ -177,9 +177,9 @@ void TS590_FT::handleCommand(const char* cmd) {
switch (cmd[2]) { switch (cmd[2]) {
case 0: case 0:
if (rig()->isVFOA()) { if (rig()->isVFOA()) {
rig()->splitOff(); rig()->splitOff(true);
} else if (rig()->isVFOB()) { } else if (rig()->isVFOB()) {
rig()->splitOn(); rig()->splitOn(true);
} else { } else {
setSyntaxError(); setSyntaxError();
} }
@ -187,9 +187,9 @@ void TS590_FT::handleCommand(const char* cmd) {
case 1: case 1:
if (rig()->isVFOA()) { if (rig()->isVFOA()) {
rig()->splitOn(); rig()->splitOn(true);
} else if (rig()->isVFOB()) { } else if (rig()->isVFOB()) {
rig()->splitOff(); rig()->splitOff(true);
} else { } else {
setSyntaxError(); setSyntaxError();
} }

View File

@ -363,6 +363,8 @@ void setup()
//Serial1.println("Start..."); //Serial1.println("Start...");
} }
bool sentRigInfFlag = false;
/*! /*!
@brief Receive a command via I2C. The most recent command will be received, which will @brief Receive a command via I2C. The most recent command will be received, which will
indicate which data the DSP should be preparing to return. indicate which data the DSP should be preparing to return.
@ -373,16 +375,20 @@ void i2cReceiveEvent(size_t numBytes)
{ {
int readCommand = 0; int readCommand = 0;
bool exitLoop = false; bool exitLoop = false;
UBitxRigState tmpState;
while (Wire1.available() > 0 && !exitLoop) { while (Wire1.available() > 0 && !exitLoop) {
readCommand = Wire1.read(); readCommand = Wire1.read();
if (readCommand == I2CMETER_RIGINF) { if (readCommand == I2CMETER_RIGINF) {
size_t len = 0; size_t len = 0;
uint8_t* const ptr = Rig.stateAsBytes(); uint8_t* const ptr = (uint8_t* const)&tmpState;
while ((Wire1.available() > 0) && (len < sizeof(UBitxRigState))) { while ((Wire1.available() > 0) && (len < sizeof(UBitxRigState))) {
ptr[len++] = Wire1.read(); ptr[len++] = Wire1.read();
} }
Rig.setRaduinoUpdate(); if (!Rig.updatedByCAT()) {
Rig.updateState(tmpState);
}
sentRigInfFlag = false; // so we know that we need to send the flag first
exitLoop = true; exitLoop = true;
} }
} }
@ -456,10 +462,18 @@ void i2cRequestEvent(void)
// Provide latest CAT updates, if any. // Provide latest CAT updates, if any.
//Wire1.write(catState.header); // temporary - just writing a single, null byte //Wire1.write(catState.header); // temporary - just writing a single, null byte
if (Rig.updatedByCAT()) { if (Rig.updatedByCAT()) {
Wire1.write(Rig.stateAsBytes(), sizeof(UBitxRigState)); if (sentRigInfFlag) {
Rig.clearUpdate(); DBGPRINTLN("I2CMETER_REQCAT -- updated by CAT");
Wire1.write(Rig.stateAsBytes(), sizeof(UBitxRigState));
Rig.clearUpdate();
} else {
Wire1.write(1);
sentRigInfFlag = true;
}
} else { } else {
Wire1.write(Rig.stateAsBytes(), sizeof(uint8_t)); DBGPRINTLN("I2CMETER_REQCAT -- NOT updated by CAT");
//Wire1.write(Rig.stateAsBytes(), sizeof(uint8_t));
Wire1.write(0);
} }
#ifdef DEBUG #ifdef DEBUG
i2cRespCounter[i2cCommand - 0x50]++; i2cRespCounter[i2cCommand - 0x50]++;