Did add some code for updating the RigState architecture. Not ready to swap it out yet, however.
This commit is contained in:
parent
c3cc9a7cf7
commit
814fe6c733
@ -1475,6 +1475,13 @@ void checkAutoSaveFreqMode()
|
|||||||
|
|
||||||
rigState.vfo[0] = vfoA;
|
rigState.vfo[0] = vfoA;
|
||||||
rigState.vfo[1] = vfoB;
|
rigState.vfo[1] = vfoB;
|
||||||
|
rigState.rit = ritRxFrequency - frequency;
|
||||||
|
rigState.flags = 0;
|
||||||
|
rigState.flags |= (vfoActive == VFO_B ? UBITX_VFOB_FLAG : 0);
|
||||||
|
rigState.flags |= (cwMode != 0 ? UBITX_CW_FLAG : 0);
|
||||||
|
rigState.flags |= (isUSB != 0 ? UBITX_USB_FLAG : 0);
|
||||||
|
rigState.flags |= (splitOn != 0 ? UBITX_SPLIT_FLAG : 0);
|
||||||
|
rigState.flags |= (ritOn != 0 ? UBITX_RIT_FLAG : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop(){
|
void loop(){
|
||||||
|
@ -341,6 +341,8 @@ extern void DisplayVersionInfo(const char* fwVersionInfo);
|
|||||||
extern int GetI2CSmeterValue(int valueType); //ubitx_ui.ino
|
extern int GetI2CSmeterValue(int valueType); //ubitx_ui.ino
|
||||||
|
|
||||||
extern void doRaduinoToTeensy(UBitxRigState* r);
|
extern void doRaduinoToTeensy(UBitxRigState* r);
|
||||||
|
extern void updateStateFromRaduino(UBitxRigState& r);
|
||||||
|
extern void updateRaduinoFromState(UBitxRigState& r);
|
||||||
|
|
||||||
extern UBitxRigState rigState;
|
extern UBitxRigState rigState;
|
||||||
|
|
||||||
|
@ -997,22 +997,9 @@ UBitxRigState catState;
|
|||||||
void idle_process()
|
void idle_process()
|
||||||
{
|
{
|
||||||
// KC4UPR 2021-02-05 added update process for Raduino-TeensyDSP coordination
|
// KC4UPR 2021-02-05 added update process for Raduino-TeensyDSP coordination
|
||||||
// Note, need to not have to copy this every time...
|
updateStateFromRaduino(rigState);
|
||||||
if (vfoActive == VFO_A) {
|
|
||||||
rigState.vfo[0] = frequency;
|
|
||||||
rigState.flags &= ~UBITX_VFOB_FLAG;
|
|
||||||
} else if (vfoActive == VFO_B) {
|
|
||||||
rigState.vfo[1] = frequency;
|
|
||||||
rigState.flags |= UBITX_VFOB_FLAG;
|
|
||||||
}
|
|
||||||
doRaduinoToTeensy(&rigState);
|
doRaduinoToTeensy(&rigState);
|
||||||
if (vfoActive == VFO_A) {
|
updateRaduinoFromState(rigState);
|
||||||
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))
|
||||||
|
@ -350,3 +350,41 @@ void doRaduinoToTeensy(UBitxRigState* r) {
|
|||||||
Serial.print(len);
|
Serial.print(len);
|
||||||
Serial.println();
|
Serial.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void updateStateFromRaduino(UBitxRigState& r) {
|
||||||
|
// Note, we really need to be checking a dirty flag for this. But, I don't have a dirty flag in this version of the data type...
|
||||||
|
if (vfoActive == VFO_A) {
|
||||||
|
rigState.vfo[0] = frequency;
|
||||||
|
rigState.flags &= ~UBITX_VFOB_FLAG;
|
||||||
|
} else if (vfoActive == VFO_B) {
|
||||||
|
rigState.vfo[1] = frequency;
|
||||||
|
rigState.flags |= UBITX_VFOB_FLAG;
|
||||||
|
}
|
||||||
|
rigState.rit = ritRxFrequency - frequency;
|
||||||
|
rigState.flags = 0;
|
||||||
|
rigState.flags |= (vfoActive == VFO_B ? UBITX_VFOB_FLAG : 0);
|
||||||
|
rigState.flags |= (cwMode != 0 ? UBITX_CW_FLAG : 0);
|
||||||
|
rigState.flags |= (isUSB != 0 ? UBITX_USB_FLAG : 0);
|
||||||
|
rigState.flags |= (splitOn != 0 ? UBITX_SPLIT_FLAG : 0);
|
||||||
|
rigState.flags |= (ritOn != 0 ? UBITX_RIT_FLAG : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateRaduinoFromState(UBitxRigState& r) {
|
||||||
|
vfoActive = rigState.flags & UBITX_VFOB_FLAG ? VFO_B : VFO_A;
|
||||||
|
if (vfoActive == VFO_A) {
|
||||||
|
if (rigState.vfo[0] != frequency) {
|
||||||
|
setFrequency(rigState.vfo[0]);
|
||||||
|
} else if (vfoActive == VFO_B) {
|
||||||
|
setFrequency(rigState.vfo[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ritRxFrequency = frequency + rigState.rit;
|
||||||
|
splitOn = rigState.flags & UBITX_SPLIT_FLAG ? 1 : 0;
|
||||||
|
ritOn = rigState.flags & UBITX_RIT_FLAG ? 1 : 0;
|
||||||
|
isUSB = rigState.flags & UBITX_USB_FLAG ? 1 : 0;
|
||||||
|
if (rigState.flags & UBITX_CW_FLAG) {
|
||||||
|
cwMode = isUSB ? 2 : 1; // 2 = cwu / 1 = cwl
|
||||||
|
} else {
|
||||||
|
cwMode = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -25,4 +25,150 @@ struct UBitxRigState {
|
|||||||
uint32_t flags = 0;
|
uint32_t flags = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**********************************************************************/
|
||||||
|
|
||||||
|
template<typename T, int ID>
|
||||||
|
struct Field {
|
||||||
|
byte id = ID;
|
||||||
|
bool dirty;
|
||||||
|
T data;
|
||||||
|
|
||||||
|
inline size_t sizeOfWrite() { return dirty ? sizeof(byte) + sizeof(T) : 0; }
|
||||||
|
|
||||||
|
template<typename STREAM> void writeChanges() {
|
||||||
|
if (dirty) {
|
||||||
|
STREAM().write(id);
|
||||||
|
STREAM().write((byte*)&data, sizeof(T));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename STREAM> int read() {
|
||||||
|
size_t len = 0;
|
||||||
|
byte* ptr = (byte*)&data;
|
||||||
|
while (STREAM().available() && len < sizeof(T)) {
|
||||||
|
ptr[len++] = STREAM().read();
|
||||||
|
}
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void merge(Field<T,ID>& f) {
|
||||||
|
if (dirty) {
|
||||||
|
f.data = data;
|
||||||
|
f.dirty = true;
|
||||||
|
} else if (f.dirty) {
|
||||||
|
data = f.data;
|
||||||
|
dirty = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
inline size_t sizeOfWrite() {
|
||||||
|
size_t size = 0;
|
||||||
|
size += vfoA.sizeOfWrite();
|
||||||
|
size += vfoB.sizeOfWrite();
|
||||||
|
size += rit.sizeOfWrite();
|
||||||
|
size += xit.sizeOfWrite();
|
||||||
|
size += flags.sizeOfWrite();
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename STREAM> void writeChanges() {
|
||||||
|
vfoA.writeChanges<STREAM>();
|
||||||
|
vfoB.writeChanges<STREAM>();
|
||||||
|
rit.writeChanges<STREAM>();
|
||||||
|
xit.writeChanges<STREAM>();
|
||||||
|
flags.writeChanges<STREAM>();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename STREAM> void readChanges(size_t size) {
|
||||||
|
size_t len = 0;
|
||||||
|
while (STREAM().available() && len < size) {
|
||||||
|
switch(STREAM().read()) {
|
||||||
|
case 0:
|
||||||
|
len += vfoA.read<STREAM>();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
len += vfoB.read<STREAM>();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
len += rit.read<STREAM>();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
len += xit.read<STREAM>();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 4:
|
||||||
|
len += flags.read<STREAM>();
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void merge(RigState& r) {
|
||||||
|
vfoA.merge(r.vfoA);
|
||||||
|
vfoB.merge(r.vfoB);
|
||||||
|
rit.merge(r.rit);
|
||||||
|
xit.merge(r.xit);
|
||||||
|
flags.merge(r.flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void markClean(RigState& r) {
|
||||||
|
vfoA.markClean();
|
||||||
|
vfoB.markClean();
|
||||||
|
rit.markClean();
|
||||||
|
xit.markClean();
|
||||||
|
flags.markClean();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
Protocol discussion:
|
||||||
|
- I2C master: Raduino
|
||||||
|
- I2C slave: TeensyDSP
|
||||||
|
|
||||||
|
Raduino state:
|
||||||
|
- Baseline uBITX variables
|
||||||
|
- I2C buffer
|
||||||
|
- On I2C transmit: make updates based on current variables
|
||||||
|
- On I2C receive:
|
||||||
|
- Update based on received I2C responses
|
||||||
|
- Update associated variables
|
||||||
|
|
||||||
|
TeensyDSP state:
|
||||||
|
- CAT buffer
|
||||||
|
- Used to receive command from CAT (when commands arrive via Serial)
|
||||||
|
- Used to transmit state to Raduino (when requested via Wire1)
|
||||||
|
- Raduino buffer
|
||||||
|
- Used to receive state from Raduino (when received via Wire1)
|
||||||
|
- Used to transmit responses to CAT (over Serial)
|
||||||
|
- Questions
|
||||||
|
- How can these be synchronized?
|
||||||
|
- At the tail end of an I2C request handler. Before sending the response to the Raduino via I2C:
|
||||||
|
- Copy updated CAT buffer items to the Raduino buffer.
|
||||||
|
- Copy updated Raduino buffer items to the CAT buffer.
|
||||||
|
- In the case of conflicts, CAT wins.
|
||||||
|
- Transmit the CAT buffer state to the Raduino.
|
||||||
|
- TeensyDSP updates 'outgoing' state based on CAT inputs.
|
||||||
|
- Make change to data.
|
||||||
|
- Mark data as dirty, if different than incoming state.
|
||||||
|
- When requested, Teensy DSP sends 'outgoing' state to Raduino.
|
||||||
|
- Send dirty data over I2C.
|
||||||
|
- Mark data as clean.
|
||||||
|
*/
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user