diff --git a/.vscode/settings.json b/.vscode/settings.json index e37bc0d..6522f48 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -114,7 +114,59 @@ "heart_wave_sample_service_cfg.h": "c", "filter.h": "c", "filters.h": "c", - "nrfx_rtc.h": "c" + "nrfx_rtc.h": "c", + "array": "cpp", + "atomic": "cpp", + "bit": "cpp", + "*.tcc": "cpp", + "cctype": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "concepts": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "list": "cpp", + "map": "cpp", + "set": "cpp", + "string": "cpp", + "unordered_map": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "random": "cpp", + "ratio": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "utility": "cpp", + "fstream": "cpp", + "initializer_list": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "new": "cpp", + "numbers": "cpp", + "ostream": "cpp", + "semaphore": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "stop_token": "cpp", + "streambuf": "cpp", + "thread": "cpp", + "cinttypes": "cpp" }, "files.encoding": "gbk" } \ No newline at end of file diff --git a/dynamic_electrocardiograph_ble_server b/dynamic_electrocardiograph_ble_server index 77410e1..5187df0 160000 --- a/dynamic_electrocardiograph_ble_server +++ b/dynamic_electrocardiograph_ble_server @@ -1 +1 @@ -Subproject commit 77410e1853a1ce9e160bddf514e3fb0eadc8a4e5 +Subproject commit 5187df0e60f21ff65c7b65a58dcab844205ec165 diff --git a/sdk b/sdk index ecff8b6..0ea0526 160000 --- a/sdk +++ b/sdk @@ -1 +1 @@ -Subproject commit ecff8b6c09f4c6f96c2a69e899529806f4bfd671 +Subproject commit 0ea0526c178ddd752afbf60b6b145cdd97ee1263 diff --git a/tools/sample_bin_parse.cpp b/tools/0_bin_parse.cpp similarity index 100% rename from tools/sample_bin_parse.cpp rename to tools/0_bin_parse.cpp diff --git a/tools/sample_bin_parse.exe b/tools/0_bin_parse.exe similarity index 55% rename from tools/sample_bin_parse.exe rename to tools/0_bin_parse.exe index 03920d9..6ab5c19 100644 Binary files a/tools/sample_bin_parse.exe and b/tools/0_bin_parse.exe differ diff --git a/tools/build.bat b/tools/build.bat index 6b3dec4..68dbfeb 100644 --- a/tools/build.bat +++ b/tools/build.bat @@ -1,2 +1,3 @@ -g++ -static -static-libgcc -static-libstdc++ -lwsock32 -lstdc++ .\sample_bin_parse.cpp -o sample_bin_parse.exe +g++ -static -static-libgcc -static-libstdc++ -lwsock32 -lstdc++ .\0_bin_parse.cpp -o 0_bin_parse.exe g++ -static -static-libgcc -static-libstdc++ -lwsock32 -lstdc++ text2bin.cpp -o text2bin.exe +g++ -static -static-libgcc -static-libstdc++ -lwsock32 -lstdc++ upload_packet_parser.cpp -o upload_packet_parser.exe diff --git a/tools/text2bin.exe b/tools/text2bin.exe index 48e0077..8affeda 100644 Binary files a/tools/text2bin.exe and b/tools/text2bin.exe differ diff --git a/tools/upload_packet_parser.cpp b/tools/upload_packet_parser.cpp new file mode 100644 index 0000000..9da330d --- /dev/null +++ b/tools/upload_packet_parser.cpp @@ -0,0 +1,102 @@ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +// +#include +// +#include +// +#include + +#pragma comment(lib, "ws2_32.lib") +#define PORT 8988 + +#define EACH_FRAME_SIZE 180 +#define DATA_NUM (EACH_FRAME_SIZE / 3) + +typedef struct parse_packet_to_csv { + uint8_t h0; + uint8_t h1; + uint8_t data[180]; + uint8_t e0; + uint8_t e1; +}; + +uint32_t chdatacache[DATA_NUM]; +void parse_chdatacache(parse_packet_to_csv *packet) { + for (size_t i = 0; i < DATA_NUM; i++) { + 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; + } +} + +int main(int argc, char *argv[]) { + /** + * @brief + * 打开raw.txt + * 读取raw.txt全部内容 + * 去掉换行,空格,回车 + * 将16进制字符串转换成二进制 + * 写入raw.bin + */ + + std::ifstream ifs("Data.txt"); + std::string str((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); + ifs.close(); + + std::string str2; + for (auto &c : str) { + if (c == ' ' || c == '\n' || c == '\r') { + continue; + } + str2.push_back(c); + } + + std::ofstream ofs("Data.bin", std::ios::binary); + for (size_t i = 0; i < str2.size(); i += 2) { + std::string str3 = str2.substr(i, 2); + char c = (char)std::stoi(str3, nullptr, 16); + ofs.write(&c, 1); + } + ofs.close(); + + /** + * @brief + * 解析上报文件 + */ + + { + std::ifstream ifs("Data.bin", std::ios::binary); + std::vector buffer((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); + ifs.close(); + + printf("buffer.size() = %d\n", buffer.size()); + std::ofstream ofs("Data.csv"); + for (size_t i = 0; i < buffer.size();) { + parse_packet_to_csv *packet = (parse_packet_to_csv *)&buffer[i]; + parse_chdatacache(packet); + if (packet->h0 == 0x4A && packet->h1 == 0xA4 && packet->e0 == 0x4B && packet->e1 == 0xB4) { + for (size_t i = 0; i < DATA_NUM; i += 3) { + ofs << chdatacache[i] << "," << chdatacache[i + 1] << "," << chdatacache[i + 2] << "\n"; + } + i += sizeof(parse_packet_to_csv); + } else { + i++; + } + } + } + + printf("parse over\n"); + + while (true) { + std::this_thread::sleep_for(std::chrono::seconds(1)); + } +} \ No newline at end of file diff --git a/tools/upload_packet_parser.exe b/tools/upload_packet_parser.exe new file mode 100644 index 0000000..f41a25b Binary files /dev/null and b/tools/upload_packet_parser.exe differ