PIDSDataDefine.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #pragma once
  2. #include <iostream>
  3. #include "Crc16.h"
  4. #include "Util/logger.h"
  5. #include <time.h>
  6. #include <ctime>
  7. #include <list>
  8. using namespace std;
  9. #define PIDS_DATA_HEAD (0xFD) // 帧头
  10. #define PIDS_DATA_TYPE (0x04) // From MIVA to PIS
  11. #define PIDS_DATA_END (0xFE) // 帧尾
  12. #define PIDS_SRC_TC1 (0x01) // 源设备车厢编号:TC1
  13. #define PIDS_SRC_TC2 (0x02) // 源设备车厢编号:TC2
  14. #define PIDS_SRC_TYPE_PIDS (0x01) // PIDS设备
  15. #define PIDS_SRC_TYPE_MIVA (0x02) // 视频分析服务器设备
  16. #define HEX2BCD(x) (((x) % 10) + ((((x) / 10) % 10) << 4)) /*20 -> 20H*/
  17. struct CarLoadData{
  18. int NoLoad;
  19. int DynamicLoad;
  20. };
  21. struct CarInferData{
  22. std::string uri;
  23. int num;
  24. };
  25. struct CarData{
  26. CarLoadData loadData;
  27. std::list<CarInferData> inferData;
  28. };
  29. struct ResultData{
  30. int Grade;
  31. int Num;
  32. };
  33. void getBCDTime(uint8_t *out)
  34. {
  35. time_t t;
  36. int i = 0;
  37. struct tm *tp = NULL;
  38. t = time(NULL);
  39. tp = localtime(&t);
  40. out[i++] = HEX2BCD(tp->tm_year % 100);
  41. out[i++] = HEX2BCD(tp->tm_year-100);
  42. out[i++] = HEX2BCD(tp->tm_mon+1);
  43. out[i++] = HEX2BCD(tp->tm_mday);
  44. out[i++] = HEX2BCD(tp->tm_hour);
  45. out[i++] = HEX2BCD(tp->tm_min);
  46. out[i++] = HEX2BCD(tp->tm_sec);
  47. }
  48. void getTime(uint8_t *out)
  49. {
  50. time_t t;
  51. int i = 0;
  52. struct tm *tp = NULL;
  53. t = time(NULL);
  54. tp = localtime(&t);
  55. out[i++] = tp->tm_year / 100 + 19;
  56. out[i++] = tp->tm_year % 100;
  57. out[i++] = tp->tm_mon+1;
  58. out[i++] = tp->tm_mday;
  59. out[i++] = tp->tm_hour;
  60. out[i++] = tp->tm_min;
  61. out[i++] = tp->tm_sec;
  62. }
  63. void getDataTime(char *ctime)
  64. {
  65. time_t rawtime;
  66. struct tm *info;
  67. time(&rawtime);
  68. info = localtime(&rawtime);
  69. strftime(ctime, 80, "%Y-%m-%d %H:%M:%S", info);
  70. }
  71. int compare(const char* time1,const char* time2)
  72. {
  73. int year1,month1,day1,hour1,min1,sec1;
  74. int year2,month2,day2,hour2,min2,sec2;
  75. sscanf(time1,"%d-%d-%d %d:%d:%d",&year1,&month1,&day1,&hour1,&min1,&sec1);
  76. sscanf(time2,"%d-%d-%d %d:%d:%d",&year2,&month2,&day2,&hour2,&min2,&sec2);
  77. int tm1 = year1*10000+month1*100+day1;
  78. int tm2 = year2*10000+month2*100+day2;
  79. if(tm1!=tm2) return (tm1>tm2)?1:0;//如果相等,大返回1,小返回0
  80. tm1 = hour1*3600+min1*60+sec1;
  81. tm2 = hour2*3600+min2*60+sec2;//将时分秒转换为秒数
  82. if(tm1!=tm2) return (tm1>tm2)?1:0;//如果相等,大返回1,小返回0
  83. return 2;//到这里必然是相等了
  84. }