SyncHelper.cpp 1.7 KB

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