COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
gs232b_lib.h File Reference

GS-232B controller includes. More...

#include "support/configCosmos.h"
#include "math/mathlib.h"
#include "support/cosmos-errno.h"
#include "device/general/cssl_lib.h"
#include <stdio.h>
Include dependency graph for gs232b_lib.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  gs232b_state
 GS-232B state. More...
 

Macros

#define GS232B_ID   1
 
#define GS232B_BAUD   9600
 
#define GS232B_BITS   8
 
#define GS232B_PARITY   0
 
#define GS232B_STOPBITS   1
 
#define GS_STATE_STOWED   0
 
#define GS_STATE_FIXED   1
 
#define GS_STATE_SEEKING   2
 
#define GS_STATE_TRACKING   3
 

Functions

int32_t gs232b_connect (string dev)
 
int32_t gs232b_disconnect ()
 
int32_t gs232b_calibrate_offset (int32_t axis)
 
float gs232b_get_az ()
 
float gs232b_get_el ()
 
int32_t gs232b_get_az_el (float &az, float &el)
 
float gs232b_get_az_offset ()
 
float gs232b_get_el_offset ()
 
void gs232b_get_state (gs232b_state &state)
 
int32_t gs232b_goto (float az, float el)
 
int32_t gs232b_stop ()
 
int32_t gs232b_az_speed (int32_t speed)
 
int32_t gs232b_getdata (char *buf, int32_t buflen)
 
int32_t gs232b_send (char *buf, bool force)
 
int32_t gs232b_test ()
 
int32_t gs232b_set_sensitivity (float sensitivity)
 

Detailed Description

GS-232B controller includes.

Contains definitions and functions for running a Yaesu GS-232B controller.

Macro Definition Documentation

#define GS232B_ID   1
#define GS232B_BAUD   9600
#define GS232B_BITS   8
#define GS232B_PARITY   0
#define GS232B_STOPBITS   1
#define GS_STATE_STOWED   0
#define GS_STATE_FIXED   1
#define GS_STATE_SEEKING   2
#define GS_STATE_TRACKING   3

Function Documentation

int32_t gs232b_connect ( string  dev)

Connects to a Yaesu GS-232B computer 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
55 {
56  int32_t iretn;
57  cssl_start();
58  if (gs232b_serial != nullptr)
59  {
61  gs232b_serial = nullptr;
62  }
63 
65  if (gs232b_serial == nullptr)
66  {
67  return CSSL_ERROR_OPEN;
68  }
69 
70  iretn = cssl_settimeout(gs232b_serial, 0, .5);
71  if (iretn < 0)
72  {
73  return iretn;
74  }
75 
76  iretn = gs232b_send((char *)"\r", true);
77  if (iretn < 0)
78  {
79  return iretn;
80  }
81  char buf[100];
82  iretn = gs232b_getdata(buf,100);
83  if (iretn < 0)
84  {
85  return iretn;
86  }
87  iretn = gs232b_send((char *)"\r", true);
88  if (iretn < 0)
89  {
90  return iretn;
91  }
92  iretn = gs232b_getdata(buf,100);
93  if (iretn < 0)
94  {
95  return iretn;
96  }
97  if (buf[0] != '?' || buf[1] != '>')
98  {
99  return GS232B_ERROR_OPEN;
100  }
101 
102  return 0;
103 }
#define GS232B_BITS
Definition: gs232b_lib.h:50
#define GS232B_STOPBITS
Definition: gs232b_lib.h:52
int iretn
Definition: rw_test.cpp:37
int32_t gs232b_getdata(char *buf, int32_t buflen)
Definition: gs232b_lib.cpp:124
#define GS232B_ERROR_OPEN
Definition: cosmos-errno.h:53
int32_t cssl_start()
Definition: cssl_lib.cpp:73
static cssl_t * gs232b_serial
GS-232B serial handle.
Definition: gs232b_lib.cpp:41
Definition: cssl_lib.h:62
#define GS232B_BAUD
Definition: gs232b_lib.h:49
int32_t gs232b_send(char *buf, bool force)
Definition: gs232b_lib.cpp:397
int32_t cssl_close(cssl_t *serial)
Definition: cssl_lib.cpp:197
cssl_t * cssl_open(const char *fname, int baud, int bits, int parity, int stop)
Definition: cssl_lib.cpp:108
char buf[128]
Definition: rw_test.cpp:40
int32_t cssl_settimeout(cssl_t *serial, int, double timeout)
Set read timeout.
Definition: cssl_lib.cpp:469
#define GS232B_PARITY
Definition: gs232b_lib.h:51
int32_t gs232b_disconnect ( )

Close currently open GS-232B.

109 {
110  if (gs232b_serial == NULL)
111  return (GS232B_ERROR_CLOSED);
112 
114  return 0;
115 }
static cssl_t * gs232b_serial
GS-232B serial handle.
Definition: gs232b_lib.cpp:41
#define GS232B_ERROR_CLOSED
Definition: cosmos-errno.h:54
int32_t cssl_close(cssl_t *serial)
Definition: cssl_lib.cpp:197
int32_t gs232b_calibrate_offset ( int32_t  axis)
float gs232b_get_az ( )
319 {
320  char buf[20];
321  gs232b_send((char *)"C\r",1);
322  gs232b_getdata(buf,20);
323  sscanf(buf,"AZ=%03f\r\n",&ant_state.currentaz);
325  return (ant_state.currentaz);
326 }
int32_t gs232b_getdata(char *buf, int32_t buflen)
Definition: gs232b_lib.cpp:124
int32_t gs232b_send(char *buf, bool force)
Definition: gs232b_lib.cpp:397
static gs232b_state ant_state
Definition: gs232b_lib.cpp:43
char buf[128]
Definition: rw_test.cpp:40
float currentaz
Definition: gs232b_lib.h:70
#define RADOF(deg)
Radians of a Degree value.
Definition: math/constants.h:29
float gs232b_get_el ( )
329 {
330  char buf[20];
331  gs232b_send((char *)"B\r",1);
332  gs232b_getdata(buf,20);
333  sscanf(buf,"EL=%03f\r\n",&ant_state.currentel);
335  return (ant_state.currentel);
336 }
int32_t gs232b_getdata(char *buf, int32_t buflen)
Definition: gs232b_lib.cpp:124
int32_t gs232b_send(char *buf, bool force)
Definition: gs232b_lib.cpp:397
static gs232b_state ant_state
Definition: gs232b_lib.cpp:43
float currentel
Definition: gs232b_lib.h:74
char buf[128]
Definition: rw_test.cpp:40
#define RADOF(deg)
Radians of a Degree value.
Definition: math/constants.h:29
int32_t gs232b_get_az_el ( float &  az,
float &  el 
)
339 {
340  int32_t iretn = 0;
341  char buf[40];
342 
343  iretn = gs232b_send((char *)"C2\r",1);
344  iretn = gs232b_getdata(buf,40);
345  if (iretn == 0)
346  {
347  iretn = gs232b_getdata(buf,40);
348  }
349  if (iretn)
350  {
351  sscanf(buf,"AZ=%03f EL=%03f\r\n",&az,&el);
352  az = RADOF(az);
353  el = RADOF(el);
354  }
355  return iretn;
356 }
int iretn
Definition: rw_test.cpp:37
int32_t gs232b_getdata(char *buf, int32_t buflen)
Definition: gs232b_lib.cpp:124
int32_t gs232b_send(char *buf, bool force)
Definition: gs232b_lib.cpp:397
char buf[128]
Definition: rw_test.cpp:40
#define RADOF(deg)
Radians of a Degree value.
Definition: math/constants.h:29
float gs232b_get_az_offset ( )
359 {
360  return (ant_state.az_offset);
361 }
static gs232b_state ant_state
Definition: gs232b_lib.cpp:43
float az_offset
Definition: gs232b_lib.h:69
float gs232b_get_el_offset ( )
364 {
365  return (ant_state.el_offset);
366 }
float el_offset
Definition: gs232b_lib.h:73
static gs232b_state ant_state
Definition: gs232b_lib.cpp:43
void gs232b_get_state ( gs232b_state state)
369 {
370  state = ant_state;
371 }
static gs232b_state ant_state
Definition: gs232b_lib.cpp:43
int32_t gs232b_goto ( float  az,
float  el 
)
225 {
226  int32_t iretn;
227  char out[50];
228  static int32_t taz = 500;
229  static int32_t tel = 500;
230  int32_t iaz, iel;
231 
232  if (az < 0 || az > RADOF(450))
233  {
234  az = fixangle(az);
235  }
236 
237  if (el < 0)
238  {
239  el = 0.;
240  }
241  else if (el > DPI)
242  {
243  el = DPI;
244  }
245 
247  if (iretn < 0)
248  {
249  return iretn;
250  }
251 
252  // if (az < DPI2 && az < ant_state.currentaz)
253  // {
254  // az += D2PI;
255  // }
256  // else if (az > D2PI && az > ant_state.currentaz)
257  // {
258  // az -= D2PI;
259  // }
260 
261 // mel = .001+(el+ant_state.currentel)/2.;
262 // del = el-ant_state.currentel;
263 // daz = (az-ant_state.currentaz)/cos(mel);
264  float daz = az - ant_state.currentaz;
265  float del = el - ant_state.currentel;
266  float sep = sqrt(daz*daz+del*del);
267 
268  // printf("az: %7.2f-%7.2f el: %7.2f-%7.2f sep: %8.3f \n",DEGOF(ant_state.currentaz),DEGOF(az),DEGOF(ant_state.currentel),DEGOF(el),DEGOF(sep));
269  if (sep > ant_state.sensitivity)
270  {
271  ant_state.targetaz = az;
272  ant_state.targetel = el;
273  switch ((int)(4.5*sep/DPI))
274  {
275  case 0:
276  break;
277  case 1:
278  gs232b_send((char *)"X1\r", true);
279  break;
280  case 2:
281  gs232b_send((char *)"X2\r", true);
282  break;
283  case 3:
284  gs232b_send((char *)"X3\r", true);
285  break;
286  case 4:
287  default:
288  gs232b_send((char *)"X4\r", true);
289  break;
290  }
291  iaz = (int)(DEGOF(az)+.5);
292  iel = (int)(DEGOF(el)+.5);
293  if (iaz != taz || iel != tel)
294  {
295  sprintf(out,"W%03d %03d\r",iaz,iel);
296  gs232b_send(out, true);
297  taz = iaz;
298  tel = iel;
299  }
300  }
301  return 0;
302 }
float targetaz
Definition: gs232b_lib.h:71
int iretn
Definition: rw_test.cpp:37
#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
int32_t gs232b_send(char *buf, bool force)
Definition: gs232b_lib.cpp:397
static gs232b_state ant_state
Definition: gs232b_lib.cpp:43
float currentel
Definition: gs232b_lib.h:74
float targetel
Definition: gs232b_lib.h:75
int32_t gs232b_get_az_el(float &az, float &el)
Definition: gs232b_lib.cpp:338
const double DPI
Double precision PI.
Definition: math/constants.h:14
float sensitivity
Definition: gs232b_lib.h:76
float currentaz
Definition: gs232b_lib.h:70
#define RADOF(deg)
Radians of a Degree value.
Definition: math/constants.h:29
int32_t gs232b_stop ( )

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

Returns
0 or negative error.
310 {
311  int32_t iretn;
312 
313  iretn = gs232b_send((char *)"S\r", true);
314 
315  return iretn;
316 }
int iretn
Definition: rw_test.cpp:37
int32_t gs232b_send(char *buf, bool force)
Definition: gs232b_lib.cpp:397
int32_t gs232b_az_speed ( int32_t  speed)
206 {
207  int32_t iretn;
208  char out[50];
209 
210  if (speed < 1 || speed > 4)
211  return (GS232B_ERROR_OUTOFRANGE);
212  sprintf(out,"X%1d\r",speed);
213  iretn = gs232b_send(out, true);
214  if (iretn < 0)
215  {
216  return iretn;
217  }
218  else
219  {
220  return (speed);
221  }
222 }
int iretn
Definition: rw_test.cpp:37
#define GS232B_ERROR_OUTOFRANGE
Definition: cosmos-errno.h:55
int32_t gs232b_send(char *buf, bool force)
Definition: gs232b_lib.cpp:397
float speed
Definition: netperf_send.cpp:40
int32_t gs232b_getdata ( char *  buf,
int32_t  buflen 
)

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

Parameters
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.
125 {
126  int32_t i,j;
127 
128  i = 0;
129 // while ((j=cssl_getdata(gs232b_serial,(uint8_t *)&buf[i],buflen-i)))
130 // {
131 // if (j < 0)
132 // {
133 // return j;
134 // }
135 // else
136 // {
137 // i += j;
138 // if (buf[i-1] == '\n')
139 // break;
140 // }
141 // }
142 // buf[i] = 0;
143 // return (i);
144 
145  while ((j=cssl_getchar(gs232b_serial)) >= 0)
146  {
147  buf[i++] = j;
148  if (j == '\n' || i == buflen)
149  {
150  break;
151  }
152  }
153  if (j >= 0)
154  {
155  buf[i] = 0;
156  return (i);
157  }
158  else
159  {
160  return j;
161  }
162 }
int i
Definition: rw_test.cpp:37
static cssl_t * gs232b_serial
GS-232B serial handle.
Definition: gs232b_lib.cpp:41
int32_t cssl_getchar(cssl_t *serial)
Definition: cssl_lib.cpp:709
char buf[128]
Definition: rw_test.cpp:40
int32_t gs232b_send ( char *  buf,
bool  force 
)
398 {
399  int32_t iretn = 0;
400  static char lastbuf[256];
401 
402  iretn = gs232b_test();
403  if (iretn < 0)
404  {
405  return iretn;
406  }
407 
408  if (strlen(buf) && (strcmp(lastbuf,buf) || force))
409  {
411  strncpy(lastbuf,buf,256);
412  }
413 
414  return iretn;
415 }
int iretn
Definition: rw_test.cpp:37
static cssl_t * gs232b_serial
GS-232B serial handle.
Definition: gs232b_lib.cpp:41
int32_t gs232b_test()
Definition: gs232b_lib.cpp:373
int32_t cssl_putstring(cssl_t *serial, char *str)
Definition: cssl_lib.cpp:535
char buf[128]
Definition: rw_test.cpp:40
int32_t gs232b_test ( )
374 {
375  int32_t iretn;
376 
377  iretn = cssl_putchar(gs232b_serial, '\r');
378  if (iretn < 0)
379  {
380  return iretn;
381  }
382 
383  char buf[100];
384  iretn = gs232b_getdata(buf,100);
385  if (iretn < 0)
386  {
387  return iretn;
388  }
389  if (buf[0] != '?' || buf[1] != '>')
390  {
391  return GS232B_ERROR_SEND;
392  }
393 
394  return 0;
395 }
int iretn
Definition: rw_test.cpp:37
int32_t gs232b_getdata(char *buf, int32_t buflen)
Definition: gs232b_lib.cpp:124
static cssl_t * gs232b_serial
GS-232B serial handle.
Definition: gs232b_lib.cpp:41
int32_t cssl_putchar(cssl_t *serial, uint8_t c)
Definition: cssl_lib.cpp:505
#define GS232B_ERROR_SEND
Definition: cosmos-errno.h:56
char buf[128]
Definition: rw_test.cpp:40
int32_t gs232b_set_sensitivity ( float  sensitivity)
418 {
419  ant_state.sensitivity = sensitivity;
420  return 0;
421 }
static gs232b_state ant_state
Definition: gs232b_lib.cpp:43
float sensitivity
Definition: gs232b_lib.h:76