#pragma once
#include "mathe/complexmath.h" // IqData
typedef IqData<float> IqDataF;
class Sensor {
int start_paddingbytes,stop_paddingbytes;
size_t handle;
public:
// Sensor Codes
enum{
API_SUCCESS = 1,
API_SUCCESS_WEAK_SIGNAL = 2,
API_ERROR = -1,
API_ERROR_COMMAND = -2,
API_ERROR_PARAMETER = -3,
API_ERROR_RANGE = -4,
API_ERROR_FORBIDDEN = -5,
API_ERROR_NO_TARGET = -6,
API_NO_RESPONSE = -100,
SELECT_IQDATA = 1<<0,
BAUDRATE_MIN = 9600,
BAUDRATE_MAX = 3000000,
// value for RADAR_PROFILE index
BIGBW_MEDIUM = 16, // 1024 Samples
SENSOR_TYPE_REACH_RS485 = 0x12,
EXACT_TYPE_REACH_GOD_MODE = 0x800,
EXACT_TYPE_REACH_SR = 0x801,
EXACT_TYPE_REACH_BE = 0x802,
EXACT_TYPE_REACH_HS = 0x803,
EXACT_TYPE_REACH_HP = 0x804,
EXACT_TYPE_REACH_SRS = 0x805,
};
Sensor();
~Sensor();
bool setBaud(unsigned rate=19200) const;
bool connect(unsigned ComNr=0,unsigned flags=0);
int read(void*v,unsigned l) const;
int write(const void*v,unsigned l) const;
static
enum action_t{ // Command bytes
READ_VAL = 0x01,
WRITE_VAL= 0x02,
MEASURE = 0x03,
SAVE_ALL = 0x0F,
READ_MIN = 0x10,
READ_MAX = 0x11,
};
enum index_t{ // Parameter index
RESULT_DATA = 0x41,
RADAR_PROFILE = 0x48,
BAUDRATE = 0x49,
SENSOR_TYPE = 0x52,
EXACT_SENSOR_TYPE = 0x57,
};
public:
typedef unsigned char byte;
// Optional third parameter allows quering MIN or MAX value
bool getValue(index_t index, unsigned&result, action_t action=READ_VAL) const;
// Optional third parameter allows suppressing answer checking,
// which is needed for baudrate changing (maybe badly implemented on device side)
bool setValue(index_t index, unsigned value, bool expect_answer=true) const;
// Some high-level queries
unsigned get_sensor_type() const;
unsigned get_result_data_selector() const;
unsigned get_baudrate() const;
unsigned get_number_samples(unsigned*pro=0) const;
// some functions returning strings
const char* get_sensor_type_string() const;
const char* get_exact_sensor_type_string() const;
static char* version_number_to_string(unsigned version_number);
static const char* status_to_string(char error_code);
const char** get_result_data_selector_string() const;
// Some setters
bool set_result_data_selector(unsigned measurement_type) const;
bool set_baudrate(unsigned baudrate) const;
bool set_number_samples(unsigned n,unsigned pro=BIGBW_MEDIUM) const;
bool save_parameters() const;
// These functions acquire I/Q (complex) samples from device.
// Probably 1024 samples. As data type is <char>, 2048 bytes.
// For 1 MBaud, this will take roughly 2 ms, but the device answers much slower.
bool deserialize_iq_data(IqDataF&) const;
bool get_measurement(IqDataF&,unsigned data_selector=0) const;
void disconnect();
bool query(const void*w, int wlen, void*r, int rlen, bool check_result=true) const;
// Basic query method. Can be used not-writing and not-reading.
// Sends and returns fixed-size byte streams as-is.
// Can check first byte of answer whether it's API_SUCCESS (=1) value
};
| Detected encoding: ASCII (7 bit) | 2
|