Raduino changes are getting to TeensyDSP over I2C. TeensyDSP successfully receiving some CAT.

This commit is contained in:
Rob French 2021-02-09 22:58:07 -06:00
parent 702f370d1b
commit aeeec69daf
12 changed files with 134 additions and 53 deletions

View File

@ -125,7 +125,6 @@ unsigned long vfoA_eeprom, vfoB_eeprom; //for protect eeprom life
unsigned long frequency;
unsigned long ritRxFrequency, ritTxFrequency; //frequency is the current frequency on the dial
unsigned int cwSpeed = 100; //this is actuall the dot period in milliseconds
extern int32_t calibration;
@ -1473,6 +1472,9 @@ void checkAutoSaveFreqMode()
saveCheckTime = 0; //for reduce cpu use rate
}
}
rigState.vfo[0] = vfoA;
rigState.vfo[1] = vfoB;
}
void loop(){

View File

@ -342,4 +342,6 @@ extern int GetI2CSmeterValue(int valueType); //ubitx_ui.ino
extern void doRaduinoToTeensy(UBitxRigState* r);
extern UBitxRigState rigState;
#endif //end of if header define

View File

@ -998,8 +998,13 @@ void idle_process()
{
// KC4UPR 2021-02-05 added update process for Raduino-TeensyDSP coordination
// Note, need to not have to copy this every time...
rigState.vfo[0] = vfoA;
rigState.vfo[1] = vfoB;
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);
//S-Meter Display

View File

@ -305,9 +305,21 @@ void doRaduinoToTeensy(UBitxRigState* r) {
Wire.beginTransmission(I2CMETER_ADDR);
Wire.write(I2CMETER_RIGINF);
//for (size_t i = 0; i < sizeof(UBitxRigState); i++) {
// Wire.write(ptr[i]);
//}
//Note, I can switch this back...
Wire.write(ptr, sizeof(UBitxRigState));
Wire.endTransmission();
Serial.print("VFO A: ");
Serial.print(r->vfo[0]);
Serial.print(", VFO B: ");
Serial.print(r->vfo[1]);
Serial.print(", Data Size: ");
Serial.print(sizeof(UBitxRigState));
Serial.println();
Wire.requestFrom(I2CMETER_ADDR, sizeof(UBitxRigState));
UBitxRigState tmp;

View File

@ -86,6 +86,10 @@ void UBitxDSP::begin() {
rx();
}
void UBitxDSP::update() {
}
void UBitxDSP::end() {
}

View File

@ -26,6 +26,7 @@ class UBitxDSP {
public:
UBitxDSP() {};
void begin();
void update();
void end();
void rx();
void txMicIn();

View File

@ -11,10 +11,12 @@ enum UpdateSource {
class UBitxRig {
public:
inline void begin() {}
inline void update() {}
inline unsigned long getFreqA() const { return state.vfo[0]; }
inline unsigned long getFreqB() const { return state.vfo[1]; }
inline short getRIT() const { return state.rit; }
inline short getXIT() const { return state.xit; }
inline long getRIT() const { return state.rit; }
inline long getXIT() const { return state.xit; }
inline bool isVFOA() const { return (state.flags & UBITX_VFOB_FLAG) != UBITX_VFOB_FLAG; }
inline bool isVFOB() const { return (state.flags & UBITX_VFOB_FLAG) == UBITX_VFOB_FLAG; }
inline bool isSplit() const { return (state.flags & UBITX_SPLIT_FLAG) == UBITX_SPLIT_FLAG; }

View File

@ -3,26 +3,26 @@
#include <Arduino.h>
#define UBITX_VFOA_UPDATE 0x01
#define UBITX_VFOB_UPDATE 0x02
#define UBITX_RIT_UPDATE 0x04
#define UBITX_XIT_UPDATE 0x08
#define UBITX_FLAGS_UPDATE 0x10
#define UBITX_VFOA_UPDATE 0x00000001
#define UBITX_VFOB_UPDATE 0x00000002
#define UBITX_RIT_UPDATE 0x00000004
#define UBITX_XIT_UPDATE 0x00000008
#define UBITX_FLAGS_UPDATE 0x00000010
#define UBITX_VFOB_FLAG 0x01
#define UBITX_SPLIT_FLAG 0x02
#define UBITX_RIT_FLAG 0x04
#define UBITX_XIT_FLAG 0x08
#define UBITX_CW_FLAG 0x10
#define UBITX_USB_FLAG 0x20
#define UBITX_TX_FLAG 0x40
#define UBITX_VFOB_FLAG 0x00000001
#define UBITX_SPLIT_FLAG 0x00000002
#define UBITX_RIT_FLAG 0x00000004
#define UBITX_XIT_FLAG 0x00000008
#define UBITX_CW_FLAG 0x00000010
#define UBITX_USB_FLAG 0x00000020
#define UBITX_TX_FLAG 0x00000040
struct UBitxRigState {
uint8_t header = 0;
uint32_t header = 0;
uint32_t vfo[2];
int16_t rit;
int16_t xit;
uint8_t flags = 0;
int32_t rit;
int32_t xit;
uint32_t flags = 0;
};
#endif

View File

@ -1,5 +1,6 @@
#include <Arduino.h>
#include "TS590.h"
#include "Debug.h"
/**********************************************************************/
@ -71,26 +72,26 @@ void TS590Command::process(const char* cmd) {
theError = NoError;
if (isReadCommand(cmd)) {
sendResponse(cmd);
DBGCMD( sendResponse(cmd) );
} else {
handleCommand(cmd);
DBGCMD( handleCommand(cmd) );
switch(theError) {
case NoError:
if (theRig->getAI()) {
sendResponse(cmd);
DBGCMD( sendResponse(cmd) );
}
break;
case SyntaxError:
ts590SyntaxError();
DBGCMD( ts590SyntaxError() );
break;
case CommError:
ts590CommError();
DBGCMD( ts590CommError() );
break;
case ProcessError:
ts590ProcessError();
DBGCMD( ts590ProcessError() );
break;
}
}
@ -225,18 +226,36 @@ TS590Command* catCommands[] = {
&cmdFR,
&cmdFT
};
int numCatCommands = sizeof(catCommands) / sizeof(catCommands[0]);
/**********************************************************************/
void UBitxTS590::begin() {
Serial.begin(9600); // USB is always 12 Mbit/sec
#ifdef DEBUG
delay(500);
Serial.print("DBG: Number of CAT commands: ");
Serial.println(numCommands);
for (int i = 0; i < numCommands; i++) {
Serial.print(" ");
Serial.println(commands[i]->prefix());
}
#endif
}
void UBitxTS590::update() {
char incomingChar;
while (Serial.available()) {
if (bufLen < ts590CommandMaxLength) {
incomingChar = Serial.read();
incomingChar = Serial.read();
if (incomingChar == ';') {
buf[bufLen++] = '\0';
strupr(buf);
processCommand();
} else if (incomingChar == '\n' && bufLen == 0) {
;
} else {
buf[bufLen++] = incomingChar;
}
@ -248,19 +267,32 @@ void UBitxTS590::update() {
}
}
typedef class TS590Command* PCmd;
int compareCATCommands(const void* a, const void* b) {
return strcmp(((TS590Command*)a)->prefix(), ((TS590Command*)b)->prefix());
TS590Command const *B = *(TS590Command const **)b;
int cmp = strncmp((char*)a, (char*)B->prefix(), 2);
#ifdef DEBUG
Serial.print("Comparison: ");
Serial.print((char*)a);
Serial.print(" ? ");
Serial.print((char*)B->prefix());
Serial.print(" --> ");
Serial.println(cmp);
#endif
return cmp;
}
void UBitxTS590::processCommand() {
TS590Command* cmd = (TS590Command*)bsearch((void*)buf, (void*)commands, sizeof(commands) / sizeof(commands[0]), sizeof(commands[0]), compareCATCommands);
TS590Command** cmd = (TS590Command**)bsearch(buf, commands, numCommands, sizeof(TS590Command*), compareCATCommands);
if (cmd == NULL) {
ts590SyntaxError();
} else {
cmd->process(buf);
(*cmd)->process(buf);
}
bufLen = 0;
}
UBitxTS590 TS590(catCommands);
UBitxTS590 TS590(catCommands, numCatCommands);
/**********************************************************************/

View File

@ -150,12 +150,9 @@ class TS590_FT : public TS590Command {
class UBitxTS590 {
public:
UBitxTS590(TS590Command** cmds): commands(cmds) {}
UBitxTS590(TS590Command** cmds, int len): commands(cmds), numCommands(len) {}
inline void begin() {
Serial.begin(9600); // USB is always 12 Mbit/sec
}
void begin();
void update();
private:
@ -164,6 +161,7 @@ class UBitxTS590 {
char buf[ts590CommandMaxLength] = {0};
int bufLen = 0;
TS590Command** commands;
int numCommands;
};
extern UBitxTS590 TS590;

View File

@ -15,6 +15,7 @@ KD8CEC, Ian Lee
#include "RigState.h"
#include "Sensors.h"
#include "TR.h"
#include "TS590.h"
//================================================================
//COMMUNICATION SECTION

View File

@ -313,9 +313,11 @@ void sendMeterData(uint8_t isSend)
void setup()
{
DBGCMD( DSP.begin() );
DBGCMD( TR.begin() );
// Startup each of the subsystems, beginning with CAT.
DBGCMD( TS590.begin() );
DBGCMD( TR.begin() );
DBGCMD( Rig.begin() );
DBGCMD( DSP.begin() );
// load configuration
EEPROM.get(EEPROM_DSPTYPE, DSPType);
@ -370,19 +372,18 @@ void setup()
void i2cReceiveEvent(size_t numBytes)
{
int readCommand = 0;
bool exitLoop = false;
while (Wire1.available() > 0) {
while (Wire1.available() > 0 && !exitLoop) {
readCommand = Wire1.read();
if (readCommand == I2CMETER_RIGINF) {
size_t len = 0;
size_t len = 0;
uint8_t* const ptr = Rig.stateAsBytes();
while (Wire.available() > 0) {
uint8_t b = Wire.read();
if (len < sizeof(UBitxRigState)) {
ptr[len++] = b;
}
while ((Wire1.available() > 0) && (len < sizeof(UBitxRigState))) {
ptr[len++] = Wire1.read();
}
Rig.setRaduinoUpdate();
exitLoop = true;
}
}
@ -460,6 +461,9 @@ void i2cRequestEvent(void)
} else {
Wire1.write(Rig.stateAsBytes(), sizeof(uint8_t));
}
#ifdef DEBUG
i2cRespCounter[i2cCommand - 0x50]++;
#endif
break;
default:
@ -501,16 +505,18 @@ const int adcIntervalMillis = ADC_INTERVAL_MS;
int frameCounter = 0;
#endif
/**********************************************************************/
void loop()
{
//char isProcess = 0; // 0: init, 1: complete ADC sampling, 2: complete FFT
//isProcess = 0;
forwardData();
// One-shot delay to ensure everything is booted up (primarily, the
// Nextion, and secondarily the Raduino.
if (isBooted < 100)
{
//Delay 20msec
// delay 20msec
for (int i = 0; i < 20; i++)
{
forwardData();
@ -520,11 +526,21 @@ void loop()
return;
}
// Start out by forwarding any data sitting in the RX buffer. We will
// do this as often as possible.
forwardData();
if (sinceFrameMillis > frameIntervalMillis) {
// Do stuff that we do once per frame--I/O.
// TODO: debug output (frame skipping / utilization).
sinceFrameMillis = 0;
// Update each of the subsystems, beginning with CAT control.
TS590.update();
TR.update();
Rig.update();
DSP.update();
#ifdef DEBUG
// For debugging, output some debug info every 1.0" (40 frames @ 40 Hz).
frameCounter++;
@ -542,6 +558,14 @@ void loop()
} else {
Serial.println(", TR State: RX");
}
Serial.print("VFO A: ");
Serial.print(Rig.getFreqA());
Serial.print(", VFO B: ");
Serial.print(Rig.getFreqB());
Serial.print(", Data Size: ");
Serial.print(sizeof(UBitxRigState));
Serial.println();
Serial.println("----------------------------------------------------------------------");
Serial.print("DBG: S-Meter Raw: ");
Serial.print(Sensors.sMeterUnscaled());
Serial.print(", S-Meter Scaled: ");
@ -578,8 +602,6 @@ void loop()
}
#endif
TR.update();
if (isTX) {
calcVSWR = Sensors.VSWR();
scaledVSWR = byte(Sensors.scaledVSWR());