~ubuntu-branches/ubuntu/wily/flrig/wily

« back to all changes in this revision

Viewing changes to .pc/0001-License-Declaration.patch/src/rigs/ICbase.cxx

  • Committer: Package Import Robot
  • Author(s): Kamal Mostafa
  • Date: 2014-10-25 11:17:10 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20141025111710-n32skgya3l9u1brw
Tags: 1.3.17-1
* New upstream release (Closes: #761839)
* Debian Standards-Version: 3.9.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Icom IC-746, 746PRO, 756, 756PRO
3
 
 * 7000, 7200, 7700 ... drivers
4
 
 *
5
 
 * a part of flrig
6
 
 *
7
 
 * Copyright 2009, Dave Freese, W1HKJ
8
 
 *
9
 
 */
10
 
 
11
 
#include "ICbase.h"
12
 
#include "debug.h"
13
 
#include "support.h"
14
 
 
15
 
//=============================================================================
16
 
 
17
 
void RIG_ICOM::adjustCIV(uchar adr)
18
 
{
19
 
        CIV = adr;
20
 
        pre_to[2] = ok[3] = bad[3] = pre_fm[3] = CIV;
21
 
}
22
 
 
23
 
void RIG_ICOM::checkresponse()
24
 
{
25
 
        if (RigSerial.IsOpen() == false)
26
 
                return;
27
 
 
28
 
        if (replystr.rfind(ok) != string::npos)
29
 
                return;
30
 
 
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());
34
 
}
35
 
 
36
 
bool RIG_ICOM::sendICcommand(string cmd, int nbr)
37
 
{
38
 
        int ret = sendCommand(cmd);
39
 
 
40
 
        if (RigSerial.IsOpen() == false)
41
 
                return false;
42
 
 
43
 
        if (ret < nbr) {
44
 
                LOG_ERROR("Expected %d received %d", nbr, ret);
45
 
                return false;
46
 
        }
47
 
 
48
 
        if (ret > nbr) replystr.erase(0, ret - nbr);
49
 
 
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());
53
 
                return false;
54
 
        }
55
 
 
56
 
// look for postamble
57
 
        if (replystr.rfind(post) == string::npos) {
58
 
                LOG_ERROR("postample: %s not at end of %s", post.c_str(), cmd.c_str());
59
 
                return false;
60
 
        }
61
 
        return true;
62
 
}
63
 
 
64
 
void RIG_ICOM::delayCommand(string cmd, int wait)
65
 
{
66
 
        int oldwait = progStatus.comm_wait;
67
 
        progStatus.comm_wait += wait;
68
 
        sendCommand(cmd);
69
 
        progStatus.comm_wait = oldwait;
70
 
}
71
 
 
72
 
bool RIG_ICOM::waitFB(const char *sz)
73
 
{
74
 
        char sztemp[50];
75
 
        string returned = "";
76
 
        string tosend = cmd;
77
 
 
78
 
        if (!RigSerial.IsOpen()) {
79
 
                replystr = returned;
80
 
                snprintf(sztemp, sizeof(sztemp), "%s TEST", sz);
81
 
                showresp(INFO, HEX, sztemp, tosend, returned);
82
 
                return false;
83
 
        }
84
 
        int cnt = 0, repeat = 0, num = cmd.length() + ok.length();
85
 
        for (repeat = 0; repeat < progStatus.comm_retries; repeat++) {
86
 
                sendCommand(cmd, 0);
87
 
                MilliSleep( (int)((num*11000.0/RigSerial.Baud())));
88
 
                returned = "";
89
 
                for ( cnt = 0; cnt < 20; cnt++) {
90
 
                        readResponse();
91
 
                        returned.append(replystr);
92
 
                        if (returned.find(ok) != string::npos) {
93
 
                                replystr = returned;
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);
97
 
                                return true;
98
 
                        }
99
 
                        if (returned.find(bad) != string::npos) {
100
 
                                replystr = returned;
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);
104
 
                                return false;
105
 
                        }
106
 
                        MilliSleep(10);
107
 
                        Fl::awake();
108
 
                }
109
 
        }
110
 
        replystr = 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);
114
 
        return false;
115
 
}
116
 
 
117
 
bool RIG_ICOM::waitFOR(size_t n, const char *sz)
118
 
{
119
 
        char sztemp[50];
120
 
        string returned = "";
121
 
        string tosend = cmd;
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()) {
126
 
                replystr = returned;
127
 
                snprintf(sztemp, sizeof(sztemp), "%s TEST", sz);
128
 
                showresp(INFO, HEX, sztemp, tosend, returned);
129
 
                return false;
130
 
        }
131
 
        for (repeat = 0; repeat < progStatus.comm_retries; repeat++) {
132
 
                sendCommand(tosend, 0);
133
 
                MilliSleep(delay);
134
 
                returned = "";
135
 
                for ( cnt = 0; cnt < 20; cnt++) {
136
 
                        readResponse();
137
 
                        returned.append(replystr);
138
 
                        if (returned.length() >= num) {
139
 
                                replystr = returned;
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);
143
 
                                return true;
144
 
                        }
145
 
                        MilliSleep(10);
146
 
                        Fl::awake();
147
 
                }
148
 
        }
149
 
        replystr = 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);
153
 
        return false;
154
 
}
155