sync_helper.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #include "sync_helper.h"
  2. /*
  3. * Description: 将char[5]解析成long long
  4. * Method: parse_time
  5. * Returns: long long
  6. * Parameter: char * time msg中携带的时间,长度为5的char数组
  7. */
  8. long long host_server::sync_helper::parse_time(const char * c)
  9. {
  10. long long ttt0 = (((long long)(c[0]))<<32) & (0x000000FF00000000);
  11. long long ttt1 = (((long long)(c[1]))<<24) & (0x00000000FF000000);
  12. long long ttt2 = (((long long)(c[2]))<<16) & (0x0000000000FF0000);
  13. long long ttt3 = (((long long)(c[3]))<<8) & (0x000000000000FF00);
  14. long long all = ttt0 + ttt1 + ttt2 + ttt3 + ((long long)(c[4]&(0xFF)));
  15. return all;
  16. }
  17. /*
  18. * Description: 将基站号与天线号拼接成一个编码
  19. * Method: parse_id
  20. * Returns: unsigned long long 拼接后的编码
  21. * Parameter: unsigned int id 基站号
  22. * Parameter: unsigned char ant_num 天线号
  23. */
  24. unsigned long long host_server::sync_helper::parse_id(unsigned int id, unsigned char antNum)
  25. {
  26. return (id << 8) + antNum;
  27. }
  28. /*
  29. * Description: 从文件中分析数据
  30. * Method: parse_from_fstream
  31. * Returns: unsigned long long
  32. * Parameter: ifstream & f
  33. * Parameter: int size
  34. */
  35. unsigned long long host_server::sync_helper::parse_from_fstream(ifstream &f, int size)
  36. {
  37. unsigned long long x(0);
  38. for(int i(0); i < size; i++)
  39. {
  40. int t;
  41. f >> hex >> t;
  42. x = (x << 8) + t;
  43. }
  44. return x;
  45. }
  46. /*
  47. * Description: 从文件中分析时间
  48. * Method: parse_time_from_fstream
  49. * Returns: unsigned long long
  50. * Parameter: ifstream & f
  51. */
  52. unsigned long long host_server::sync_helper::parse_time_from_fstream(ifstream &f)
  53. {
  54. char* t = new char[5];
  55. for (int i = 0; i < 5; i++)
  56. {
  57. int tmp;
  58. f >> hex >> tmp;
  59. t[i] = tmp;
  60. }
  61. auto time = sync_helper::parse_time(t);
  62. delete[] t;
  63. return time;
  64. }