From ecdac7b3d38e66ad96bc7e260930f6f15f0c4769 Mon Sep 17 00:00:00 2001 From: Qukich Date: Sun, 25 Jun 2023 16:36:30 +0300 Subject: [PATCH] delete serial ports --- hdlc/client.c => client.c | 25 +++++++++++-------------- hdlc/client.h => client.h | 10 +++------- hdlc/hdlc_frame.c => hdlc_frame.c | 0 hdlc/hdlc_frame.h => hdlc_frame.h | 0 4 files changed, 14 insertions(+), 21 deletions(-) rename hdlc/client.c => client.c (78%) rename hdlc/client.h => client.h (61%) rename hdlc/hdlc_frame.c => hdlc_frame.c (100%) rename hdlc/hdlc_frame.h => hdlc_frame.h (100%) diff --git a/hdlc/client.c b/client.c similarity index 78% rename from hdlc/client.c rename to client.c index 51b4b0a..a456c45 100644 --- a/hdlc/client.c +++ b/client.c @@ -6,13 +6,12 @@ #define START_FLAG 0x7E #define END_FLAG 0x7E -void init_Client(Client* client, bool test_is_valid, uint8_t address, void* serial_port) { +void init_Client(Client* client, bool test_is_valid, uint8_t address) { client->TEST_IS_VALID = test_is_valid; client->address = address; client->_send_sequence_number = 0; client->poll_final = 1; client->_receive_sequence_number = 0; - client->serial_port = serial_port; } @@ -23,21 +22,20 @@ void connect(Client* client) { uint8_t result[256]; create_frame(&u_frame.base, result); - void* serial_port = client->serial_port; - sendSerialData(serial_port, u_frame.base.data, u_frame.base.data_length); + // Wait for acknowledgment frame bool flag = true; - uint8_t data[u_frame.base.data_length]; + uint8_t data; while(flag){ - int bytes_received = receiveSerialData(serial_port, data, 256); - if (bytes_received > 0){ + data = uart_read(); + if (data > 0){ flag = false; } } HDLCFrame frame; - init_HDLCFrame(&frame, 0, 0, data + 3, 256 - 6); - if (validate(data, 256)) { + init_HDLCFrame(&frame, 0, 0, &data + 3, 256 - 6); + if (validate(&data, 256)) { return; } else { // Connection failed @@ -53,17 +51,16 @@ void send(Client* client, uint8_t* data, size_t data_length) { uint8_t result[256]; create_frame(&i_frame.base, result); - sendSerialData(client->serial_port, i_frame.base.data, i_frame.base.data_length); + uart_send_byte(*i_frame.base.data); client->_send_sequence_number++; } -void receive_data(Client* client, uint8_t* recivedData, int lenRecived) { - void* serial_port = client->serial_port; +void receive_data(uint8_t* recivedData) { bool flag = true; while(flag){ - int bytes_received = receiveSerialData(serial_port, recivedData, lenRecived); - if (bytes_received > 0){ + *recivedData = uart_read(); + if (recivedData > 0){ flag = false; } } diff --git a/hdlc/client.h b/client.h similarity index 61% rename from hdlc/client.h rename to client.h index fb18c71..0a19d58 100644 --- a/hdlc/client.h +++ b/client.h @@ -1,9 +1,8 @@ - - #ifndef CLIENT_H #define CLIENT_H #include "hdlc_frame.h" +#include "uart_module.h" #include #include // Для использования size_t #include @@ -14,15 +13,12 @@ typedef struct { uint8_t _send_sequence_number; uint8_t poll_final; uint8_t _receive_sequence_number; - void* serial_port; // Указатель на объект последовательного порта } Client; -void init_Client(Client* client, bool test_is_valid, uint8_t address, void* serial_port); +void init_Client(Client* client, bool test_is_valid, uint8_t address); void connect(Client* client); void send(Client* client, uint8_t* data, size_t data_length); -void receive_data(Client* client, uint8_t* recivedData, int lenRecived); +void receive_data(uint8_t* recivedData); bool validate(const uint8_t* frame, size_t length); -int sendSerialData(const char* port, uint8_t* data, size_t length); -int receiveSerialData(const char* port, uint8_t* data, int length); #endif diff --git a/hdlc/hdlc_frame.c b/hdlc_frame.c similarity index 100% rename from hdlc/hdlc_frame.c rename to hdlc_frame.c diff --git a/hdlc/hdlc_frame.h b/hdlc_frame.h similarity index 100% rename from hdlc/hdlc_frame.h rename to hdlc_frame.h