Increase Buffer for SW Serial and Modified Protocol for EEProm

This commit is contained in:
phdlee 2018-06-16 21:45:55 +09:00
parent 0e13dd0267
commit 82177199c4
3 changed files with 36 additions and 18 deletions

View File

@ -32,6 +32,7 @@ SWSerial_Write to sSerial.write
SWSerial_Available to sSerial.available SWSerial_Available to sSerial.available
SWSerial_Read to sSerial.read SWSerial_Read to sSerial.read
KD8CEC, Ian Lee
----------------------------------------------------------------------- -----------------------------------------------------------------------
License License
All licenses for the source code are subject to the license of the original source SoftwareSerial Library. All licenses for the source code are subject to the license of the original source SoftwareSerial Library.
@ -76,7 +77,7 @@ http://arduiniana.org.
//================================================================ //================================================================
#define TX_PIN 9 #define TX_PIN 9
#define RX_PIN 8 #define RX_PIN 8
#define _SS_MAX_RX_BUFF 20 // RX buffer size #define _SS_MAX_RX_BUFF 35 // RX buffer size
#define PRINT_MAX_LENGTH 30 #define PRINT_MAX_LENGTH 30
//================================================================ //================================================================

View File

@ -32,9 +32,11 @@
#define UBITX_DISPLAY_NEXTION //NEXTION LCD #define UBITX_DISPLAY_NEXTION //NEXTION LCD
//#define UBITX_CONTROL_MCU //CONTROL MCU //#define UBITX_CONTROL_MCU //CONTROL MCU
//#define UBITX_DISPLAY_NEXTION_SAFE //Only EEProm Write 770~775
#define I2C_LCD_MASTER_ADDRESS_DEFAULT 0x27 //0x27 //DEFAULT, if Set I2C Address by uBITX Manager, read from EEProm #define I2C_LCD_MASTER_ADDRESS_DEFAULT 0x27 //0x27 //DEFAULT, if Set I2C Address by uBITX Manager, read from EEProm
#define I2C_LCD_SECOND_ADDRESS_DEFAULT 0x3F //0x27 //only using Dual LCD Mode #define I2C_LCD_SECOND_ADDRESS_DEFAULT 0x3F //0x27 //only using Dual LCD Mode
#define EXTEND_KEY_GROUP1 //MODE, BAND(-), BAND(+), STEP #define EXTEND_KEY_GROUP1 //MODE, BAND(-), BAND(+), STEP
//#define EXTEND_KEY_GROUP2 //Numeric (0~9), Point(.), Enter //Not supported in Version 1.0x //#define EXTEND_KEY_GROUP2 //Numeric (0~9), Point(.), Enter //Not supported in Version 1.0x

View File

@ -41,7 +41,7 @@ char c[30], b[30];
char softBuff[20]; char softBuff[20];
char softTemp[20]; char softTemp[20];
void LCD2004_Init() void LCDNextion_Init()
{ {
SWSerial_Begin(9600); SWSerial_Begin(9600);
memset(softBuffLines[0], ' ', TEXT_LINE_LENGTH); memset(softBuffLines[0], ' ', TEXT_LINE_LENGTH);
@ -52,8 +52,8 @@ void LCD2004_Init()
void LCD_Init(void) void LCD_Init(void)
{ {
LCD2004_Init(); LCDNextion_Init();
initMeter(); //for Meter Display //initMeter(); //for Meter Display
} }
//=================================================================== //===================================================================
@ -187,7 +187,7 @@ byte L_displayOption2; //byte displayOption2 (Reserve)
#define TS_CMD_SWTRIG 21 //SW Action Trigger for WSPR and more #define TS_CMD_SWTRIG 21 //SW Action Trigger for WSPR and more
#define TS_CMD_READMEM 31 //Read EEProm #define TS_CMD_READMEM 31 //Read EEProm
#define TS_CMD_WRITEMEM 32 //Write EEProm #define TS_CMD_WRITEMEM 32 //Write EEProm
#define TS_CMD_FACTORYRESET 33 //Factory Reset #define TS_CMD_FACTORYRESET 85 //Factory Reset
#define TS_CMD_UBITX_REBOOT 95 //Reboot #define TS_CMD_UBITX_REBOOT 95 //Reboot
char nowdisp = 0; char nowdisp = 0;
@ -630,10 +630,10 @@ void updateDisplay() {
#define RESPONSE_EEPROM_HEX_R 72 //Nextion order (Reverse) #define RESPONSE_EEPROM_HEX_R 72 //Nextion order (Reverse)
#define RESPONSE_EEPROM_STR 87 //String #define RESPONSE_EEPROM_STR 87 //String
uint8_t ResponseHeader[11]={'p', 'm', '.', 's', 'h', '.', 't', 'x', 't', '=', '"'}; const uint8_t ResponseHeader[11]={'p', 'm', '.', 's', 'h', '.', 't', 'x', 't', '=', '"'};
uint8_t ResponseFooter[4]={'"', 0xFF, 0xFF, 0xFF}; const uint8_t ResponseFooter[4]={'"', 0xFF, 0xFF, 0xFF};
char HexCodes[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', }; const char HexCodes[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', };
//void sendSpectrumData(unsigned long startFreq, unsigned long incStep, int scanCount, int delayTime, int sendCount) //void sendSpectrumData(unsigned long startFreq, unsigned long incStep, int scanCount, int delayTime, int sendCount)
//sendResponseData(RESPONSE_EEPROM, 0, eepromIndex, eepromReadLength, eepromDataType, 1); //sendResponseData(RESPONSE_EEPROM, 0, eepromIndex, eepromReadLength, eepromDataType, 1);
//protocol Type : 0 - Spectrum, 1 : EEProm //protocol Type : 0 - Spectrum, 1 : EEProm
@ -860,16 +860,35 @@ void SWS_Process(void)
} }
else if (commandType == TS_CMD_WRITEMEM) //Write Mem else if (commandType == TS_CMD_WRITEMEM) //Write Mem
{ {
/*
Address : 2 byte int
Length : Data Length
Checksum : (Addr0+Addr1+Len) %256
Data : Variable (Max 23)
*/
uint16_t eepromIndex = *(uint16_t *)(&swr_buffer[commandStartIndex + 4]); uint16_t eepromIndex = *(uint16_t *)(&swr_buffer[commandStartIndex + 4]);
byte eepromData = swr_buffer[commandStartIndex + 6]; byte writeLength = swr_buffer[commandStartIndex + 6];
byte eepromCheckSum = swr_buffer[commandStartIndex + 7]; byte writeCheckSum = swr_buffer[commandStartIndex + 7];
//Check Checksum //Check Checksum
//if (eepromCheckSum == (swr_buffer[commandStartIndex + 4] + swr_buffer[commandStartIndex + 5] + swr_buffer[commandStartIndex + 6])) if (writeCheckSum == (swr_buffer[commandStartIndex + 4] + swr_buffer[commandStartIndex + 5] + swr_buffer[commandStartIndex + 6]))
if (eepromCheckSum == (swr_buffer[commandStartIndex + 4] + swr_buffer[commandStartIndex + 5])) //if (writeCheckSum == (swr_buffer[commandStartIndex + 4] + swr_buffer[commandStartIndex + 5] + writeLength))
{ {
if (eepromIndex > 64) //if (eepromIndex > 64) //Safe #1
EEPROM.write(eepromIndex, eepromData); #ifdef UBITX_DISPLAY_NEXTION_SAFE
//Safe #2
if (eepromIndex < 770 || eepromIndex > 775 )
{
eepromIndex = -2;
}
else
#else
if (1 == 1)
#endif
{
for (int i = 0; i < writeLength; i++)
EEPROM.write(eepromIndex + i , swr_buffer[commandStartIndex + 8 + i]);
}
} }
else else
{ {
@ -892,10 +911,6 @@ void SWS_Process(void)
} }
} }
} }
//else if (commandType == TS_CMD_UBITX_REBOOT)
//{
//asm volatile (" jmp 0");
//}
setFrequency(frequency); setFrequency(frequency);
SetCarrierFreq(); SetCarrierFreq();