mirror of
https://github.com/lumapu/ahoy.git
synced 2025-05-24 22:36:10 +02:00
improv: first two commands are working (state and device info)
This commit is contained in:
parent
62c9cb7529
commit
ba3f84d684
3 changed files with 28 additions and 23 deletions
|
@ -98,6 +98,7 @@ void app::setup() {
|
|||
//-----------------------------------------------------------------------------
|
||||
void app::loop(void) {
|
||||
mInnerLoopCb();
|
||||
mImprov.tickSerial();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -173,7 +174,7 @@ void app::regularTickers(void) {
|
|||
if (mConfig->plugin.display.type != 0)
|
||||
everySec(std::bind(&DisplayType::tickerSecond, &mDisplay), "disp");
|
||||
every(std::bind(&PubSerialType::tick, &mPubSerial), mConfig->serial.interval, "uart");
|
||||
everySec(std::bind(&Improv::tickSerial, &mImprov), "impro");
|
||||
//everySec(std::bind(&Improv::tickSerial, &mImprov), "impro");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
@ -49,21 +49,23 @@
|
|||
#endif
|
||||
|
||||
//template <class T>
|
||||
inline void DBGPRINT(String str) { DSERIAL.print(str); if(NULL != mCb) mCb(str); }
|
||||
inline void DBGPRINT(String str, bool ser = true) { if(ser) DSERIAL.print(str); if(NULL != mCb) mCb(str); }
|
||||
//template <class T>
|
||||
inline void DBGPRINTLN(String str) { DBGPRINT(str); DBGPRINT(F("\r\n")); }
|
||||
inline void DHEX(uint8_t b) {
|
||||
if( b<0x10 ) DSERIAL.print(F("0"));
|
||||
DSERIAL.print(b,HEX);
|
||||
inline void DBGPRINTLN(String str, bool ser = true) { DBGPRINT(str); DBGPRINT(F("\r\n")); }
|
||||
inline void DHEX(uint8_t b, bool ser = true) {
|
||||
if(ser) {
|
||||
if( b<0x10 ) DSERIAL.print(F("0"));
|
||||
DSERIAL.print(b,HEX);
|
||||
}
|
||||
if(NULL != mCb) {
|
||||
if( b<0x10 ) mCb(F("0"));
|
||||
mCb(String(b, HEX));
|
||||
}
|
||||
}
|
||||
|
||||
inline void DBGHEXLN(uint8_t b) {
|
||||
DHEX(b);
|
||||
DBGPRINT(F("\r\n"));
|
||||
inline void DBGHEXLN(uint8_t b, bool ser = true) {
|
||||
DHEX(b, ser);
|
||||
DBGPRINT(F("\r\n"), ser);
|
||||
}
|
||||
/*inline void DHEX(uint16_t b) {
|
||||
if( b<0x10 ) DSERIAL.print(F("000"));
|
||||
|
|
|
@ -25,15 +25,15 @@ class Improv {
|
|||
if(Serial.available() == 0)
|
||||
return;
|
||||
|
||||
uint8_t buf[80];
|
||||
uint8_t len = Serial.readBytes(buf, 80);
|
||||
dumpBuf(buf, len);
|
||||
uint8_t buf[40];
|
||||
uint8_t len = Serial.readBytes(buf, 40);
|
||||
|
||||
if(!checkPaket(&buf[0], 13, [this](uint8_t type, uint8_t buf[], uint8_t len) {
|
||||
if(!checkPaket(&buf[0], len, [this](uint8_t type, uint8_t buf[], uint8_t len) {
|
||||
parsePayload(type, buf, len);
|
||||
})) {
|
||||
DBGPRINT(F("checkHeader failed"));
|
||||
DBGPRINTLN(F("check paket failed"));
|
||||
}
|
||||
dumpBuf(buf, len);
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -64,21 +64,24 @@ class Improv {
|
|||
|
||||
void dumpBuf(uint8_t buf[], uint8_t len) {
|
||||
for(uint8_t i = 0; i < len; i++) {
|
||||
DHEX(buf[i]);
|
||||
DBGPRINT(" ");
|
||||
DHEX(buf[i], false);
|
||||
DBGPRINT(" ", false);
|
||||
}
|
||||
DBGPRINTLN("");
|
||||
DBGPRINTLN("", false);
|
||||
}
|
||||
|
||||
inline uint8_t buildChecksum(uint8_t buf[], uint8_t len) {
|
||||
uint8_t calc = 0;
|
||||
for(uint8_t i = 0; i < (len - 1); i++) {
|
||||
for(uint8_t i = 0; i < len; i++) {
|
||||
calc += buf[i];
|
||||
}
|
||||
return calc;
|
||||
}
|
||||
|
||||
inline bool checkChecksum(uint8_t buf[], uint8_t len) {
|
||||
/*DHEX(buf[len], false);
|
||||
DBGPRINT(F(" == "), false);
|
||||
DBGHEXLN(buildChecksum(buf, len), false);*/
|
||||
return ((buildChecksum(buf, len)) == buf[len]);
|
||||
}
|
||||
|
||||
|
@ -93,7 +96,7 @@ class Improv {
|
|||
if(0x01 != buf[6])
|
||||
return false;
|
||||
|
||||
if(!checkChecksum(buf, (6+3 + buf[9])))
|
||||
if(!checkChecksum(buf, (9 + buf[8])))
|
||||
return false;
|
||||
|
||||
cb(buf[7], &buf[9], buf[8]);
|
||||
|
@ -151,17 +154,16 @@ class Improv {
|
|||
buf[5] = 'V';
|
||||
buf[6] = 1; // protocol version
|
||||
|
||||
buf[len] = buildChecksum(buf, (len+1));
|
||||
buf[len] = buildChecksum(buf, len);
|
||||
len++;
|
||||
dumpBuf(buf, len);
|
||||
Serial.write(buf, len);
|
||||
dumpBuf(buf, len);
|
||||
}
|
||||
|
||||
void parsePayload(uint8_t type, uint8_t buf[], uint8_t len) {
|
||||
DBGPRINTLN(F("parsePayload"));
|
||||
if(TYPE_RPC == type) {
|
||||
if(GET_CURRENT_STATE == buf[0])
|
||||
setState(0x00);
|
||||
setState(STATE_AUTHORIZED);
|
||||
else if(GET_DEVICE_INFO == buf[0])
|
||||
sendDevInfo();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue