1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2025-04-21 12:31:19 +02:00

ready for hardware debugging

This commit is contained in:
travis-farmer 2024-12-15 16:43:26 -05:00
parent 0a6bc136b0
commit 74bfb0ca6e
No known key found for this signature in database
GPG Key ID: 0BC296791D14CB35
2 changed files with 2 additions and 68 deletions

View File

@ -41,48 +41,6 @@ taskBuffer::~taskBuffer()
// destructor
}
/* -= updateCrc =-
//
// add the CRC value from _calculateCrc (2 bytes) to the buffer.
*/
void taskBuffer::updateCrc(uint8_t *crcBuf, uint8_t *buf, uint16_t len) {
if (sizeof(crcBuf) != 2) return;
uint16_t crc = _calculateCrc(buf, len);
crcBuf[0] = lowByte(crc);
crcBuf[1] = highByte(crc);
}
/* -= crcGood =-
//
// return TRUE if CRC matched between buffer copy, and calculated.
*/
bool taskBuffer::crcGood(uint8_t *buf, uint16_t len) {
uint16_t aduCrc = buf[len] | (buf[len + 1] << 8);
uint16_t calculatedCrc = _calculateCrc(buf, len);
#if defined(IO_DIAG)
DIAG(F("CRC is %d Expected %d"),calculatedCrc, aduCrc);
#endif
if (aduCrc == calculatedCrc) return true;
else return false;
}
/* -= calculateCrc =-
//
// use bitwise XOR to calculate CRC into a 16-bit byte
*/
uint16_t taskBuffer::_calculateCrc(uint8_t *buf, uint16_t len) {
uint16_t value = 0xFFFF;
for (uint16_t i = 0; i < len; i++) {
value ^= (uint16_t)buf[i];
for (uint8_t j = 0; j < 8; j++) {
bool lsb = value & 1;
value >>= 1;
if (lsb == true) value ^= 0xA001;
}
}
return value;
}
void taskBuffer::doCommand(uint8_t *commandBuffer, int commandSize) {
for (taskBuffer * t=first;t;t=t->next) t->doCommand2(commandBuffer,commandSize);
}
@ -90,13 +48,10 @@ void taskBuffer::doCommand(uint8_t *commandBuffer, int commandSize) {
void taskBuffer::doCommand2(uint8_t *commandBuffer, int commandSize) {
// process commands here to be sent
uint8_t crcBuffer[2];
updateCrc(crcBuffer, commandBuffer, commandSize);
//_serial->begin(115200);
//ArduinoPins::fastWriteDigital(bus->_txPin, HIGH);
digitalWrite(_txPin,HIGH);
unsigned long startMillis = millis();
serial->write(commandBuffer, 7);
serial->write(endChar, 1);
serial->flush();
@ -353,6 +308,7 @@ bool RSprotonode::_configure(VPIN vpin, ConfigTypeEnum configType, int paramCoun
DIAG(F("EX-IOExpander485 Vpin %u cannot be used as a digital input pin"), pin);
}
resFlag = 0;
return false;
}
int RSprotonode::_configureAnalogIn(VPIN vpin) {
@ -439,7 +395,6 @@ void RSprotonode::_write(VPIN vpin, int value) {
void RSprotonode::_writeAnalogue(VPIN vpin, int value, uint8_t profile, uint16_t duration) {
uint8_t servoBuffer[7];
uint8_t responseBuffer[1];
int pin = vpin - _firstVpin;
servoBuffer[0] = EXIOWRAN;
servoBuffer[1] = (uint8_t) pin;

View File

@ -88,7 +88,6 @@ static taskBuffer *first;
STARTBYTE = 0xFD,
ENDBYTE = 0xFE,
};
uint16_t _calculateCrc(uint8_t *buf, uint16_t len);
void doCommand2(uint8_t *commandBuffer=NULL, int commandSize=0);
void loop2();
void parseRx(uint8_t *buf);
@ -96,8 +95,6 @@ static taskBuffer *first;
public:
taskBuffer(Stream * myserial);
~taskBuffer();
void updateCrc(uint8_t *crcBuf, uint8_t *buf, uint16_t len);
bool crcGood(uint8_t *buf, uint16_t len);
static void doCommand(uint8_t *commandBuffer=NULL, int commandSize=0);
static void init(unsigned long baud, int8_t txPin=-1);
static void loop();
@ -155,21 +152,17 @@ public:
uint8_t _numDigitalPins = 0;
uint8_t _numAnaloguePins = 0;
uint8_t _majorVer = 0;
uint8_t _minorVer = 0;
uint8_t _patchVer = 0;
uint8_t* _digitalInputStates = NULL;
uint8_t* _analogueInputStates = NULL;
uint8_t* _analogueInputBuffer = NULL; // buffer for I2C input transfers
uint8_t _readCommandBuffer[4];
uint8_t _digitalPinBytes = 0; // Size of allocated memory buffer (may be longer than needed)
uint8_t _analoguePinBytes = 0; // Size of allocated memory buffer (may be longer than needed)
uint8_t* _analoguePinMap = NULL;
int resFlag = 0;
bool _initalized;
static void create(VPIN firstVpin, int nPins, uint8_t nodeID) {
if (checkNoOverlap(firstVpin, nPins)) new RSprotonode(firstVpin, nPins, nodeID);
@ -195,21 +188,11 @@ public:
}
bool _configure(VPIN vpin, ConfigTypeEnum configType, int paramCount, int params[]) override;
int _configureAnalogIn(VPIN vpin) override;
void _begin() override;
int _read(VPIN vpin) override;
void _write(VPIN vpin, int value) override;
bool testAndStripMasterFlag(uint8_t *buf);
int _readAnalogue(VPIN vpin) override;
void _writeAnalogue(VPIN vpin, int value, uint8_t profile, uint16_t duration) override;
uint8_t getBusNumber() {
@ -220,7 +203,6 @@ public:
DIAG(F("EX-IOExpander485 node:%d v%d.%d.%d Vpins %u-%u %S"), _nodeID, _majorVer, _minorVer, _patchVer, (int)_firstVpin, (int)_firstVpin+_nPins-1, _deviceState == DEVSTATE_FAILED ? F("OFFLINE") : F(""));
}
};
/**********************************************************************
@ -266,11 +248,8 @@ private:
RSprotonode *_nodeListStart = NULL, *_nodeListEnd = NULL;
RSprotonode *_currentNode = NULL;
uint8_t _exceptionResponse = 0;
uint8_t getExceptionResponse();
uint16_t _receiveDataIndex = 0; // Index of next data byte to be received.
RSproto *_nextBus = NULL; // Pointer to next bus instance in list.
void setTimeout(unsigned long timeout);
// Helper function for error handling
void reportError(uint8_t status, bool fail=true) {