fix final version(hdlc)
This commit is contained in:
parent
80cd73c3d6
commit
800f48bc11
4
.gitignore
vendored
4
.gitignore
vendored
@ -7,3 +7,7 @@ uart.c
|
|||||||
uart.h
|
uart.h
|
||||||
|
|
||||||
!./hdlc
|
!./hdlc
|
||||||
|
/.idea/Display_Avr_3.iml
|
||||||
|
/.idea/.gitignore
|
||||||
|
/.idea/vcs.xml
|
||||||
|
/.idea/modules.xml
|
||||||
|
@ -28,17 +28,15 @@ void init_hdlc_client(struct Client* client, int connecting_frame_timeout){
|
|||||||
// client->current_state_hdlc.dest_index = 0;
|
// client->current_state_hdlc.dest_index = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void hdlc_connect(struct Client* client, hdlc_control_t* frame){
|
void hdlc_connect(struct Client* client){
|
||||||
client->state = CONNECTING;
|
client->state = CONNECTING;
|
||||||
|
|
||||||
client->frameS.seq_no = 0;
|
client->frameS.seq_no = 0;
|
||||||
client->frameS.frame = S_FRAME;
|
client->frameS.frame = S_FRAME;
|
||||||
client->current_index_frame = client->frameS.seq_no;
|
client->current_index_frame = client->frameS.seq_no;
|
||||||
|
|
||||||
*frame = client->frameS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int hdlc_send_data(struct Client* client, hdlc_control_t* frame, uint8_t* data, size_t data_len){
|
int hdlc_send_data(struct Client* client, uint8_t* data, size_t data_len){
|
||||||
if (client->state != READY_STATE){
|
if (client->state != READY_STATE){
|
||||||
return ERR_INVALID_STATE;
|
return ERR_INVALID_STATE;
|
||||||
}
|
}
|
||||||
@ -55,22 +53,30 @@ int hdlc_send_data(struct Client* client, hdlc_control_t* frame, uint8_t* data,
|
|||||||
client->len_data_i_frame = data_len;
|
client->len_data_i_frame = data_len;
|
||||||
client->current_index_frame = client->frameI.seq_no;
|
client->current_index_frame = client->frameI.seq_no;
|
||||||
|
|
||||||
*frame = client->frameI;
|
|
||||||
|
|
||||||
client->state = RECIVING;
|
client->state = RECIVING;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int hdlc_get_raw_frame(struct Client *client, hdlc_control_t* frame, uint8_t* buffer, size_t lenBuffer) {
|
int hdlc_get_raw_frame(struct Client *client, uint8_t* buffer, size_t lenBuffer) {
|
||||||
if (frame->frame == S_FRAME || frame->frame == S_FRAME_NACK){
|
if(client->state == RECIVING){
|
||||||
int ret = hdlc_frame_data(frame, NULL, 0, buffer, &lenBuffer);
|
int ret = hdlc_frame_data(client->frameI, &client->data_i_frame,
|
||||||
|
client->len_data_i_frame, buffer, &lenBuffer);
|
||||||
|
if (ret < 0){
|
||||||
|
printf("err in get_frame: %d\n", ret);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (client->state == CONNECTING){
|
||||||
|
int ret = hdlc_frame_data(client->frameS, NULL, 0, buffer, &lenBuffer);
|
||||||
|
|
||||||
if (ret < 0){
|
if (ret < 0){
|
||||||
printf("err in get_frame: %d\n", ret);
|
printf("err in get_frame: %d\n", ret);
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
int ret = hdlc_frame_data(frame, &client->data_i_frame,
|
|
||||||
client->len_data_i_frame, buffer, &lenBuffer);
|
if (client->state == DISCONNECTING){
|
||||||
|
int ret = hdlc_frame_data(client->frame_rej, NULL, 0, buffer, &lenBuffer);
|
||||||
|
|
||||||
if (ret < 0){
|
if (ret < 0){
|
||||||
printf("err in get_frame: %d\n", ret);
|
printf("err in get_frame: %d\n", ret);
|
||||||
}
|
}
|
||||||
|
@ -30,9 +30,9 @@ struct Client{
|
|||||||
|
|
||||||
//название функций
|
//название функций
|
||||||
void init_hdlc_client(struct Client* client, int connecting_frame_timeout);
|
void init_hdlc_client(struct Client* client, int connecting_frame_timeout);
|
||||||
void hdlc_connect(struct Client* client, hdlc_control_t* frame);
|
void hdlc_connect(struct Client* client);
|
||||||
int hdlc_send_data(struct Client* client, hdlc_control_t* frame, uint8_t* data, size_t data_len);
|
int hdlc_send_data(struct Client* client, uint8_t* data, size_t data_len);
|
||||||
int hdlc_get_raw_frame(struct Client *client, hdlc_control_t* frame, uint8_t* buffer, size_t lenBuffer);
|
int hdlc_get_raw_frame(struct Client *client, uint8_t* buffer, size_t lenBuffer);
|
||||||
//принимает буффер с уарта
|
//принимает буффер с уарта
|
||||||
int hdlc_decode_recived_raw_data(struct Client* client, uint8_t* buffer, size_t len_buffer, uint8_t* recived_data, size_t* len_recived_data);
|
int hdlc_decode_recived_raw_data(struct Client* client, uint8_t* buffer, size_t len_buffer, uint8_t* recived_data, size_t* len_recived_data);
|
||||||
int hdlc_timeout_handler(struct Client* client, int delta_time);
|
int hdlc_timeout_handler(struct Client* client, int delta_time);
|
||||||
|
@ -8,66 +8,65 @@ struct Client hdlc;
|
|||||||
bool flag_connection = false;
|
bool flag_connection = false;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Lsd_inciliation();
|
Lsd_inciliation();
|
||||||
UART_init();
|
UART_init();
|
||||||
init_hdlc_client(&hdlc, 200);
|
init_hdlc_client(&hdlc, 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
if (!flag_connection){
|
if (!flag_connection){
|
||||||
hdlc_control_t frame;
|
hdlc_connect(&hdlc);
|
||||||
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;
|
uint8_t buffer;
|
||||||
hdlc_get_raw_frame(&hdlc, &hdlc->frame_rej, &buffer, sizeof(buffer));
|
hdlc_get_raw_frame(&hdlc, &buffer, sizeof(buffer));
|
||||||
|
|
||||||
UART_send(&buffer, sizeof(buffer));
|
UART_send(&buffer, sizeof(buffer));
|
||||||
}
|
|
||||||
|
|
||||||
if (ret == 0 && client->state == READY_STATE){
|
bool flag_recive = true;
|
||||||
flag_connection = 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user