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_esp_idf.h
Go to the documentation of this file.
1
23#pragma once
24
25#include "sfe_platform.h"
26
27#if defined(SFE_IRIDIUM_ESP_IDF)
28
29#include "sdkconfig.h"
30#include "driver/uart.h"
31
33{
34
38 class SfeSerial : public IridiumDeviceBus
39 {
40 public:
41 SfeSerial(void);
42
53 bool init(uart_port_t port);
54
55 bool ping() { return false; }
56 uint16_t available();
57 size_t writeBytes(const uint8_t *data, size_t length);
58 size_t readBytes(uint8_t *data, size_t length);
59 bool setBaudRate(unsigned long baud);
60
61 private:
62 uart_port_t _port;
63 bool _initialized;
64 };
65
71 class SfeOutput
72 {
73 public:
74 virtual ~SfeOutput() {}
75 virtual size_t write(const uint8_t *buffer, size_t length) = 0;
76 };
77
81 class SfeStdoutOutput : public SfeOutput
82 {
83 public:
84 size_t write(const uint8_t *buffer, size_t length);
85 };
86
90 class SfeUartOutput : public SfeOutput
91 {
92 public:
93 SfeUartOutput(uart_port_t port) : _port(port) {}
94 size_t write(const uint8_t *buffer, size_t length);
95
96 private:
97 uart_port_t _port;
98 };
99
103 class SfeCallbackOutput : public SfeOutput
104 {
105 public:
106 typedef void (*callback_t)(const uint8_t *buffer, size_t length, void *userContext);
107 SfeCallbackOutput(callback_t callback, void *userContext = nullptr) : _callback(callback), _userContext(userContext) {}
108 size_t write(const uint8_t *buffer, size_t length)
109 {
110 if (_callback != nullptr)
111 _callback(buffer, length, _userContext);
112 return length;
113 }
114
115 private:
116 callback_t _callback;
117 void *_userContext;
118 };
119
120 // The default debug output port
121 extern SfeStdoutOutput sfeStdout;
122
126 class SfePrint
127 {
128 public:
129 SfePrint(void) { _outputPort = nullptr; }
130
131 void init(SfeOutput &outputPort) { _outputPort = &outputPort; }
132 inline bool operator==(SfePrint const &other) const { return _outputPort == other._outputPort; }
133 inline bool operator!=(SfePrint const &other) const { return !(*this == other); }
134 inline bool isSet(void) const { return _outputPort != nullptr; }
135
136 void write(uint8_t c)
137 {
138 if (_outputPort != nullptr)
139 _outputPort->write(&c, 1);
140 }
141 void write(const uint8_t *buffer, size_t length)
142 {
143 if ((_outputPort != nullptr) && (buffer != nullptr))
144 _outputPort->write(buffer, length);
145 }
146 void print(const char *c)
147 {
148 if ((_outputPort != nullptr) && (c != nullptr))
149 _outputPort->write((const uint8_t *)c, strlen(c));
150 }
151 void print(long value, int base = DEC)
152 {
153 char buf[24];
154 if (base == HEX)
155 snprintf(buf, sizeof(buf), "%lX", (unsigned long)value);
156 else
157 snprintf(buf, sizeof(buf), "%ld", value);
158 print(buf);
159 }
160 void print(unsigned long value, int base = DEC)
161 {
162 char buf[24];
163 if (base == HEX)
164 snprintf(buf, sizeof(buf), "%lX", value);
165 else
166 snprintf(buf, sizeof(buf), "%lu", value);
167 print(buf);
168 }
169 void print(int value, int base = DEC) { print((long)value, base); }
170 void print(unsigned int value, int base = DEC) { print((unsigned long)value, base); }
171 void print(double value, int decimalPlaces)
172 {
173 char buf[40];
174 snprintf(buf, sizeof(buf), "%.*f", decimalPlaces, value);
175 print(buf);
176 }
177 void println() { print("\r\n"); }
178 void println(const char *c)
179 {
180 print(c);
181 println();
182 }
183
184 private:
185 SfeOutput *_outputPort;
186 };
187
188 // The type used by the public API for debug output ports: enableDebugging() etc.
189 typedef SfeOutput sfe_print_t;
190
191} // namespace SparkFun_Iridium_9604
192
193#endif // SFE_IRIDIUM_ESP_IDF
Definition: nmeaMessage.h:30