Display_Avr_3/main_sketch/main_sketch.ino
2024-02-09 12:36:55 +03:00

73 lines
1.7 KiB
C++

#include "lcd.h"
#include "client.h"
#include "uart.h"
#include "stdbool.h"
#include "stdio.h"
struct Client hdlc;
bool flag_connection = false;
void setup() {
Lsd_inciliation();
UART_init();
init_hdlc_client(&hdlc, 200);
}
void loop() {
if (!flag_connection){
hdlc_control_t frame;
hdlc_connect(&hdlc, &frame);
uint8_t buffer;
hdlc_get_raw_frame(&hdlc, &frame, &buffer, sizeof(buffer));
UART_send(&buffer, sizeof(buffer));
bool flag_recive = true;
while(flag_recive){
uint8_t buffer;
UART_receive(&buffer, sizeof(buffer));
int err = hdlc_timeout_handler(&hdlc, 1);
if (err != 0){
return err;
}
int ret = hdlc_decode_recived_raw_data(&hdlc, &fake_buffer, sizeof(fake_buffer), 0, 0);
if (ret == -6){
uint8_t buffer;
hdlc_get_raw_frame(&hdlc, &hdlc->frame_rej, &buffer, sizeof(buffer));
UART_send(&buffer, sizeof(buffer));
}
if (ret == 0 && client->state == READY_STATE){
flag_connection = true;
}
}
} else {
bool flag_recive = true;
while(flag_recive){
uint8_t buffer;
UART_receive(&buffer, sizeof(buffer));
int err = hdlc_timeout_handler(&hdlc, 1);
if (err != 0){
return err;
}
uint8_t recived_data;
size_t len_recived_data;
int ret = hdlc_decode_recived_raw_data(&hdlc, &fake_buffer, sizeof(fake_buffer), &recived_data, &len_recived_data);
if (ret == -6){
uint8_t buffer;
hdlc_get_raw_frame(&hdlc, &hdlc->frame_rej, &buffer, sizeof(buffer));
UART_send(&buffer, sizeof(buffer));
}
printLsd(recived_data);
}
}
}