Significant revamp of RigState to only send changes. Not done yet.
This commit is contained in:
@@ -26,15 +26,13 @@ struct UBitxRigState {
|
||||
};
|
||||
|
||||
/**********************************************************************/
|
||||
// NEW IMPLEMENTATION
|
||||
|
||||
template<typename T, int ID>
|
||||
struct Field {
|
||||
byte id = ID;
|
||||
bool dirty;
|
||||
T data;
|
||||
uint32_t data;
|
||||
|
||||
inline size_t sizeOfWrite() { return dirty ? sizeof(byte) + sizeof(T) : 0; }
|
||||
|
||||
/*
|
||||
template<typename STREAM> void writeChanges() {
|
||||
if (dirty) {
|
||||
STREAM().write(id);
|
||||
@@ -50,8 +48,9 @@ struct Field {
|
||||
}
|
||||
return len;
|
||||
}
|
||||
*/
|
||||
|
||||
inline void merge(Field<T,ID>& f) {
|
||||
inline void merge(Field& f) {
|
||||
if (dirty) {
|
||||
f.data = data;
|
||||
f.dirty = true;
|
||||
@@ -64,13 +63,56 @@ struct Field {
|
||||
inline void markClean() { dirty = false; }
|
||||
};
|
||||
|
||||
struct RigState {
|
||||
Field<uint32_t, 0> vfoA;
|
||||
Field<uint32_t, 1> vfoB;
|
||||
Field<int32_t, 2> rit;
|
||||
Field<int32_t, 3> xit;
|
||||
Field<uint32_t, 4> flags;
|
||||
#define WIREBUS_NONE 0
|
||||
#define WIREBUS_VFO_A 1
|
||||
#define WIREBUS_VFO_B 2
|
||||
#define WIREBUS_RIT_OFS 3
|
||||
#define WIREBUS_XIT_OFS 4
|
||||
#define WIREBUS_FLAGS 5
|
||||
#define WIREBUS_NUM_FIELDS 6
|
||||
|
||||
typedef bool (*readfunc)(uint32_t*);
|
||||
typedef void (*writefunc)(uint32_t);
|
||||
|
||||
struct RigState {
|
||||
Field field[WIREBUS_NUM_FIELDS];
|
||||
readfunc readFunc[WIREBUS_NUM_FIELDS];
|
||||
writefunc writeFunc[WIREBUS_NUM_FIELDS;
|
||||
int numDirty;
|
||||
|
||||
void begin();
|
||||
void update();
|
||||
|
||||
/*!
|
||||
* @brief Read in the specified (by index) external value, and use
|
||||
* it to update the rig state.
|
||||
*/
|
||||
inline bool read(byte i) {
|
||||
return readFunc[i](&field[i].data);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Use the specified (vy index) rig state field to update the
|
||||
* external value.
|
||||
*/
|
||||
inline void write(byte i) {
|
||||
writeFunc[i](field[i].data);
|
||||
}
|
||||
|
||||
inline unsigned getFreqA() const { return field[WIREBUS_VFO_A].data; }
|
||||
inline unsigned getFreqB() const { return field[WIREBUS_VFO_B].data; }
|
||||
inline int getRIT() const { return int(field[WIREBUS_VFO_A].data); }
|
||||
inline int getXIT() const { return int(field[WIREBUS_VFO_B].data); }
|
||||
inline bool isVFOA() const { return (field[WIREBUS_FLAGS].data & UBITX_VFOB_FLAG) != UBITX_VFOB_FLAG; }
|
||||
inline bool isVFOB() const { return (field[WIREBUS_FLAGS].data & UBITX_VFOB_FLAG) == UBITX_VFOB_FLAG; }
|
||||
inline bool isSplit() const { return (field[WIREBUS_FLAGS].data & UBITX_SPLIT_FLAG) == UBITX_SPLIT_FLAG; }
|
||||
inline bool isRITOn() const { return (field[WIREBUS_FLAGS].data & UBITX_RIT_FLAG) == UBITX_RIT_FLAG; }
|
||||
inline bool isXITOn() const { return (field[WIREBUS_FLAGS].data & UBITX_XIT_FLAG) == UBITX_XIT_FLAG; }
|
||||
inline bool isCW() const { return (field[WIREBUS_FLAGS].data & UBITX_CW_FLAG) == UBITX_CW_FLAG; }
|
||||
inline bool isLSB() const { return (field[WIREBUS_FLAGS].data & UBITX_USB_FLAG) != UBITX_USB_FLAG; }
|
||||
inline bool isUSB() const { return (field[WIREBUS_FLAGS].data & UBITX_USB_FLAG) == UBITX_USB_FLAG; }
|
||||
|
||||
/*
|
||||
inline size_t sizeOfWrite() {
|
||||
size_t size = 0;
|
||||
size += vfoA.sizeOfWrite();
|
||||
@@ -134,8 +176,20 @@ struct RigState {
|
||||
xit.markClean();
|
||||
flags.markClean();
|
||||
}
|
||||
*/
|
||||
};
|
||||
|
||||
#ifdef TEENSYDUINO
|
||||
|
||||
extern RigState inState; // the state as received from the Raduino
|
||||
extern RigState outState; // the state as commanded via CAT
|
||||
|
||||
#else
|
||||
|
||||
extern RigState rigState;
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
Protocol discussion:
|
||||
- I2C master: Raduino
|
||||
|
||||
Reference in New Issue
Block a user