123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380 |
- #include "devMsg.h"
- #include "ProtocolPack.h"
- #include "log.h"
- #include "records.h"
- #include "main.h"
- #include "app.h"
- DEVICEINFO_DEF *gDevInfo=&sut_saveRecDev.record;
- GNSSINFO_DEF *gGnssInfo=&sut_saveRecGnss.record;
- NEARINFO_DEF *gNearInfo=&sut_saveRecNear.record;
- /*打印保存的设备信息记录*/
- void DevRecShow(void){
- wlog_info("[DevInfo]Date:%02x-%02x-%02x %02x:%02x:%02x",gDevInfo->BCDTime[0],gDevInfo->BCDTime[1],gDevInfo->BCDTime[2],gDevInfo->BCDTime[3],gDevInfo->BCDTime[4],gDevInfo->BCDTime[5]);
- wlog_info("[DevInfo]Motion:ax=%d,ay=%d,az=%d,step=%d",gDevInfo->aspeed_x,gDevInfo->aspeed_y,gDevInfo->aspeed_z,gDevInfo->steps);
- wlog_info("[DevInfo]Bat=%d,CSQ=%d",gDevInfo->bat,gDevInfo->csq);
- wlog_info("[DevInfo]Lbs:mcc=%d,mnc=%d,lac=%d,cellid=%08x",gDevInfo->mcc,gDevInfo->mnc,gDevInfo->lac,gDevInfo->cellid);
- }
- /*打印保存的GNSS信息记录*/
- void GnssRecShow(void){
- wlog_info("[GnssInfo]Date:%02x-%02x-%02x %02x:%02x:%02x",gGnssInfo->BCDTime[0],gGnssInfo->BCDTime[1],gGnssInfo->BCDTime[2],gGnssInfo->BCDTime[3],gGnssInfo->BCDTime[4],gGnssInfo->BCDTime[5]);
- wlog_info("[GnssInfo]Location:L=%d,lat=%d,lon=%d,height=%d,speed=%d,dir=%d",gGnssInfo->located,gGnssInfo->latitude,gGnssInfo->longitude,gGnssInfo->height,gGnssInfo->speed,gGnssInfo->direction);
- wlog_info("[GnssInfo]onUseGps=%d,onViewGps=%d",gGnssInfo->onUseGps,gGnssInfo->onViewGps);
- }
- /*打印保存的NEAR信息记录*/
- void NearRecShow(void){
- int i;
- wlog_info("[NearInfo]Date:%02x-%02x-%02x %02x:%02x:%02x",gNearInfo->BCDTime[0],gNearInfo->BCDTime[1],gNearInfo->BCDTime[2],gNearInfo->BCDTime[3],gNearInfo->BCDTime[4],gNearInfo->BCDTime[5]);
- for(i=0;i<gNearInfo->num;i++){
- wlog_info("[NearInfo][%d]mac:%02x%02x%02x%02x%02x%02x,rssi:%d",i,gNearInfo->info[i].mac[0],gNearInfo->info[i].mac[1],gNearInfo->info[i].mac[2],gNearInfo->info[i].mac[3],gNearInfo->info[i].mac[4],gNearInfo->info[i].mac[5],gNearInfo->info[i].rssi);
- }
- }
- /*获取LBS与MOTION前清除缓存*/
- void clearLbsMotionOfDevinfo(void){
- gDevInfo->aspeed_x=0;
- gDevInfo->aspeed_y=0;
- gDevInfo->aspeed_z=0;
- gDevInfo->steps=0;
- gDevInfo->mcc=0;
- gDevInfo->mnc=0;
- gDevInfo->lac=0;
- gDevInfo->cellid=0;
- }
- /*填充设备状态信息*/
- int fillDevInfo(unsigned char *pBuf,DEVICEINFO_DEF *devinfo){
- int i,j;
- SUTDS ds;
- SUTDL dl;
- i=0;
- //设置补传状态
- if(app.recBuChuanFlag==FALSE) devinfo->status=1;
- else devinfo->status=2;
- //上传类型
- pBuf[i++]=devinfo->status;
- //时间
- for(j=0;j<sizeof(devinfo->BCDTime);j++) pBuf[i++]=devinfo->BCDTime[j];
- //硬件状态
- pBuf[i++]=devinfo->hardWareStatus;
- //告警状态
- pBuf[i++]=devinfo->warnStatus;
- //加速度x轴
- ds.Data.usData=devinfo->aspeed_x;
- pBuf[i++] = ds.Data.ucData.b2;
- pBuf[i++] = ds.Data.ucData.b1;
- //加速度y轴
- ds.Data.usData=devinfo->aspeed_y;
- pBuf[i++] = ds.Data.ucData.b2;
- pBuf[i++] = ds.Data.ucData.b1;
- //加速度z轴
- ds.Data.usData=devinfo->aspeed_z;
- pBuf[i++] = ds.Data.ucData.b2;
- pBuf[i++] = ds.Data.ucData.b1;
- //步数
- dl.Data.ulData=devinfo->steps;
- pBuf[i++]=dl.Data.ucData.b4;
- pBuf[i++]=dl.Data.ucData.b3;
- pBuf[i++]=dl.Data.ucData.b2;
- pBuf[i++]=dl.Data.ucData.b1;
- //电池
- pBuf[i++]=devinfo->bat;
- //信号强度
- pBuf[i++]=devinfo->csq;
- //国家代号
- ds.Data.usData=devinfo->mcc;
- pBuf[i++] = ds.Data.ucData.b2;
- pBuf[i++] = ds.Data.ucData.b1;
- //移动网络号
- pBuf[i++]=devinfo->mnc;
- //位置区码
- ds.Data.usData=devinfo->lac;
- pBuf[i++] = ds.Data.ucData.b2;
- pBuf[i++] = ds.Data.ucData.b1;
- //移动基站
- dl.Data.ulData=devinfo->cellid;
- pBuf[i++]=dl.Data.ucData.b4;
- pBuf[i++]=dl.Data.ucData.b3;
- pBuf[i++]=dl.Data.ucData.b2;
- pBuf[i++]=dl.Data.ucData.b1;
-
- return i;
- }
- /*读取一则设备状态信息,实际时要从本地读出来,这里每次只模拟一则
- 返回0表示没有数据了
- */
- char getNextDevStatusInfo(DEV_SAVE_DEF *devinfo){
- #ifdef USE_DEMO_DATA
- static char flag=1;
- char ret;
- DEVICEINFO_DEF *record=&devinfo->record;
- memset((unsigned char *)record, 0, sizeof(DEVICEINFO_DEF));
- ret=flag;
- //正常上报
- record->status=1;
- //时间
- record->BCDTime[0]=0x20;
- record->BCDTime[1]=0x06;
- record->BCDTime[2]=0x19;
- record->BCDTime[3]=0x12;
- record->BCDTime[4]=0x00;
- record->BCDTime[5]=0x00;
- //硬件状态
- record->hardWareStatus=0x00;
- //告警状态
- record->warnStatus=WARN_NORMAL;
- //x,y,z
- record->aspeed_x=0;
- record->aspeed_y=0;
- record->aspeed_z=0;
- //步数
- record->steps=0;
- //电池电量
- record->bat=41;
- //信号强度
- record->csq=30;
- //MCC
- record->mcc=460;
- //MNC
- record->mnc=0x00;
- //LAC
- record->lac=0x5555;
- //CELLID
- record->cellid=0x11223344;
- if(flag==1) flag=0;
- else flag=1;
- return ret;
- #else
- char ret;
-
- ret=recordRead(REC_DEVINFO, (void *)devinfo);
- if(ret != 0){
- //没有记录或出错了
- wlog_warn("DevInfo read end");
- return 0;
- }
- //读取一条成功
- //wlog_info("DevInfo read one ok");
- return 1;
- #endif
- }
- /*打包设备状态信息条数及设备状态信息*/
- int GetDeviceStatusInfo(unsigned char *pBuf,int leftsize){
- DEV_SAVE_DEF saveinfo;
- DEVICEINFO_DEF *devinfo=&saveinfo.record;
- unsigned char *infoNum=pBuf;
- unsigned char *infoBuf=pBuf+1;
- int i,k,ls;
- unsigned char j,num=0;
- i=0;ls=leftsize;
- //每次读取,将临时索引修正为读索引
- app.devReadTmp=app.devReadIndex;
- while(1){
- if(ls<sizeof(DEVICEINFO_DEF)){
- wlog_warn("buffer fill full:dev");
- break;
- }
- if(0==getNextDevStatusInfo(&saveinfo)) break;//设备信息读完了
- k=fillDevInfo(infoBuf+i,devinfo);
- i += k;//填充buffer索引增加
- num ++;//填充设备个数增加
- ls -= k;//剩余缓存字节减小
- }
- *infoNum=num;
- return (i+1);
- }
- /*填充GNSS状态信息*/
- int fillGnssInfo(unsigned char *pBuf,GNSSINFO_DEF *gnssInfo){
- int i,j;
- SUTDS ds;
- SUTDL dl;
- i=0;
- //设置补传状态
- if(app.recBuChuanFlag==FALSE) gnssInfo->status=1;
- else gnssInfo->status=2;
- //上传类型
- pBuf[i++]=gnssInfo->status;
- //时间
- for(j=0;j<sizeof(gnssInfo->BCDTime);j++) pBuf[i++]=gnssInfo->BCDTime[j];
- //定位
- pBuf[i++]=gnssInfo->located;
- //纬度
- dl.Data.ulData=gnssInfo->latitude;
- pBuf[i++]=dl.Data.ucData.b4;
- pBuf[i++]=dl.Data.ucData.b3;
- pBuf[i++]=dl.Data.ucData.b2;
- pBuf[i++]=dl.Data.ucData.b1;
- //经度
- dl.Data.ulData=gnssInfo->longitude;
- pBuf[i++]=dl.Data.ucData.b4;
- pBuf[i++]=dl.Data.ucData.b3;
- pBuf[i++]=dl.Data.ucData.b2;
- pBuf[i++]=dl.Data.ucData.b1;
- //高程
- ds.Data.usData=gnssInfo->height;
- pBuf[i++] = ds.Data.ucData.b2;
- pBuf[i++] = ds.Data.ucData.b1;
- //速度
- ds.Data.usData=gnssInfo->speed;
- pBuf[i++] = ds.Data.ucData.b2;
- pBuf[i++] = ds.Data.ucData.b1;
- //方向
- ds.Data.usData=gnssInfo->direction;
- pBuf[i++] = ds.Data.ucData.b2;
- pBuf[i++] = ds.Data.ucData.b1;
- //GPS个数
- pBuf[i++]=gnssInfo->onUseGps;
- //BD个数
- pBuf[i++]=gnssInfo->onViewGps;
- return i;
- }
- /*读取一则设备状态信息,实际时要从本地读出来,这里每次只模拟一则*/
- char getNextGnssInfo(GNSS_SAVE_DEF *devinfo){
- #ifdef USE_DEMO_DATA
- GNSSINFO_DEF *record=&devinfo->record;
- static char flag=1;
- char ret;
- ret=flag;
- memset((unsigned char *)record, 0, sizeof(GNSSINFO_DEF));
- //正常上报位置
- record->status=1;
- //时间
- record->BCDTime[0]=0x20;
- record->BCDTime[1]=0x06;
- record->BCDTime[2]=0x19;
- record->BCDTime[3]=0x12;
- record->BCDTime[4]=0x00;
- record->BCDTime[5]=0x00;
- //定位状态
- record->located=0x00;
- if(flag==1) flag=0;
- else flag=1;
- return ret;
- #else
- char ret;
- ret=recordRead(REC_GNSSINFO, (void *)devinfo);
- if(ret != 0){
- //没有记录或出错了
- wlog_warn("GnssInfo read end");
- return 0;
- }
- //读取一条成功
- //wlog_info("GnssInfo read one ok");
- return 1;
- #endif
- }
- /*打包GNSS位置信息条数及GNSS位置信息*/
- int GetGnssInfo(unsigned char *pBuf,int leftsize){
- GNSS_SAVE_DEF saveinfo;
- GNSSINFO_DEF *gnssInfo=&saveinfo.record;
- unsigned char *infoNum=pBuf;
- unsigned char *infoBuf=pBuf+1;
- int i,k,ls;
- unsigned char j,num=0;
- i=0;ls=leftsize;
- //每次读取,将临时索引修正为读索引
- app.gnssReadTmp=app.gnssReadIndex;
- while(1){
- if(ls<sizeof(GNSSINFO_DEF)){
- wlog_warn("buffer fill full:gnss");
- break;
- }
- if(0==getNextGnssInfo(&saveinfo)) break;//GNSS信息读完了
- k=fillGnssInfo(infoBuf+i,gnssInfo);
- i += k;//填充buffer索引增加
- num ++;//填充设备个数增加
- ls -= k;//剩余缓存字节减小
- }
- *infoNum=num;
- return (i+1);
- }
- /*填充NEAR状态信息*/
- int fillNearInfo(unsigned char *pBuf,NEARINFO_DEF *nearInfo){
- int i,j,k;
- i=0;
- //时间
- for(j=0;j<sizeof(nearInfo->BCDTime);j++) pBuf[i++]=nearInfo->BCDTime[j];
- //设备个数
- pBuf[i++]=nearInfo->num;
- for(j=0;j<nearInfo->num;j++){
- //mac
- for(k=0;k<sizeof(nearInfo->info[j].mac);k++) pBuf[i++]=nearInfo->info[j].mac[k];
- //rssi
- pBuf[i++]=nearInfo->info[j].rssi;
- }
-
- return i;
- }
- /*读取一则设备状态信息,实际时要从本地读出来,这里每次只模拟一则*/
- char getNextNearInfo(NEAR_SAVE_DEF *devinfo){
- #ifdef USE_DEMO_DATA
- NEARINFO_DEF *record=&devinfo->record;
- static char flag=1;
- char ret;
- ret=flag;
- memset((unsigned char *)record, 0, sizeof(NEARINFO_DEF));
- //时间
- record->BCDTime[0]=0x20;
- record->BCDTime[1]=0x07;
- record->BCDTime[2]=0x01;
- record->BCDTime[3]=0x12;
- record->BCDTime[4]=0x00;
- record->BCDTime[5]=0x00;
- record->num=0;
- if(flag==1) flag=0;
- else flag=1;
- return ret;
- #else
- char ret;
- ret=recordRead(REC_NEARINFO, (void *)devinfo);
- if(ret != 0){
- //没有记录或出错了
- wlog_warn("NearInfo read end");
- return 0;
- }
- //读取一条成功
- //wlog_info("NearInfo read one ok");
- return 1;
- #endif
- }
- /*打包附近设备信息条数及附近设备信息*/
- int GetNearbyDeviceInfo(unsigned char *pBuf,int leftsize){
- NEAR_SAVE_DEF saveinfo;
- NEARINFO_DEF *nearInfo=&saveinfo.record;
- unsigned char *infoNum=pBuf;
- unsigned char *infoBuf=pBuf+1;
- int i,k,ls;
- unsigned char j,num=0;
- i=0;ls=leftsize;
- //每次读取,将临时索引修正为读索引
- app.nearReadTmp=app.nearReadIndex;
- while(1){
- if(ls<sizeof(NEARINFO_DEF)){
- wlog_warn("buffer fill full:near");
- break;
- }
- if(0==getNextNearInfo(&saveinfo)) break;//NEAR信息读完了
- k=fillNearInfo(infoBuf+i,nearInfo);
- i += k;//填充buffer索引增加
- num ++;//填充设备个数增加
- ls -= k;//剩余缓存字节减小
- }
- *infoNum=num;
- return (i+1);
- }
|