Newer
Older
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
//
// file : readthread.cpp
//
// description : reading thread
//
// project : TANGO Device Server
//
// $Author: graziano $
//
// $Revision: 1.1 $
//
// $Log: readthread.cpp,v $
// Revision 1.1 2017-12-21 11:26:12 graziano
// first commit
//
//
//
//
//
//
// copyleft : Sincrotrone Trieste S.C.p.A.
// Strada Statale 14 - km 163,5 in AREA Science Park
// 34012 Basovizza, Trieste ITALY
//
#include "readthread.h"
#include "ConexAgp.h"
#include <math.h>
static const char __FILE__rev[] = __FILE__ " $Revision: 1.1 $";
namespace ConexAgp_ns
{
//+------------------------------------------------------------------
//
// method: readthread::readthread()
//
// description: readthread constructor
//
//-------------------------------------------------------------------
readthread::readthread(Tango::DeviceImpl* devImpl):Tango::LogAdapter(devImpl)
{
DEBUG_STREAM << "readthread::readthread(): constructor... :" << __FILE__rev << endl;
device = devImpl;
}
//+------------------------------------------------------------------
//
// method: readthread::~readthread()
//
// description: readthread destructor
//
//-------------------------------------------------------------------
readthread::~readthread()
{
DEBUG_STREAM << "readthread::~readthread(): destructor... !" << endl;
}
//+------------------------------------------------------------------
//
// method: readthread::run()
//
// description: Run
//
//-------------------------------------------------------------------
void readthread::run(void *)
{
INFO_STREAM << "readthread::run(): running... !" << endl;
/*int pausesec,pausenano,pausesec_dfl,pausenano_dfl,
cnt_err = 0,
max_cnt_err = 3,
ret;*/
abortflag = false;
ConexAgp *_device = static_cast<ConexAgp *>(device);
while (!abortflag)
{
DEBUG_STREAM << "readthread::run(): looping "<< endl;
string tstate;
_device->SendReceive(GET_STATE, tstate);
if(tstate.length() == 6)
{
/*uint16_t positioner_err = ((tstate[0]-0x30) << 12) |
((tstate[1]-0x30) << 8) |
((tstate[2]-0x30) << 4) |
((tstate[3]-0x30));
uint8_t controller_state = (((tstate[4]-0x30) << 4) | ((tstate[5]-0x30)));*/
stringstream pos_err;
pos_err << tstate[0] << tstate[1] << tstate[2] << tstate[3];
uint16_t positioner_err;
pos_err >> hex >> positioner_err;
stringstream contr_state;
contr_state << tstate[4] << tstate[5];
uint16_t controller_state;
contr_state >> hex >> controller_state;
INFO_STREAM << __func__<<": state '" << tstate << "' len="<<tstate.length() << " positioner_err=0x"<<hex<<positioner_err<<" controller_state=0x"<<(int)controller_state<<dec;
stringstream _status;
Tango::DevState _state;
if(positioner_err != 0)
{
_state = Tango::ALARM;
_status << "Positioner error=0x"<<hex << positioner_err << dec;
if(positioner_err & 0x0020)
_status << " (Motion time out)";
}
else
{
map<uint8_t,state_desc>::iterator it = _device->controller_states.find(controller_state);
if(it != _device->controller_states.end())
{
_state = it->second._state;
_status << it->second._status;
}
else
{
_state = Tango::UNKNOWN;
_status << "Unknown state 0x" << (int)controller_state;
}
}
_device->set_state(_state);
_device->push_change_event("State");
_device->push_archive_event("State");
_device->set_status(_status.str());
}
else
{
INFO_STREAM << __func__<<": error parsing state '" << tstate << "' len="<<tstate.length();
}
usleep(10000);
double posx;
_device->SendReceive(string(GET_POSITION), posx);
*(_device->attr_Position_read) = posx;
_device->push_change_event("Position",_device->attr_Position_read);
_device->push_archive_event("Position",_device->attr_Position_read);
usleep(10000);
double postx;
_device->SendReceive(string(GET_TARGET_POSITION), postx);
*(_device->attr_TargetPosition_read) = postx;
usleep(10000);
INFO_STREAM << __func__<<": " << posx << " -> "<<*(_device->attr_Position_read);
abort_sleep(1);
}
INFO_STREAM << "readthread::run(): exit!!!" << endl;
}
//+------------------------------------------------------------------
//
// method: readthread::abort_sleep
//
// description: Resume from sleep if abort_flag set (sec.)
//
//-------------------------------------------------------------------
void readthread::abort_sleep(double time)
{
for (int i = 0; i < (time/0.3); i++) {
if (abortflag)
break;
omni_thread::sleep(0,300000000);
}
}
}