MeshProtocolSimulator  1.0.0
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Attributes | List of all members
JSONLogsWriter Class Reference

Public Member Functions

bool begin (const JSONSettings &settings, std::string path)
 Begins simulation logging. More...
 
void terminate ()
 Terminates logging and closes file. Output file "status" property will be set to "terminated". More...
 
void end (int errorCode, std::string errorText)
 Ends logging and closes file. Output file "status" property will be set to "success" or "error" depends on error code. More...
 
void exceptionEnd (int errorCode, std::string errorText)
 Ends logging and closes file. Output file "status" property will be set to "success" or "exception" depends on error code. More...
 
void end ()
 Ends logging and closes file. Output file "status" property will be set to "success". More...
 
void logMessageTransmit (RawMessage &message)
 Logs message transmission to output log file. More...
 
void logMessageReceive (MeshMAC node, std::chrono::nanoseconds receiveTime, RawMessage &message, float RSSI)
 Logs message receiving to output log file. More...
 
void logReceiveInterference (MeshMAC node, std::chrono::nanoseconds simulationTime, MeshMAC sender_node1, uint64_t sender_node1_UID, float rssi1, MeshMAC sender_node2, uint64_t sender_node2_UID, float rssi2)
 Logs receive interference (two nodes sends simultaneously and message cannot be received by "node") to output log file. More...
 
void logTransmitInterference (MeshMAC node, uint64_t node_UID, std::chrono::nanoseconds simulationTime, MeshMAC sender_node, uint64_t sender_node_UID, float RSSI)
 Logs transmit interference (one node is sending message and another wants to send him message) to output log file. More...
 
void logMessageLost (MeshMAC sender, MeshMAC receiver, uint64_t node_UID, std::chrono::nanoseconds simulationTime, float RSSI)
 Logs lost message due to bad link quality to output log file. More...
 
void logAPLReceived (MeshMAC node, MeshMAC sender_node, std::chrono::nanoseconds simulationTime, char *messageData, size_t length)
 Logs application layer received message to output log file. More...
 
void logTableChange (MeshMAC node, std::string &descriptor, TableChangeType changeType, std::chrono::nanoseconds simulationTime, const char *data, size_t length)
 Logs application layer received message to output log file. More...
 

Static Public Member Functions

static std::string EncodeSpecialCharacters (const char *text, size_t inLength)
 Encodes special characters in json string value. Escaped characters are '', '\f', '
', '\r', '\t', '\', '"', '\0'. More...
 
static std::string EncodeSpecialCharacters (std::string &text)
 Encodes special characters in json string value. Escaped characters are '', '\f', '
', '\r', '\t', '\', '"', '\0'. More...
 
static std::string GetCurrentTimeISO8601 ()
 Gets current pc time and converts it to ISO 8601. More...
 

Public Attributes

std::string version = "0.0.1"
 Emulator version.
 

Protected Attributes

bool beginCalled = false
 
std::chrono::steady_clock::time_point simulationStartTime
 
std::ofstream outFile
 
bool anyLogWritten = false
 

Member Function Documentation

◆ begin()

bool JSONLogsWriter::begin ( const JSONSettings settings,
std::string  path 
)

Begins simulation logging.

Parameters
settingsInitial simulation settings. Those settings has to be validated before passing here.
pathPath, where will be output JSON file stored.
Returns
Returns true when logger was started.

◆ EncodeSpecialCharacters() [1/2]

std::string JSONLogsWriter::EncodeSpecialCharacters ( const char *  text,
size_t  inLength 
)
static

Encodes special characters in json string value. Escaped characters are '', '\f', '
', '\r', '\t', '\', '"', '\0'.

Parameters
textText to check.
inLengthCount of characters in text.
Returns
Returns text with encoded special characters.

◆ EncodeSpecialCharacters() [2/2]

static std::string JSONLogsWriter::EncodeSpecialCharacters ( std::string &  text)
inlinestatic

Encodes special characters in json string value. Escaped characters are '', '\f', '
', '\r', '\t', '\', '"', '\0'.

Parameters
textText to check.
Returns
Returns text with encoded special characters.

◆ end() [1/2]

void JSONLogsWriter::end ( )

Ends logging and closes file. Output file "status" property will be set to "success".

Note
One of ending methods (terminate, end, exceptionEnd) has to be called at the end of logging, else output file will be corrupted.

◆ end() [2/2]

void JSONLogsWriter::end ( int  errorCode,
std::string  errorText 
)

Ends logging and closes file. Output file "status" property will be set to "success" or "error" depends on error code.

Parameters
errorCodeError code. When set to 0, "status" property will be set to "success".
errorTextText, that describes an error, that happened. Igored when errorCode is 0.
Note
One of ending methods (terminate, end, exceptionEnd) has to be called at the end of logging, else output file will be corrupted.

◆ exceptionEnd()

void JSONLogsWriter::exceptionEnd ( int  errorCode,
std::string  errorText 
)

Ends logging and closes file. Output file "status" property will be set to "success" or "exception" depends on error code.

Parameters
errorCodeError code. When set to 0, "status" property will be set to "success".
errorTextText, that describes an exception, that happened. Igored when errorCode is 0.
Note
One of ending methods (terminate, end, exceptionEnd) has to be called at the end of logging, else output file will be corrupted.

◆ GetCurrentTimeISO8601()

std::string JSONLogsWriter::GetCurrentTimeISO8601 ( )
static

Gets current pc time and converts it to ISO 8601.

Returns
Returns string containing current pc time in ISO 8601 form.

◆ logAPLReceived()

void JSONLogsWriter::logAPLReceived ( MeshMAC  node,
MeshMAC  sender_node,
std::chrono::nanoseconds  simulationTime,
char *  messageData,
size_t  length 
)

Logs application layer received message to output log file.

Parameters
nodeMAC address of node, which received message.
sender_nodeMAC address of node, the data was received from.
simulationTimeSimulation time, when message was received by application layer.
messageDataData, which was received.
lengthLength of message data.
Note
Log can be written only when begin was called.

◆ logMessageLost()

void JSONLogsWriter::logMessageLost ( MeshMAC  sender,
MeshMAC  receiver,
uint64_t  node_UID,
std::chrono::nanoseconds  simulationTime,
float  RSSI 
)

Logs lost message due to bad link quality to output log file.

Parameters
senderMAC address of node, which sent message.
receiverMAC address of node, which cannot receive message.
node_UIDUnique message identifier.
simulationTimeSimulation time, when this issue happened.
RSSIRSSI value of message.
Note
Log can be written only when begin was called.

◆ logMessageReceive()

void JSONLogsWriter::logMessageReceive ( MeshMAC  node,
std::chrono::nanoseconds  receiveTime,
RawMessage message,
float  RSSI 
)

Logs message receiving to output log file.

Parameters
nodeMAC address of node, which received message.
receiveTimeSimulation time, when message was received by node.
messageReceived message.
RSSIRSSI value of received message.
Note
Log can be written only when begin was called.

◆ logMessageTransmit()

void JSONLogsWriter::logMessageTransmit ( RawMessage message)

Logs message transmission to output log file.

Parameters
messageTransmitted message.
Note
Log can be written only when begin was called.

◆ logReceiveInterference()

void JSONLogsWriter::logReceiveInterference ( MeshMAC  node,
std::chrono::nanoseconds  simulationTime,
MeshMAC  sender_node1,
uint64_t  sender_node1_UID,
float  rssi1,
MeshMAC  sender_node2,
uint64_t  sender_node2_UID,
float  rssi2 
)

Logs receive interference (two nodes sends simultaneously and message cannot be received by "node") to output log file.

Parameters
nodeMAC address of node, which cannot receive message.
simulationTimeSimulation time, when interference happened.
sender_node1MAC address of first sender node, which caused interference.
sender_node1_UIDFirst sender node's unique message identifier.
rssi1RSSI value of first message.
sender_node2MAC address of second sender node, which caused interference.
sender_node2_UIDSecond sender node's unique message identifier.
rssi2RSSI value of second message.
Note
Log can be written only when begin was called.

◆ logTableChange()

void JSONLogsWriter::logTableChange ( MeshMAC  node,
std::string &  descriptor,
TableChangeType  changeType,
std::chrono::nanoseconds  simulationTime,
const char *  data,
size_t  length 
)

Logs application layer received message to output log file.

Parameters
nodeMAC address of node, which table was changed.
descriptorTable descriptor.
changeTypeType of change.
simulationTimeSimulation time, when table change happened.
dataData of change.
lengthLength of data.
Note
Log can be written only when begin was called.

◆ logTransmitInterference()

void JSONLogsWriter::logTransmitInterference ( MeshMAC  node,
uint64_t  node_UID,
std::chrono::nanoseconds  simulationTime,
MeshMAC  sender_node,
uint64_t  sender_node_UID,
float  RSSI 
)

Logs transmit interference (one node is sending message and another wants to send him message) to output log file.

Parameters
nodeMAC address of node, which cannot receive message, because it is already sending message.
node_UIDSender node's unique message identifier.
simulationTimeSimulation time, when interference happened.
sender_nodeMAC address of sender node, which caused interference.
sender_node_UIDSender node's unique message identifier.
RSSIRSSI value of first sent message.
Note
Log can be written only when begin was called.

◆ terminate()

void JSONLogsWriter::terminate ( )

Terminates logging and closes file. Output file "status" property will be set to "terminated".

Note
One of ending methods (terminate, end, exceptionEnd) has to be called at the end of logging, else output file will be corrupted.

The documentation for this class was generated from the following files: