fix index
This commit is contained in:
parent
0f99988c3e
commit
ca36c67ba2
@ -18,6 +18,7 @@ void init_hdlc_client(struct Client* client, int connecting_frame_timeout){
|
||||
client->state = IDLE_STATE;
|
||||
client->connecting_frame_timeout = connecting_frame_timeout;
|
||||
connecting_frame_timeout_bf = connecting_frame_timeout;
|
||||
client->current_index_frame = 20;
|
||||
|
||||
// client->current_state_hdlc.control_escape = 0;
|
||||
// client->current_state_hdlc.fcs = FCS_INIT_VALUE;
|
||||
@ -30,13 +31,9 @@ void init_hdlc_client(struct Client* client, int connecting_frame_timeout){
|
||||
void hdlc_connect(struct Client* client, hdlc_control_t* frame){
|
||||
client->state = CONNECTING;
|
||||
|
||||
if (client->frameS.seq_no != 0){
|
||||
*frame = client->frameS;
|
||||
return;
|
||||
}
|
||||
|
||||
client->frameS.seq_no = 0;
|
||||
client->frameS.frame = S_FRAME;
|
||||
client->current_index_frame = client->frameS.seq_no;
|
||||
|
||||
*frame = client->frameS;
|
||||
}
|
||||
@ -52,15 +49,11 @@ int hdlc_send_data(struct Client* client, hdlc_control_t* frame, uint8_t* data,
|
||||
return ERR_INVALID_DATA_SIZE;
|
||||
}
|
||||
|
||||
if (client->frameI.seq_no != 0){
|
||||
*frame = client->frameI;
|
||||
return 0;
|
||||
}
|
||||
|
||||
client->frameI.seq_no = 0;
|
||||
client->frameI.frame = I_FRAME;
|
||||
client->data_i_frame = *data;
|
||||
client->len_data_i_frame = data_len;
|
||||
client->current_index_frame = client->frameI.seq_no;
|
||||
|
||||
*frame = client->frameI;
|
||||
|
||||
@ -71,6 +64,7 @@ int hdlc_send_data(struct Client* client, hdlc_control_t* frame, uint8_t* data,
|
||||
int hdlc_get_raw_frame(struct Client *client, hdlc_control_t* frame, uint8_t* buffer, size_t lenBuffer) {
|
||||
if (frame->frame == S_FRAME || frame->frame == S_FRAME_NACK){
|
||||
int ret = hdlc_frame_data(frame, NULL, 0, buffer, &lenBuffer);
|
||||
|
||||
if (ret < 0){
|
||||
printf("err in get_frame: %d\n", ret);
|
||||
}
|
||||
@ -96,6 +90,13 @@ int hdlc_decode_recived_raw_data(struct Client* client, uint8_t* buffer, size_t
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (recv_control.seq_no != client->current_index_frame){
|
||||
client->state = DISCONNECTING;
|
||||
client->frame_rej.seq_no = 0;
|
||||
client->frame_rej.frame = S_FRAME_NACK;
|
||||
return ERR_INVALID_SEQ_NUMBER_FRAME;
|
||||
}
|
||||
|
||||
switch (recv_control.frame) {
|
||||
case S_FRAME:
|
||||
client->state = READY_STATE;
|
||||
@ -121,4 +122,5 @@ int hdlc_timeout_handler(struct Client* client, int delta_time){
|
||||
if (client->connecting_frame_timeout <= 0){
|
||||
return ERR_FRAME_TIME_OUT;
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -17,7 +17,8 @@ enum HDLCState {
|
||||
struct Client{
|
||||
enum HDLCState state;
|
||||
int connecting_frame_timeout; //-1
|
||||
hdlc_state_t current_state_hdlc;
|
||||
uint8_t current_index_frame;
|
||||
//hdlc_state_t current_state_hdlc;
|
||||
hdlc_control_t frameS;
|
||||
hdlc_control_t frameI;
|
||||
uint8_t data_i_frame;
|
||||
|
@ -24,7 +24,6 @@ int main(){
|
||||
|
||||
hdlc_control_t frame_data;
|
||||
uint8_t data = 33;
|
||||
printf("%llu\n", sizeof(data));
|
||||
hdlc_send_data(&hdlc, &frame_data, &data, sizeof(data));
|
||||
uint8_t buffer_for_ex_data[7];
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user