Browse Source

bugfixes

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
main
Stephan Richter 12 months ago
parent
commit
59f49b4bd4
  1. 21
      SoftRS485.cpp

21
SoftRS485.cpp

@ -12,11 +12,12 @@
// Pins // Pins
int _RO, _RE, _DE, _DI; int _RO, _RE, _DE, _DI;
const long _pulse_len = 1000; const unsigned long _pulse_len = 1000;
const long _break = _pulse_len * 20; const unsigned long _break = _pulse_len * 20;
boolean _line = LOW; // current state of the transmission line
long _last_flip = 0; // timestamp since last flip of line state unsigned long _last_flip = 0; // timestamp of last flip of line state
boolean _start = false; // indicates whether a start bit shall be ignored boolean _line = LOW; // current state of the transmission line
boolean _start = false; // indicates whether a start bit shall be ignored
// Receive vars // Receive vars
byte _recv_msg[MSG_LEN]; // message buffer byte _recv_msg[MSG_LEN]; // message buffer
@ -25,9 +26,9 @@ int _pos = 0; // character position within the buffer
int _idx = 0; // bit position within the current character int _idx = 0; // bit position within the current character
// variables, that could be local, but are stored globally for speed optimization // variables, that could be local, but are stored globally for speed optimization
long _diff = 0; // time difference between last flips unsigned long _diff = 0; // time difference between last flips
long _now = 0; // current time unsigned long _now = 0; // current time
long _count = 0; // helper for bit iteration unsigned long _count = 0; // helper for bit iteration
#if defined CONTROLLINO_MAXI #if defined CONTROLLINO_MAXI
@ -74,9 +75,9 @@ void interrupt485(){
Serial.print(_line); Serial.print(_line);
#endif #endif
if (_idx == 8){ // full byte received if (_idx == 8){ // full byte received
if (_recv_msg[_pos] == 0x00){ // received byte is string terminator if (_pos == MSG_LEN || _recv_msg[_pos] == 0x00){ // received byte is string terminator
_avail = true; // notify about complete transmission _avail = true; // notify about complete transmission
// TODO: prevent writing out of buffer boundaries! break;
} }
_pos++; // advance to nect character of buffer _pos++; // advance to nect character of buffer
_idx=0; // start with first bit of that character _idx=0; // start with first bit of that character

Loading…
Cancel
Save