lib60870-C
2.3.2
C source code library for the IEC 60870-5-101/104 protocols
|
Typedefs | |
typedef struct sCS101_Master * | CS101_Master |
CS101_Master type. | |
Functions | |
CS101_Master | CS101_Master_create (SerialPort port, const LinkLayerParameters llParameters, const CS101_AppLayerParameters alParameters, IEC60870_LinkLayerMode mode) |
Create a new master instance. More... | |
CS101_Master | CS101_Master_createEx (SerialPort serialPort, const LinkLayerParameters llParameters, const CS101_AppLayerParameters alParameters, IEC60870_LinkLayerMode linkLayerMode, int queueSize) |
Create a new master instance and specify message queue size (for balanced mode) More... | |
void | CS101_Master_run (CS101_Master self) |
Receive a new message and run the protocol state machine(s). More... | |
void | CS101_Master_start (CS101_Master self) |
Start a background thread that handles the link layer connections. More... | |
void | CS101_Master_stop (CS101_Master self) |
Stops the background thread that handles the link layer connections. More... | |
void | CS101_Master_addSlave (CS101_Master self, int address) |
Add a new slave connection. More... | |
void | CS101_Master_pollSingleSlave (CS101_Master self, int address) |
Poll a slave (only unbalanced mode) More... | |
void | CS101_Master_destroy (CS101_Master self) |
Destroy the master instance and release all resources. | |
void | CS101_Master_setDIR (CS101_Master self, bool dir) |
Set the value of the DIR bit when sending messages (only balanced mode) More... | |
void | CS101_Master_setOwnAddress (CS101_Master self, int address) |
Set the own link layer address (only balanced mode) More... | |
void | CS101_Master_useSlaveAddress (CS101_Master self, int address) |
Set the slave address for the following send functions. More... | |
CS101_AppLayerParameters | CS101_Master_getAppLayerParameters (CS101_Master self) |
Returns the application layer parameters object of this master instance. More... | |
LinkLayerParameters | CS101_Master_getLinkLayerParameters (CS101_Master self) |
Returns the link layer parameters object of this master instance. More... | |
bool | CS101_Master_isChannelReady (CS101_Master self, int address) |
Is the channel ready to transmit an ASDU (only unbalanced mode) More... | |
void | CS101_Master_sendLinkLayerTestFunction (CS101_Master self) |
Manually send link layer test function. More... | |
void | CS101_Master_sendInterrogationCommand (CS101_Master self, CS101_CauseOfTransmission cot, int ca, QualifierOfInterrogation qoi) |
send an interrogation command More... | |
void | CS101_Master_sendCounterInterrogationCommand (CS101_Master self, CS101_CauseOfTransmission cot, int ca, uint8_t qcc) |
send a counter interrogation command More... | |
void | CS101_Master_sendReadCommand (CS101_Master self, int ca, int ioa) |
Sends a read command (C_RD_NA_1 typeID: 102) More... | |
void | CS101_Master_sendClockSyncCommand (CS101_Master self, int ca, CP56Time2a time) |
Sends a clock synchronization command (C_CS_NA_1 typeID: 103) More... | |
void | CS101_Master_sendTestCommand (CS101_Master self, int ca) |
Send a test command (C_TS_NA_1 typeID: 104) More... | |
void | CS101_Master_sendProcessCommand (CS101_Master self, CS101_CauseOfTransmission cot, int ca, InformationObject command) |
Send a process command to the controlled (or other) station. More... | |
void | CS101_Master_sendASDU (CS101_Master self, CS101_ASDU asdu) |
Send a user specified ASDU. More... | |
void | CS101_Master_setASDUReceivedHandler (CS101_Master self, CS101_ASDUReceivedHandler handler, void *parameter) |
Register a callback handler for received ASDUs. More... | |
void | CS101_Master_setLinkLayerStateChanged (CS101_Master self, IEC60870_LinkLayerStateChangedHandler handler, void *parameter) |
Set a callback handler for link layer state changes. | |
void | CS101_Master_setRawMessageHandler (CS101_Master self, IEC60870_RawMessageHandler handler, void *parameter) |
Set the raw message callback (called when a message is sent or received) More... | |
void | CS101_Master_setIdleTimeout (CS101_Master self, int timeoutInMs) |
Set the idle timeout (only for balanced mode) More... | |
void CS101_Master_addSlave | ( | CS101_Master | self, |
int | address | ||
) |
Add a new slave connection.
This function creates and starts a new link layer state machine to be used for communication with the slave. It has to be called before any application data can be send/received to/from the slave.
address | link layer address of the slave |
CS101_Master CS101_Master_create | ( | SerialPort | port, |
const LinkLayerParameters | llParameters, | ||
const CS101_AppLayerParameters | alParameters, | ||
IEC60870_LinkLayerMode | mode | ||
) |
Create a new master instance.
port | the serial port to use |
llParameters | the link layer parameters to use |
alParameters | the application layer parameters to use |
mode | the link layer mode (either IEC60870_LINK_LAYER_BALANCED or IEC60870_LINK_LAYER_UNBALANCED) |
CS101_Master CS101_Master_createEx | ( | SerialPort | serialPort, |
const LinkLayerParameters | llParameters, | ||
const CS101_AppLayerParameters | alParameters, | ||
IEC60870_LinkLayerMode | linkLayerMode, | ||
int | queueSize | ||
) |
Create a new master instance and specify message queue size (for balanced mode)
port | the serial port to use |
llParameters | the link layer parameters to use |
alParameters | the application layer parameters to use |
mode | the link layer mode (either IEC60870_LINK_LAYER_BALANCED or IEC60870_LINK_LAYER_UNBALANCED) |
queueSize | set the message queue size (only for balanced mode) |
CS101_AppLayerParameters CS101_Master_getAppLayerParameters | ( | CS101_Master | self | ) |
Returns the application layer parameters object of this master instance.
LinkLayerParameters CS101_Master_getLinkLayerParameters | ( | CS101_Master | self | ) |
Returns the link layer parameters object of this master instance.
bool CS101_Master_isChannelReady | ( | CS101_Master | self, |
int | address | ||
) |
Is the channel ready to transmit an ASDU (only unbalanced mode)
The function will return true when the channel (slave) transmit buffer is empty.
address | slave address of the recipient |
void CS101_Master_pollSingleSlave | ( | CS101_Master | self, |
int | address | ||
) |
Poll a slave (only unbalanced mode)
NOTE: This command will instruct the unbalanced link layer to send a request for class 2 data. It is required to frequently call this message for each slave in order to receive application layer data from the slave
address | the link layer address of the slave |
void CS101_Master_run | ( | CS101_Master | self | ) |
Receive a new message and run the protocol state machine(s).
NOTE: This function has to be called frequently in order to send and receive messages to and from slaves.
void CS101_Master_sendASDU | ( | CS101_Master | self, |
CS101_ASDU | asdu | ||
) |
Send a user specified ASDU.
This function can be used for any kind of ASDU types. It can also be used for monitoring messages in reverse direction.
NOTE: The ASDU is put into a message queue and will be sent whenever the link layer state machine is able to transmit the ASDU. The ASDUs will be sent in the order they are put into the queue.
asdu | the ASDU to send |
void CS101_Master_sendClockSyncCommand | ( | CS101_Master | self, |
int | ca, | ||
CP56Time2a | time | ||
) |
Sends a clock synchronization command (C_CS_NA_1 typeID: 103)
ca | Common address of the slave/server |
time | new system time for the slave/server |
void CS101_Master_sendCounterInterrogationCommand | ( | CS101_Master | self, |
CS101_CauseOfTransmission | cot, | ||
int | ca, | ||
uint8_t | qcc | ||
) |
send a counter interrogation command
cot | cause of transmission |
ca | Common address of the slave/server |
qcc |
void CS101_Master_sendInterrogationCommand | ( | CS101_Master | self, |
CS101_CauseOfTransmission | cot, | ||
int | ca, | ||
QualifierOfInterrogation | qoi | ||
) |
send an interrogation command
cot | cause of transmission |
ca | Common address of the slave/server |
qoi | qualifier of interrogation (20 for station interrogation) |
void CS101_Master_sendLinkLayerTestFunction | ( | CS101_Master | self | ) |
Manually send link layer test function.
Together with the IEC60870_LinkLayerStateChangedHandler this function can be used to ensure that the link is working correctly
void CS101_Master_sendProcessCommand | ( | CS101_Master | self, |
CS101_CauseOfTransmission | cot, | ||
int | ca, | ||
InformationObject | command | ||
) |
Send a process command to the controlled (or other) station.
cot | the cause of transmission (should be ACTIVATION to select/execute or ACT_TERM to cancel the command) |
ca | the common address of the information object |
command | the command information object (e.g. SingleCommand or DoubleCommand) |
void CS101_Master_sendReadCommand | ( | CS101_Master | self, |
int | ca, | ||
int | ioa | ||
) |
Sends a read command (C_RD_NA_1 typeID: 102)
This will send a read command C_RC_NA_1 (102) to the slave/outstation. The COT is always REQUEST (5). It is used to implement the cyclical polling of data application function.
ca | Common address of the slave/server |
ioa | Information object address of the data point to read |
void CS101_Master_sendTestCommand | ( | CS101_Master | self, |
int | ca | ||
) |
Send a test command (C_TS_NA_1 typeID: 104)
Note: This command is not supported by IEC 60870-5-104
ca | Common address of the slave/server |
void CS101_Master_setASDUReceivedHandler | ( | CS101_Master | self, |
CS101_ASDUReceivedHandler | handler, | ||
void * | parameter | ||
) |
Register a callback handler for received ASDUs.
handler | user provided callback handler function |
parameter | user provided parameter that is passed to the callback handler |
void CS101_Master_setDIR | ( | CS101_Master | self, |
bool | dir | ||
) |
Set the value of the DIR bit when sending messages (only balanced mode)
NOTE: Default value is true (controlling station). In the case of two equivalent stations the value is defined by agreement.
dir | the value of the DIR bit when sending messages |
void CS101_Master_setIdleTimeout | ( | CS101_Master | self, |
int | timeoutInMs | ||
) |
Set the idle timeout (only for balanced mode)
Time with no activity after which the connection is considered in idle (LL_STATE_IDLE) state.
timeoutInMs | the timeout value in milliseconds |
void CS101_Master_setOwnAddress | ( | CS101_Master | self, |
int | address | ||
) |
Set the own link layer address (only balanced mode)
address | the link layer address to use |
void CS101_Master_setRawMessageHandler | ( | CS101_Master | self, |
IEC60870_RawMessageHandler | handler, | ||
void * | parameter | ||
) |
Set the raw message callback (called when a message is sent or received)
handler | user provided callback handler function |
parameter | user provided parameter that is passed to the callback handler |
void CS101_Master_start | ( | CS101_Master | self | ) |
Start a background thread that handles the link layer connections.
NOTE: This requires threads. If you don't want to use a separate thread for the master instance you have to call the CS101_Master_run function periodically.
self | CS101_Master instance |
void CS101_Master_stop | ( | CS101_Master | self | ) |
Stops the background thread that handles the link layer connections.
self | CS101_Master instance |
void CS101_Master_useSlaveAddress | ( | CS101_Master | self, |
int | address | ||
) |
Set the slave address for the following send functions.
NOTE: This is always required in unbalanced mode. Some balanced slaves also check the link layer address. In this case the slave address has also to be set in balanced mode.
address | the link layer address of the slave to address |