mirror of
https://codeberg.org/mclemens/ubitxv6.git
synced 2024-06-13 11:40:48 +00:00
Simplify timeout logic, saving nearly 100 bytes
This commit is contained in:
parent
e8c80a8304
commit
18a05460aa
|
@ -15,10 +15,9 @@
|
||||||
* it gives time out error with WSJTX 1.8.0
|
* it gives time out error with WSJTX 1.8.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static unsigned long rxBufferArriveTime = 0;
|
static const uint8_t FT817_MESSAGE_SIZE = 5;
|
||||||
static uint8_t rxBufferCheckCount = 0;
|
|
||||||
|
|
||||||
static uint8_t cat[5];//Data is ordered parameters 1-4, then command code last
|
//Data is ordered parameters 1-4, then command code last
|
||||||
enum CatDataIndex_e : uint8_t {
|
enum CatDataIndex_e : uint8_t {
|
||||||
P1 = 0,
|
P1 = 0,
|
||||||
P2 = 1,
|
P2 = 1,
|
||||||
|
@ -27,10 +26,8 @@ enum CatDataIndex_e : uint8_t {
|
||||||
CMD = 4
|
CMD = 4
|
||||||
};
|
};
|
||||||
|
|
||||||
static uint8_t insideCat = 0;
|
|
||||||
|
|
||||||
//for broken protocol
|
//for broken protocol
|
||||||
static const uint16_t CAT_RECEIVE_TIMEOUT = 500;
|
static const uint16_t CAT_RECEIVE_TIMEOUT_MS = 500;
|
||||||
|
|
||||||
static const uint8_t CAT_MODE_LSB = 0x00;
|
static const uint8_t CAT_MODE_LSB = 0x00;
|
||||||
static const uint8_t CAT_MODE_USB = 0x01;
|
static const uint8_t CAT_MODE_USB = 0x01;
|
||||||
|
@ -44,8 +41,6 @@ static const uint8_t CAT_MODE_FMN = 0x88;
|
||||||
|
|
||||||
static const uint8_t ACK = 0;
|
static const uint8_t ACK = 0;
|
||||||
|
|
||||||
unsigned int skipTimeCount = 0;
|
|
||||||
|
|
||||||
uint8_t setHighNibble(uint8_t b, uint8_t v) {
|
uint8_t setHighNibble(uint8_t b, uint8_t v) {
|
||||||
// Clear the high nibble
|
// Clear the high nibble
|
||||||
b &= 0x0f;
|
b &= 0x0f;
|
||||||
|
@ -118,7 +113,7 @@ unsigned long readFreq(uint8_t* cmd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//void ReadEEPRom_FT817(uint8_t fromType)
|
//void ReadEEPRom_FT817(uint8_t fromType)
|
||||||
void catReadEEPRom(void)
|
void catReadEEPRom(uint8_t* cat)
|
||||||
{
|
{
|
||||||
//for remove warnings
|
//for remove warnings
|
||||||
uint8_t temp0 = cat[P1];
|
uint8_t temp0 = cat[P1];
|
||||||
|
@ -347,7 +342,7 @@ void processCATCommand2(uint8_t* cmd) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0xBB: //Read FT-817 EEPROM Data (for comfirtable)
|
case 0xBB: //Read FT-817 EEPROM Data (for comfirtable)
|
||||||
catReadEEPRom();
|
catReadEEPRom(cmd);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0xe7 :
|
case 0xe7 :
|
||||||
|
@ -381,67 +376,34 @@ void processCATCommand2(uint8_t* cmd) {
|
||||||
response[0] = 0x00;
|
response[0] = 0x00;
|
||||||
Serial.write(response[0]);
|
Serial.write(response[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
insideCat = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int catCount = 0;
|
|
||||||
void checkCAT(){
|
void checkCAT(){
|
||||||
uint8_t i;
|
static uint8_t rx_buffer[FT817_MESSAGE_SIZE];
|
||||||
|
static uint8_t current_index = 0;
|
||||||
|
static uint32_t timeout = 0;
|
||||||
//Check Serial Port Buffer
|
//Check Serial Port Buffer
|
||||||
if (Serial.available() == 0) { //Set Buffer Clear status
|
if (Serial.available() == 0) { //Set Buffer Clear status
|
||||||
rxBufferCheckCount = 0;
|
if(timeout < millis()){
|
||||||
return;
|
current_index = 0;
|
||||||
}
|
timeout = 0;
|
||||||
else if (Serial.available() < 5) { //First Arrived
|
|
||||||
if (rxBufferCheckCount == 0){
|
|
||||||
rxBufferCheckCount = Serial.available();
|
|
||||||
rxBufferArriveTime = millis() + CAT_RECEIVE_TIMEOUT; //Set time for timeout
|
|
||||||
}
|
|
||||||
else if (rxBufferArriveTime < millis()){ //Clear Buffer
|
|
||||||
for (i = 0; i < Serial.available(); i++)
|
|
||||||
rxBufferCheckCount = Serial.read();
|
|
||||||
rxBufferCheckCount = 0;
|
|
||||||
}
|
|
||||||
else if (rxBufferCheckCount < Serial.available()){ // Increase buffer count, slow arrive
|
|
||||||
rxBufferCheckCount = Serial.available();
|
|
||||||
rxBufferArriveTime = millis() + CAT_RECEIVE_TIMEOUT; //Set time for timeout
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
|
if(0 == current_index){
|
||||||
//Arived CAT DATA
|
timeout = millis() + CAT_RECEIVE_TIMEOUT_MS;
|
||||||
for (i = 0; i < 5; i++)
|
}
|
||||||
cat[i] = Serial.read();
|
rx_buffer[current_index] = Serial.read();
|
||||||
|
++current_index;
|
||||||
|
if(current_index < FT817_MESSAGE_SIZE){
|
||||||
//this code is not re-entrant.
|
return;
|
||||||
if (insideCat == 1)
|
}
|
||||||
return;
|
|
||||||
insideCat = 1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This routine is enabled to debug the cat protocol
|
|
||||||
**/
|
|
||||||
catCount++;
|
|
||||||
|
|
||||||
/*
|
|
||||||
if (cat[CMD] != 0xf7 && cat[CMD] != 0xbb && cat[CMD] != 0x03){
|
|
||||||
sprintf(b, "%d %02x %02x%02x%02x%02x", catCount, cat[CMD],cat[P1], cat[P2], cat[P3], cat[P4]);
|
|
||||||
printLine2(b);
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
processCATCommand2(rx_buffer);
|
||||||
if (!doingCAT){
|
current_index = 0;
|
||||||
doingCAT = 1;
|
timeout = 0;
|
||||||
displayText("CAT on", 100,120,100,40, ILI9341_ORANGE, ILI9341_BLACK, ILI9341_WHITE);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
processCATCommand2(cat);
|
|
||||||
insideCat = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user