Added code to sync PC and GVRET timing so that frames sent from
SavvyCAN line up properly in timestamp. Incremented version num.
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
#ifndef CONFIG
|
#ifndef CONFIG
|
||||||
#define CONFIG
|
#define CONFIG
|
||||||
|
|
||||||
#define VERSION 151
|
#define VERSION 152
|
||||||
|
|
||||||
//try to keep this in sync.
|
//try to keep this in sync.
|
||||||
//SavvyCAN will complain if you connect a GVRET board with a revision
|
//SavvyCAN will complain if you connect a GVRET board with a revision
|
||||||
|
|||||||
+33
-5
@@ -115,6 +115,11 @@ void SerialWorker::setSerialPort(QSerialPortInfo *port)
|
|||||||
output.append((char)0xF1); //yet another command
|
output.append((char)0xF1); //yet another command
|
||||||
output.append((char)0x09); //comm validation command
|
output.append((char)0x09); //comm validation command
|
||||||
|
|
||||||
|
output.append((char)0xF1); //and another command
|
||||||
|
output.append((char)0x01); //Time Sync - Not implemented until 333 but we can try
|
||||||
|
|
||||||
|
continuousTimeSync = true;
|
||||||
|
|
||||||
serial->write(output);
|
serial->write(output);
|
||||||
if (doValidation) connected = false;
|
if (doValidation) connected = false;
|
||||||
else connected = true;
|
else connected = true;
|
||||||
@@ -236,8 +241,9 @@ void SerialWorker::procRXChar(unsigned char c)
|
|||||||
rx_state = BUILD_CAN_FRAME;
|
rx_state = BUILD_CAN_FRAME;
|
||||||
rx_step = 0;
|
rx_step = 0;
|
||||||
break;
|
break;
|
||||||
case 1: //we don't accept time sync commands from the firmware
|
case 1: //time sync
|
||||||
rx_state = IDLE;
|
rx_state = TIME_SYNC;
|
||||||
|
rx_step = 0;
|
||||||
break;
|
break;
|
||||||
case 2: //process a return reply for digital input states.
|
case 2: //process a return reply for digital input states.
|
||||||
rx_state = GET_DIG_INPUTS;
|
rx_state = GET_DIG_INPUTS;
|
||||||
@@ -319,6 +325,8 @@ void SerialWorker::procRXChar(unsigned char c)
|
|||||||
{
|
{
|
||||||
buildFrame->isReceived = true;
|
buildFrame->isReceived = true;
|
||||||
canModel->addFrame(*buildFrame, false);
|
canModel->addFrame(*buildFrame, false);
|
||||||
|
//take the time the frame came in and try to resync the time base.
|
||||||
|
if (continuousTimeSync) txTimestampBasis = QDateTime::currentMSecsSinceEpoch() - (buildFrame->timestamp / 1000);
|
||||||
framesRapid++;
|
framesRapid++;
|
||||||
if (buildFrame->ID == targetID) emit gotTargettedFrame(canModel->rowCount() - 1);
|
if (buildFrame->ID == targetID) emit gotTargettedFrame(canModel->rowCount() - 1);
|
||||||
}
|
}
|
||||||
@@ -327,6 +335,29 @@ void SerialWorker::procRXChar(unsigned char c)
|
|||||||
}
|
}
|
||||||
rx_step++;
|
rx_step++;
|
||||||
break;
|
break;
|
||||||
|
case TIME_SYNC: //gives a pretty good base guess for the proper timestamp. Can be refined when traffic starts to flow (if wanted)
|
||||||
|
switch (rx_step)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
buildTimeBasis = c;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
buildTimeBasis += ((uint32_t)c << 8);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
buildTimeBasis += ((uint32_t)c << 16);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
buildTimeBasis += ((uint32_t)c << 24);
|
||||||
|
qDebug() << "GVRET firmware reports timestamp of " << buildTimeBasis;
|
||||||
|
txTimestampBasis = QDateTime::currentMSecsSinceEpoch() - ((uint64_t)buildTimeBasis / (uint64_t)1000ull);
|
||||||
|
continuousTimeSync = false;
|
||||||
|
rx_state = IDLE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
rx_step++;
|
||||||
|
break;
|
||||||
|
|
||||||
case GET_ANALOG_INPUTS: //get 9 bytes - 2 per analog input plus checksum
|
case GET_ANALOG_INPUTS: //get 9 bytes - 2 per analog input plus checksum
|
||||||
switch (rx_step)
|
switch (rx_step)
|
||||||
{
|
{
|
||||||
@@ -414,9 +445,6 @@ void SerialWorker::procRXChar(unsigned char c)
|
|||||||
}
|
}
|
||||||
rx_step++;
|
rx_step++;
|
||||||
break;
|
break;
|
||||||
case TIME_SYNC:
|
|
||||||
rx_state = IDLE;
|
|
||||||
break;
|
|
||||||
case SET_DIG_OUTPUTS:
|
case SET_DIG_OUTPUTS:
|
||||||
rx_state = IDLE;
|
rx_state = IDLE;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ private:
|
|||||||
bool doValidation;
|
bool doValidation;
|
||||||
bool gotValidated;
|
bool gotValidated;
|
||||||
bool isAutoRestart;
|
bool isAutoRestart;
|
||||||
|
bool continuousTimeSync;
|
||||||
QSerialPort *serial;
|
QSerialPort *serial;
|
||||||
QSerialPortInfo *currentPort;
|
QSerialPortInfo *currentPort;
|
||||||
CANFrameModel *canModel;
|
CANFrameModel *canModel;
|
||||||
@@ -86,6 +87,7 @@ private:
|
|||||||
int deviceBuildNum;
|
int deviceBuildNum;
|
||||||
int deviceSingleWireMode;
|
int deviceSingleWireMode;
|
||||||
uint64_t txTimestampBasis;
|
uint64_t txTimestampBasis;
|
||||||
|
uint32_t buildTimeBasis;
|
||||||
|
|
||||||
void procRXChar(unsigned char);
|
void procRXChar(unsigned char);
|
||||||
void sendCommValidation();
|
void sendCommValidation();
|
||||||
|
|||||||
Reference in New Issue
Block a user