129 #include <inttypes.h>
138 #define NO_IGNORE_CHAR '\x01'
140 #ifndef SDI12_BUFFER_SIZE
151 #define SDI12_BUFFER_SIZE 81
154 #if defined(ESP32) || defined(ESP8266)
183 #define READTIME sdi12timer.SDI12TimerRead()
188 #define READTIME TCNTX
205 static SDI12* _activeObject;
215 static const uint16_t bitWidth_micros;
220 static const uint16_t lineBreak_micros;
224 static const uint16_t marking_micros;
229 static const uint8_t txBitWidth;
233 static const uint8_t rxWindowWidth;
237 static const uint8_t bitsPerTick_Q10;
241 static const uint8_t WAITING_FOR_START_BIT;
246 static uint16_t prevBitTCNT;
253 static uint8_t rxState;
260 static uint8_t rxMask;
264 static uint8_t rxValue;
274 static uint16_t mul8x8to16(uint8_t x, uint8_t y);
291 static uint16_t bitTimes(uint8_t dt);
330 static volatile uint8_t _rxBufferTail;
334 static volatile uint8_t _rxBufferHead;
338 bool _bufferOverflow;
492 int peekNextDigit(LookaheadMode lookahead,
bool detectDecimal);
527 explicit SDI12(int8_t dataPin);
557 void begin(int8_t dataPin);
717 typedef enum SDI12_STATES {
746 static uint8_t parity_even_bit(uint8_t v);
756 void setPinInterrupts(
bool enable);
765 void setState(SDI12_STATES state);
832 void wakeSensors(int8_t extraWakeTime = 0);
849 void writeChar(uint8_t out);
863 virtual size_t write(uint8_t
byte);
882 void sendCommand(String& cmd, int8_t extraWakeTime = 0);
883 void sendCommand(
const char* cmd, int8_t extraWakeTime = 0);
938 void charToBuffer(uint8_t c);
const __FlashStringHelper * FlashString
Helper for strings stored in flash.
Definition: SDI12.h:135
#define SDI12_BUFFER_SIZE
The buffer size for incoming SDI-12 data.
Definition: SDI12.h:151
#define NO_IGNORE_CHAR
a char not found in a valid ASCII numeric field
Definition: SDI12.h:138
This file defines the timing units needed for various Arduino boards.
The main class for SDI 12 instances.
Definition: SDI12.h:194
The class used to define the processor timer for the SDI-12 serial emulation.
Definition: SDI12_boards.h:33
void sendCommand(String &cmd, int8_t extraWakeTime=0)
Send a command out on the data line, acting as a datalogger (master)
Definition: SDI12.cpp:490
void sendResponse(String &resp)
Send a response out on the data line (for slave use)
Definition: SDI12.cpp:519
virtual size_t write(uint8_t byte)
Write out a byte on the SDI-12 line.
Definition: SDI12.cpp:482
void setDataPin(int8_t dataPin)
Set the data pin for the current SDI-12 instance.
Definition: SDI12.cpp:279
int8_t getDataPin()
Get the data pin for the current SDI-12 instance.
Definition: SDI12.cpp:284
~SDI12()
Destroy the SDI12 object.
Definition: SDI12.cpp:243
SDI12()
Construct a new SDI12 instance with no data pin set.
Definition: SDI12.cpp:213
void end()
Disable the SDI-12 object (but do not destroy it).
Definition: SDI12.cpp:265
int16_t TIMEOUT
The value to return if a parse or read times out with no return from the sensor.
Definition: SDI12.h:580
void begin()
Begin the SDI-12 object.
Definition: SDI12.cpp:252
void setTimeoutValue(int16_t value)
Set the value to return if a parse int or parse float times out with no return from the sensor.
Definition: SDI12.cpp:274
static void handleInterrupt()
Intermediary used by the ISR - passes off responsibility for the interrupt to the active object.
Definition: SDI12.cpp:560
void forceListen()
Set line state to SDI12_LISTENING.
Definition: SDI12.cpp:400
void forceHold()
Set line state to SDI12_HOLDING.
Definition: SDI12.cpp:395
bool isActive()
Check if this instance is active.
Definition: SDI12.cpp:301
bool setActive()
Set this instance as the active SDI-12 instance.
Definition: SDI12.cpp:291
void flush() override
Wait for sending to finish - because no TX buffering, does nothing.
Definition: SDI12.h:438
int available() override
Return the number of bytes available in the Rx buffer.
Definition: SDI12.cpp:100
long parseInt(LookaheadMode lookahead=SKIP_ALL, char ignore=NO_IGNORE_CHAR)
Return the first valid (long) integer value from the current position.
Definition: SDI12.cpp:152
float parseFloat(LookaheadMode lookahead=SKIP_ALL, char ignore=NO_IGNORE_CHAR)
Return the first valid float value from the current position.
Definition: SDI12.cpp:178
int peek() override
Reveal next byte in the Rx buffer without consuming it.
Definition: SDI12.cpp:106
void clearBuffer()
Clear the Rx buffer by setting the head and tail pointers to the same value.
Definition: SDI12.cpp:113
int peekNextDigit(LookaheadMode lookahead, bool detectDecimal)
Return the next numeric digit in the stream or -1 if timeout.
Definition: SDI12.cpp:128
int read() override
Return next byte in the Rx buffer, consuming it.
Definition: SDI12.cpp:119