High-Flying Electronics Technology Co. Ltd HF-A11X Manual De Usuario

Descargar
Página de 62
HF-A11x V3.1 User Manual 
Shanghai High-Flying Electronics Technology Co., Ltd 
www.hi-flying.com 
56
APPENDIX B: USER DEVICE PSEUDO-
CODE REFERENCE FOR AGREEMENT 
TRANSMITION MODE
 
#define MAX_DAT_BUF_LEN  
      1024   
#define AGREE_HEAD_LEN                6 
  
#define MAX_SEND_CMD_LEN MAX_ DAT_BUF_LEN+8   
#define RECV_CMD_LEN AGREE_HEAD_LEN+2 
 
 
 
// Define data structure 
struct STRAGREE 

 // 
SEND 命令 
 
unsigned char send_cmd[MAX_SEND_CMD_LEN]; 
 
 
unsigned short send_len;  
 
 
unsigned char send_s; 
 
 
 
 int 
waiting_4_send_ack; 
     
 // 
RECV 命令 
 
unsigned char recv_cmd[RECV_CMD_LEN];   
 
unsigned short recv_len;   
 
 
 
unsigned char recv_s; 
 
 
 
 int 
waiting_4_recv_ack; 
     
} agree_data; 
 
 
function do_send_ cmd() 
 
if (is_waiting_for_send_ack & is_timeout) 
 
 
 
 send_cmd_out(); 
   
 else 
if 
(!is_waiting_for_send_ack) 
 

   generate_new_send_cmd(); 
 
 
 send_cmd_out(); 
   

 else 
 
 
add waiting time; 
 
 
 
 
 
 
 
function do_recv_cmd() 
 
if (is_waiting_for_recv_ack & is_timeout)  
 
 
 recv_cmd_out();    
 
else if (!is_waiting_for_recv_ack)    

   generate_new_recv_cmd();  
 
 recv_cmd_out();    

 else 
 
 
add waiting time; 
 
 
 
 
 
 
 
 
function do_send_ack_cmd() 
 
if (receiv SEND ACK and check OK & is_waiting_for_send_ack)   
 { 
 
 agree_data.send_s++; 
 
    
 
 
agree_data. waiting_4_send_ack= 0;