delete serial ports
This commit is contained in:
parent
c16d9662dd
commit
ecdac7b3d3
@ -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;
|
||||
}
|
||||
}
|
@ -1,9 +1,8 @@
|
||||
|
||||
|
||||
#ifndef CLIENT_H
|
||||
#define CLIENT_H
|
||||
|
||||
#include "hdlc_frame.h"
|
||||
#include "uart_module.h"
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h> // Для использования size_t
|
||||
#include <stdint.h>
|
||||
@ -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
|
Loading…
Reference in New Issue
Block a user