83 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
		
		
			
		
	
	
			83 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
|   | #ifndef handle_h__
 | |||
|  | #define handle_h__
 | |||
|  | 
 | |||
|  | #include "rtthread.h"
 | |||
|  | #include "signal.h"
 | |||
|  | #include "list.h"
 | |||
|  | #include "bytearray.h"
 | |||
|  | 
 | |||
|  | 
 | |||
|  | 
 | |||
|  | typedef struct{ | |||
|  |    | |||
|  | }mcu_data; | |||
|  | 
 | |||
|  | struct _port_mcu; | |||
|  | typedef struct _port_mcu port_mcu; | |||
|  | 
 | |||
|  | 
 | |||
|  | // 管理通信逻辑
 | |||
|  | typedef struct _handle_def{ | |||
|  |   const char *name; | |||
|  |   int static_; | |||
|  |   int interval; | |||
|  |   port_mcu *p; | |||
|  |   void (*del)(struct _handle_def *h); | |||
|  |   void (*start)(struct _handle_def *h); | |||
|  |   void (*dolater)(struct _handle_def *h,uint8_t src,uint8_t cmd,array_def *data,char *err_str); | |||
|  |   void (*timeout)(struct _handle_def *h); | |||
|  |    | |||
|  | }handle_def; | |||
|  | 
 | |||
|  | 
 | |||
|  | 
 | |||
|  | 
 | |||
|  | typedef int (*port_read_fun)(int off,uint8_t *buff,int size); | |||
|  | 
 | |||
|  | int port_init(void); | |||
|  | 
 | |||
|  | port_mcu *port_creat(uint8_t addr,sig_thread t); | |||
|  | 
 | |||
|  | void port_delete(port_mcu **p); | |||
|  | 
 | |||
|  | 
 | |||
|  | // 开始定时器,重复调用会重新开始
 | |||
|  | void port_timer_start(port_mcu *p); | |||
|  | // 停止定时器
 | |||
|  | void port_timer_stop(port_mcu *p); | |||
|  | // 开始一个通信操作,h是此项操作的类
 | |||
|  | int port_start(port_mcu *p,handle_def *h); | |||
|  | // 设置忙状态
 | |||
|  | void port_set_busy(port_mcu *p,int busy); | |||
|  | // 获取忙状态
 | |||
|  | int port_get_busy(port_mcu *p); | |||
|  | // 获取通信地址
 | |||
|  | uint8_t port_get_addr(port_mcu *p); | |||
|  | 
 | |||
|  | 
 | |||
|  | 
 | |||
|  | 
 | |||
|  | //signal port_send_signal(void *obj,list_def *addrs,uint8_t cmd,list_def *comp_cmd,array_def *data);
 | |||
|  | signal port_send_signal(port_mcu *obj,uint8_t addr,uint8_t cmd,list_def *comp_cmd,array_def *data,int timeout_ms,int retry); | |||
|  | 
 | |||
|  | void port_recv_call(port_mcu *obj,uint8_t src,uint8_t cmd,array_def *data,char *err_str); | |||
|  | 
 | |||
|  | // 结束信号,ack=0成功,-1失败
 | |||
|  | signal port_end_signal(port_mcu *obj,port_mcu *src,void *data,int ack,char *err_str); | |||
|  | 
 | |||
|  | 
 | |||
|  | 
 | |||
|  | 
 | |||
|  | 
 | |||
|  | 
 | |||
|  | 
 | |||
|  | handle_def *updata_creat(const uint8_t *data,int size); | |||
|  | 
 | |||
|  | handle_def *updata_scheme_creat(const uint8_t *data,int size); | |||
|  | 
 | |||
|  | handle_def *usercmd_creat(uint8_t cmd,array_def *data); | |||
|  | 
 | |||
|  | 
 | |||
|  | #endif
 | |||
|  | 
 |