RF-Positioning-System V0.1
by Max Heinekamp
Loading...
Searching...
No Matches
SCPI Class Reference

This class handles the SCPI communication with the instrument. It is responsible for parsing SCPI commands, sending responses, and managing errors. More...

#include <scpi.h>

Classes

struct  SCPI_Error
 Struct to represent an error in the SCPI error queue. More...
struct  SCPIClient
struct  SessionCloseLog
class  SessionStream
 Stream wrapper around a tracked SCPIClient's EthernetClient that transparently counts bytes transferred and timestamps last activity, without needing any changes to the vendored SCPI parser library (which only ever needs a plain Stream&). More...

Public Member Functions

 SCPI ()
 Construct a new SCPI object.
void setup ()
 Set up the SCPI server and register all available commands.
void processEthernet ()
 Process incoming SCPI commands over Ethernet.
void processSerial ()
 Process incoming SCPI commands over Serial.
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.
const char * getError ()
 Get the oldest error message from the error queue, compliant with section 21.8 of the SCPI standard.
int getPort ()
 Get the port number of the SCPI server.
void reinitEthernet ()
 Re-initialize the Ethernet stack (re-reads IP/MAC from flash, re-begins Ethernet and the SCPI server, and drops all tracked client sessions). Used to recover after a hardware reset.
void printSessionList (Stream &interface)
 Print the live SCPI session table (DIAGnostic:SESSion:LIST?).
void printSessionLog (Stream &interface)
 Print the session close-reason ring buffer (DIAGnostic:SESSion:LOG?).
void printSocketList (Stream &interface)
 Print the raw state of all 8 W5500 hardware sockets, not just the ones tracked as SCPI sessions (DIAGnostic:SOCKet:LIST?).
void printSystemDiagnostics (Stream &interface)
 Print system/reset health diagnostics (DIAGnostic:SYStem?).
void printAllHeaders (Stream &interface)
 Print every registered SCPI command header, one per line (SYSTem:HELP:HEADers?).
void printHeaderSyntax (Stream &interface, const char *header)
 Print syntax help for a single command header (SYSTem:HELP:SYNTax?).

Private Member Functions

void registerCommands ()
 Register SCPI commands from scpi_commands.h/cpp.
void logSessionClose (const SCPIClient &slot, const char *reason)

Private Attributes

EthernetServer * scpi_server = nullptr
SCPI_Parser my_instrument
SCPIClient scpi_clients [MAX_SCPI_CLIENTS]
SessionCloseLog sessionLog [SESSION_LOG_SIZE]
int sessionLogHead = 0
int sessionLogCount = 0
unsigned long linkFlapCount = 0
unsigned long reinitCount = 0
EthernetLinkStatus lastLinkStatus = Unknown
bool server_started = false
SCPI_Error errorQueue [ERROR_QUEUE_SIZE]
int errorHead = 0
 Points to the next free slot.
int errorTail = 0
 Points to the oldest error.
int errorCount = 0
 Tracks number of stored errors.
bool queueOverflow = false
 Tracks if queue overflowed.
int port = 0
 Store SCPI port number at time of initialization.

Static Private Attributes

static const int MAX_SCPI_CLIENTS = 4
static const int SESSION_LOG_SIZE = 16

Detailed Description

This class handles the SCPI communication with the instrument. It is responsible for parsing SCPI commands, sending responses, and managing errors.

The SCPI class uses the Vrekrer SCPI parser library to handle SCPI commands. It also manages an error queue to store error messages and codes. The class is designed to work with both Ethernet and Serial communication interfaces. It registers all available SCPI commands and processes incoming commands from the specified interface.

Definition at line 26 of file scpi.h.

Constructor & Destructor Documentation

◆ SCPI()

SCPI::SCPI ( )

Construct a new SCPI object.

Definition at line 43 of file scpi.cpp.

Member Function Documentation

◆ getError()

const char * SCPI::getError ( )

Get the oldest error message from the error queue, compliant with section 21.8 of the SCPI standard.

Returns
const char* String containing the oldest error message with the error code as a csv.

Definition at line 449 of file scpi.cpp.

◆ getPort()

int SCPI::getPort ( )

Get the port number of the SCPI server.

Returns
int port number of the SCPI server.

Definition at line 471 of file scpi.cpp.

◆ logError()

void SCPI::logError ( int code,
const char * message )

Log an error message to the SCPI error queue, compliant with section 21.8 of the SCPI standard.

Parameters
codeError code (see SCPI standard)
messageError message (see SCPI standard)

Definition at line 435 of file scpi.cpp.

◆ logSessionClose()

void SCPI::logSessionClose ( const SCPIClient & slot,
const char * reason )
private

Definition at line 391 of file scpi.cpp.

◆ printAllHeaders()

void SCPI::printAllHeaders ( Stream & interface)

Print every registered SCPI command header, one per line (SYSTem:HELP:HEADers?).

Parameters
interfaceStream interface to print to.

Definition at line 557 of file scpi.cpp.

◆ PrintDebugInfo()

void SCPI::PrintDebugInfo ( Stream & interface)

Print debug information about the SCPI parser to the specified interface.

Parameters
interfaceStream interface to print debug information to.

Definition at line 431 of file scpi.cpp.

◆ printHeaderSyntax()

void SCPI::printHeaderSyntax ( Stream & interface,
const char * header )

Print syntax help for a single command header (SYSTem:HELP:SYNTax?).

Parameters
interfaceStream interface to print to.
headerThe header to look up (must match its full spelling as printed by printAllHeaders() — short forms are not resolved here).

Definition at line 567 of file scpi.cpp.

◆ printSessionList()

void SCPI::printSessionList ( Stream & interface)

Print the live SCPI session table (DIAGnostic:SESSion:LIST?).

Parameters
interfaceStream interface to print to.

Definition at line 475 of file scpi.cpp.

◆ printSessionLog()

void SCPI::printSessionLog ( Stream & interface)

Print the session close-reason ring buffer (DIAGnostic:SESSion:LOG?).

Parameters
interfaceStream interface to print to.

Definition at line 505 of file scpi.cpp.

◆ printSocketList()

void SCPI::printSocketList ( Stream & interface)

Print the raw state of all 8 W5500 hardware sockets, not just the ones tracked as SCPI sessions (DIAGnostic:SOCKet:LIST?).

Parameters
interfaceStream interface to print to.

Definition at line 525 of file scpi.cpp.

◆ printSystemDiagnostics()

void SCPI::printSystemDiagnostics ( Stream & interface)

Print system/reset health diagnostics (DIAGnostic:SYStem?).

Parameters
interfaceStream interface to print to.

Definition at line 546 of file scpi.cpp.

◆ processEthernet()

void SCPI::processEthernet ( )

Process incoming SCPI commands over Ethernet.

IMPORTANT: MUST SET CORRECT TERMINATION CHARACTERS

Definition at line 305 of file scpi.cpp.

◆ processSerial()

void SCPI::processSerial ( )

Process incoming SCPI commands over Serial.

Definition at line 427 of file scpi.cpp.

◆ registerCommands()

void SCPI::registerCommands ( )
private

Register SCPI commands from scpi_commands.h/cpp.

Definition at line 274 of file scpi.cpp.

◆ reinitEthernet()

void SCPI::reinitEthernet ( )

Re-initialize the Ethernet stack (re-reads IP/MAC from flash, re-begins Ethernet and the SCPI server, and drops all tracked client sessions). Used to recover after a hardware reset.

Definition at line 406 of file scpi.cpp.

◆ setup()

void SCPI::setup ( )

Set up the SCPI server and register all available commands.

Definition at line 280 of file scpi.cpp.

Member Data Documentation

◆ errorCount

int SCPI::errorCount = 0
private

Tracks number of stored errors.

Definition at line 233 of file scpi.h.

◆ errorHead

int SCPI::errorHead = 0
private

Points to the next free slot.

Definition at line 231 of file scpi.h.

◆ errorQueue

SCPI_Error SCPI::errorQueue[ERROR_QUEUE_SIZE]
private

Definition at line 230 of file scpi.h.

◆ errorTail

int SCPI::errorTail = 0
private

Points to the oldest error.

Definition at line 232 of file scpi.h.

◆ lastLinkStatus

EthernetLinkStatus SCPI::lastLinkStatus = Unknown
private

Definition at line 216 of file scpi.h.

◆ linkFlapCount

unsigned long SCPI::linkFlapCount = 0
private

Definition at line 214 of file scpi.h.

◆ MAX_SCPI_CLIENTS

const int SCPI::MAX_SCPI_CLIENTS = 4
staticprivate

Definition at line 145 of file scpi.h.

◆ my_instrument

SCPI_Parser SCPI::my_instrument
private

Definition at line 142 of file scpi.h.

◆ port

int SCPI::port = 0
private

Store SCPI port number at time of initialization.

Definition at line 236 of file scpi.h.

◆ queueOverflow

bool SCPI::queueOverflow = false
private

Tracks if queue overflowed.

Definition at line 234 of file scpi.h.

◆ reinitCount

unsigned long SCPI::reinitCount = 0
private

Definition at line 215 of file scpi.h.

◆ scpi_clients

SCPIClient SCPI::scpi_clients[MAX_SCPI_CLIENTS]
private

Definition at line 156 of file scpi.h.

◆ scpi_server

EthernetServer* SCPI::scpi_server = nullptr
private

Definition at line 141 of file scpi.h.

◆ server_started

bool SCPI::server_started = false
private

Definition at line 218 of file scpi.h.

◆ SESSION_LOG_SIZE

const int SCPI::SESSION_LOG_SIZE = 16
staticprivate

Definition at line 198 of file scpi.h.

◆ sessionLog

SessionCloseLog SCPI::sessionLog[SESSION_LOG_SIZE]
private

Definition at line 209 of file scpi.h.

◆ sessionLogCount

int SCPI::sessionLogCount = 0
private

Definition at line 211 of file scpi.h.

◆ sessionLogHead

int SCPI::sessionLogHead = 0
private

Definition at line 210 of file scpi.h.


The documentation for this class was generated from the following files:
  • /home/runner/work/RF-Positioning-System/RF-Positioning-System/Code/RF-Positioning-System/include/scpi.h
  • /home/runner/work/RF-Positioning-System/RF-Positioning-System/Code/RF-Positioning-System/src/scpi.cpp