![]() |
GaIA BIOS Library
|
Modbus/TCP master common utility functions. More...
Functions | |
| mb_tcp_transaction_t * | mb_tcp_get_transaction_by_id (mb_tcp_master_ch_t *ch, uni16_t id) |
| Returns the transaction with the given id. | |
| mb_tcp_master_ch_t * | mb_tcp_get_ch_by_socket (int sock) |
| Returns the master channel corresponding to the given socket. | |
| int | mb_tcp_register_master_ch (mb_tcp_master_ch_t *ch) |
| Registers a master channel. | |
| int | mb_tcp_unregister_master_ch (mb_tcp_master_ch_t *ch) |
| Unregisters a master channel. | |
| int | mb_tcp_store_response (mb_tcp_master_ch_t *ch, const uint8_t *buf, uint32_t len) |
| Stores a response in the pending transaction corresponding to the transaction id present in the specified buffer. | |
| void | mb_tcp_finalize_transaction (mb_tcp_transaction_t *trans) |
| Finalizes the specified transaction copying the received data in the output buffer specified by the user when the transaction was started. | |
| void | mb_tcp_fire_transaction_event (mb_tcp_master_ch_t *ch, mb_tcp_transaction_t *trans, int event) |
| Fires the specified transaction event. | |
Modbus/TCP master common utility functions.
These functions should be used in the implementation of the Modbus/TCP master protocol for a specific platform.
| void mb_tcp_finalize_transaction | ( | mb_tcp_transaction_t * | trans | ) |
Finalizes the specified transaction copying the received data in the output buffer specified by the user when the transaction was started.
Data is copied restoring the correct byte order for register read operations.
| trans | transaction to be finalized. |
| void mb_tcp_fire_transaction_event | ( | mb_tcp_master_ch_t * | ch, |
| mb_tcp_transaction_t * | trans, | ||
| int | event ) |
Fires the specified transaction event.
The callback provided by the user when the transaction was started is called by this function.
| ch | master channel. |
| trans | transaction for which the event has been generated. |
| event | transaction event. It can be MB_TRANS_EVENT_COMPLETED if the transaction was successfully completed or MB_TRANS_EVENT_TIMEOUT if a timeout occurred. |
| mb_tcp_master_ch_t * mb_tcp_get_ch_by_socket | ( | int | sock | ) |
Returns the master channel corresponding to the given socket.
This function is used to get a specific channel when the only available information is the socket (e.g. in TCP/IP stack callbacks).
| sock | socket. |
| mb_tcp_transaction_t * mb_tcp_get_transaction_by_id | ( | mb_tcp_master_ch_t * | ch, |
| uni16_t | id ) |
Returns the transaction with the given id.
| ch | master channel. |
| id | transaction id. |
| int mb_tcp_register_master_ch | ( | mb_tcp_master_ch_t * | ch | ) |
Registers a master channel.
This function should be called when the channel initialization is complete and it must be invoked if mb_tcp_get_ch_by_socket is needed.
| ch | master channel. |
| int mb_tcp_store_response | ( | mb_tcp_master_ch_t * | ch, |
| const uint8_t * | buf, | ||
| uint32_t | len ) |
Stores a response in the pending transaction corresponding to the transaction id present in the specified buffer.
| ch | master channel. |
| buf | data received. It is expected to be a Modbus/TCP ADU. |
| len | length of the data. |
| int mb_tcp_unregister_master_ch | ( | mb_tcp_master_ch_t * | ch | ) |
Unregisters a master channel.
This function should be called when the channel has been closed.
| ch | master channel. |