SparkFun Iridium 9604  v1.0.0
Library for the Iridium 9604 Hybrid LTE-M Cellular + Iridium Satellite (SBD) + GNSS IoT module
Loading...
Searching...
No Matches
sfe_bus.h
Go to the documentation of this file.
1
23#pragma once
24
25#include "sfe_platform.h"
26
28{
29
37 {
38 public:
39 virtual ~IridiumDeviceBus() {}
40
49 virtual bool ping() = 0;
50
56 virtual uint16_t available() = 0;
57
68 virtual size_t writeBytes(const uint8_t *data, size_t length) = 0;
69
77 virtual size_t readBytes(uint8_t *data, size_t length) = 0;
78
88 virtual bool setBaudRate(unsigned long baud) = 0;
89 };
90
91#if defined(SFE_IRIDIUM_ARDUINO)
92
98 class SfeSerial : public IridiumDeviceBus
99 {
100 public:
104 SfeSerial(void);
105
117 bool init(HardwareSerial &serialPort);
118
120 bool ping() { return false; }
121
127 uint16_t available();
128
136 size_t writeBytes(const uint8_t *data, size_t length);
137
145 size_t readBytes(uint8_t *data, size_t length);
146
157 bool setBaudRate(unsigned long baud);
158
159 private:
160 HardwareSerial *_serialPort;
161 };
162
168 class SfePrint
169 {
170 public:
172 SfePrint(void) { _outputPort = nullptr; }
173
175 void init(Print &outputPort) { _outputPort = &outputPort; }
177 inline bool operator==(SfePrint const &other) const { return _outputPort == other._outputPort; }
179 inline bool operator!=(SfePrint const &other) const { return !(*this == other); }
181 inline bool isSet(void) const { return _outputPort != nullptr; }
182
183 void write(uint8_t c)
184 {
185 if (_outputPort != nullptr)
186 _outputPort->write(c);
187 }
188 void write(const uint8_t *buffer, size_t length)
189 {
190 if ((_outputPort != nullptr) && (buffer != nullptr))
191 _outputPort->write(buffer, length);
192 }
193 void print(const char *c)
194 {
195 if ((_outputPort != nullptr) && (c != nullptr))
196 _outputPort->print(c);
197 }
198 void print(int value, int base = DEC)
199 {
200 if (_outputPort != nullptr)
201 _outputPort->print(value, base);
202 }
203 void print(unsigned int value, int base = DEC)
204 {
205 if (_outputPort != nullptr)
206 _outputPort->print(value, base);
207 }
208 void print(long value, int base = DEC)
209 {
210 if (_outputPort != nullptr)
211 _outputPort->print(value, base);
212 }
213 void print(unsigned long value, int base = DEC)
214 {
215 if (_outputPort != nullptr)
216 _outputPort->print(value, base);
217 }
218 void print(double value, int decimalPlaces)
219 {
220 if (_outputPort != nullptr)
221 _outputPort->print(value, decimalPlaces);
222 }
223 void println()
224 {
225 if (_outputPort != nullptr)
226 _outputPort->println();
227 }
228 void println(const char *c)
229 {
230 print(c);
231 println();
232 }
233
234 private:
235 Print *_outputPort;
236 };
237
238 // The type used by the public API for debug output ports: enableDebugging() etc.
239 typedef Print sfe_print_t;
240
241#endif // SFE_IRIDIUM_ARDUINO
242
243} // namespace SparkFun_Iridium_9604
244
245#if defined(SFE_IRIDIUM_ESP_IDF)
246// ESP-IDF bus class (SfeSerial), output ports (SfeOutput) and SfePrint
247#include "sfe_bus_esp_idf.h"
248#endif
The following abstract class is used as an interface for the platform-specific implementations....
Definition: sfe_bus.h:37
virtual uint16_t available()=0
Get the number of bytes currently available to read from this bus.
virtual bool setBaudRate(unsigned long baud)=0
(Re)configure the UART baud rate.
virtual size_t writeBytes(const uint8_t *data, size_t length)=0
Write a block of bytes out over this bus.
virtual bool ping()=0
Check whether a device is present on this bus.
virtual ~IridiumDeviceBus()
Definition: sfe_bus.h:39
virtual size_t readBytes(uint8_t *data, size_t length)=0
Read a block of bytes in from this bus. Does not wait for data.
Definition: nmeaMessage.h:30