delete serial ports

This commit is contained in:
Qukich 2023-06-25 16:36:30 +03:00
parent c16d9662dd
commit ecdac7b3d3
4 changed files with 14 additions and 21 deletions

View File

@ -6,13 +6,12 @@
#define START_FLAG 0x7E #define START_FLAG 0x7E
#define END_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->TEST_IS_VALID = test_is_valid;
client->address = address; client->address = address;
client->_send_sequence_number = 0; client->_send_sequence_number = 0;
client->poll_final = 1; client->poll_final = 1;
client->_receive_sequence_number = 0; client->_receive_sequence_number = 0;
client->serial_port = serial_port;
} }
@ -23,21 +22,20 @@ void connect(Client* client) {
uint8_t result[256]; uint8_t result[256];
create_frame(&u_frame.base, result); 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 // Wait for acknowledgment frame
bool flag = true; bool flag = true;
uint8_t data[u_frame.base.data_length]; uint8_t data;
while(flag){ while(flag){
int bytes_received = receiveSerialData(serial_port, data, 256); data = uart_read();
if (bytes_received > 0){ if (data > 0){
flag = false; flag = false;
} }
} }
HDLCFrame frame; HDLCFrame frame;
init_HDLCFrame(&frame, 0, 0, data + 3, 256 - 6); init_HDLCFrame(&frame, 0, 0, &data + 3, 256 - 6);
if (validate(data, 256)) { if (validate(&data, 256)) {
return; return;
} else { } else {
// Connection failed // Connection failed
@ -53,17 +51,16 @@ void send(Client* client, uint8_t* data, size_t data_length) {
uint8_t result[256]; uint8_t result[256];
create_frame(&i_frame.base, result); 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++; client->_send_sequence_number++;
} }
void receive_data(Client* client, uint8_t* recivedData, int lenRecived) { void receive_data(uint8_t* recivedData) {
void* serial_port = client->serial_port;
bool flag = true; bool flag = true;
while(flag){ while(flag){
int bytes_received = receiveSerialData(serial_port, recivedData, lenRecived); *recivedData = uart_read();
if (bytes_received > 0){ if (recivedData > 0){
flag = false; flag = false;
} }
} }

View File

@ -1,9 +1,8 @@
#ifndef CLIENT_H #ifndef CLIENT_H
#define CLIENT_H #define CLIENT_H
#include "hdlc_frame.h" #include "hdlc_frame.h"
#include "uart_module.h"
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h> // Для использования size_t #include <stddef.h> // Для использования size_t
#include <stdint.h> #include <stdint.h>
@ -14,15 +13,12 @@ typedef struct {
uint8_t _send_sequence_number; uint8_t _send_sequence_number;
uint8_t poll_final; uint8_t poll_final;
uint8_t _receive_sequence_number; uint8_t _receive_sequence_number;
void* serial_port; // Указатель на объект последовательного порта
} Client; } 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 connect(Client* client);
void send(Client* client, uint8_t* data, size_t data_length); 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); 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 #endif