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.
122 lines
4.8 KiB
122 lines
4.8 KiB
#pragma once
|
|
#include <fstream>
|
|
#include <functional>
|
|
#include <iostream>
|
|
#include <list>
|
|
#include <map>
|
|
#include <memory>
|
|
#include <mutex>
|
|
#include <set>
|
|
#include <sstream>
|
|
#include <string>
|
|
#include <thread>
|
|
#include <vector>
|
|
|
|
#include "../ify_hrs_protocol/heart_rate_sensor_protocol.h"
|
|
#include "electrocardiograph_tester.hpp"
|
|
|
|
#define SDK_VERSION 1
|
|
|
|
namespace iflytop {
|
|
using namespace std;
|
|
|
|
typedef enum {
|
|
kcmd_cmd,
|
|
kcmd_receipt,
|
|
kcmd_report,
|
|
kcmd_ch4_data,
|
|
} raw_data_type_t;
|
|
|
|
typedef function<void(bool checkok, ify_hrs_packet_t *report_packet, size_t len)> on_report_t;
|
|
typedef function<void(uint32_t rxcnt, uint32_t report_packet_checksum)> on_ch4_check_sum_packet_report_t;
|
|
typedef function<void(raw_data_type_t type, uint8_t *hex, uint32_t hexlen)> on_raw_data_t;
|
|
|
|
class IDataChannel {
|
|
public:
|
|
virtual ~IDataChannel(){};
|
|
virtual bool isOpen() = 0;
|
|
virtual bool send(const uint8_t *data, size_t len) = 0;
|
|
virtual void regRxListener(function<void(uint8_t *data, size_t len)> cb) = 0;
|
|
};
|
|
|
|
class RxReceiptContext {
|
|
public:
|
|
bool waittingForReceipt;
|
|
bool receiptIsReady;
|
|
uint16_t waittingIndex;
|
|
uint8_t receipt[1024];
|
|
size_t receiptLen;
|
|
};
|
|
|
|
class ElectrocardiographTester {
|
|
ElectrocardiographTester() {}
|
|
|
|
IDataChannel *m_channel = nullptr;
|
|
|
|
uint8_t m_rxcache[1024];
|
|
int32_t m_rxlen = 0;
|
|
bool m_rxcache_is_full = false;
|
|
|
|
mutex lock_;
|
|
|
|
unique_ptr<thread> m_thread;
|
|
|
|
RxReceiptContext m_rxReceiptContext;
|
|
mutex m_rxReceiptContext_lock;
|
|
|
|
/*******************************************************************************
|
|
* TX CONTEXT *
|
|
*******************************************************************************/
|
|
mutex m_tx_lock;
|
|
uint8_t m_txbuf[1024];
|
|
uint8_t m_rxbuf[1024];
|
|
ify_hrs_packet_t *m_txcmd = (ify_hrs_packet_t *)m_txbuf;
|
|
ify_hrs_packet_t *m_rxcmd = (ify_hrs_packet_t *)m_rxbuf;
|
|
int32_t m_rxsize;
|
|
uint8_t m_txindex = 0;
|
|
|
|
/*******************************************************************************
|
|
* ReportCB *
|
|
*******************************************************************************/
|
|
on_report_t m_on_report;
|
|
on_ch4_check_sum_packet_report_t m_on_ch4_check_sum_packet_report;
|
|
on_raw_data_t m_on_raw_data_cb;
|
|
|
|
public:
|
|
static ElectrocardiographTester *ins();
|
|
|
|
void initialize(IDataChannel *channel);
|
|
void regReportCB(on_report_t cb);
|
|
void regCh4CheckSumPacketReport(on_ch4_check_sum_packet_report_t cb);
|
|
void regRawDataCB(on_raw_data_t cb);
|
|
|
|
public:
|
|
void readDeviceVersion(device_version_info_receipt_t *version); // 读取设备版本信息
|
|
void readSensorInfo(sensor_info_receipt_t *sensor); // 读取传感器信息
|
|
void readDeviceState(device_state_receipt_t *state); // 读取设备状态信息
|
|
void readTime(read_time_receipt_t *time); // 读取设备时间
|
|
void syncTime(uint8_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second); // 同步设备时间
|
|
// void startCapture(); // 开始采集
|
|
// void stopCapture(); // 停止采集
|
|
void startRealtimeReport(); // 开始实时数据上报
|
|
void stopRealtimeReport(); // 停止实时数据上报
|
|
void readRecordsInfo(int32_t recordoff, read_record_info_receipt_t *recordinfo); // 读取记录信息
|
|
void delRecord(uint8_t *recordId); // 删除记录
|
|
void startUploadRecord(uint8_t *recordId); // 开始上传记录
|
|
void stopUploadRecord(); // 停止上传记录
|
|
void readSn(string &sn);
|
|
void reset(); // 重置设备
|
|
|
|
void testCmdStartCapture();
|
|
void testCmdStopCapture();
|
|
uint8_t testCmdReadReg(uint8_t addr);
|
|
void testCmdWriteReg(uint8_t addr, uint8_t val);
|
|
|
|
private:
|
|
void sendCmd(ify_hrs_packet_t *tx, int32_t txlen, ify_hrs_packet_t *rx, int32_t *rxlen, int32_t overtime);
|
|
void processCh3RxData(uint8_t *rx, int32_t rxlen); // 指令通道
|
|
void processCh4RxData(uint8_t *rx, int32_t rxlen); // 心电原始数据通道
|
|
void processRxReportPacket(ify_hrs_packet_t *rx, int32_t rxlen);
|
|
};
|
|
|
|
} // namespace iflytop
|