Byte spacing tests
This commit is contained in:
parent
13cd7c74b6
commit
d9d66989d7
@ -93,6 +93,8 @@ void mbsn_set_read_timeout(mbsn_t* mbsn, int32_t timeout_ms);
|
||||
|
||||
void mbsn_set_byte_timeout(mbsn_t* mbsn, int32_t timeout_ms);
|
||||
|
||||
void mbsn_set_byte_spacing(mbsn_t* mbsn, uint32_t spacing_ms);
|
||||
|
||||
void mbsn_set_destination_rtu_address(mbsn_t* mbsn, uint8_t address);
|
||||
|
||||
mbsn_error mbsn_server_receive(mbsn_t* mbsn);
|
||||
|
||||
@ -86,7 +86,7 @@ int read_byte_timeout_third(uint8_t* b, int32_t timeout) {
|
||||
|
||||
|
||||
void test_server_receive_base(mbsn_transport transport) {
|
||||
mbsn_t server;
|
||||
mbsn_t server, client;
|
||||
mbsn_error err;
|
||||
mbsn_platform_conf platform_conf;
|
||||
|
||||
@ -134,6 +134,26 @@ void test_server_receive_base(mbsn_transport transport) {
|
||||
|
||||
err = mbsn_server_receive(&server);
|
||||
expect(err == MBSN_ERROR_TIMEOUT);
|
||||
|
||||
|
||||
should("honor byte spacing on RTU");
|
||||
if (transport == MBSN_TRANSPORT_RTU) {
|
||||
reset(client);
|
||||
platform_conf.transport = transport;
|
||||
platform_conf.read_byte = read_byte_socket_client;
|
||||
platform_conf.write_byte = write_byte_socket_client;
|
||||
|
||||
reset_sockets();
|
||||
|
||||
check(mbsn_client_create(&client, &platform_conf));
|
||||
|
||||
mbsn_set_byte_spacing(&client, 200);
|
||||
|
||||
uint64_t start = now_ms();
|
||||
check(mbsn_send_raw_pdu(&client, 1, (uint16_t[]){htons(1), htons(1)}, 4));
|
||||
uint64_t diff = now_ms() - start;
|
||||
assert(diff >= 200 * 8);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -124,41 +124,41 @@ int write_byte_fd(int fd, uint8_t b, int32_t timeout_ms) {
|
||||
}
|
||||
|
||||
|
||||
int read_byte_pipe_server(uint8_t* b, int32_t timeout_ms) {
|
||||
int read_byte_socket_server(uint8_t* b, int32_t timeout_ms) {
|
||||
return read_byte_fd(sockets[0], b, timeout_ms);
|
||||
}
|
||||
|
||||
|
||||
int write_byte_pipe_server(uint8_t b, int32_t timeout_ms) {
|
||||
int write_byte_socket_server(uint8_t b, int32_t timeout_ms) {
|
||||
return write_byte_fd(sockets[0], b, timeout_ms);
|
||||
}
|
||||
|
||||
|
||||
int read_byte_pipe_client(uint8_t* b, int32_t timeout_ms) {
|
||||
int read_byte_socket_client(uint8_t* b, int32_t timeout_ms) {
|
||||
return read_byte_fd(sockets[1], b, timeout_ms);
|
||||
}
|
||||
|
||||
|
||||
int write_byte_pipe_client(uint8_t b, int32_t timeout_ms) {
|
||||
int write_byte_socket_client(uint8_t b, int32_t timeout_ms) {
|
||||
return write_byte_fd(sockets[1], b, timeout_ms);
|
||||
}
|
||||
|
||||
|
||||
mbsn_platform_conf mbsn_platform_conf_server;
|
||||
mbsn_platform_conf* platform_conf_pipe_server(mbsn_transport transport) {
|
||||
mbsn_platform_conf* platform_conf_socket_server(mbsn_transport transport) {
|
||||
mbsn_platform_conf_server.transport = transport;
|
||||
mbsn_platform_conf_server.read_byte = read_byte_pipe_server;
|
||||
mbsn_platform_conf_server.write_byte = write_byte_pipe_server;
|
||||
mbsn_platform_conf_server.read_byte = read_byte_socket_server;
|
||||
mbsn_platform_conf_server.write_byte = write_byte_socket_server;
|
||||
mbsn_platform_conf_server.sleep = platform_sleep;
|
||||
return &mbsn_platform_conf_server;
|
||||
}
|
||||
|
||||
|
||||
mbsn_platform_conf mbsn_platform_conf_client;
|
||||
mbsn_platform_conf* platform_conf_pipe_client(mbsn_transport transport) {
|
||||
mbsn_platform_conf* platform_conf_socket_client(mbsn_transport transport) {
|
||||
mbsn_platform_conf_client.transport = transport;
|
||||
mbsn_platform_conf_client.read_byte = read_byte_pipe_client;
|
||||
mbsn_platform_conf_client.write_byte = write_byte_pipe_client;
|
||||
mbsn_platform_conf_client.read_byte = read_byte_socket_client;
|
||||
mbsn_platform_conf_client.write_byte = write_byte_socket_client;
|
||||
mbsn_platform_conf_client.sleep = platform_sleep;
|
||||
return &mbsn_platform_conf_client;
|
||||
}
|
||||
@ -178,8 +178,7 @@ void* server_listen_thread() {
|
||||
if (is_server_listen_thread_stopped())
|
||||
break;
|
||||
|
||||
mbsn_error err = mbsn_server_receive(&SERVER);
|
||||
check(err);
|
||||
check(mbsn_server_receive(&SERVER));
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@ -205,8 +204,8 @@ void start_client_and_server(mbsn_transport transport, mbsn_callbacks server_cal
|
||||
reset(SERVER);
|
||||
reset(CLIENT);
|
||||
|
||||
check(mbsn_server_create(&SERVER, TEST_SERVER_ADDR, platform_conf_pipe_server(transport), server_callbacks));
|
||||
check(mbsn_client_create(&CLIENT, platform_conf_pipe_client(transport)));
|
||||
check(mbsn_server_create(&SERVER, TEST_SERVER_ADDR, platform_conf_socket_server(transport), server_callbacks));
|
||||
check(mbsn_client_create(&CLIENT, platform_conf_socket_client(transport)));
|
||||
|
||||
mbsn_set_destination_rtu_address(&CLIENT, TEST_SERVER_ADDR);
|
||||
mbsn_set_read_timeout(&SERVER, 500);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user