You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
2.4 KiB

1 year ago
  1. #include <fstream>
  2. #include <functional>
  3. #include <iostream>
  4. #include <list>
  5. #include <map>
  6. #include <memory>
  7. #include <set>
  8. #include <sstream>
  9. #include <string>
  10. #include <thread>
  11. #include <vector>
  12. //
  13. #include <winsock2.h>
  14. //
  15. #include <Windows.h>
  16. //
  17. #include <stdio.h>
  18. #pragma comment(lib, "ws2_32.lib")
  19. #define PORT 8988
  20. #define EACH_FRAME_SIZE 180
  21. #define DATA_NUM (EACH_FRAME_SIZE / 3)
  22. typedef struct parse_packet_to_csv {
  23. uint8_t h0;
  24. uint8_t h1;
  25. uint8_t data[180];
  26. uint8_t e0;
  27. uint8_t e1;
  28. };
  29. uint32_t chdatacache[DATA_NUM];
  30. void parse_chdatacache(parse_packet_to_csv *packet) {
  31. for (size_t i = 0; i < DATA_NUM; i++) {
  32. chdatacache[i] = (uint32_t)packet->data[i * 3] << 0 | (uint32_t)packet->data[i * 3 + 1] << 8 | (uint32_t)packet->data[i * 3 + 2] << 16;
  33. }
  34. }
  35. int main(int argc, char *argv[]) {
  36. /**
  37. * @brief
  38. * raw.txt
  39. * ȡraw.txtȫ
  40. * ȥУո񣬻س
  41. * 16ַתɶ
  42. * дraw.bin
  43. */
  44. std::ifstream ifs("Data.txt");
  45. std::string str((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
  46. ifs.close();
  47. std::string str2;
  48. for (auto &c : str) {
  49. if (c == ' ' || c == '\n' || c == '\r') {
  50. continue;
  51. }
  52. str2.push_back(c);
  53. }
  54. std::ofstream ofs("Data.bin", std::ios::binary);
  55. for (size_t i = 0; i < str2.size(); i += 2) {
  56. std::string str3 = str2.substr(i, 2);
  57. char c = (char)std::stoi(str3, nullptr, 16);
  58. ofs.write(&c, 1);
  59. }
  60. ofs.close();
  61. /**
  62. * @brief
  63. * ϱļ
  64. */
  65. {
  66. std::ifstream ifs("Data.bin", std::ios::binary);
  67. std::vector<char> buffer((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
  68. ifs.close();
  69. printf("buffer.size() = %d\n", buffer.size());
  70. std::ofstream ofs("Data.csv");
  71. for (size_t i = 0; i < buffer.size();) {
  72. parse_packet_to_csv *packet = (parse_packet_to_csv *)&buffer[i];
  73. parse_chdatacache(packet);
  74. if (packet->h0 == 0x4A && packet->h1 == 0xA4 && packet->e0 == 0x4B && packet->e1 == 0xB4) {
  75. for (size_t i = 0; i < DATA_NUM; i += 3) {
  76. ofs << chdatacache[i] << "," << chdatacache[i + 1] << "," << chdatacache[i + 2] << "\n";
  77. }
  78. i += sizeof(parse_packet_to_csv);
  79. } else {
  80. i++;
  81. }
  82. }
  83. }
  84. printf("parse over\n");
  85. while (true) {
  86. std::this_thread::sleep_for(std::chrono::seconds(1));
  87. }
  88. }