Skip to content

Commit 24464a6

Browse files
committed
Use LED blinking in MySensor where appropriate
Signed-off-by: Tomas Hozza <[email protected]>
1 parent 58efd87 commit 24464a6

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

libraries/MySensors/MySensor.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,12 +327,18 @@ boolean MySensor::sendRoute(MyMessage &message) {
327327
// If we still don't have any parent id, re-request and skip this message.
328328
if (nc.parentNodeId == AUTO) {
329329
findParentNode();
330+
#ifdef WITH_LEDS_BLINKING
331+
errBlink(1);
332+
#endif
330333
return false;
331334
}
332335

333336
// If we still don't have any node id, re-request and skip this message.
334337
if (nc.nodeId == AUTO) {
335338
requestNodeId();
339+
#ifdef WITH_LEDS_BLINKING
340+
errBlink(1);
341+
#endif
336342
return false;
337343
}
338344

@@ -369,10 +375,16 @@ boolean MySensor::sendRoute(MyMessage &message) {
369375
}
370376
if (hw_millis() - enter > MY_VERIFICATION_TIMEOUT_MS) {
371377
debug(PSTR("nonce tmo\n"));
378+
#ifdef WITH_LEDS_BLINKING
379+
errBlink(1);
380+
#endif
372381
return false;
373382
}
374383
if (!signOk) {
375384
debug(PSTR("sign fail\n"));
385+
#ifdef WITH_LEDS_BLINKING
386+
errBlink(1);
387+
#endif
376388
return false;
377389
}
378390
// After this point, only the 'last' member of the message structure is allowed to be altered if the message has been signed,
@@ -431,6 +443,9 @@ boolean MySensor::sendRoute(MyMessage &message) {
431443
if (!ok) {
432444
// Failure when sending to parent node. The parent node might be down and we
433445
// need to find another route to gateway.
446+
#ifdef WITH_LEDS_BLINKING
447+
errBlink(1);
448+
#endif
434449
failedTransmissions++;
435450
if (autoFindParent && failedTransmissions > SEARCH_FAILURES) {
436451
findParentNode();
@@ -445,6 +460,9 @@ boolean MySensor::sendWrite(uint8_t to, MyMessage &message) {
445460
mSetVersion(message, PROTOCOL_VERSION);
446461
uint8_t length = mGetSigned(message) ? MAX_MESSAGE_LENGTH : mGetLength(message);
447462
message.last = nc.nodeId;
463+
#ifdef WITH_LEDS_BLINKING
464+
txBlink(1);
465+
#endif
448466
bool ok = radio.send(to, &message, min(MAX_MESSAGE_LENGTH, HEADER_SIZE + length));
449467

450468
debug(PSTR("send: %d-%d-%d-%d s=%d,c=%d,t=%d,pt=%d,l=%d,sg=%d,st=%s:%s\n"),
@@ -504,6 +522,9 @@ boolean MySensor::process() {
504522
debug(PSTR("fw upd fail\n"));
505523
// Give up. We have requested MY_OTA_RETRY times without any packet in return.
506524
fwUpdateOngoing = false;
525+
#ifdef WITH_LEDS_BLINKING
526+
errBlink(1);
527+
#endif
507528
return false;
508529
}
509530
fwRetry--;
@@ -525,6 +546,9 @@ boolean MySensor::process() {
525546
#endif
526547

527548
uint8_t len = radio.receive((uint8_t *)&msg);
549+
#ifdef WITH_LEDS_BLINKING
550+
rxBlink(1);
551+
#endif
528552

529553
#ifdef MY_SIGNING_FEATURE
530554
// Before processing message, reject unsigned messages if signing is required and check signature (if it is signed and addressed to us)
@@ -537,10 +561,16 @@ boolean MySensor::process() {
537561
if (!mGetSigned(msg)) {
538562
// Got unsigned message that should have been signed
539563
debug(PSTR("no sign\n"));
564+
#ifdef WITH_LEDS_BLINKING
565+
errBlink(1);
566+
#endif
540567
return false;
541568
}
542569
else if (!signer.verifyMsg(msg)) {
543570
debug(PSTR("verify fail\n"));
571+
#ifdef WITH_LEDS_BLINKING
572+
errBlink(1);
573+
#endif
544574
return false; // This signed message has been tampered with!
545575
}
546576
}
@@ -554,6 +584,9 @@ boolean MySensor::process() {
554584

555585
if(!(mGetVersion(msg) == PROTOCOL_VERSION)) {
556586
debug(PSTR("ver mismatch\n"));
587+
#ifdef WITH_LEDS_BLINKING
588+
errBlink(1);
589+
#endif
557590
return false;
558591
}
559592

0 commit comments

Comments
 (0)