COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
kpc9612p_lib.cpp File Reference
Include dependency graph for kpc9612p_lib.cpp:

Functions

uint16_t kpc9612p_calc_fcs (uint8_t *data, uint16_t length)
 
int32_t kpc9612p_connect (char *dev, kpc9612p_handle *handle, uint8_t flag)
 
int32_t kpc9612p_disconnect (kpc9612p_handle *handle)
 
int32_t kpc9612p_recvframe (kpc9612p_handle *handle)
 
int32_t kpc9612p_sendframe (kpc9612p_handle *handle)
 
int32_t kpc9612p_loadframe (kpc9612p_handle *handle, uint8_t *data, uint16_t size)
 
int32_t kpc9612p_loadframe (kpc9612p_handle *handle, vector< uint8_t > data)
 
int32_t kpc9612p_unloadframe (kpc9612p_handle *handle, uint8_t *data, uint16_t size)
 
int32_t kpc9612p_unloadframe (kpc9612p_handle *handle, vector< uint8_t > &data)
 
int32_t kpc9612p_exitkiss (kpc9612p_handle *handle)
 
int32_t kpc9612p_enterkiss (kpc9612p_handle *handle)
 
int32_t kpc9612p_entercmd (kpc9612p_handle *handle)
 

Variables

uint16_t kpc9612p_fcstab [256]
 

Function Documentation

uint16_t kpc9612p_calc_fcs ( uint8_t *  data,
uint16_t  length 
)
68 { uint16_t fcs;
69 
70  fcs = 0xffff;
71  while (length--)
72  { fcs = (fcs >> 8) ^ kpc9612p_fcstab[(fcs ^ ((uint16_t)*data)) & 0xff];
73  data++;
74  }
75  return (~fcs);
76 }
png_uint_32 length
Definition: png.c:2173
uint16_t kpc9612p_fcstab[256]
Definition: kpc9612p_lib.cpp:32
int32_t kpc9612p_connect ( char *  dev,
kpc9612p_handle handle,
uint8_t  flag 
)
79 {
80  int32_t iretn;
81  cssl_start();
83  if (handle->serial == NULL) return (CSSL_ERROR_OPEN);
84  cssl_settimeout(handle->serial, 0, 1.);
85  cssl_setflowcontrol(handle->serial, 0, 0);
86  handle->flag = flag;
87 
88  iretn = kpc9612p_entercmd(handle);
89  if (iretn < 0)
90  {
91  return iretn;
92  }
93 
94  iretn = kpc9612p_enterkiss(handle);
95  if (iretn < 0)
96  {
97  return iretn;
98  }
99 
100  return 0;
101 }
int32_t kpc9612p_entercmd(kpc9612p_handle *handle)
Definition: kpc9612p_lib.cpp:237
int iretn
Definition: rw_test.cpp:37
int32_t cssl_start()
Definition: cssl_lib.cpp:73
Definition: cssl_lib.h:62
cssl_t * serial
Definition: kpc9612p_lib.h:90
#define KPC9612P_BAUD
Definition: kpc9612p_lib.h:58
int32_t cssl_setflowcontrol(cssl_t *serial, int rtscts, int xonxoff)
Definition: cssl_lib.cpp:389
#define KPC9612P_PARITY
Definition: kpc9612p_lib.h:60
uint8_t flag
Definition: kpc9612p_lib.h:92
#define KPC9612P_BITS
Definition: kpc9612p_lib.h:59
#define KPC9612P_STOPBITS
Definition: kpc9612p_lib.h:61
cssl_t * cssl_open(const char *fname, int baud, int bits, int parity, int stop)
Definition: cssl_lib.cpp:108
int32_t kpc9612p_enterkiss(kpc9612p_handle *handle)
Definition: kpc9612p_lib.cpp:230
int32_t cssl_settimeout(cssl_t *serial, int, double timeout)
Set read timeout.
Definition: cssl_lib.cpp:469
int32_t kpc9612p_disconnect ( kpc9612p_handle handle)
104 {
105  if (handle->serial == NULL) return (CSSL_ERROR_NOTSTARTED);
106 
107  cssl_close(handle->serial);
108  return 0;
109 }
Definition: cssl_lib.h:58
cssl_t * serial
Definition: kpc9612p_lib.h:90
int32_t cssl_close(cssl_t *serial)
Definition: cssl_lib.cpp:197
int32_t kpc9612p_recvframe ( kpc9612p_handle handle)
112 {
113  int32_t iretn;
114 
115  iretn = cssl_getslip(handle->serial, handle->frame.full, KPC9612P_FULL_SIZE);
116  if (iretn >= 0)
117  {
118  // int16_t ch = cssl_getchar(handle->serial);
119  // ch = cssl_getchar(handle->serial);
120  handle->frame.size = iretn;
121  }
122  else
123  {
124  handle->frame.size = 0;
125  }
126 
127  return iretn;
128 }
#define KPC9612P_FULL_SIZE
Definition: kpc9612p_lib.h:53
int iretn
Definition: rw_test.cpp:37
int32_t cssl_getslip(cssl_t *serial, uint8_t *buf, uint16_t size)
Read SLIP frame.
Definition: cssl_lib.cpp:826
kpc9612p_frame frame
Definition: kpc9612p_lib.h:91
cssl_t * serial
Definition: kpc9612p_lib.h:90
uint16_t size
Definition: kpc9612p_lib.h:85
uint8_t full[(254+19)]
Definition: kpc9612p_lib.h:83
int32_t kpc9612p_sendframe ( kpc9612p_handle handle)
131 {
132  int32_t iretn;
133 
134  handle->frame.part.header.flag = handle->flag;
135  iretn = cssl_putslip(handle->serial, handle->frame.full, handle->frame.size);
136 
137  return iretn;
138 }
struct kpc9612p_frame::@12::@14 part
int iretn
Definition: rw_test.cpp:37
kpc9612p_frame frame
Definition: kpc9612p_lib.h:91
cssl_t * serial
Definition: kpc9612p_lib.h:90
uint8_t flag
Definition: kpc9612p_lib.h:92
uint16_t size
Definition: kpc9612p_lib.h:85
int32_t cssl_putslip(cssl_t *serial, uint8_t *buf, size_t size)
Definition: cssl_lib.cpp:586
uint8_t full[(254+19)]
Definition: kpc9612p_lib.h:83
int32_t kpc9612p_loadframe ( kpc9612p_handle handle,
uint8_t *  data,
uint16_t  size 
)
141 {
142  uint16_t tsize;
143  // uint16_t fcs;
144 
145  handle->frame.part.header.flag = handle->flag;
146  handle->frame.part.header.protocol_id = AX25_NOLAYER3;
147  memcpy(handle->frame.part.header.destination_address,(char *)"ABCDEFG",7);
148  memcpy(handle->frame.part.header.source_address,(char *)"GROUND ",7);
149  for (uint16_t i=0; i<7; ++i)
150  {
151  handle->frame.part.header.destination_address[i] <<= 1;
152  handle->frame.part.header.source_address[i] <<= 1;
153  }
154  tsize = (size <= KPC9612P_PAYLOAD_SIZE?size:KPC9612P_PAYLOAD_SIZE);
155  // handle->frame.size = tsize + 19;
156  handle->frame.size = tsize + 17;
157  memcpy(handle->frame.part.payload, data, tsize);
158  // fcs = kpc9612p_calc_fcs(handle->frame.full, handle->frame.size);
159  // handle->frame.part.payload[tsize] = fcs%256;
160  // handle->frame.part.payload[tsize+1] = fcs>>8;
161  // handle->frame.part.payload[tsize+2] = AX25_FLAG;
162 
163  return (tsize);
164 }
int i
Definition: rw_test.cpp:37
struct kpc9612p_frame::@12::@14 part
#define KPC9612P_PAYLOAD_SIZE
Definition: kpc9612p_lib.h:50
kpc9612p_frame frame
Definition: kpc9612p_lib.h:91
uint8_t flag
Definition: kpc9612p_lib.h:92
#define AX25_NOLAYER3
Definition: kisstnc_lib.h:55
uint16_t size
Definition: kpc9612p_lib.h:85
int32_t kpc9612p_loadframe ( kpc9612p_handle handle,
vector< uint8_t >  data 
)
167 {
168  uint16_t tsize;
169  // uint16_t fcs;
170 
171  handle->frame.part.header.flag = handle->flag;
172  handle->frame.part.header.protocol_id = AX25_NOLAYER3;
173  memcpy(handle->frame.part.header.destination_address,(char *)"ABCDEFG",7);
174  memcpy(handle->frame.part.header.source_address,(char *)"GROUND ",7);
175  for (uint16_t i=0; i<7; ++i)
176  {
177  handle->frame.part.header.destination_address[i] <<= 1;
178  handle->frame.part.header.source_address[i] <<= 1;
179  }
180  tsize = (data.size() <= KPC9612P_PAYLOAD_SIZE?data.size():KPC9612P_PAYLOAD_SIZE);
181  // handle->frame.size = tsize + 19;
182  handle->frame.size = tsize + 17;
183  memcpy(handle->frame.part.payload, &data[0], tsize);
184  // fcs = kpc9612p_calc_fcs(handle->frame.full, handle->frame.size);
185  // handle->frame.part.payload[tsize] = fcs%256;
186  // handle->frame.part.payload[tsize+1] = fcs>>8;
187  // handle->frame.part.payload[tsize+2] = AX25_FLAG;
188 
189  return (tsize);
190 }
int i
Definition: rw_test.cpp:37
struct kpc9612p_frame::@12::@14 part
#define KPC9612P_PAYLOAD_SIZE
Definition: kpc9612p_lib.h:50
kpc9612p_frame frame
Definition: kpc9612p_lib.h:91
uint8_t flag
Definition: kpc9612p_lib.h:92
#define AX25_NOLAYER3
Definition: kisstnc_lib.h:55
uint16_t size
Definition: kpc9612p_lib.h:85
int32_t kpc9612p_unloadframe ( kpc9612p_handle handle,
uint8_t *  data,
uint16_t  size 
)
193 {
194  uint16_t tsize;
195 
196  tsize = (handle->frame.size-17 <= size?handle->frame.size-17:size);
197  memcpy(data, handle->frame.part.payload, tsize);
198  data[tsize] = 0;
199  return (tsize);
200 }
struct kpc9612p_frame::@12::@14 part
kpc9612p_frame frame
Definition: kpc9612p_lib.h:91
uint16_t size
Definition: kpc9612p_lib.h:85
int32_t kpc9612p_unloadframe ( kpc9612p_handle handle,
vector< uint8_t > &  data 
)
203 {
204  uint16_t tsize;
205 
206  if (handle->frame.size >= 17)
207  {
208  tsize = handle->frame.size-17;
209  data.resize(tsize);
210  memcpy(&data[0], handle->frame.part.payload, tsize);
211  }
212  else
213  {
214  tsize = 0;
215  data.resize(tsize);
216  }
217  return (tsize);
218 }
struct kpc9612p_frame::@12::@14 part
kpc9612p_frame frame
Definition: kpc9612p_lib.h:91
uint16_t size
Definition: kpc9612p_lib.h:85
int32_t kpc9612p_exitkiss ( kpc9612p_handle handle)
221 {
222  cssl_putchar(handle->serial, 0xc0);
223  cssl_putchar(handle->serial, 0xff);
224  cssl_putchar(handle->serial, 0xc0);
225  COSMOS_SLEEP(1.);
226  cssl_putchar(handle->serial, '\r');
227  return 0;
228 }
int32_t cssl_putchar(cssl_t *serial, uint8_t c)
Definition: cssl_lib.cpp:505
cssl_t * serial
Definition: kpc9612p_lib.h:90
int32_t kpc9612p_enterkiss ( kpc9612p_handle handle)
231 {
232  cssl_putstring(handle->serial, (char *)"INTFACE KISS\r");
233  cssl_putstring(handle->serial, (char *)"RESET\r");
234  return 0;
235 }
cssl_t * serial
Definition: kpc9612p_lib.h:90
int32_t cssl_putstring(cssl_t *serial, char *str)
Definition: cssl_lib.cpp:535
int32_t kpc9612p_entercmd ( kpc9612p_handle handle)
238 {
239  int32_t iretn;
240  uint8_t buffer[256];
241 
242  // Check if we are in COMMAND mode already
243  cssl_drain(handle->serial);
244  iretn = cssl_putchar(handle->serial, '\r');
245  if (iretn < 0)
246  {
247  return iretn;
248  }
249  iretn = cssl_getdata(handle->serial, buffer, 255);
250  if (iretn < 0)
251  {
252  return iretn;
253  }
254  if (iretn > 4 && !strcmp((char *)&buffer[iretn-4], "cmd:"))
255  {
256  return 0;
257  }
258  // If not, check if we are in KISS mode
259  iretn = kpc9612p_exitkiss(handle);
260  if (iretn < 0)
261  {
262  return iretn;
263  }
264  iretn = cssl_getdata(handle->serial, buffer, 255);
265  if (iretn < 0)
266  {
267  return iretn;
268  }
269  if (iretn > 4 && !strcmp((char *)&buffer[iretn-4], "cmd:"))
270  {
271  return 0;
272  }
273  // If still not, check if we are in TRANSPARENT mode
274  COSMOS_SLEEP(1.);
275  iretn = cssl_putchar(handle->serial, 0x03);
276  if (iretn < 0)
277  {
278  return iretn;
279  }
280  iretn = cssl_putchar(handle->serial, 0x03);
281  if (iretn < 0)
282  {
283  return iretn;
284  }
285  iretn = cssl_putchar(handle->serial, 0x03);
286  if (iretn < 0)
287  {
288  return iretn;
289  }
290  COSMOS_SLEEP(1.);
291  iretn = cssl_getdata(handle->serial, buffer, 255);
292  if (iretn < 0)
293  {
294  return iretn;
295  }
296  if (iretn > 4 && !strcmp((char *)&buffer[iretn-4], "cmd:"))
297  {
298  return 0;
299  }
300  // Failure
302 }
int iretn
Definition: rw_test.cpp:37
int32_t kpc9612p_exitkiss(kpc9612p_handle *handle)
Definition: kpc9612p_lib.cpp:220
static char buffer[255]
Definition: propagator_simple.cpp:60
int32_t cssl_putchar(cssl_t *serial, uint8_t c)
Definition: cssl_lib.cpp:505
cssl_t * serial
Definition: kpc9612p_lib.h:90
#define GENERAL_ERROR_UNDEFINED
Definition: cosmos-errno.h:295
int32_t cssl_getdata(cssl_t *serial, uint8_t *buffer, int size)
Definition: cssl_lib.cpp:738
int32_t cssl_drain(cssl_t *serial)
Definition: cssl_lib.cpp:685

Variable Documentation

uint16_t kpc9612p_fcstab[256]