Skip to content

Commit a4752f5

Browse files
committed
Add ACan. Fix bug in OpenLcbCore.cpp.
1 parent f4cdd84 commit a4752f5

File tree

8 files changed

+21
-13
lines changed

8 files changed

+21
-13
lines changed

.DS_Store

0 Bytes
Binary file not shown.

src/.DS_Store

4 KB
Binary file not shown.

src/ACan/ACan.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
//

src/ESP32/ESP32can.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ int ESP32can::write(uint32_t _txId, uint8_t _txLength, uint8_t* _txData) {
241241
}
242242

243243
int ESP32can::avail() {
244-
dP("\nESP32can::avail");
244+
//dP("\nESP32can::avail");
245245
if ((readRegister(REG_SR) & 0x01) != 0x01) {
246246
// no packet
247247
return 0;

src/GCSerial.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ RTR CAN Message
5252
#include "debugging.h"
5353
#include <HardwareSerial.h>
5454

55+
extern void userUI(char) __attribute__((weak));
56+
5557
class OlcbCanClass : public OlcbCan {
5658
int charToHex(char c){
5759
if(c>='0' && c<='9') return c - '0';
@@ -130,6 +132,7 @@ class OlcbCanClass : public OlcbCan {
130132
//while( (c=inf->read()) >0 ) {
131133
while( (c=Serial.read()) >0 ) {
132134
if(c==':') { state = 1; break; }
135+
if( userUI ) userUI(c);
133136
}
134137
if(state!=1) return false;
135138
buff[0] =':';

src/OlcbCommonCAN/OpenLcbCore.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,12 @@ int16_t OpenLcbCore::findIndexOfEventID(EventID *key, int16_t startIndex)
366366
// get the state of an event from the user program
367367
extern uint8_t userState(uint16_t) __attribute__((weak));
368368
uint8_t getState(uint16_t index) {
369-
if(userState) return userState(index);
370-
return 7;
369+
if(userState) {
370+
uint8_t us = userState(index);
371+
dP("\nUserState="); dP(us);
372+
return us;
373+
}
374+
return 7; // UNKNOWN
371375
}
372376
void OpenLcbCore::check() {
373377
// see in any replies are waiting to send
@@ -460,7 +464,7 @@ void OpenLcbCore::sendTeach(EventID e) { /// DPH added for Clock
460464
sendEvent = sendEvent < index ? sendEvent : index;
461465
}
462466

463-
bool OpenLcbCore::receivedFrame(OlcbCanInterface* rcv) {
467+
bool OpenLcbCore::receivedFrame(OlcbCanInterface* rcv) {
464468
//dP("\nIn receivedFrame");
465469
//dP("\nIn OpenLcbCore::receivedFrame()");
466470
EventID eventid;
@@ -473,9 +477,10 @@ void OpenLcbCore::sendTeach(EventID e) { /// DPH added for Clock
473477
while((index = findIndexOfEventID(&eventid, index)) != -1)
474478
{
475479
// yes, we have to reply with ConsumerIdentified
476-
if (events[index].flags & Event::CAN_CONSUME_FLAG) {
477-
events[index].flags |= Event::IDENT_FLAG;
478-
sendEvent = sendEvent < index ? sendEvent : index;
480+
uint16_t eindex = this->eventsIndex[index];
481+
if (events[eindex].flags & Event::CAN_CONSUME_FLAG) {
482+
events[eindex].flags |= Event::IDENT_FLAG;
483+
sendEvent = sendEvent < eindex ? sendEvent : eindex;
479484
}
480485
index++;
481486
if(index>=numEvents) break;
@@ -489,9 +494,10 @@ void OpenLcbCore::sendTeach(EventID e) { /// DPH added for Clock
489494
while((index = findIndexOfEventID(&eventid, index)) != -1)
490495
{
491496
// yes, we have to reply with ProducerIdentified
492-
if (events[index].flags & Event::CAN_PRODUCE_FLAG) {
493-
events[index].flags |= Event::IDENT_FLAG;
494-
sendEvent = sendEvent < index ? sendEvent : index;
497+
uint16_t eindex = this->eventsIndex[index];
498+
if (events[eindex].flags & Event::CAN_PRODUCE_FLAG) {
499+
events[eindex].flags |= Event::IDENT_FLAG;
500+
sendEvent = sendEvent < eindex ? sendEvent : eindex;
495501
}
496502
index++;
497503
if(index>=numEvents) break;
@@ -504,7 +510,7 @@ void OpenLcbCore::sendTeach(EventID e) { /// DPH added for Clock
504510
for (int i = 0; i < numEvents; i++) {
505511
events[i].flags |= Event::IDENT_FLAG;
506512
}
507-
sendEvent = 0;
513+
sendEvent = 0;
508514
} else if (rcv->isPCEventReport()) {
509515
// found a PC Event Report, see if we consume it
510516
handlePCEventReport(rcv);
@@ -514,7 +520,6 @@ void OpenLcbCore::sendTeach(EventID e) { /// DPH added for Clock
514520
} else return false;
515521
return true;
516522
}
517-
518523
void OpenLcbCore::handlePCEventReport(OlcbCanInterface* rcv) {
519524
// dP("\nIn handlePCEventReport");
520525
EventID eventid;

src/libraries/.DS_Store

6 KB
Binary file not shown.

src/libraries/readme.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)