xinbiao.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. #include "includes.h"
  2. SUT_XINBIAO_PAGE sut_xinbiaopage[XINBIAO_NUM];
  3. SUT_XINBIAO_PAGE New_xinbiaopage;
  4. SUT_XINBIAO_INFO sut_xinbiao_info;
  5. USERARR UserArr[MAX_USER]; //临时存储当前所有成员 //每次 86 都需要更新
  6. LEADER leader[XINBIAO_NUM]; //根据 UserArr 每次更新 进表格 存入文件系统
  7. /*
  8. 获得新的信标页
  9. callID //是, 更新页
  10. //否,创建新页
  11. */
  12. //+POC=8C00%08x%02x;%d;%d;%d;%d;%d;\r\n"
  13. //+POC:8C00 934C0008 00 3B
  14. void Recv_PackNewxinbiaopage(char*msg)
  15. {
  16. char i,j;
  17. char start=0;
  18. char *Pmsg=0;
  19. char data[500];
  20. msg[17]=0;
  21. New_xinbiaopage.xb_CallID=htoi(msg+9);
  22. //find user name
  23. for(i=0;i<MAX_USER;i++){
  24. if(UserArr[i].id==New_xinbiaopage.xb_CallID){
  25. strcpy(New_xinbiaopage.xb_CallName,UserArr[i].UserName);
  26. }
  27. }
  28. StrAsciiToHex(msg[21],data);
  29. Pmsg=data;
  30. //456;789
  31. for(i=0;i<strlen(Pmsg);i++){
  32. if(Pmsg[i]==';'){
  33. Pmsg[i]=0;
  34. switch(j){
  35. case 0:
  36. New_xinbiaopage.xb_longitue=atoi(Pmsg+start);
  37. break;
  38. case 1:
  39. New_xinbiaopage.xb_latitue=atoi(Pmsg+start);
  40. break;
  41. case 2:
  42. New_xinbiaopage.xb_heading=atoi(Pmsg+start);
  43. break;
  44. case 3:
  45. New_xinbiaopage.xb_headerSpeed=atoi(Pmsg+start);
  46. break;
  47. case 4:
  48. New_xinbiaopage.xb_elevation=atoi(Pmsg+start);
  49. break;
  50. }
  51. i++;
  52. start=i;
  53. j++;
  54. }
  55. }
  56. }
  57. void PushXinbiao(SUT_XINBIAO_PAGE*NewXinbiao)
  58. {
  59. char i=0;
  60. for(i=0;i<sut_xinbiao_info.Max_id;i++){
  61. if(NewXinbiao->xb_CallID==sut_xinbiaopage[i].xb_CallID){
  62. memcpy(&sut_xinbiaopage[i],NewXinbiao,sizeof(SUT_XINBIAO_PAGE));
  63. return;
  64. }
  65. }
  66. //否,创建新页
  67. NewXinbiao->xb_id=sut_xinbiao_info.Max_id;
  68. memcpy(&sut_xinbiaopage[i+1],NewXinbiao,sizeof(SUT_XINBIAO_PAGE));
  69. sut_xinbiao_info.Max_id++;
  70. //处理完 清空
  71. memset(NewXinbiao,0,sizeof(NewXinbiao));
  72. }
  73. void CalcDistance(SUT_XINBIAO_PAGE*NewXinbiao)
  74. {
  75. }
  76. /*
  77. 信标协议 cmd 00 通用
  78. 0a 摇晕 只收不发
  79. a0 解除摇晕
  80. 0b 摇毙 不收不发
  81. b0 解除摇毙
  82. 0c 强制打开GPS
  83. */
  84. void XinbiaoPackSend(char cmd)
  85. {
  86. char temp[100]={0};
  87. snprintf(temp,sizeof(temp),"AT+POC=150000%08x%02x;%d;%d;%d;%d;%d;\r\n",sutPocStatus.LocalGroup.ID,cmd,sutGpsInfo.longitue\
  88. ,sutGpsInfo.latitue,sutGpsInfo.heading,sutGpsInfo.headerSpeed,sutGpsInfo.elevation);
  89. //strcpy(data,temp);
  90. msgAtSend(temp);
  91. MSG_INFO(1,temp);
  92. }
  93. //定时发送信标
  94. void Xinbiao_handler(unsigned int interval){
  95. static unsigned short cnt=0;
  96. //char Packdata[100]={0};
  97. if(sutApp.gtMode!=0) return;
  98. if(newPara.Xinbiao_SendMode==0)return;
  99. if(newPara.gpsEnable==0)return;
  100. if(++cnt<((newPara.Xinbiao_Time+1)*5*1000/interval) && gpsCheckCnt==0) return;
  101. cnt=0;
  102. gpsCheckCnt=0;
  103. if(sutGpsInfo.isGpsValid){
  104. XinbiaoPackSend(NULLCMD);
  105. }
  106. }
  107. void ReadXbFile()
  108. {
  109. int fd,i=0;
  110. fd=LSAPI_FS_Open(XINBIAO_FILE, LSAPI_FS_O_RDWR,0);
  111. if(fd<0){
  112. MSG_ERR(1,"%s open read failed", XINBIAO_FILE);
  113. return;
  114. }
  115. LSAPI_FS_Seek(fd, 0L, LSAPI_FS_SEEK_SET);
  116. LSAPI_FS_Read(fd, (unsigned char *)&sut_xinbiaopage, sizeof(SUT_XINBIAO_PAGE)*XINBIAO_NUM);
  117. for(i=0;i<XINBIAO_NUM;i++){
  118. if(sut_xinbiaopage[i].xb_id==0){
  119. if(i!=0)sut_xinbiao_info.Max_id=sut_xinbiaopage[i-1].xb_id;
  120. break;
  121. }
  122. }
  123. }
  124. void WriteXbFile()
  125. {
  126. int fd;
  127. MSG_INFO(1,"%s save start",XINBIAO_FILE);
  128. fd=LSAPI_FS_Open(XINBIAO_FILE, LSAPI_FS_O_RDWR,0x0);
  129. if(fd<0){
  130. MSG_ERR(1,"%s open failed",XINBIAO_FILE);
  131. return;
  132. }
  133. LSAPI_FS_Seek(fd, 0L, LSAPI_FS_SEEK_SET);
  134. LSAPI_FS_Write(fd, (unsigned char *)&sut_xinbiaopage, sizeof(SUT_XINBIAO_PAGE)*XINBIAO_NUM);
  135. LSAPI_FS_Close(fd);
  136. MSG_INFO(1,"%s save done", XINBIAO_FILE);
  137. }
  138. /*******************************************************************************************
  139. 下面为 首长功能
  140. *******************************************************************************************/
  141. signed char Record_Leader_CurIndex(){
  142. unsigned char i;
  143. for(i=0;i<MAX_USER;i++){
  144. if(leader[i].id==0)return i;//找到空白
  145. }
  146. return -1;
  147. }
  148. char Record_Leader_Scanf(int id){
  149. unsigned char i;
  150. for(i=0;i<MAX_USER;i++){
  151. if(leader[i].id==id)break;
  152. if(leader[i].id==0)break;//找到空白
  153. }
  154. if(i==MAX_USER)i=0; //覆盖第一条
  155. return i;
  156. }
  157. void Record_Leader_Status(char type){
  158. unsigned char i;
  159. unsigned char index;
  160. for(i=1;i<MAX_USER;i++){
  161. index=Record_Leader_Scanf(UserArr[i-1].id);
  162. leader[index].id=UserArr[i-1].id;
  163. if(type=0){//摇匀
  164. if(sut_check_box.checkstatus[i])leader[index].status=1;
  165. else leader[index].status=0;
  166. }else{
  167. if(sut_check_box.checkstatus[i])leader[index].status=2;
  168. else leader[index].status=0;
  169. }
  170. }
  171. }
  172. // ID cmd ;
  173. //+POC:8C00 934C0008 00 3B
  174. void LeaderRecv_handler(char*msg,char type)
  175. {
  176. char i;
  177. char start=0;
  178. char *Pmsg=0;
  179. int id=0;
  180. char data[250];
  181. StrAsciiToHex(msg[21],data);
  182. Pmsg=data;
  183. //456;789
  184. for(i=0;i<strlen(Pmsg);i++){
  185. if(Pmsg[i]==';'){
  186. Pmsg[i]=0;
  187. id=atoi(Pmsg+start);
  188. if(id==sutPocStatus.LocalUser.ID){
  189. sutPocStatus.LeaderCmd=type;
  190. if(sutPocStatus.spk)msgAtSend("AT+POC=0C0000\r\n");//说话状态释放话语权
  191. break;
  192. }
  193. i++;
  194. start=i;
  195. }
  196. }
  197. }
  198. void LeaderPackSend(char cmd)
  199. {
  200. char temp[250]={0};
  201. char buf[8];
  202. int i;
  203. int max;
  204. max=Record_Leader_CurIndex();
  205. if(max==-1)return;
  206. snprintf(temp,sizeof(temp),"AT+POC=150000%08x%02x;",sutPocStatus.LocalGroup.ID,cmd);
  207. for(i=0;i<max;i++){
  208. snprintf(buf,sizeof(buf),"%x;",leader[i].id);
  209. strcat(temp,buf);
  210. }
  211. strcat(temp,"\r\n");
  212. msgAtSend(temp);
  213. MSG_INFO(1,temp);
  214. }
  215. //LEADER leader[XINBIAO_NUM];
  216. void ReadLeaderFile()
  217. {
  218. int fd,i=0;
  219. fd=LSAPI_FS_Open(LEADER_FILE, LSAPI_FS_O_RDWR,0);
  220. if(fd<0){
  221. MSG_ERR(1,"%s open read failed", LEADER_FILE);
  222. return;
  223. }
  224. LSAPI_FS_Seek(fd, 0L, LSAPI_FS_SEEK_SET);
  225. LSAPI_FS_Read(fd, (unsigned char *)&leader, sizeof(LEADER)*XINBIAO_NUM);
  226. }
  227. void WriteLeaderFile()
  228. {
  229. int fd;
  230. MSG_INFO(1,"%s save start",LEADER_FILE);
  231. fd=LSAPI_FS_Open(LEADER_FILE, LSAPI_FS_O_RDWR,0x0);
  232. if(fd<0){
  233. MSG_ERR(1,"%s open failed",LEADER_FILE);
  234. return;
  235. }
  236. LSAPI_FS_Seek(fd, 0L, LSAPI_FS_SEEK_SET);
  237. LSAPI_FS_Write(fd, (unsigned char *)&leader, sizeof(LEADER)*XINBIAO_NUM);
  238. LSAPI_FS_Close(fd);
  239. MSG_INFO(1,"%s save done", LEADER_FILE);
  240. }