comm.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #ifndef __COMM_H
  2. #define __COMM_H
  3. #include <string>
  4. #include <sstream>
  5. #include <cstdio>
  6. #include <vector>
  7. #include <cstring>
  8. #include <cmath>
  9. #include<iostream>
  10. #include <fstream>
  11. #include <algorithm>
  12. using namespace std;
  13. #define EVENT_MOD_INITIALIZER_MK_LOADED 0x50900001 // 主密钥初始化成功
  14. #define EVENT_MOD_INITIALIZER_MK_FAILED 0x50980002 // 主密钥初始化失败
  15. #define PUKFILENAME_RSA "RVCPubKey.ini"
  16. #define PUKFILENAME_SM2 "RVCSM2PubKey.ini"
  17. #define PFKEYFILENAME_DES "CMBRVCKeys.dat"
  18. #define PFKEYFILENAME_SM4 "CMBRVCSm4Keys.dat"
  19. typedef unsigned char BYTE;
  20. void GetNewForm(const char* form, char* newForm);
  21. string GetOutPutStr(const char* form, ...);
  22. int no_begin_with(const char strA[], const char strB[]);
  23. int str2int(const string str, int& ret);
  24. vector<string> split_str(string strA, string strB);
  25. int ip2byte(const string str, BYTE ip[]);
  26. char* Hex2Str(const char* src, int& dstLen);
  27. char* Str2Hex(const char* str, int strLen);
  28. #ifdef __linux__
  29. #define RUNTIME_PATH "/opt/run/runinfo/runcfg"
  30. #include <sys/types.h>
  31. #include <ifaddrs.h>
  32. #include <netinet/in.h>
  33. #include <arpa/inet.h>
  34. #include <unistd.h>
  35. int getIPFromLinux(char* ip);
  36. bool get_cpu_id_by_asm(std::string& cpu_id);
  37. bool get_cpu_id_by_system(std::string& cpu_id, const string save_path = RUNTIME_PATH);
  38. bool get_board_serial_by_system(std::string& board_serial, const string save_path = RUNTIME_PATH);
  39. bool get_disk_serial_by_system(std::vector<string>& serial_no, int &errCode,const string save_path = RUNTIME_PATH);
  40. bool file_is_exist(string filePath);
  41. bool dir_is_exist(string dirPath);
  42. int file_create(string filePath);
  43. int dir_create(string dirPath);
  44. int remove_file(string filePath);
  45. int remove_dir(string dirPath);
  46. #include<sys/time.h>
  47. #include <time.h>
  48. typedef struct {
  49. int year;
  50. int month;
  51. int day;
  52. int hour;
  53. int minute;
  54. int second;
  55. } TIME;
  56. bool set_system_time(TIME* _time);
  57. extern "C" bool set_system_time_by_sec(int sec);
  58. TIME* get_system_time();
  59. #endif //__linux__
  60. #endif // !__COMM_H