Display_Avr_3/hdlc_screen/hdlc/client.h
2024-02-22 17:16:03 +03:00

50 lines
1.7 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef CLIENT_H
#define CLIENT_H
#include <stdint.h>
#include <stdbool.h>
#include "hdlc.h"
#define ERR_INVALID_DATA_SIZE -1
#define ERR_ALL_BUFFERS_FILL -2
#define ERR_INVALID_PARAMS -3
#define ERR_INVALID_STATE -4
#define ERR_FRAME_TIME_OUT -5
#define ERR_INVALID_SEQ_NUMBER_FRAME -6
#define ERR_TIMEOUT_ANSWER -7
enum HDLCState {
UNINITIALIZED_STATE = 0, // состояние до инцилизации
IDLE_STATE, // Состояние ожидания начала
READY_STATE, // Состояние принятия
CONNECTING, // состояние соединения
DISCONNECTING, // состояния отключения
RECIVING, // состояние приема и отправки
SEND, //данные отправлены
};
struct Client{
enum HDLCState state;
int connecting_frame_timeout; //-1
uint8_t current_index_frame;
hdlc_state_t current_state_hdlc;
hdlc_control_t frameS;
hdlc_control_t frameI;
uint8_t* data_i_frame;
size_t len_data_i_frame;
// hdlc_control_t frame3;
// hdlc_control_t frame4;
hdlc_control_t frame_rej;
};
//название функций
void init_hdlc_client(struct Client* client, int connecting_frame_timeout);
void hdlc_connect(struct Client* client);
int hdlc_send_data(struct Client* client, uint8_t data[], size_t data_len);
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_timeout_handler(struct Client* client, int delta_time);
#endif //CLIENT_H