#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;inum;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;jBCDTime);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(lsstatus=1; else gnssInfo->status=2; //上传类型 pBuf[i++]=gnssInfo->status; //时间 for(j=0;jBCDTime);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(lsBCDTime);j++) pBuf[i++]=nearInfo->BCDTime[j]; //设备个数 pBuf[i++]=nearInfo->num; for(j=0;jnum;j++){ //mac for(k=0;kinfo[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