wangjianlin 1 semana atrás
pai
commit
3e135a1312
11 arquivos alterados com 191 adições e 66 exclusões
  1. 27 9
      main.c
  2. 18 0
      src/w_funs.c
  3. 4 0
      src/w_funs.h
  4. 9 0
      src/w_param.c
  5. 15 0
      src/w_param.h
  6. 18 2
      src/w_poc.h
  7. 75 4
      src/w_poc_cmds.c
  8. 2 0
      src/w_poc_cmds.h
  9. 0 42
      src/w_pt.h
  10. 22 9
      src/w_que_handler.c
  11. 1 0
      src/w_que_handler.h

+ 27 - 9
main.c

@@ -33,12 +33,12 @@ char msgCmp(char *msg, char *target){
 	return 1;
 }
 #define wlog_app(...) OEM_sys_log_print("WAPP","info", ##__VA_ARGS__)
-#define MSG_METHOD 1	//0 AT命令方式 1 API调用方式
+#define MSG_METHOD 0	//0 AT命令方式 1 API调用方式
 unsigned char loginStatus=0;
 void wpoc_msg_rx_at(char *msg){
 	const char *marker="+WPTT:";
-	wlog_app("%s", msg);
 	if(!msgCmp(msg, marker)) return;
+	wlog_app("%s", msg);
 	msg+=strlen(marker);
 	if(msgCmp(msg, "LOGIN=")){
 		if(msg[6]=='0') loginStatus=0;
@@ -47,10 +47,13 @@ void wpoc_msg_rx_at(char *msg){
 }
 
 void wpoc_msg_rx_event(WPOC_EVENT_RX event, unsigned char *data, int datalen){
-	wlog_app("event get:%d", event);
+	WPOC_LOGINACK_DEF *uinfo;
 	switch(event){
 		case WPOC_RX_EVENT_LOGIN:
+			uinfo=(WPOC_LOGINACK_DEF *)data;
 			wlog_app("login done");
+			wlog_app("uid:%08x,name:%s", uinfo->user_id, uinfo->user_name);
+			wlog_app("group:%08x,unum:%d,name:%s", uinfo->be_group_id, uinfo->user_num_in_group, uinfo->be_group_name);
 			loginStatus=1;
 			break;
 		case WPOC_RX_EVENT_LINEOFF:
@@ -58,8 +61,9 @@ void wpoc_msg_rx_event(WPOC_EVENT_RX event, unsigned char *data, int datalen){
 			loginStatus=0;
 			break;
 		case WPOC_RX_EVENT_TIMES:
-			wlog_app("time ack");
+			wlog_app("time ack:%s", (char *)data);
 			break;
+		default:wlog_app("unhandle event:%d", event);break;
 	}
 }
 
@@ -76,6 +80,10 @@ static int test_task(void *param){
 	unsigned int psn=241200001;
 	int ret;
 	int tick=0;
+	WPOC_REQ_GROUP_DEF groupQuery={
+		.startIndex=0,
+		.totalNum=-1
+	};
 	ql_rtos_task_sleep_ms(10000);
 	ql_set_auto_connect(1, TRUE);
 	ql_start_data_call(1, 0, NULL, NULL, NULL, 0);
@@ -86,6 +94,8 @@ static int test_task(void *param){
 	wpoc_param_set(WPOC_PARAM_ACCOUNT_PASS, "123456");
 	wpoc_param_set(WPOC_PARAM_DNS, "106.12.172.105");
 	wpoc_param_set(WPOC_PARAM_PLATFORM, "EC600M");
+	wpoc_param_set(WPOC_PARAM_GROUPNUMS, 100);
+	wpoc_param_set(WPOC_PARAM_USERNUMS, 100);
 	ret=wpoc_init(hlog_show);
 	for(;;){
 		ql_rtos_task_sleep_ms(1000);
@@ -93,11 +103,19 @@ static int test_task(void *param){
 		//查询时间
 		if(++tick<30) continue;
 		tick=0;
-	#if MSG_METHOD==0
-		wpoc_msg_at_tx("AT+WPTT:REQTIME\r\n");
-	#else
-		wpoc_msg_event_tx(WPOC_TX_EVENT_REQTIME, NULL, NULL);
-	#endif
+		if(tick==5){
+		#if MSG_METHOD==0
+			wpoc_msg_at_tx("AT+WPTT:GROUPS=0,-1\r\n");
+		#else
+			wpoc_msg_event_tx(WPOC_TX_EVENT_REQGOUPS, &groupQuery, sizeof(WPOC_REQ_GROUP_DEF));
+		#endif
+		}else if(tick==30){
+		#if MSG_METHOD==0
+			wpoc_msg_at_tx("AT+WPTT:REQTIME\r\n");
+		#else
+			wpoc_msg_event_tx(WPOC_TX_EVENT_REQTIME, NULL, NULL);
+		#endif
+		}
 	}
 	return 0;
 }

+ 18 - 0
src/w_funs.c

@@ -5,4 +5,22 @@ unsigned int funs_random_get(unsigned int mix, unsigned int max){
 	unsigned int mixx=(mix>max?0:mix);
 	srand(OEM_sys_get_tick());
 	return (mixx+rand()%(max-mixx+1));
+}
+
+char wpoc_msg_cmp(char *msg, char *target){
+	char *p1=target, *p2=msg;
+	while(*p1 != 0){
+		if(*p1 != *p2) return 0;
+		p1++;p2++;
+	}
+	return 1;
+}
+
+void strcat_hexstr_string(char *src, char *newstr,bool need_end){
+	char buf[3];
+	for(int i=0;i<strlen(newstr);i++){
+		sprintf(buf, "%02x", newstr[i]);
+		strcat(src, buf);
+	}
+	if(need_end==true) strcat(src, "\r\n");
 }

+ 4 - 0
src/w_funs.h

@@ -2,5 +2,9 @@
 #ifndef __W_FUNS_H_
 #define __W_FUNS_H_
 
+#include <stdbool.h>
+
 unsigned int funs_random_get(unsigned int mix, unsigned int max);
+char wpoc_msg_cmp(char *msg, char *target);
+void strcat_hexstr_string(char *src, char *newstr,bool need_end);
 #endif

+ 9 - 0
src/w_param.c

@@ -6,6 +6,7 @@ WPOC_APP_DEF wpoc_app={0};
 
 int wpoc_param_set(WPOC_PARAM_ENUM type, void *param){
 	unsigned int *tmp_uint;
+	unsigned short *tmp_ushort;
 	char *tmp_char;
 	if(param==NULL) return -1;
 	switch(type){
@@ -30,6 +31,14 @@ int wpoc_param_set(WPOC_PARAM_ENUM type, void *param){
 			tmp_char=(char *)param;
 			snprintf(wpoc.platform,sizeof(wpoc.platform), "%s", tmp_char);
 			break;
+		case WPOC_PARAM_GROUPNUMS:
+			tmp_uint=(unsigned int *)param;
+			wpoc.maxGroupNum=*tmp_uint;
+			break;
+		case WPOC_PARAM_USERNUMS:
+			tmp_uint=(unsigned int *)param;
+			wpoc.maxUserNum=*tmp_uint;
+			break;
 		default:return -2;
 	}
 	return 0;

+ 15 - 0
src/w_param.h

@@ -11,7 +11,20 @@ typedef struct{
 	char dns[30];
 	char platform[16];
 	char hardid[20];
+	unsigned int maxGroupNum;
+	unsigned int maxUserNum;
 }WPOC_DEF;
+typedef struct{
+	unsigned int id;
+	unsigned int mem_num;
+	char name[GROUP_USER_NAME_MAX];
+}GROUP_INFO_DEF;
+typedef struct{
+	unsigned int usrSetMaxGroupNum;
+	unsigned int maxGroupNum;
+	unsigned int validGroupNum;
+	GROUP_INFO_DEF **groupInfo;
+}GROUP_INFO_LIST;
 typedef struct{
 	unsigned char poc_tcp:1;	//tcp link status
 	unsigned char poc_login:1;	//tcp login status
@@ -21,8 +34,10 @@ typedef struct{
 	unsigned char poc_login_counter;
 	unsigned char poc_login_timeout_counter;
 	unsigned char poc_heartick;
+	unsigned short poc_voice_port;
 	char tcp_ip[20];
 	WPOC_MSG_RX_DEF *usrMsgRx;
+	GROUP_INFO_LIST groupList;
 }WPOC_APP_DEF;
 #pragma pack(pop)
 

+ 18 - 2
src/w_poc.h

@@ -11,9 +11,17 @@ typedef enum{
 	WPOC_PARAM_ACCOUNT_PASS,	//设置密码
 	WPOC_PARAM_DNS,				//设置服务器
 	WPOC_PARAM_PLATFORM,		//设置开发平台类型
+	WPOC_PARAM_GROUPNUMS,		//设置预存最大群组数量(不设置则默认为100个)
+	WPOC_PARAM_USERNUMS			//设置预存最大组成员数量(不设置则默认为100个)
 }WPOC_PARAM_ENUM;
+//上层事件请求组信息参数
+typedef struct{
+	int startIndex;
+	int totalNum;
+}WPOC_REQ_GROUP_DEF;
 //上层应用请求事件
 typedef enum{
+	WPOC_TX_EVENT_REQGOUPS,		//请求群组信息
 	WPOC_TX_EVENT_REQTIME,		//请求时间(登陆后有效)
 }WPOC_EVENT_TX;
 //主动上报上层应用事件
@@ -30,6 +38,16 @@ typedef struct{
 	WPOC_MSG_RX_EVENT_FUN wpoc_msg_rx_event_fun;//callback mode
 }WPOC_MSG_RX_DEF;
 
+#define GROUP_USER_NAME_MAX 30
+//登录成功时的参数
+typedef struct{
+	unsigned int user_id;
+	char user_name[GROUP_USER_NAME_MAX];
+	unsigned int be_group_id;
+	char be_group_name[GROUP_USER_NAME_MAX];
+	unsigned short user_num_in_group;
+}WPOC_LOGINACK_DEF;
+
 //上层应用设置参数接口,不同参数类型可能不一样,详参考demo
 int wpoc_param_set(WPOC_PARAM_ENUM type, void *param);
 //上层应用启动POC接口(参数为传POC的日志接口)
@@ -40,6 +58,4 @@ int wpoc_msg_at_tx(char *msg);
 int wpoc_msg_event_tx(WPOC_EVENT_TX event, unsigned char *data, int datalen);
 
 
-//POC用到的接口(比对target字符串是否与msg字符串开头开始匹配,真为成功),上层可用也可以不用理会
-char wpoc_msg_cmp(char *msg, char *target);
 #endif

+ 75 - 4
src/w_poc_cmds.c

@@ -52,6 +52,25 @@ int wpoc_login_req(OEM_sock *handle, unsigned int psn, char *pass,char *hardid,c
 	rlen=OEM_sys_sock_send_data(handle, out, outsize);
 	return rlen;
 }
+int wpoc_query_group_req(OEM_sock *handle){
+	wlog_info("try query group");
+	QueryGroup _querygroup=QUERY_GROUP__INIT;
+	_querygroup.detail=QUERY_GROUP__DETAIL_LEVEL__ALL_INFO;
+	_querygroup.has_max_groups=true;
+	wpoc_app.groupList.usrSetMaxGroupNum=wpoc.maxGroupNum;
+	_querygroup.max_groups=wpoc_app.groupList.usrSetMaxGroupNum;
+	int rlen=query_group__get_packed_size(&_querygroup);
+	unsigned char *pb=(unsigned char *)malloc(rlen+1);
+	if(pb==NULL) return -1;
+	rlen=query_group__pack(&_querygroup, pb+1);
+	int outsize;
+	unsigned char *out=w_packing_buf(&outsize, U_QUERY_GROUP, pb, rlen+1);
+	free(pb);
+	if(out==NULL) return -2;
+	
+	rlen=OEM_sys_sock_send_data(handle, out, outsize);
+	return rlen;
+}
 int wpoc_ping_req(OEM_sock *handle,bool need_time_ack){
 	wlog_info("try ping req:%s", need_time_ack==true?"with time":"no time");
 	Ping _ping=PING__INIT;
@@ -205,16 +224,66 @@ void w_unpacking_buf(unsigned char *usrbuf, int usrsize){
 static void d_login_ack(const ProtobufCMessage *msg){
 	LoginAck *ack=(LoginAck *)msg;
 	if(ack->result!=0){
-		wlog_warn("login fail");
+		wlog_warn("login fail:%d",ack->result);
 		return;
 	}
-	wlog_warn("login ok");
+	wlog_warn("login ok:port=%d",ack->confi->talk_port);
 	wpoc_app.poc_login=1;
 	wpoc_app.poc_firstLogin=1;
-	wpoc_que_data_send(WPOC_QUE_DATA_RX_LOGINACK, NULL, 0);
+	wpoc_app.poc_voice_port=ack->confi->talk_port;
+	WPOC_LOGINACK_DEF uinfo;
+	uinfo.user_id=ack->usr->id;
+	snprintf(uinfo.user_name, sizeof(uinfo.user_name), "%s", ack->usr->name);
+	uinfo.be_group_id=ack->currg_group->id;
+	snprintf(uinfo.be_group_name, sizeof(uinfo.be_group_name), "%s", ack->currg_group->name);
+	uinfo.user_num_in_group=ack->currg_group->umembers;
+	wpoc_que_data_send(WPOC_QUE_DATA_RX_LOGINACK, &uinfo, sizeof(WPOC_LOGINACK_DEF));
+	wpoc_que_data_send(WPOC_QUE_DATA_TX_QUERY_GROUP, NULL, 0);
 }
 static void d_query_group_ack(const ProtobufCMessage *msg){
 	QueryGroupAck *ack=(QueryGroupAck *)msg;
+	if(ack->result!=0){
+		wlog_warn("query group fail:%d", ack->result);
+		return;
+	}
+	wlog_info("query group ok:%u", ack->n_groups);
+	int i;
+	unsigned int num;
+	GROUP_INFO_LIST *gInfo=&wpoc_app.groupList;
+	if(gInfo->usrSetMaxGroupNum==0) gInfo->usrSetMaxGroupNum=100;
+	if(gInfo->groupInfo==NULL || gInfo->maxGroupNum!=gInfo->usrSetMaxGroupNum){
+		if(gInfo->groupInfo!=NULL){
+			for(i=0;i<gInfo->maxGroupNum;i++) OEM_sys_free(gInfo->groupInfo[i]);
+			OEM_sys_free(gInfo->groupInfo);
+			//try to new
+			num=gInfo->usrSetMaxGroupNum;
+			gInfo->groupInfo=(GROUP_INFO_DEF **)OEM_sys_malloc(num*sizeof(GROUP_INFO_DEF*));
+			if(gInfo->groupInfo==NULL){
+				wlog_error("groupInfo new fail");
+				return;
+			}
+			for(i=0;i<num;i++){
+				gInfo->groupInfo[i]=(GROUP_INFO_DEF *)OEM_sys_malloc(sizeof(GROUP_INFO_DEF));
+				if(gInfo->groupInfo[i]==NULL){
+					wlog_error("groupInfo new no enough:%d,%d", i, num);
+					for(num=0;i<i;i++) OEM_sys_free(gInfo->groupInfo[i]);
+					OEM_sys_free(gInfo->groupInfo);
+					gInfo->groupInfo=NULL;
+					return;
+				}
+			}
+		}
+		//start to save
+		gInfo->maxGroupNum=gInfo->usrSetMaxGroupNum;
+		num=(ack->n_groups>gInfo->maxGroupNum?gInfo->maxGroupNum:ack->n_groups);
+		for(i=0;i<num;i++){
+			wlog_info("group<%d>id=%08x,mem=%d,name=%s", i,ack->groups[i]->id, ack->groups[i]->umembers,ack->groups[i]->name);
+			gInfo->groupInfo[i]->id=ack->groups[i]->id;
+			gInfo->groupInfo[i]->mem_num=ack->groups[i]->umembers;
+			snprintf(gInfo->groupInfo[i]->name,sizeof(gInfo->groupInfo[i]->name), "%s", ack->groups[i]->name);
+		}
+		gInfo->validGroupNum=num;
+	}
 }
 static void d_join_group_ack(const ProtobufCMessage *msg){
 	JoinGroupAck *ack=(JoinGroupAck *)msg;
@@ -264,7 +333,9 @@ void w_poc_cmd_que_tx_login(void *param1){
 	};
 	wpoc_que_data_send(WPOC_QUE_DATA_TX_LOGIN, &usrdata, sizeof(WPOC_CMD_DATA_DEF));
 }
-
+void w_poc_cmd_que_tx_query_group(void){
+	wpoc_que_data_send(WPOC_QUE_DATA_TX_QUERY_GROUP, NULL, 0);
+}
 void w_poc_cmd_que_tx_ping(unsigned int value){
 	WPOC_CMD_DATA_DEF usrdata={
 		.data1=value

+ 2 - 0
src/w_poc_cmds.h

@@ -9,12 +9,14 @@ typedef struct{
 	unsigned int data1;
 }WPOC_CMD_DATA_DEF;
 int wpoc_login_req(OEM_sock *handle, unsigned int psn, char *pass,char *hardid,char *platform);
+int wpoc_query_group_req(OEM_sock *handle);
 int wpoc_ping_req(OEM_sock *handle,bool need_time_ack);
 void w_unpacking_buf(unsigned char *usrbuf, int usrsize);
 
 
 void w_poc_cmd_que_notes(void);
 void w_poc_cmd_que_tx_login(void *param1);
+void w_poc_cmd_que_tx_query_group(void);
 void w_poc_cmd_que_tx_ping(unsigned int value);
 #endif
 

+ 0 - 42
src/w_pt.h

@@ -1,42 +0,0 @@
-#ifndef __W_PT_H_
-#define __W_PT_H_
-
-//wc-switch
-typedef unsigned short wc_t;
-
-#define WC_INIT(s) s = 0;
-
-#define WC_RESUME(s) switch(s) { case 0:
-
-#define WC_SET(s) s = __LINE__; case __LINE__:
-
-#define WC_END(s) }
-
-//wt
-struct wt {
-  lc_t wc;
-};
-
-#define WT_WAITING 0
-#define WT_YIELDED 1
-#define WT_EXITED  2
-#define WT_ENDED   3
-
-#define WT_INIT(pt)   WC_INIT((pt)->lc)
-
-#define WT_THREAD(name_args) char name_args
-
-#define WT_BEGIN(pt) { char WT_YIELD_FLAG = 1; WC_RESUME((pt)->lc)
-
-#define WT_END(pt) WC_END((pt)->lc); WT_YIELD_FLAG = 0; \
-                   WT_INIT(pt); return WT_ENDED; }
-
-#define WT_WAIT_UNTIL(pt, condition)	        \
-  do {						\
-    WC_SET((pt)->lc);				\
-    if(!(condition)) {				\
-      return WT_WAITING;			\
-    }						\
-  } while(0)
-
-#endif

+ 22 - 9
src/w_que_handler.c

@@ -18,6 +18,7 @@ static void call_func_note_lineoff(unsigned char *data, int datalen);
 static void call_func_cmds(unsigned char *data, int datalen);
 //internal
 static void call_func_login_req(unsigned char *data, int datalen);
+static void call_func_query_req(unsigned char *data, int datalen);
 static void call_func_ping_req(unsigned char *data, int datalen);
 //extern
 static void call_func_login_ack(unsigned char *data, int datalen);
@@ -26,6 +27,7 @@ static const WPOC_EVENT_LIST wpoc_event_entries[]={
 	{WPOC_QUE_DATA_CMDS, call_func_cmds},
 	{WPOC_QUE_DATA_TX_LINEOFF, call_func_note_lineoff},
 	{WPOC_QUE_DATA_TX_LOGIN, call_func_login_req},
+	{WPOC_QUE_DATA_TX_QUERY_GROUP, call_func_query_req},
 	{WPOC_QUE_DATA_TX_PING, call_func_ping_req},
 	{WPOC_QUE_DATA_RX_LOGINACK, call_func_login_ack},
 	{WPOC_QUE_DATA_RX_PONG_TIMEACK, call_func_times}
@@ -81,6 +83,10 @@ static void call_func_login_req(unsigned char *data, int datalen){
 	WPOC_DEF *info=(WPOC_DEF *)tdata->param1;
 	wpoc_login_req(sock, info->psn, info->pass,info->hardid,info->platform);
 }
+static void call_func_query_req(unsigned char *data, int datalen){
+	OEM_sock *sock=wpoc_get_tcp_sock();
+	wpoc_query_group_req(sock);
+}
 static void call_func_ping_req(unsigned char *data, int datalen){
 	WPOC_CMD_DATA_DEF *tdata=(WPOC_CMD_DATA_DEF *)data;
 	OEM_sock *sock=wpoc_get_tcp_sock();
@@ -90,10 +96,18 @@ static void call_func_ping_req(unsigned char *data, int datalen){
 static void call_func_login_ack(unsigned char *data, int datalen){
 	WPOC_MSG_TR_AT_FUN at_fun=wpoc_app.usrMsgRx->wpoc_msg_rx_at_fun;
 	WPOC_MSG_RX_EVENT_FUN cb_fun=wpoc_app.usrMsgRx->wpoc_msg_rx_event_fun;
+	WPOC_LOGINACK_DEF *uinfo=(WPOC_LOGINACK_DEF *)data;
 	if(at_fun!=NULL){
+		char buf[64];
 		at_fun("+WPTT:LOGIN=1\r\n");
+		snprintf(buf, sizeof(buf), "+WPTT:ME=%08x,",uinfo->user_id);
+		strcat_hexstr_string(buf, uinfo->user_name,true);
+		at_fun(buf);
+		snprintf(buf, sizeof(buf), "+WPTT:BE=%08x,%04x,",uinfo->be_group_id,uinfo->user_num_in_group);
+		strcat_hexstr_string(buf, uinfo->be_group_name,true);
+		at_fun(buf);
 	}else if(cb_fun!=NULL){
-		cb_fun(WPOC_RX_EVENT_LOGIN, NULL, 0);
+		cb_fun(WPOC_RX_EVENT_LOGIN, data, datalen);
 	}
 }
 static void call_func_times(unsigned char *data, int datalen){
@@ -107,14 +121,7 @@ static void call_func_times(unsigned char *data, int datalen){
 		cb_fun(WPOC_RX_EVENT_TIMES, data, datalen);
 	}
 }
-char wpoc_msg_cmp(char *msg, char *target){
-	char *p1=target, *p2=msg;
-	while(*p1 != 0){
-		if(*p1 != *p2) return 0;
-		p1++;p2++;
-	}
-	return 1;
-}
+
 //cmds
 static void call_func_cmds(unsigned char *data, int datalen){
 	const char *func_cmds_mark="AT+WPTT:";
@@ -163,7 +170,13 @@ int wpoc_msg_at_tx(char *msg){
 int wpoc_msg_event_tx(WPOC_EVENT_TX event, unsigned char *data, int datalen){
 	if(wpoc_app.poc_tcp==0) return -1;
 	if(wpoc_app.poc_login==0) return -2;
+	WPOC_REQ_GROUP_DEF *groupQuery;
 	switch(event){
+		case WPOC_TX_EVENT_REQGOUPS:
+			groupQuery=(WPOC_REQ_GROUP_DEF *)data;
+			if(groupQuery==NULL) return -3;
+			w_poc_cmd_que_tx_ping(groupQuery->startIndex, groupQuery->totalNum);
+			break;
 		case WPOC_TX_EVENT_REQTIME:
 			w_poc_cmd_que_tx_ping(true);
 			break;

+ 1 - 0
src/w_que_handler.h

@@ -5,6 +5,7 @@
 typedef enum{
 	//TX
 	WPOC_QUE_DATA_TX_LOGIN,
+	WPOC_QUE_DATA_TX_QUERY_GROUP,
 	WPOC_QUE_DATA_TX_PING,
 	//RX
 	WPOC_QUE_DATA_RX_LOGINACK,