17#define VREKRER_SCPI_PARSER_NO_IMPL
18#include "Vrekrer_scpi_parser.h"
66 void logError(
int code,
const char* message);
141 EthernetServer* scpi_server =
nullptr;
142 SCPI_Parser my_instrument;
145 static const int MAX_SCPI_CLIENTS = 4;
147 EthernetClient client;
149 unsigned long connectedAt = 0;
150 unsigned long lastActivity = 0;
151 unsigned long rxBytes = 0;
152 unsigned long txBytes = 0;
154 uint16_t remotePort = 0;
163 class SessionStream :
public Stream {
165 SessionStream(
SCPIClient& session) : session_(session) {}
166 int available()
override {
return session_.client.available(); }
167 int read()
override {
168 int c = session_.client.read();
171 session_.lastActivity = millis();
175 int peek()
override {
return session_.client.peek(); }
176 void flush()
override { session_.client.flush(); }
177 size_t write(uint8_t b)
override {
178 size_t n = session_.client.write(b);
180 session_.txBytes += n;
181 session_.lastActivity = millis();
185 size_t write(
const uint8_t* buf,
size_t size)
override {
186 size_t n = session_.client.write(buf, size);
188 session_.txBytes += n;
189 session_.lastActivity = millis();
198 static const int SESSION_LOG_SIZE = 16;
200 unsigned long closedAt = 0;
202 uint16_t remotePort = 0;
203 char reason[16] =
"";
204 unsigned long durationMs = 0;
205 unsigned long idleMsAtClose = 0;
206 unsigned long rxBytes = 0;
207 unsigned long txBytes = 0;
210 int sessionLogHead = 0;
211 int sessionLogCount = 0;
212 void logSessionClose(
const SCPIClient& slot,
const char* reason);
214 unsigned long linkFlapCount = 0;
215 unsigned long reinitCount = 0;
216 EthernetLinkStatus lastLinkStatus = Unknown;
218 bool server_started =
false;
int errorCount
Tracks number of stored errors.
int getPort()
Get the port number of the SCPI server.
void registerCommands()
Register SCPI commands from scpi_commands.h/cpp.
void printHeaderSyntax(Stream &interface, const char *header)
Print syntax help for a single command header (SYSTem:HELP:SYNTax?).
int errorTail
Points to the oldest error.
void printSocketList(Stream &interface)
Print the raw state of all 8 W5500 hardware sockets, not just the ones tracked as SCPI sessions (DIAG...
int errorHead
Points to the next free slot.
void printSessionLog(Stream &interface)
Print the session close-reason ring buffer (DIAGnostic:SESSion:LOG?).
void PrintDebugInfo(Stream &interface)
Print debug information about the SCPI parser to the specified interface.
void logError(int code, const char *message)
Log an error message to the SCPI error queue, compliant with section 21.8 of the SCPI standard.
void processEthernet()
Process incoming SCPI commands over Ethernet.
void printSessionList(Stream &interface)
Print the live SCPI session table (DIAGnostic:SESSion:LIST?).
const char * getError()
Get the oldest error message from the error queue, compliant with section 21.8 of the SCPI standard.
void processSerial()
Process incoming SCPI commands over Serial.
void setup()
Set up the SCPI server and register all available commands.
void printAllHeaders(Stream &interface)
Print every registered SCPI command header, one per line (SYSTem:HELP:HEADers?).
SCPI()
Construct a new SCPI object.
bool queueOverflow
Tracks if queue overflowed.
int port
Store SCPI port number at time of initialization.
void reinitEthernet()
Re-initialize the Ethernet stack (re-reads IP/MAC from flash, re-begins Ethernet and the SCPI server,...
void printSystemDiagnostics(Stream &interface)
Print system/reset health diagnostics (DIAGnostic:SYStem?).
Configuration file for the entire project.
Struct to represent an error in the SCPI error queue.