Functions | Variables
modbus-rtu.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <assert.h>
#include "libmodbus/modbus-private.h"
#include "libmodbus/modbus-rtu.h"
#include "libmodbus/modbus-rtu-private.h"
Include dependency graph for modbus-rtu.c:

Go to the source code of this file.

Functions

static int _modbus_rtu_build_request_basis (modbus_t *ctx, int function, int addr, int nb, uint8_t *req)
 
static int _modbus_rtu_build_response_basis (sft_t *sft, uint8_t *rsp)
 
int _modbus_rtu_check_integrity (modbus_t *ctx, uint8_t *msg, const int msg_length)
 
void _modbus_rtu_close (modbus_t *ctx)
 
static int _modbus_rtu_connect (modbus_t *ctx)
 
int _modbus_rtu_filter_request (modbus_t *ctx, int slave)
 
int _modbus_rtu_flush (modbus_t *)
 
int _modbus_rtu_prepare_response_tid (const uint8_t *req, int *req_length)
 
ssize_t _modbus_rtu_recv (modbus_t *ctx, uint8_t *rsp, int rsp_length)
 
int _modbus_rtu_select (modbus_t *ctx, fd_set *rfds, struct timeval *tv, int length_to_read)
 
ssize_t _modbus_rtu_send (modbus_t *ctx, const uint8_t *req, int req_length)
 
int _modbus_rtu_send_msg_pre (uint8_t *req, int req_length)
 
static int _modbus_set_slave (modbus_t *ctx, int slave)
 
static uint16_t crc16 (uint8_t *buffer, uint16_t buffer_length)
 
modbus_tmodbus_new_rtu (const char *device, int baud, char parity, int data_bit, int stop_bit)
 
int modbus_rtu_get_serial_mode (modbus_t *ctx)
 
int modbus_rtu_set_serial_mode (modbus_t *ctx, int mode)
 

Variables

const modbus_backend_t _modbus_rtu_backend
 
static const uint8_t table_crc_hi []
 
static const uint8_t table_crc_lo []
 

Function Documentation

static int _modbus_rtu_build_request_basis ( modbus_t ctx,
int  function,
int  addr,
int  nb,
uint8_t *  req 
)
static

Definition at line 115 of file modbus-rtu.c.

static int _modbus_rtu_build_response_basis ( sft_t sft,
uint8_t *  rsp 
)
static

Definition at line 131 of file modbus-rtu.c.

int _modbus_rtu_check_integrity ( modbus_t ctx,
uint8_t *  msg,
const int  msg_length 
)

Definition at line 284 of file modbus-rtu.c.

void _modbus_rtu_close ( modbus_t ctx)

Definition at line 811 of file modbus-rtu.c.

static int _modbus_rtu_connect ( modbus_t ctx)
static

Definition at line 310 of file modbus-rtu.c.

int _modbus_rtu_filter_request ( modbus_t ctx,
int  slave 
)

Definition at line 881 of file modbus-rtu.c.

int _modbus_rtu_flush ( modbus_t ctx)

Definition at line 831 of file modbus-rtu.c.

int _modbus_rtu_prepare_response_tid ( const uint8_t *  req,
int *  req_length 
)

Definition at line 157 of file modbus-rtu.c.

ssize_t _modbus_rtu_recv ( modbus_t ctx,
uint8_t *  rsp,
int  rsp_length 
)

Definition at line 271 of file modbus-rtu.c.

int _modbus_rtu_select ( modbus_t ctx,
fd_set *  rfds,
struct timeval *  tv,
int  length_to_read 
)

Definition at line 842 of file modbus-rtu.c.

ssize_t _modbus_rtu_send ( modbus_t ctx,
const uint8_t *  req,
int  req_length 
)

Definition at line 260 of file modbus-rtu.c.

int _modbus_rtu_send_msg_pre ( uint8_t *  req,
int  req_length 
)

Definition at line 164 of file modbus-rtu.c.

static int _modbus_set_slave ( modbus_t ctx,
int  slave 
)
static

Definition at line 101 of file modbus-rtu.c.

static uint16_t crc16 ( uint8_t *  buffer,
uint16_t  buffer_length 
)
static

Definition at line 141 of file modbus-rtu.c.

modbus_t* modbus_new_rtu ( const char *  device,
int  baud,
char  parity,
int  data_bit,
int  stop_bit 
)

Definition at line 917 of file modbus-rtu.c.

int modbus_rtu_get_serial_mode ( modbus_t ctx)

Definition at line 793 of file modbus-rtu.c.

int modbus_rtu_set_serial_mode ( modbus_t ctx,
int  mode 
)

Definition at line 745 of file modbus-rtu.c.

Variable Documentation

const modbus_backend_t _modbus_rtu_backend
Initial value:
= {
NULL,
}
static int _modbus_rtu_build_response_basis(sft_t *sft, uint8_t *rsp)
Definition: modbus-rtu.c:131
#define _MODBUS_RTU_HEADER_LENGTH
static int _modbus_set_slave(modbus_t *ctx, int slave)
Definition: modbus-rtu.c:101
#define MODBUS_RTU_MAX_ADU_LENGTH
Definition: modbus-rtu.h:29
int _modbus_rtu_send_msg_pre(uint8_t *req, int req_length)
Definition: modbus-rtu.c:164
ssize_t _modbus_rtu_recv(modbus_t *ctx, uint8_t *rsp, int rsp_length)
Definition: modbus-rtu.c:271
int _modbus_rtu_filter_request(modbus_t *ctx, int slave)
Definition: modbus-rtu.c:881
#define _MODBUS_RTU_CHECKSUM_LENGTH
int _modbus_rtu_check_integrity(modbus_t *ctx, uint8_t *msg, const int msg_length)
Definition: modbus-rtu.c:284
static int _modbus_rtu_build_request_basis(modbus_t *ctx, int function, int addr, int nb, uint8_t *req)
Definition: modbus-rtu.c:115
ssize_t _modbus_rtu_send(modbus_t *ctx, const uint8_t *req, int req_length)
Definition: modbus-rtu.c:260
int _modbus_rtu_prepare_response_tid(const uint8_t *req, int *req_length)
Definition: modbus-rtu.c:157
int _modbus_rtu_flush(modbus_t *)
Definition: modbus-rtu.c:831
void _modbus_rtu_close(modbus_t *ctx)
Definition: modbus-rtu.c:811
int _modbus_rtu_select(modbus_t *ctx, fd_set *rfds, struct timeval *tv, int length_to_read)
Definition: modbus-rtu.c:842
static int _modbus_rtu_connect(modbus_t *ctx)
Definition: modbus-rtu.c:310

Definition at line 896 of file modbus-rtu.c.

const uint8_t table_crc_hi[]
static
Initial value:
= {
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,
0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,
0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1,
0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1,
0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,
0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40,
0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1,
0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,
0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40,
0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,
0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,
0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,
0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,
0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40,
0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1,
0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,
0x80, 0x41, 0x00, 0xC1, 0x81, 0x40
}

Definition at line 40 of file modbus-rtu.c.

const uint8_t table_crc_lo[]
static
Initial value:
= {
0x00, 0xC0, 0xC1, 0x01, 0xC3, 0x03, 0x02, 0xC2, 0xC6, 0x06,
0x07, 0xC7, 0x05, 0xC5, 0xC4, 0x04, 0xCC, 0x0C, 0x0D, 0xCD,
0x0F, 0xCF, 0xCE, 0x0E, 0x0A, 0xCA, 0xCB, 0x0B, 0xC9, 0x09,
0x08, 0xC8, 0xD8, 0x18, 0x19, 0xD9, 0x1B, 0xDB, 0xDA, 0x1A,
0x1E, 0xDE, 0xDF, 0x1F, 0xDD, 0x1D, 0x1C, 0xDC, 0x14, 0xD4,
0xD5, 0x15, 0xD7, 0x17, 0x16, 0xD6, 0xD2, 0x12, 0x13, 0xD3,
0x11, 0xD1, 0xD0, 0x10, 0xF0, 0x30, 0x31, 0xF1, 0x33, 0xF3,
0xF2, 0x32, 0x36, 0xF6, 0xF7, 0x37, 0xF5, 0x35, 0x34, 0xF4,
0x3C, 0xFC, 0xFD, 0x3D, 0xFF, 0x3F, 0x3E, 0xFE, 0xFA, 0x3A,
0x3B, 0xFB, 0x39, 0xF9, 0xF8, 0x38, 0x28, 0xE8, 0xE9, 0x29,
0xEB, 0x2B, 0x2A, 0xEA, 0xEE, 0x2E, 0x2F, 0xEF, 0x2D, 0xED,
0xEC, 0x2C, 0xE4, 0x24, 0x25, 0xE5, 0x27, 0xE7, 0xE6, 0x26,
0x22, 0xE2, 0xE3, 0x23, 0xE1, 0x21, 0x20, 0xE0, 0xA0, 0x60,
0x61, 0xA1, 0x63, 0xA3, 0xA2, 0x62, 0x66, 0xA6, 0xA7, 0x67,
0xA5, 0x65, 0x64, 0xA4, 0x6C, 0xAC, 0xAD, 0x6D, 0xAF, 0x6F,
0x6E, 0xAE, 0xAA, 0x6A, 0x6B, 0xAB, 0x69, 0xA9, 0xA8, 0x68,
0x78, 0xB8, 0xB9, 0x79, 0xBB, 0x7B, 0x7A, 0xBA, 0xBE, 0x7E,
0x7F, 0xBF, 0x7D, 0xBD, 0xBC, 0x7C, 0xB4, 0x74, 0x75, 0xB5,
0x77, 0xB7, 0xB6, 0x76, 0x72, 0xB2, 0xB3, 0x73, 0xB1, 0x71,
0x70, 0xB0, 0x50, 0x90, 0x91, 0x51, 0x93, 0x53, 0x52, 0x92,
0x96, 0x56, 0x57, 0x97, 0x55, 0x95, 0x94, 0x54, 0x9C, 0x5C,
0x5D, 0x9D, 0x5F, 0x9F, 0x9E, 0x5E, 0x5A, 0x9A, 0x9B, 0x5B,
0x99, 0x59, 0x58, 0x98, 0x88, 0x48, 0x49, 0x89, 0x4B, 0x8B,
0x8A, 0x4A, 0x4E, 0x8E, 0x8F, 0x4F, 0x8D, 0x4D, 0x4C, 0x8C,
0x44, 0x84, 0x85, 0x45, 0x87, 0x47, 0x46, 0x86, 0x82, 0x42,
0x43, 0x83, 0x41, 0x81, 0x80, 0x40
}

Definition at line 70 of file modbus-rtu.c.



libmodbus
Author(s):
autogenerated on Sat Nov 21 2020 03:17:32