123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- #pragma once
- #include <iostream>
- #include "Crc16.h"
- #include "Util/logger.h"
- #include <time.h>
- #include <ctime>
- #include <list>
- using namespace std;
- #define PIDS_DATA_HEAD (0xFD) // 帧头
- #define PIDS_DATA_TYPE (0x04) // From MIVA to PIS
- #define PIDS_DATA_END (0xFE) // 帧尾
- #define PIDS_SRC_TC1 (0x01) // 源设备车厢编号:TC1
- #define PIDS_SRC_TC2 (0x02) // 源设备车厢编号:TC2
- #define PIDS_SRC_TYPE_PIDS (0x01) // PIDS设备
- #define PIDS_SRC_TYPE_MIVA (0x02) // 视频分析服务器设备
- #define HEX2BCD(x) (((x) % 10) + ((((x) / 10) % 10) << 4)) /*20 -> 20H*/
- struct CarLoadData{
- int NoLoad;
- int DynamicLoad;
- };
- struct CarInferData{
- std::string uri;
- int num;
- };
- struct CarData{
- CarLoadData loadData;
- std::list<CarInferData> inferData;
- };
- struct ResultData{
- int Grade;
- int Num;
- };
- void getBCDTime(uint8_t *out)
- {
- time_t t;
- int i = 0;
- struct tm *tp = NULL;
- t = time(NULL);
- tp = localtime(&t);
- out[i++] = HEX2BCD(tp->tm_year % 100);
- out[i++] = HEX2BCD(tp->tm_year-100);
- out[i++] = HEX2BCD(tp->tm_mon+1);
- out[i++] = HEX2BCD(tp->tm_mday);
- out[i++] = HEX2BCD(tp->tm_hour);
- out[i++] = HEX2BCD(tp->tm_min);
- out[i++] = HEX2BCD(tp->tm_sec);
- }
- void getTime(uint8_t *out)
- {
- time_t t;
- int i = 0;
- struct tm *tp = NULL;
- t = time(NULL);
- tp = localtime(&t);
- out[i++] = tp->tm_year / 100 + 19;
- out[i++] = tp->tm_year % 100;
- out[i++] = tp->tm_mon+1;
- out[i++] = tp->tm_mday;
- out[i++] = tp->tm_hour;
- out[i++] = tp->tm_min;
- out[i++] = tp->tm_sec;
- }
- void getDataTime(char *ctime)
- {
- time_t rawtime;
- struct tm *info;
- time(&rawtime);
- info = localtime(&rawtime);
- strftime(ctime, 80, "%Y-%m-%d %H:%M:%S", info);
- }
- int compare(const char* time1,const char* time2)
- {
- int year1,month1,day1,hour1,min1,sec1;
- int year2,month2,day2,hour2,min2,sec2;
- sscanf(time1,"%d-%d-%d %d:%d:%d",&year1,&month1,&day1,&hour1,&min1,&sec1);
- sscanf(time2,"%d-%d-%d %d:%d:%d",&year2,&month2,&day2,&hour2,&min2,&sec2);
- int tm1 = year1*10000+month1*100+day1;
- int tm2 = year2*10000+month2*100+day2;
- if(tm1!=tm2) return (tm1>tm2)?1:0;//如果相等,大返回1,小返回0
- tm1 = hour1*3600+min1*60+sec1;
- tm2 = hour2*3600+min2*60+sec2;//将时分秒转换为秒数
- if(tm1!=tm2) return (tm1>tm2)?1:0;//如果相等,大返回1,小返回0
- return 2;//到这里必然是相等了
- }
|