2
* Icom IC-746, 746PRO, 756, 756PRO
3
* 7000, 7200, 7700 ... drivers
7
* Copyright 2009, Dave Freese, W1HKJ
15
//=============================================================================
17
void RIG_ICOM::adjustCIV(uchar adr)
20
pre_to[2] = ok[3] = bad[3] = pre_fm[3] = CIV;
23
void RIG_ICOM::checkresponse()
25
if (RigSerial.IsOpen() == false)
28
if (replystr.rfind(ok) != string::npos)
31
string s1 = str2hex(cmd.c_str(), cmd.length());
32
string s2 = str2hex(replystr.c_str(), replystr.length());
33
LOG_ERROR("\nsent %s\nreply %s", s1.c_str(), s2.c_str());
36
bool RIG_ICOM::sendICcommand(string cmd, int nbr)
38
int ret = sendCommand(cmd);
40
if (RigSerial.IsOpen() == false)
44
LOG_ERROR("Expected %d received %d", nbr, ret);
48
if (ret > nbr) replystr.erase(0, ret - nbr);
50
// look for preamble at beginning
51
if (replystr.rfind(pre_fm) == string::npos) {
52
LOG_ERROR("preamble: %s not in %s", pre_fm.c_str(), cmd.c_str());
57
if (replystr.rfind(post) == string::npos) {
58
LOG_ERROR("postample: %s not at end of %s", post.c_str(), cmd.c_str());
64
void RIG_ICOM::delayCommand(string cmd, int wait)
66
int oldwait = progStatus.comm_wait;
67
progStatus.comm_wait += wait;
69
progStatus.comm_wait = oldwait;
72
bool RIG_ICOM::waitFB(const char *sz)
78
if (!RigSerial.IsOpen()) {
80
snprintf(sztemp, sizeof(sztemp), "%s TEST", sz);
81
showresp(INFO, HEX, sztemp, tosend, returned);
84
int cnt = 0, repeat = 0, num = cmd.length() + ok.length();
85
for (repeat = 0; repeat < progStatus.comm_retries; repeat++) {
87
MilliSleep( (int)((num*11000.0/RigSerial.Baud())));
89
for ( cnt = 0; cnt < 20; cnt++) {
91
returned.append(replystr);
92
if (returned.find(ok) != string::npos) {
94
waited = cnt * 10 * repeat;
95
snprintf(sztemp, sizeof(sztemp), "%s ans in %d ms, OK", sz, waited);
96
showresp(INFO, HEX, sztemp, tosend, returned);
99
if (returned.find(bad) != string::npos) {
101
waited = cnt * 10 * repeat;
102
snprintf(sztemp, sizeof(sztemp), "%s ans in %d ms, FAIL", sz, waited);
103
showresp(ERR, HEX, sztemp, tosend, returned);
111
waited = cnt * 10 * repeat;
112
snprintf(sztemp, sizeof(sztemp), "%s TIMED OUT in %d ms", sz, waited);
113
showresp(INFO, HEX, sztemp, tosend, returned);
117
bool RIG_ICOM::waitFOR(size_t n, const char *sz)
120
string returned = "";
122
int cnt = 0, repeat = 0;
123
size_t num = n + cmd.length();
124
int delay = num * 11000.0 / RigSerial.Baud();
125
if (!RigSerial.IsOpen()) {
127
snprintf(sztemp, sizeof(sztemp), "%s TEST", sz);
128
showresp(INFO, HEX, sztemp, tosend, returned);
131
for (repeat = 0; repeat < progStatus.comm_retries; repeat++) {
132
sendCommand(tosend, 0);
135
for ( cnt = 0; cnt < 20; cnt++) {
137
returned.append(replystr);
138
if (returned.length() >= num) {
140
waited = cnt * 10 * repeat + delay;
141
snprintf(sztemp, sizeof(sztemp), "%s ans in %d ms, OK ", sz, waited);
142
showresp(INFO, HEX, sztemp, tosend, returned);
150
waited = cnt * 10 * repeat + delay;
151
snprintf(sztemp, sizeof(sztemp), "%s TIMED OUT in %d ms", sz, waited);
152
showresp(INFO, HEX, sztemp, tosend, returned);