forked from wd8rde/libExtio_genesis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmdbase.h
135 lines (120 loc) · 3.26 KB
/
cmdbase.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#ifndef CMDBASE_H_
#define CMDBASE_H_
#include "hid_util.h"
#include "cmdpacket.h"
#include "genesis_observer.h"
class CmdBase
{
public:
typedef enum
{
OK,
FAILED_TO_SEND,
BAD_ARG
} tGenesisErr;
typedef struct tGenesisThreadData
{
CmdBase* p_instance;
// someday, may want to expand this
} tGenesisThreadData;
typedef enum
{
NONE = 0,
SET_NAME,
SET_FREQ,
SMOOTH,
AF_ON,
AF_OFF,
RF_ON,
RF_OFF,
ATT_ON,
ATT_OFF,
MUTE_ON,
MUTE_OFF,
TRV_ON,
TRV_OFF,
SET_FILT,
TX_ON,
TX_OFF,
PA10_ON,
LINE_MIC,
PTT_CMD,
AUTO_COR,
SEC_RX2,
MONITOR,
K_SPEED,
K_MODE,
K_RATIO,
DOT_ON,
DOT_OFF,
DASH_ON,
DASH_OFF,
PWR_SWR,
IDLE,
LAST_CMD
}t_cmd_enum;
typedef struct
{
const CmdBase::t_cmd_enum cmd;
const char* cmd_str;
}t_cmdinfo;
typedef enum
{
K_MODE_NONE = 0x00,
K_MODE_IAMBIC = 0x01,
K_MODE_KEYER_MODE_B = 0x02,
K_MODE_REV_PADDLE = 0x04
}t_k_mode;
public:
CmdBase();
virtual ~CmdBase();
void register_observer(Genesis_Observer *p_observer);
bool Init(int vendor_id, int product_id);
bool Close();
tGenesisErr set_name(const char* name);
tGenesisErr set_freq(const long freq);
tGenesisErr smooth(const long freq);
tGenesisErr set_filt(const int fltr);
tGenesisErr af_amp(const bool on_off);
tGenesisErr rf_preamp(const bool on_off);
tGenesisErr att(const bool on_off);
tGenesisErr mute(const bool on_off);
tGenesisErr trv(const bool on_off);
tGenesisErr tx(const bool on_off);
tGenesisErr k_speed(const int wpm);
tGenesisErr k_mode(const int mode);
tGenesisErr k_ratio(const double ratio);
tGenesisErr pa10(const bool on_off);
tGenesisErr line_mic(const bool on_off);
tGenesisErr ptt_cmd(const bool on_off);
tGenesisErr auto_cor(const bool on_off);
tGenesisErr sec_rx2(const bool on_off);
tGenesisErr monitor(const bool on_off);
void* usb_read_thread_func();
void set_tx_dropout_ms(unsigned long tx_dropout_ms);
protected:
typedef enum
{
TX_STATE_IGNORE = 0,
TX_STATE_ON = 1,
TX_STATE_DROPPING = 2
}t_tx_state;
virtual const t_cmdinfo get_cmd_info(CmdBase::t_cmd_enum cmd);
bool init_usb_read_thread();
tGenesisErr private_set_freq(const long freq, const char* p_cmd);
tGenesisErr private_send_on_off_cmd(const bool on_off, const char *p_on_cmd, const char *p_off_cmd);
tGenesisErr private_cmd_arg2only(const unsigned char arg, const char *p_cmd);
t_cmd_enum private_parse_packet(CmdPacket &packet);
const t_cmd_enum private_str2cmd(std::string cmd);
t_tx_state private_handle_cmd(t_cmd_enum cmd, CmdPacket &packet);
hid_handle m_dev_handle;
pthread_t m_usb_read_thread;
bool m_usb_read_thread_running;
pthread_mutex_t m_usb_read_mutex;
Genesis_Observer* mp_observer;
long long m_tx_dropout_timeout_ns;
private:
static void* static_thread_func(void* p_data);
static const t_cmdinfo cmdinfo[];
};
#endif /*CMDBASE_H_*/