COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
prkx2su_lib.cpp File Reference
#include "support/configCosmos.h"
#include "device/general/prkx2su_lib.h"
#include <cstring>
#include <cmath>
Include dependency graph for prkx2su_lib.cpp:

Functions

int32_t prkx2su_init (string dev)
 
int32_t prkx2su_connect ()
 
int32_t prkx2su_disconnect ()
 
int32_t prkx2su_getdata (uint8_t axis, string buf, uint16_t buflen)
 
int32_t prkx2su_status (uint8_t axis)
 
int32_t prkx2su_get_limits (uint8_t axis)
 
int32_t prkx2su_stop (uint8_t axis)
 
int32_t prkx2su_ramp (uint8_t axis, uint8_t speed)
 
int32_t prkx2su_minimum_speed (uint8_t axis, uint8_t speed)
 
int32_t prkx2su_maximum_speed (uint8_t axis, uint8_t speed)
 
int32_t prkx2su_goto (float az, float el)
 
float prkx2su_get_az ()
 
float prkx2su_get_el ()
 
int32_t prkx2su_get_az_el (float &az, float &el)
 
int32_t prkx2su_write_calibration (uint8_t axis, float value)
 
float prkx2su_get_az_offset ()
 
float prkx2su_get_el_offset ()
 
void prkx2su_get_state (prkx2su_state &state)
 
int32_t prkx2su_test (uint8_t axis)
 
int32_t prkx2su_send (uint8_t axis, string buf, bool force)
 
int32_t prkx2su_set_sensitivity (float sensitivity)
 

Variables

static Serialprkx2su_serial [2]
 prkx2su serial handle More...
 
static prkx2su_state ant_state
 

Function Documentation

int32_t prkx2su_init ( string  dev)
45 {
46  string device;
47 
48  device = dev + "_az";
50  device = dev + "_el";
52 
53  return 0;
54 }
static Serial * prkx2su_serial[2]
prkx2su serial handle
Definition: prkx2su_lib.cpp:40
#define PRKX2SU_STOPBITS
Definition: prkx2su_class.h:14
Definition: serialclass.h:43
#define PRKX2SU_AXIS_EL
Definition: prkx2su_class.h:16
#define PRKX2SU_BAUD
Definition: prkx2su_class.h:11
#define PRKX2SU_AXIS_AZ
Definition: prkx2su_class.h:15
#define PRKX2SU_PARITY
Definition: prkx2su_class.h:13
#define PRKX2SU_BITS
Definition: prkx2su_class.h:12
static string device
Definition: ax25_recv.cpp:39
int32_t prkx2su_connect ( )

Connects to am MII prkx2su antenna controller, which in turn drives a Yaesu G-5500 antenna controller.

Parameters
devpointer to a character string with the serial port it is connected to.
See also
cssl_start
cssl_open
cssl_setflowcontrol
66 {
67  int32_t iretn;
68 // cssl_start();
69 
70  if (prkx2su_serial[PRKX2SU_AXIS_AZ]->get_open())
71  {
72  iretn = prkx2su_disconnect();
73  if (iretn < 0)
74  {
75  return iretn;
76  }
77  }
78 
80  if (iretn < 0)
81  {
82  return iretn;
83  }
84 
86  if (iretn < 0)
87  {
89  return iretn;
90  }
91 
92  iretn = prkx2su_send(PRKX2SU_AXIS_AZ, "", true);
93  if (iretn < 0)
94  {
96  return iretn;
97  }
98 
99  if (prkx2su_serial[PRKX2SU_AXIS_EL]->get_open())
100  {
101  return SERIAL_ERROR_OPEN;
102  }
103 
105  if (iretn < 0)
106  {
108  return iretn;
109  }
110 
112  if (iretn < 0)
113  {
115  return iretn;
116  }
117 
118  iretn = prkx2su_send(PRKX2SU_AXIS_EL, "", true);
119  if (iretn < 0)
120  {
122  return iretn;
123  }
124 
125  return 0;
126 }
int32_t prkx2su_disconnect()
Definition: prkx2su_lib.cpp:131
static Serial * prkx2su_serial[2]
prkx2su serial handle
Definition: prkx2su_lib.cpp:40
int iretn
Definition: rw_test.cpp:37
#define PRKX2SU_AXIS_EL
Definition: prkx2su_class.h:16
int32_t prkx2su_send(uint8_t axis, string buf, bool force)
Definition: prkx2su_lib.cpp:471
#define PRKX2SU_AXIS_AZ
Definition: prkx2su_class.h:15
int32_t open_device()
Definition: serialclass.cpp:60
int32_t set_timeout(int, double timeout)
Definition: serialclass.cpp:515
#define SERIAL_ERROR_OPEN
Definition: cosmos-errno.h:177
int32_t prkx2su_disconnect ( )

Close currently open prkx2su.

132 {
133  int32_t iretn = 0;
134  if (prkx2su_serial[PRKX2SU_AXIS_AZ]->get_open())
135  {
137  }
138 
139  if (prkx2su_serial[PRKX2SU_AXIS_EL] != nullptr)
140  {
142  }
143 
144  return iretn;
145 }
static Serial * prkx2su_serial[2]
prkx2su serial handle
Definition: prkx2su_lib.cpp:40
int32_t close_device()
Definition: serialclass.cpp:126
int iretn
Definition: rw_test.cpp:37
#define PRKX2SU_AXIS_EL
Definition: prkx2su_class.h:16
#define PRKX2SU_AXIS_AZ
Definition: prkx2su_class.h:15
int32_t prkx2su_getdata ( uint8_t  axis,
string  buf,
uint16_t  buflen 
)

Routine to use in blocking mode. Reads the serial port until a New Line is received, then returns entire buffer.

Parameters
axisAxis to read.
bufPointer to a char buffer
buflen32 bit signed integer indicating the maximum size of the buffer
Returns
32 bit signed integer containing the number of bytes read.
156 {
157  int32_t j;
158 
159  buf.clear();
160  while((j=prkx2su_serial[axis]->get_char()) >= 0)
161  {
162  buf.push_back(static_cast<char>(j));
163  if (j == ';' || static_cast<uint16_t>(buf.size()) == buflen)
164  {
165  break;
166  }
167  }
168 
169  if (j < 0)
170  {
171  return j;
172  }
173  else
174  {
175  return static_cast<int32_t>(buf.size());
176  }
177 }
static Serial * prkx2su_serial[2]
prkx2su serial handle
Definition: prkx2su_lib.cpp:40
char buf[128]
Definition: rw_test.cpp:40
int32_t prkx2su_status ( uint8_t  axis)

Poll controller for Status and Heading. Turns calibration mode on in prkx2su.

Parameters
axis32 bit signed integer , 0 = Azimuth, 1 = Elevation
185 {
186  int32_t iretn;
187  iretn = prkx2su_send(axis, "BIn;", true);
188  if (iretn < 0)
189  {
190  return iretn;
191  }
192  string buf;
193  iretn = prkx2su_getdata(axis, buf, 2000);
194  if (iretn < 0)
195  {
196  return iretn;
197  }
198  switch (axis)
199  {
200  case PRKX2SU_AXIS_AZ:
201  sscanf(buf.c_str(), "%c%c%f", &ant_state.azid, &ant_state.azstatus, &ant_state.currentaz);
203  break;
204  case PRKX2SU_AXIS_EL:
205  sscanf(buf.c_str(), "%c%c%f", &ant_state.elid, &ant_state.elstatus, &ant_state.currentel);
207  break;
208  }
209  return iretn;
210 }
uint8_t elstatus
Definition: prkx2su_lib.h:75
int iretn
Definition: rw_test.cpp:37
#define PRKX2SU_AXIS_EL
Definition: prkx2su_class.h:16
float currentel
Definition: prkx2su_lib.h:80
int32_t prkx2su_send(uint8_t axis, string buf, bool force)
Definition: prkx2su_lib.cpp:471
#define PRKX2SU_AXIS_AZ
Definition: prkx2su_class.h:15
uint8_t azstatus
Definition: prkx2su_lib.h:65
uint8_t elid
Definition: prkx2su_lib.h:74
static prkx2su_state ant_state
Definition: prkx2su_lib.cpp:42
int32_t prkx2su_getdata(uint8_t axis, string buf, uint16_t buflen)
Definition: prkx2su_lib.cpp:155
float currentaz
Definition: prkx2su_lib.h:72
char buf[128]
Definition: rw_test.cpp:40
uint8_t azid
Definition: prkx2su_lib.h:64
#define RADOF(deg)
Radians of a Degree value.
Definition: math/constants.h:29
int32_t prkx2su_get_limits ( uint8_t  axis)
213 {
214  string buf;
215  int32_t iretn;
216  iretn = prkx2su_send(axis, "RH0;", true);
217  if (iretn < 0)
218  {
219  return iretn;
220  }
221  iretn = prkx2su_getdata(axis, buf, 200);
222  if (iretn < 0)
223  {
224  return iretn;
225  }
226  switch (axis)
227  {
228  case PRKX2SU_AXIS_AZ:
229  sscanf(buf.c_str(), "H%f", &ant_state.minaz);
231  break;
232  case PRKX2SU_AXIS_EL:
233  sscanf(buf.c_str(), "H%f", &ant_state.minel);
235  break;
236  }
237  iretn = prkx2su_send(axis, "RI0;", true);
238  if (iretn < 0)
239  {
240  return iretn;
241  }
242  iretn = prkx2su_getdata(axis, buf, 200);
243  if (iretn < 0)
244  {
245  return iretn;
246  }
247  switch (axis)
248  {
249  case PRKX2SU_AXIS_AZ:
250  sscanf(buf.c_str(), "H%f", &ant_state.maxaz);
252  break;
253  case PRKX2SU_AXIS_EL:
254  sscanf(buf.c_str(), "H%f", &ant_state.maxel);
256  break;
257  }
258  return iretn;
259 }
float minaz
Definition: prkx2su_lib.h:70
int iretn
Definition: rw_test.cpp:37
#define PRKX2SU_AXIS_EL
Definition: prkx2su_class.h:16
int32_t prkx2su_send(uint8_t axis, string buf, bool force)
Definition: prkx2su_lib.cpp:471
#define PRKX2SU_AXIS_AZ
Definition: prkx2su_class.h:15
float minel
Definition: prkx2su_lib.h:78
static prkx2su_state ant_state
Definition: prkx2su_lib.cpp:42
int32_t prkx2su_getdata(uint8_t axis, string buf, uint16_t buflen)
Definition: prkx2su_lib.cpp:155
float maxaz
Definition: prkx2su_lib.h:71
char buf[128]
Definition: rw_test.cpp:40
float maxel
Definition: prkx2su_lib.h:79
#define RADOF(deg)
Radians of a Degree value.
Definition: math/constants.h:29
int32_t prkx2su_stop ( uint8_t  axis)

Routine to stop current action. Whatever the current command is, it will cancelled before completeion.

Returns
0 or negative error.
267 {
268  int32_t iretn;
269  iretn = prkx2su_send(axis, ";", true);
270  return iretn;
271 }
int iretn
Definition: rw_test.cpp:37
int32_t prkx2su_send(uint8_t axis, string buf, bool force)
Definition: prkx2su_lib.cpp:471
int32_t prkx2su_ramp ( uint8_t  axis,
uint8_t  speed 
)
274 {
275  int32_t iretn;
276  char out[50];
277 
278  if (speed < 1 || speed > 10)
279  return (PRKX2SU_ERROR_OUTOFRANGE);
280  sprintf(out,"WNn%03hhu;", speed);
281  iretn = prkx2su_send(axis, out, true);
282  if (iretn < 0)
283  {
284  return iretn;
285  }
286  else
287  {
288  return (speed);
289  }
290 }
int iretn
Definition: rw_test.cpp:37
#define PRKX2SU_ERROR_OUTOFRANGE
Definition: cosmos-errno.h:251
int32_t prkx2su_send(uint8_t axis, string buf, bool force)
Definition: prkx2su_lib.cpp:471
float speed
Definition: netperf_send.cpp:40
int32_t prkx2su_minimum_speed ( uint8_t  axis,
uint8_t  speed 
)
293 {
294  int32_t iretn;
295  char out[50];
296 
297  if (speed < 1 || speed > 10)
298  return (PRKX2SU_ERROR_OUTOFRANGE);
299  sprintf(out,"WFn%03hhu;", speed);
300  iretn = prkx2su_send(axis, out, true);
301  if (iretn < 0)
302  {
303  return iretn;
304  }
305  else
306  {
307  return (speed);
308  }
309 }
int iretn
Definition: rw_test.cpp:37
#define PRKX2SU_ERROR_OUTOFRANGE
Definition: cosmos-errno.h:251
int32_t prkx2su_send(uint8_t axis, string buf, bool force)
Definition: prkx2su_lib.cpp:471
float speed
Definition: netperf_send.cpp:40
int32_t prkx2su_maximum_speed ( uint8_t  axis,
uint8_t  speed 
)
312 {
313  int32_t iretn;
314  char out[50];
315 
316  if (speed < 1 || speed > 10)
317  return (PRKX2SU_ERROR_OUTOFRANGE);
318  sprintf(out,"WGn%03hhu;", speed);
319  iretn = prkx2su_send(axis, out, true);
320  if (iretn < 0)
321  {
322  return iretn;
323  }
324  else
325  {
326  return (speed);
327  }
328 }
int iretn
Definition: rw_test.cpp:37
#define PRKX2SU_ERROR_OUTOFRANGE
Definition: cosmos-errno.h:251
int32_t prkx2su_send(uint8_t axis, string buf, bool force)
Definition: prkx2su_lib.cpp:471
float speed
Definition: netperf_send.cpp:40
int32_t prkx2su_goto ( float  az,
float  el 
)
331 {
332  int32_t iretn;
333  char out[50];
334 
335  if (az < 0 || az > RADOF(360))
336  {
337  az = fixangle(az);
338  }
339 
340  if (el < 0)
341  {
342  el = 0.;
343  }
344  else if (el > DPI2)
345  {
346  el = DPI2;
347  }
348 
349  float daz = az - ant_state.targetaz;
350  float del = el - ant_state.targetel;
351  float sep = sqrt(daz*daz+del*del);
352 
353  if (sep > ant_state.sensitivity)
354  {
355  ant_state.targetaz = az;
356  ant_state.targetel = el;
357  az = DEGOF(az);
358  el = DEGOF(el);
359  sprintf(out, "APn%03d.%1d\r;", (int16_t)az, (int16_t)(10 * (az - (int16_t)az)));
360  iretn = prkx2su_send(PRKX2SU_AXIS_AZ, out, true);
361  if (iretn >= 0)
362  {
363  sprintf(out, "APn%03d.%1d\r;", (int16_t)el, (int16_t)(10 * (el - (int16_t)el)));
364  iretn = prkx2su_send(PRKX2SU_AXIS_EL, out, true);
365  if (iretn >= 0)
366  {
368  }
369  }
370  }
371 
372  return 0;
373 }
int32_t prkx2su_get_az_el(float &az, float &el)
Definition: prkx2su_lib.cpp:385
int iretn
Definition: rw_test.cpp:37
#define PRKX2SU_AXIS_EL
Definition: prkx2su_class.h:16
float currentel
Definition: prkx2su_lib.h:80
float sensitivity
Definition: prkx2su_lib.h:83
const double DPI2
Double precision PI/2.
Definition: math/constants.h:18
int32_t prkx2su_send(uint8_t axis, string buf, bool force)
Definition: prkx2su_lib.cpp:471
float targetel
Definition: prkx2su_lib.h:81
#define PRKX2SU_AXIS_AZ
Definition: prkx2su_class.h:15
#define DEGOF(rad)
Degrees of a Radian value.
Definition: math/constants.h:33
double fixangle(double angle)
Limit angle to range 0-2PI.
Definition: mathlib.cpp:2159
static prkx2su_state ant_state
Definition: prkx2su_lib.cpp:42
float currentaz
Definition: prkx2su_lib.h:72
float targetaz
Definition: prkx2su_lib.h:73
#define RADOF(deg)
Radians of a Degree value.
Definition: math/constants.h:29
float prkx2su_get_az ( )
376 {
377  return (ant_state.currentaz);
378 }
static prkx2su_state ant_state
Definition: prkx2su_lib.cpp:42
float currentaz
Definition: prkx2su_lib.h:72
float prkx2su_get_el ( )
381 {
382  return (ant_state.currentel);
383 }
float currentel
Definition: prkx2su_lib.h:80
static prkx2su_state ant_state
Definition: prkx2su_lib.cpp:42
int32_t prkx2su_get_az_el ( float &  az,
float &  el 
)
386 {
387  int32_t iretn = 0;
388 
390  if (iretn >= 0)
391  {
393  if (iretn >= 0)
394  {
395  az = ant_state.currentaz;
396  el = ant_state.currentel;
397  }
398  }
399  return iretn;
400 }
int iretn
Definition: rw_test.cpp:37
#define PRKX2SU_AXIS_EL
Definition: prkx2su_class.h:16
float currentel
Definition: prkx2su_lib.h:80
#define PRKX2SU_AXIS_AZ
Definition: prkx2su_class.h:15
static prkx2su_state ant_state
Definition: prkx2su_lib.cpp:42
float currentaz
Definition: prkx2su_lib.h:72
int32_t prkx2su_status(uint8_t axis)
Definition: prkx2su_lib.cpp:184
int32_t prkx2su_write_calibration ( uint8_t  axis,
float  value 
)
403 {
404  int32_t iretn;
405  char out[50];
406 
407  if (value < 0.)
408  {
409  value = 0.;
410  }
411  switch (axis)
412  {
413  case PRKX2SU_AXIS_AZ:
414  if (value > D2PI)
415  {
416  value = D2PI;
417  }
418  break;
419  case PRKX2SU_AXIS_EL:
420  if (value > DPI)
421  {
422  value = DPI;
423  }
424  }
425 
426  value = DEGOF(value);
427  sprintf(out, "Awn%03d.%1d;", (int16_t)value, (int16_t)(10 * (value - (int16_t)value)));
428  iretn = prkx2su_send(axis, out, true);
429  return iretn;
430 }
int iretn
Definition: rw_test.cpp:37
#define PRKX2SU_AXIS_EL
Definition: prkx2su_class.h:16
int32_t prkx2su_send(uint8_t axis, string buf, bool force)
Definition: prkx2su_lib.cpp:471
#define PRKX2SU_AXIS_AZ
Definition: prkx2su_class.h:15
#define DEGOF(rad)
Degrees of a Radian value.
Definition: math/constants.h:33
const double D2PI
Double precision 2*PI.
Definition: math/constants.h:16
const double DPI
Double precision PI.
Definition: math/constants.h:14
float prkx2su_get_az_offset ( )
433 {
434  return (ant_state.az_offset);
435 }
static prkx2su_state ant_state
Definition: prkx2su_lib.cpp:42
float az_offset
Definition: prkx2su_lib.h:69
float prkx2su_get_el_offset ( )
438 {
439  return (ant_state.el_offset);
440 }
float el_offset
Definition: prkx2su_lib.h:77
static prkx2su_state ant_state
Definition: prkx2su_lib.cpp:42
void prkx2su_get_state ( prkx2su_state state)
443 {
444  state = ant_state;
445 }
static prkx2su_state ant_state
Definition: prkx2su_lib.cpp:42
int32_t prkx2su_test ( uint8_t  axis)
448 {
449  int32_t iretn;
450 
451  iretn = prkx2su_serial[axis]->put_string("R10;");
452  if (iretn < 0)
453  {
454  return iretn;
455  }
456 
457  string buf;
458  iretn = prkx2su_getdata(axis, buf, 100);
459  if (iretn < 0)
460  {
461  return iretn;
462  }
463  if (buf[0] != '1' || buf[1] != 0x1 || buf[buf.size()-1] != ';')
464  {
465  return PRKX2SU_ERROR_SEND;
466  }
467 
468  return 0;
469 }
static Serial * prkx2su_serial[2]
prkx2su serial handle
Definition: prkx2su_lib.cpp:40
int32_t put_string(string data)
Definition: serialclass.cpp:686
int iretn
Definition: rw_test.cpp:37
#define PRKX2SU_ERROR_SEND
Definition: cosmos-errno.h:252
int32_t prkx2su_getdata(uint8_t axis, string buf, uint16_t buflen)
Definition: prkx2su_lib.cpp:155
char buf[128]
Definition: rw_test.cpp:40
int32_t prkx2su_send ( uint8_t  axis,
string  buf,
bool  force 
)
472 {
473  int32_t iretn = 0;
474  string lastbuf;
475 
476  iretn = prkx2su_test(axis);
477  if (iretn < 0)
478  {
479  return iretn;
480  }
481 
482  if (lastbuf != buf || force)
483  {
484  prkx2su_serial[axis]->put_string(buf);
485  lastbuf = buf;
486  }
487 
488  return iretn;
489 }
static Serial * prkx2su_serial[2]
prkx2su serial handle
Definition: prkx2su_lib.cpp:40
int32_t put_string(string data)
Definition: serialclass.cpp:686
int iretn
Definition: rw_test.cpp:37
char buf[128]
Definition: rw_test.cpp:40
int32_t prkx2su_test(uint8_t axis)
Definition: prkx2su_lib.cpp:447
int32_t prkx2su_set_sensitivity ( float  sensitivity)
492 {
493  ant_state.sensitivity = sensitivity;
494  return 0;
495 }
float sensitivity
Definition: prkx2su_lib.h:83
static prkx2su_state ant_state
Definition: prkx2su_lib.cpp:42

Variable Documentation

Serial* prkx2su_serial[2]
static

prkx2su serial handle

Internal descriptor for cssl serial control of prkx2su.

prkx2su_state ant_state
static