mirror of
https://github.com/rvdbreemen/OTGW-firmware
synced 2024-11-16 04:33:49 +01:00
push update of OTGW serial class
This commit is contained in:
parent
00f5e42a24
commit
1521b5aab1
@ -78,22 +78,17 @@ OTGWSerial::OTGWSerial(int resetPin, int progressLed)
|
||||
}
|
||||
|
||||
int OTGWSerial::available() {
|
||||
if (upgradeEvent()) {
|
||||
return 0;
|
||||
} else {
|
||||
return HardwareSerial::available();
|
||||
}
|
||||
if (upgradeEvent()) return 0;
|
||||
return HardwareSerial::available();
|
||||
}
|
||||
|
||||
// Reimplement the read function. Other read functions call this to implement their functionality.
|
||||
int OTGWSerial::read() {
|
||||
int retval;
|
||||
char ch;
|
||||
if (upgradeEvent()) return -1;
|
||||
retval = HardwareSerial::read();
|
||||
if (retval >= 0) {
|
||||
ch = retval;
|
||||
matchBanner(&ch);
|
||||
matchBanner(retval);
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
@ -108,7 +103,6 @@ size_t OTGWSerial::write(uint8_t c) {
|
||||
return HardwareSerial::write(c);
|
||||
}
|
||||
|
||||
|
||||
size_t OTGWSerial::write(const uint8_t *buffer, size_t len) {
|
||||
if (upgradeEvent()) return 0;
|
||||
return HardwareSerial::write(buffer, len);
|
||||
@ -158,18 +152,19 @@ void OTGWSerial::progress(int weight) {
|
||||
}
|
||||
|
||||
// Look for the banner in the incoming data and extract the version number
|
||||
void OTGWSerial::matchBanner(const char *str, int len) {
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (banner[_banner_matched] == '\0') {
|
||||
if (isspace(str[i])) {
|
||||
_version[_version_pos] = '\0';
|
||||
_banner_matched = 0;
|
||||
_version_pos = 0;
|
||||
} else {
|
||||
_version[_version_pos++] = str[i];
|
||||
}
|
||||
} else if (str[i] != banner[_banner_matched++]) {
|
||||
void OTGWSerial::matchBanner(char ch) {
|
||||
if (banner[_banner_matched] == '\0') {
|
||||
if (isspace(ch)) {
|
||||
_version[_version_pos] = '\0';
|
||||
_banner_matched = 0;
|
||||
_version_pos = 0;
|
||||
} else {
|
||||
_version[_version_pos++] = ch;
|
||||
}
|
||||
} else if (ch != banner[_banner_matched++]) {
|
||||
_banner_matched = 0;
|
||||
if (ch == banner[_banner_matched]) {
|
||||
_banner_matched++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -72,25 +72,22 @@ class OTGWSerial: public HardwareSerial {
|
||||
size_t write(uint8_t c);
|
||||
size_t write(const uint8_t *buffer, size_t len);
|
||||
size_t write(const char *buffer, size_t len) {
|
||||
return write((const uint8_t *)buffer, len);
|
||||
return write((const uint8_t *)buffer, len);
|
||||
}
|
||||
|
||||
// These handle ambiguity for write(0) case, because (0) can be a pointer or an integer
|
||||
inline size_t write(short t) { return write((uint8_t)t); }
|
||||
inline size_t write(unsigned short t) { return write((uint8_t)t); }
|
||||
inline size_t write(int t) { return write((uint8_t)t); }
|
||||
inline size_t write(unsigned int t) { return write((uint8_t)t); }
|
||||
inline size_t write(long t) { return write((uint8_t)t); }
|
||||
inline size_t write(unsigned long t) { return write((uint8_t)t); }
|
||||
// Enable write(char) to fall through to write(uint8_t)
|
||||
inline size_t write(char c) { return write((uint8_t) c); }
|
||||
inline size_t write(int8_t c) { return write((uint8_t) c); }
|
||||
|
||||
size_t write(const char *buffer) {
|
||||
if(buffer == NULL)
|
||||
return 0;
|
||||
return write((const uint8_t *)buffer, strlen(buffer));
|
||||
if (buffer == nullptr) return 0;
|
||||
return write((const uint8_t *)buffer, strlen(buffer));
|
||||
}
|
||||
// These handle ambiguity for write(0) case, because (0) can be a pointer or an integer
|
||||
inline size_t write(short t) {return write((uint8_t)t);}
|
||||
inline size_t write(unsigned short t) {return write((uint8_t)t);}
|
||||
inline size_t write(int t) {return write((uint8_t)t);}
|
||||
inline size_t write(unsigned int t) {return write((uint8_t)t);}
|
||||
inline size_t write(long t) {return write((uint8_t)t);}
|
||||
inline size_t write(unsigned long t) {return write((uint8_t)t);}
|
||||
// Enable write(char) to fall through to write(uint8_t)
|
||||
inline size_t write(char c) {return write((uint8_t) c);}
|
||||
inline size_t write(int8_t c) {return write((uint8_t) c);}
|
||||
|
||||
const char *firmwareVersion();
|
||||
bool busy();
|
||||
@ -109,7 +106,7 @@ class OTGWSerial: public HardwareSerial {
|
||||
|
||||
void SetLED(int state);
|
||||
void progress(int weight);
|
||||
void matchBanner(const char *str, int len = 1);
|
||||
void matchBanner(char ch);
|
||||
unsigned char hexChecksum(char *hex, int len);
|
||||
OTGWError readHexFile(const char *hexfile, int *total = nullptr);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user