diff --git a/.vscode/settings.json b/.vscode/settings.json index cad4efe..87ff0fe 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -118,7 +118,66 @@ "device_state.h": "c", "board_adc_module_ctrl.h": "c", "board_ecg_sensor.h": "c", - "board_light_ctrl.h": "c" + "board_light_ctrl.h": "c", + "atomic": "cpp", + "bit": "cpp", + "cctype": "cpp", + "charconv": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "concepts": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "exception": "cpp", + "format": "cpp", + "fstream": "cpp", + "functional": "cpp", + "initializer_list": "cpp", + "ios": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "iterator": "cpp", + "limits": "cpp", + "list": "cpp", + "locale": "cpp", + "map": "cpp", + "memory": "cpp", + "new": "cpp", + "ostream": "cpp", + "ratio": "cpp", + "set": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "stop_token": "cpp", + "streambuf": "cpp", + "string": "cpp", + "system_error": "cpp", + "thread": "cpp", + "tuple": "cpp", + "unordered_map": "cpp", + "utility": "cpp", + "vector": "cpp", + "xfacet": "cpp", + "xhash": "cpp", + "xiosbase": "cpp", + "xlocale": "cpp", + "xlocbuf": "cpp", + "xlocinfo": "cpp", + "xlocmes": "cpp", + "xlocmon": "cpp", + "xlocnum": "cpp", + "xloctime": "cpp", + "xmemory": "cpp", + "xstring": "cpp", + "xtr1common": "cpp", + "xtree": "cpp", + "xutility": "cpp" }, "files.encoding": "gbk" } \ No newline at end of file diff --git a/dynamic_electrocardiograph_ble_server b/dynamic_electrocardiograph_ble_server index 718b118..b6bd394 160000 --- a/dynamic_electrocardiograph_ble_server +++ b/dynamic_electrocardiograph_ble_server @@ -1 +1 @@ -Subproject commit 718b1187ddec42d53c08267a63197f25fd1152dd +Subproject commit b6bd39498f17312e42fb19c0920feea43493ea1d diff --git a/tools/build.bat b/tools/build.bat index 6b3dec4..efaced1 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++ text2bin.cpp -o text2bin.exe +g++ -static -static-libgcc -static-libstdc++ -lwsock32 -lstdc++ one_lead_upload_packet_parser.cpp -o one_lead_upload_packet_parser.exe diff --git a/tools/one_lead_upload_packet_parser.cpp b/tools/one_lead_upload_packet_parser.cpp new file mode 100644 index 0000000..ac5d5b3 --- /dev/null +++ b/tools/one_lead_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[128]; + uint8_t e0; + uint8_t e1; +}; + +uint32_t chdatacache[64]; +void parse_chdatacache(parse_packet_to_csv *packet) { + for (size_t i = 0; i < 64; i++) { + chdatacache[i] = (packet->data[i * 2]) | (packet->data[i * 2 + 1] << 8); + } +} + +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 < 64; i += 1) { + ofs << chdatacache[i] << "\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/one_lead_upload_packet_parser.exe b/tools/one_lead_upload_packet_parser.exe new file mode 100644 index 0000000..1c444f4 Binary files /dev/null and b/tools/one_lead_upload_packet_parser.exe differ diff --git a/tools/sample_bin_parse.exe b/tools/sample_bin_parse.exe index 03920d9..9653ef9 100644 Binary files a/tools/sample_bin_parse.exe and b/tools/sample_bin_parse.exe differ diff --git a/tools/text2bin.exe b/tools/text2bin.exe index 48e0077..dd29e08 100644 Binary files a/tools/text2bin.exe and b/tools/text2bin.exe differ