Browse Source

重构工程

master
zhaohe 1 year ago
parent
commit
a0f6c47238
  1. 3
      .gitmodules
  2. 6
      .vscode/settings.json
  3. 4
      app/app.uvoptx
  4. 8
      app/app.uvprojx
  5. 2
      app/src/app_basic_service/basic/event.h
  6. 6
      app/src/app_main.c
  7. 2
      app/src/app_main.h
  8. 2
      app/src/ble_data_processer_utils.c
  9. 2
      app/src/ble_data_processer_utils.h
  10. 4
      app/src/main.c
  11. 1
      oximeter_ble_server
  12. 2
      protocol
  13. 9
      scripter/build_app.bat
  14. 121
      tools/one_lead_realtime_report_parser.cpp
  15. BIN
      tools/one_lead_realtime_report_parser.exe
  16. 102
      tools/one_lead_upload_packet_parser.cpp
  17. BIN
      tools/one_lead_upload_packet_parser.exe
  18. 54
      tools/sample_bin_parse.cpp
  19. BIN
      tools/sample_bin_parse.exe
  20. 54
      tools/text2bin.cpp
  21. BIN
      tools/text2bin.exe

3
.gitmodules

@ -13,3 +13,6 @@
[submodule "protocol"]
path = protocol
url = zwsd@192.168.1.3:p_oximeter/oximeter_protocol.git
[submodule "oximeter_ble_server"]
path = oximeter_ble_server
url = zwsd@192.168.1.3:p_oximeter/oximeter_ble_server.git

6
.vscode/settings.json

@ -51,7 +51,7 @@
"app_sdcard.h": "c",
"diskio_blkdev.h": "c",
"three_conduction_main.h": "c",
"one_conduction_main.h": "c",
"app_main.h": "c",
"one_conduction_board.h": "c",
"driver_ssd1306.h": "c",
"driver_ssd1306_font.h": "c",
@ -218,7 +218,9 @@
"nrf_fstorage.h": "c",
"zdata_statistics.h": "c",
"iflytop_simple_filter.h": "c",
"state.h": "c"
"state.h": "c",
"light_ctrl.h": "c",
"ble_data_processer_utils.h": "c"
},
"files.encoding": "gbk"
}

4
app/app.uvoptx

@ -398,8 +398,8 @@
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>.\src\one_conduction_main.c</PathWithFileName>
<FilenameWithoutPath>one_conduction_main.c</FilenameWithoutPath>
<PathWithFileName>.\src\app_main.c</PathWithFileName>
<FilenameWithoutPath>app_main.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>

8
app/app.uvprojx

@ -394,9 +394,9 @@
<FilePath>.\src\main.c</FilePath>
</File>
<File>
<FileName>one_conduction_main.c</FileName>
<FileName>app_main.c</FileName>
<FileType>1</FileType>
<FilePath>.\src\one_conduction_main.c</FilePath>
<FilePath>.\src\app_main.c</FilePath>
</File>
<File>
<FileName>zapp.c</FileName>
@ -4313,9 +4313,9 @@
<FilePath>.\src\main.c</FilePath>
</File>
<File>
<FileName>one_conduction_main.c</FileName>
<FileName>app_main.c</FileName>
<FileType>1</FileType>
<FilePath>.\src\one_conduction_main.c</FilePath>
<FilePath>.\src\app_main.c</FilePath>
</File>
<File>
<FileName>zapp.c</FileName>

2
app/src/app_basic_service/basic/event.h

@ -3,7 +3,7 @@
#include <stdint.h>
#include "aproject_config/config.h"
#include "ify_hrs_protocol/heart_rate_sensor_protocol.h"
#include "protocol/oximeter_ble_protocol.h"
#define ECG_DATA_REPORT_FRAME_NUM 50 // ecg每次上报的帧数

6
app/src/one_conduction_main.c → app/src/app_main.c

@ -2,7 +2,7 @@
#include <stdint.h>
#include "aproject_config/config.h"
#include "ify_hrs_protocol/heart_rate_sensor_protocol.h"
#include "protocol/oximeter_ble_protocol.h"
#include "zdatachannel_service.h"
//
#include "app_basic_service/device_version_info_mgr.h"
@ -449,12 +449,12 @@ void on_state_change(state_machine_event_t event, device_state_t state) {
}
}
void one_conduction_main() {
void app_main() {
device_info_init();
sn_t sn;
device_info_read_sn(&sn);
ZLOGI("one_conduction_main %s active:%d", sn.sn, device_info_get_active_flag());
ZLOGI("app_main %s active:%d", sn.sn, device_info_get_active_flag());
ZLOG_FLUSH();
zapp_ebus_reg_event_listener(on_zapp_ebus_event);

2
app/src/one_conduction_main.h → app/src/app_main.h

@ -1,5 +1,5 @@
#pragma once
#include <stdint.h>
void one_conduction_main();
void app_main();
void one_conduction_process_rx_packet(uint8_t* rx, int len);

2
app/src/ble_data_processer_utils.c

@ -1,6 +1,6 @@
#include "ble_data_processer_utils.h"
#include "ify_hrs_protocol/heart_rate_sensor_protocol.h"
#include "protocol/oximeter_ble_protocol.h"
#include "zdatachannel_service.h"
static uint8_t _bletxbuf[BLE_MSG_BUF_SIZE];

2
app/src/ble_data_processer_utils.h

@ -2,7 +2,7 @@
#include <stdint.h>
#include "app_basic_service/zapp.h"
#include "ify_hrs_protocol/heart_rate_sensor_protocol.h"
#include "protocol/oximeter_ble_protocol.h"
#define BLE_MSG_BUF_SIZE 255
extern uint8_t bletxbuf[];

4
app/src/main.c

@ -10,7 +10,7 @@
#include "app_basic_service/zapp.h"
#include "zble_module.h"
#include "zdatachannel_service.h"
#include "one_conduction_main.h"
#include "app_main.h"
//
ZDATACHANNEL_DEF(m_zhrs, 2 /*优先级*/, 1 /*client num*/); //
/**
@ -77,7 +77,7 @@ int main() {
/*******************************************************************************
* *
*******************************************************************************/
one_conduction_main();
app_main();
/*******************************************************************************
* LOOP *
*******************************************************************************/

1
oximeter_ble_server

@ -0,0 +1 @@
Subproject commit 34a1c922a7336ef7602e1aa54fb04334a3d7274a

2
protocol

@ -1 +1 @@
Subproject commit 286f8bbe136357e72b72f7d3e2a5b0ad64e99710
Subproject commit 93ba9dbc3fe99c97276ab9737a710911642dc2b8

9
scripter/build_app.bat

@ -3,11 +3,12 @@
@REM ±àÒëapp
call scripter\keil_build.bat app\app.uvprojx app\_build\app.hex
md output
del output\app_whole.hex
del output\app.zip
del output\one_lead_ecg_ads1291.zip
del output\one_lead_ecg_ads1291.hex
del output\oximeter_ble_client.zip
del output\oximeter_ble_client.hex
@REM ¼ì²éÊÇ·ñ±àÒë³É¹¦
if not exist app\_build\app.hex (
@ -59,5 +60,5 @@ del output\settings.hex
del output\app.hex
copy /y output\app.zip output\one_lead_ecg_ads1291.zip
copy /y output\app_whole.hex output\one_lead_ecg_ads1291.hex
copy /y output\app.zip output\oximeter_ble_client.zip
copy /y output\app_whole.hex output\oximeter_ble_client.hex

121
tools/one_lead_realtime_report_parser.cpp

@ -1,121 +0,0 @@
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <set>
#include <sstream>
#include <string>
#include <thread>
#include <vector>
//
#include <winsock2.h>
//
#include <Windows.h>
//
#include <stdio.h>
#pragma comment(lib, "ws2_32.lib")
#define PORT 8988
// #define EACH_FRAME_SIZE 180
// #define DATA_NUM (EACH_FRAME_SIZE / 3)
// 5A A5
// 03 00 65
// 05 00 00 00
// 77 07
// 80 07
// 7F 07
// 88 07
// 8D 07
// 5B B5
#pragma pack(1)
typedef struct parse_packet_to_csv {
uint8_t h0;
uint8_t h1;
uint8_t header[3];
uint8_t index[4];
uint16_t data[5];
uint8_t e0;
uint8_t e1;
};
#pragma pack()
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
uint16_t chdatacache[5];
void parse_chdatacache(parse_packet_to_csv *packet) {
chdatacache[0] = packet->data[0];
chdatacache[1] = packet->data[1];
chdatacache[2] = packet->data[2];
chdatacache[3] = packet->data[3];
chdatacache[4] = packet->data[4];
}
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<char>(ifs)), std::istreambuf_iterator<char>());
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<char> buffer((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
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];
if (packet->h0 == 0x5A && packet->h1 == 0xA5 && packet->e0 == 0x5B && packet->e1 == 0xB5) {
parse_chdatacache(packet);
for (size_t i = 0; i < ARRAY_SIZE(chdatacache); 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));
}
}

BIN
tools/one_lead_realtime_report_parser.exe

102
tools/one_lead_upload_packet_parser.cpp

@ -1,102 +0,0 @@
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <set>
#include <sstream>
#include <string>
#include <thread>
#include <vector>
//
#include <winsock2.h>
//
#include <Windows.h>
//
#include <stdio.h>
#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<char>(ifs)), std::istreambuf_iterator<char>());
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<char> buffer((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
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));
}
}

BIN
tools/one_lead_upload_packet_parser.exe

54
tools/sample_bin_parse.cpp

@ -1,54 +0,0 @@
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <set>
#include <sstream>
#include <string>
#include <thread>
#include <vector>
//
#include <winsock2.h>
//
#include <Windows.h>
//
#include <stdio.h>
#pragma comment(lib, "ws2_32.lib")
#define PORT 8988
int main(int argc, char *argv[]) {
// 打开 0.bin
// 读取 0.bin 到数组中
// 每次读9byte
// 3byte 3byte 3byte
// 存放到0.csv中
std::ifstream ifs("0.bin", std::ios::binary);
if (!ifs) {
std::cerr << "open 0.bin failed" << std::endl;
return -1;
}
std::ofstream ofs("0.csv", std::ios::binary | std::ios::trunc);
if (!ofs) {
std::cerr << "open 0.csv failed" << std::endl;
return -1;
}
char buf[9];
while (ifs.read(buf, 9)) {
unsigned int a = 0;
unsigned int b = 0;
unsigned int c = 0;
a = (unsigned char)buf[0] | (unsigned char)buf[1] << 8 | (unsigned char)buf[2] << 16;
b = (unsigned char)buf[3] | (unsigned char)buf[4] << 8 | (unsigned char)buf[5] << 16;
c = (unsigned char)buf[6] | (unsigned char)buf[7] << 8 | (unsigned char)buf[8] << 16;
ofs << a << "," << b << "," << c << std::endl;
}
return 0;
}

BIN
tools/sample_bin_parse.exe

54
tools/text2bin.cpp

@ -1,54 +0,0 @@
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <set>
#include <sstream>
#include <string>
#include <thread>
#include <vector>
//
#include <winsock2.h>
//
#include <Windows.h>
//
#include <stdio.h>
#pragma comment(lib, "ws2_32.lib")
#define PORT 8988
int main(int argc, char *argv[]) {
/**
* @brief
* raw.txt
* raw.txt全部内容
*
* 16
* raw.bin
*/
std::ifstream ifs("raw.txt");
std::string str((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
ifs.close();
std::string str2;
for (auto &c : str) {
if (c == ' ' || c == '\n' || c == '\r') {
continue;
}
str2.push_back(c);
}
std::ofstream ofs("raw.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();
return 0;
}

BIN
tools/text2bin.exe

Loading…
Cancel
Save