Compare commits

...

2 Commits

Author SHA1 Message Date
Rob French f3887e7950 commit before I totally change the RigState architecture 2021-02-15 22:38:05 -06:00
Rob French 2cbc9abae8 Updated files list. 2021-02-15 08:06:31 -06:00
7 changed files with 48 additions and 88 deletions

1
Raduino/RigState.cpp Symbolic link
View File

@ -0,0 +1 @@
../TeensyDSP/RigState.cpp

View File

@ -255,11 +255,11 @@ extern byte I2C_LCD_SECOND_ADDRESS; //only using Dual LCD Mode
#define I2CMETER_CALCR 0x55 //Calculated SWR Meter #define I2CMETER_CALCR 0x55 //Calculated SWR Meter
#define I2CMETER_UNCALCR 0x54 //Uncalculated SWR Meter #define I2CMETER_UNCALCR 0x54 //Uncalculated SWR Meter
// Raduino provides updated data to TeensyDSP // Raduino<=>TeensyDSP data exchange
#define I2CMETER_RIGINF 0x50 #define I2CMETER_RIGINF 0x50
// Raduino requests any CAT updates from TeensyDSP // Raduino requests any CAT updates from TeensyDSP
#define I2CMETER_REQCAT 0x51 //#define I2CMETER_REQCAT 0x51
//============================================================================== //==============================================================================
// for public, Variable, functions // for public, Variable, functions

View File

@ -3,36 +3,25 @@
#include "RigState.h" #include "RigState.h"
enum UpdateSource {
NoSource,
RaduinoSource,
CATSource
};
class UBitxRig { class UBitxRig {
public: public:
inline void begin() {} inline void begin() {}
inline void update() {} inline void update() {}
inline unsigned getFreqA() const { return catState.getFreqA(); }
inline unsigned getFreqB() const { return catState.getFreqB(); } inline unsigned getFreqA() const { return radState.getFreqA(); }
inline int getRIT() const { return catState.getRIT(); } inline unsigned getFreqB() const { return radState.getFreqB(); }
inline int getXIT() const { return catState.getXIT(); } inline int getRIT() const { return radState.getRIT(); }
inline bool isVFOA() const { return catState.isVFOA(); } inline int getXIT() const { return radState.getXIT(); }
inline bool isVFOB() const { return catState.isVFOB(); } inline bool isVFOA() const { return radState.isVFOA(); }
inline bool isSplit() const { return catState.isSplit(); } inline bool isVFOB() const { return radState.isVFOB(); }
inline bool isRITOn() const { return catState.isRITOn(); } inline bool isSplit() const { return radState.isSplit(); }
inline bool isXITOn() const { return catState.isXITOn(); } inline bool isRITOn() const { return radState.isRITOn(); }
inline bool isModeCW() const { return catState.isCW() && catState.isUSB(); } inline bool isXITOn() const { return radState.isXITOn(); }
inline bool isModeCWR() const { return catState.isCW() && catState.isLSB(); } inline bool isModeCW() const { return radState.isCW() && radState.isUSB(); }
inline bool isModeUSB() const { return catState.isUSB() && !catState.isCW(); } inline bool isModeCWR() const { return radState.isCW() && radState.isLSB(); }
inline bool isModeLSB() const { return catState.isLSB() && !catState.isCW(); } inline bool isModeUSB() const { return radState.isUSB() && !radState.isCW(); }
inline bool isModeLSB() const { return radState.isLSB() && !radState.isCW(); }
inline bool isAI() const { return autoInfo; } inline bool isAI() const { return autoInfo; }
//inline bool updatedByCAT() const { return lastUpdatedBy == CATSource; }
//inline bool updatedByRaduino() const { return lastUpdatedBy == RaduinoSource; }
//inline void clearUpdate() { lastUpdatedBy = NoSource; }
//inline void setRaduinoUpdate() { lastUpdatedBy = RaduinoSource; }
//inline void setCATUpdate() { lastUpdatedBy = CATSource; }
inline void setFreqA(unsigned freq) { catState.setFreqA(freq); } inline void setFreqA(unsigned freq) { catState.setFreqA(freq); }
inline void setFreqB(unsigned freq) { catState.setFreqB(freq); } inline void setFreqB(unsigned freq) { catState.setFreqB(freq); }
@ -55,18 +44,8 @@ class UBitxRig {
inline void aiOn() { autoInfo = true; } inline void aiOn() { autoInfo = true; }
inline void aiOff() { autoInfo = false; } inline void aiOff() { autoInfo = false; }
inline void updateState(UBitxRigState& r, bool isCAT = false) { inline UBitxRigState& cat() { return catState; }
if ((r.vfo[0] == state.vfo[0]) && inline UBitxRigState& rad() { return radState; }
(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;
}
}
/********************************************************************/ /********************************************************************/
// New functional/mode-based Rig methods // New functional/mode-based Rig methods
@ -80,10 +59,9 @@ class UBitxRig {
//void getBand(); //void getBand();
private: private:
bool autoInfo = false;
UpdateSource lastUpdatedBy = NoSource;
UBitxRigState catState; UBitxRigState catState;
UBitxRigState radState; UBitxRigState radState;
bool autoInfo = false;
}; };
extern UBitxRig Rig; extern UBitxRig Rig;

View File

@ -182,9 +182,14 @@ BaseField* raduinoFields[WIREBUS_NUM_FIELDS] = {
/**********************************************************************/ /**********************************************************************/
RaduinoState::RaduinoState(): RigState(raduinoFields, WIREBUS_NUM_FIELDS) {} RigState::RigState(): RigState(raduinoFields, WIREBUS_NUM_FIELDS) {}
void RaduinoState::begin() { /*!
* @brief Begin using the RigState object. In order to force an
* update (e.g. sending current state to the remote device),
* all fields are marked dirty.
*/
void RigState::begin() {
for (byte i = 0; i < numFields; i++) { for (byte i = 0; i < numFields; i++) {
if (read(i)) { if (read(i)) {
makeDirty(i); makeDirty(i);
@ -192,7 +197,7 @@ void RaduinoState::begin() {
} }
} }
void RaduinoState::update() { void RigState::update() {
// First we need to determine which fields have changed (and are // First we need to determine which fields have changed (and are
// thus dirty and need to be sent to the TeensyDSP). // thus dirty and need to be sent to the TeensyDSP).
for (byte i = 0; i < numFields; i++) { for (byte i = 0; i < numFields; i++) {
@ -202,35 +207,19 @@ void RaduinoState::update() {
} }
// Next we need to send the current (changed) Raduino information // Next we need to send the current (changed) Raduino information
// to the TeensyDSP. The expected response is the number of fields // to the TeensyDSP.
// (in bytes) that the TeensyDSP needs to send in response.
Wire.beginTransmission(I2CMETER_ADDR); Wire.beginTransmission(I2CMETER_ADDR);
Wire.write(I2CMETER_RIGINF); Wire.write(I2CMETER_RIGINF);
// NOTE - I don't think I actually need to do this line, i.e. I don't think the slave cares... it'll read what is sent to it.
//Wire.write(numDirty * (sizeof(byte) + sizeof(uint32_t)), 1); // Write the number of dirty fields (in bytes).
for (byte i = 0; i < numFields; i++) { for (byte i = 0; i < numFields; i++) {
if (isDirty(i)) { // Write each field that is dirty to the bus. if (isDirty(i)) { // Write each field that is dirty to the bus.
Wire.write(i); // write the field number/ID Wire.write(i); // - write the field number/ID
Wire.write(data(i), dataSize(i)); // write the field data Wire.write(data(i), dataSize(i)); // - write the field data
makeClean(i); makeClean(i);
} }
} }
Wire.endTransmission(); Wire.endTransmission();
// Now we're going to read the response from the TeensyDSP. All delay(1); // some delay required between ending transmission and requesting?
// fields should be marked as clean at this point (unless there's
// something that has been updated via interrupt???).
Wire.requestFrom(I2CMETER_ADDR, 1);
byte numBytes;
while (Wire.available()) {
numBytes = Wire.read(); // Should only get executed for one byte... but just in case.
}
if (numBytes == 0) return;
// Let the TeensyDSP know that we want it to send its deltas now.
Wire.beginTransmission(I2CMETER_ADDR);
Wire.write(I2CMETER_RIGREQ);
Wire.endTransmission();
// Retrieve all of the deltas. Mark any received field as dirty. // Retrieve all of the deltas. Mark any received field as dirty.
Wire.requestFrom(I2CMETER_ADDR, numBytes); Wire.requestFrom(I2CMETER_ADDR, numBytes);
@ -276,7 +265,7 @@ void RaduinoState::update() {
* instance, when a RIGINF signal is received via I2C. It * instance, when a RIGINF signal is received via I2C. It
* receives the incoming data from the Raduino. * receives the incoming data from the Raduino.
*/ */
void RaduinoState::receiveRIGINF() { void RigState::receive_RIGINF() {
// 1st (-1) byte read should be a field index. // 1st (-1) byte read should be a field index.
// 2nd (0) thru 5th (3) bytes are bytes of the field. // 2nd (0) thru 5th (3) bytes are bytes of the field.
// We'll read as many fields as the Raduino sends. // We'll read as many fields as the Raduino sends.
@ -312,7 +301,7 @@ void RaduinoState::receiveRIGINF() {
* instance, when a RIGINF signal is received via I2C. It * instance, when a RIGINF signal is received via I2C. It
* sends a response to the Raduino * sends a response to the Raduino
*/ */
void RaduinoState::respondRIGINF(byte numBytes, RigState& catState) { void RigState::send_RIGINF(byte numBytes, RigState& catState) {
// Now we need to determine the differences from the other state (i.e. // Now we need to determine the differences from the other state (i.e.
// from the catState) and send those differences. // from the catState) and send those differences.
byte rigRegBytes = 0; byte rigRegBytes = 0;

View File

@ -40,7 +40,7 @@ struct BaseField {
}; };
template<typename R, typename W> template<typename R, typename W>
struct Field : public BaesField { struct Field : public BaseField {
/*! /*!
* @brief Using the supplied read function, which should take a * @brief Using the supplied read function, which should take a
* pointer to data as its input, read from (some source) and * pointer to data as its input, read from (some source) and

View File

@ -68,8 +68,8 @@ extern int magnitudelimit_low;
#define I2CMETER_CALCR 0x55 //Calculated SWR Meter #define I2CMETER_CALCR 0x55 //Calculated SWR Meter
#define I2CMETER_UNCALCR 0x54 //Uncalculated SWR Meter #define I2CMETER_UNCALCR 0x54 //Uncalculated SWR Meter
// Raduino provides updated data to TeensyDSP // Raduino<=>TeensyDSP data exchange
#define I2CMETER_RIGINF 0x50 #define I2CMETER_RIGINF 0x50
// Raduino requests any CAT updates from TeensyDSP // Raduino requests any CAT updates from TeensyDSP
#define I2CMETER_REQCAT 0x51 //#define I2CMETER_REQCAT 0x51

View File

@ -374,12 +374,11 @@ void i2cReceiveEvent(size_t numBytes)
int readCommand = 0; int readCommand = 0;
bool exitLoop = false; bool exitLoop = false;
// Does this really need to be a while loop? Don't we know the number of bytes?
while (Wire1.available() > 0 && !exitLoop) { while (Wire1.available() > 0 && !exitLoop) {
readCommand = Wire1.read(); readCommand = Wire1.read();
if (readCommand == I2CMETER_RIGINF) { if (readCommand == I2CMETER_RIGINF) {
// NEEDS TO GET UPDATED Rig.rad().receive_RIGINF(numBytes - 1);
//rigState.getSizeOfChanges();
//rigState.update(I2CMETER_RIGINF);
exitLoop = true; exitLoop = true;
} }
} }
@ -415,37 +414,26 @@ void i2cRequestEvent(void)
case I2CMETER_CALCS: case I2CMETER_CALCS:
// Returns an already-calculated S-meter value. // Returns an already-calculated S-meter value.
Wire1.write(scaledSMeter); Wire1.write(scaledSMeter);
#ifdef DEBUG
i2cRespCounter[i2cCommand - 0x50]++;
#endif
break; break;
case I2CMETER_UNCALCS: case I2CMETER_UNCALCS:
// Returns a raw signal strength value. // Returns a raw signal strength value.
Wire1.write(Sensors.sMeterUnscaled() >> 2); // divided by 4... do we want this? Wire1.write(Sensors.sMeterUnscaled() >> 2); // divided by 4... do we want this?
#ifdef DEBUG
i2cRespCounter[i2cCommand - 0x50]++;
#endif
break; break;
case I2CMETER_CALCP: case I2CMETER_CALCP:
// Returns a raw forward power value. // Returns a raw forward power value.
Wire1.write(int(fwdPower * 100.0)); Wire1.write(int(fwdPower * 100.0));
#ifdef DEBUG
i2cRespCounter[i2cCommand - 0x50]++;
#endif
break; break;
case I2CMETER_CALCR: case I2CMETER_CALCR:
// Returns a raw reverse power value. // Returns a raw reverse power value.
Wire1.write(int(revPower * 100.0)); Wire1.write(int(revPower * 100.0));
#ifdef DEBUG
i2cRespCounter[i2cCommand - 0x50]++;
#endif
break; break;
case I2CMETER_RIGINF: case I2CMETER_RIGINF:
// Receive current rig state; transmit any CAT updates, if required. // Receive current rig state; transmit any CAT updates, if required.
Rig.cat().send_RIGINF();
//Wire1.write(catState.header); // temporary - just writing a single, null byte //Wire1.write(catState.header); // temporary - just writing a single, null byte
// NEEDS TO GET UPDATED // NEEDS TO GET UPDATED
break; break;
@ -468,14 +456,18 @@ void i2cRequestEvent(void)
//Wire1.write(Rig.stateAsBytes(), sizeof(uint8_t)); //Wire1.write(Rig.stateAsBytes(), sizeof(uint8_t));
Wire1.write(0); Wire1.write(0);
} }
#ifdef DEBUG
i2cRespCounter[i2cCommand - 0x50]++;
#endif
break; break;
default: default:
break; break;
} }
#ifdef DEBUG
if (0x50 <= i2cCommand && i2cCommand <= 0x59)
{
i2cRespCounter[i2cCommand - 0x50]++;
}
#endif
} }
//extern void Decode_Morse(float magnitude); //extern void Decode_Morse(float magnitude);