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

MIXWTNC controller includes. More...

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

Go to the source code of this file.

Classes

struct  mixwtnc_frame
 
struct  mixwtnc_handle
 

Macros

#define MIXWTNC_MTU   254
 
#define MIXWTNC_PAYLOAD_SIZE   MIXWTNC_MTU
 
#define MIXWTNC_FULL_SIZE   (MIXWTNC_PAYLOAD_SIZE+19)
 
#define AX25_FLAG   0x7E
 
#define AX25_NOLAYER3   0xF0
 
#define MIXWTNC_ID   1
 
#define MIXWTNC_BAUD   19200
 
#define MIXWTNC_BITS   8
 
#define MIXWTNC_PARITY   0
 
#define MIXWTNC_STOPBITS   1
 

Functions

int32_t mixwtnc_connect (char *dev, mixwtnc_handle *handle, uint8_t flag)
 
int32_t mixwtnc_disconnect (mixwtnc_handle *handle)
 
int32_t mixwtnc_recvframe (mixwtnc_handle *handle)
 
int32_t mixwtnc_sendframe (mixwtnc_handle *handle)
 
int32_t mixwtnc_loadframe (mixwtnc_handle *handle, uint8_t *data, uint16_t size)
 
int32_t mixwtnc_loadframe (mixwtnc_handle *handle, vector< uint8_t > data)
 
int32_t mixwtnc_unloadframe (mixwtnc_handle *handle, uint8_t *data, uint16_t size)
 
int32_t mixwtnc_unloadframe (mixwtnc_handle *handle, vector< uint8_t > &data)
 
int32_t mixwtnc_unloadframe (mixwtnc_frame *frame, vector< uint8_t > &data)
 
uint16_t mixwtnc_calc_fcs (uint8_t *data, uint16_t length)
 
int32_t mixwtnc_exitkiss (mixwtnc_handle *handle)
 
int32_t mixwtnc_enterkiss (mixwtnc_handle *handle)
 

Detailed Description

MIXWTNC controller includes.

  • Contains definitions and functions for communicating with
  • a MixW TNC in KISS mode (where TNC auto-generates FCS!).

Macro Definition Documentation

#define MIXWTNC_MTU   254
#define MIXWTNC_PAYLOAD_SIZE   MIXWTNC_MTU
#define MIXWTNC_FULL_SIZE   (MIXWTNC_PAYLOAD_SIZE+19)
#define AX25_FLAG   0x7E
#define AX25_NOLAYER3   0xF0
#define MIXWTNC_ID   1
#define MIXWTNC_BAUD   19200
#define MIXWTNC_BITS   8
#define MIXWTNC_PARITY   0
#define MIXWTNC_STOPBITS   1

Function Documentation

int32_t mixwtnc_connect ( char *  dev,
mixwtnc_handle handle,
uint8_t  flag 
)
79 {
80  cssl_start();
82  if (handle->serial == NULL) return (CSSL_ERROR_OPEN);
83  cssl_settimeout(handle->serial, 0, .1);
84  cssl_setflowcontrol(handle->serial, 0, 0);
85  handle->flag = flag;
86 
87  return 0;
88 }
#define MIXWTNC_STOPBITS
Definition: mixwtnc_lib.h:61
#define MIXWTNC_BAUD
Definition: mixwtnc_lib.h:58
#define MIXWTNC_PARITY
Definition: mixwtnc_lib.h:60
int32_t cssl_start()
Definition: cssl_lib.cpp:73
Definition: cssl_lib.h:62
#define MIXWTNC_BITS
Definition: mixwtnc_lib.h:59
uint8_t flag
Definition: mixwtnc_lib.h:92
int32_t cssl_setflowcontrol(cssl_t *serial, int rtscts, int xonxoff)
Definition: cssl_lib.cpp:389
cssl_t * cssl_open(const char *fname, int baud, int bits, int parity, int stop)
Definition: cssl_lib.cpp:108
int32_t cssl_settimeout(cssl_t *serial, int, double timeout)
Set read timeout.
Definition: cssl_lib.cpp:469
cssl_t * serial
Definition: mixwtnc_lib.h:90
int32_t mixwtnc_disconnect ( mixwtnc_handle handle)
91 {
92  if (handle->serial == NULL) return (CSSL_ERROR_NOTSTARTED);
93 
94  cssl_close(handle->serial);
95  return 0;
96 }
Definition: cssl_lib.h:58
int32_t cssl_close(cssl_t *serial)
Definition: cssl_lib.cpp:197
cssl_t * serial
Definition: mixwtnc_lib.h:90
int32_t mixwtnc_recvframe ( mixwtnc_handle handle)
99 {
100  int32_t iretn;
101 
102  iretn = cssl_getslip(handle->serial, handle->frame.full, MIXWTNC_FULL_SIZE);
103  if (iretn >= 0)
104  {
105  handle->frame.size = iretn;
106  }
107  else
108  {
109  handle->frame.size = 0;
110  }
111 
112  return iretn;
113 }
#define MIXWTNC_FULL_SIZE
Definition: mixwtnc_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
uint16_t size
Definition: mixwtnc_lib.h:85
mixwtnc_frame frame
Definition: mixwtnc_lib.h:91
uint8_t full[(254+19)]
Definition: mixwtnc_lib.h:83
cssl_t * serial
Definition: mixwtnc_lib.h:90
int32_t mixwtnc_sendframe ( mixwtnc_handle handle)
116 {
117  int32_t iretn;
118 
119  handle->frame.part.header.flag = handle->flag;
120  iretn = cssl_putslip(handle->serial, handle->frame.full, handle->frame.size);
121 
122  return iretn;
123 }
int iretn
Definition: rw_test.cpp:37
struct mixwtnc_frame::@18::@20 part
uint8_t flag
Definition: mixwtnc_lib.h:92
uint16_t size
Definition: mixwtnc_lib.h:85
mixwtnc_frame frame
Definition: mixwtnc_lib.h:91
uint8_t full[(254+19)]
Definition: mixwtnc_lib.h:83
int32_t cssl_putslip(cssl_t *serial, uint8_t *buf, size_t size)
Definition: cssl_lib.cpp:586
cssl_t * serial
Definition: mixwtnc_lib.h:90
int32_t mixwtnc_loadframe ( mixwtnc_handle handle,
uint8_t *  data,
uint16_t  size 
)
126 {
127  uint16_t tsize; //, fcs;
128 
129  handle->frame.part.header.flag = handle->flag;
130  handle->frame.part.header.protocol_id = AX25_NOLAYER3;
131  memcpy(handle->frame.part.header.destination_address,(char *)"ABCDEFG",7);
132  memcpy(handle->frame.part.header.source_address,(char *)"GROUND ",7);
133  for (uint16_t i=0; i<7; ++i)
134  {
135  handle->frame.part.header.destination_address[i] <<= 1;
136  handle->frame.part.header.source_address[i] <<= 1;
137  }
138  tsize = (size <= MIXWTNC_PAYLOAD_SIZE?size:MIXWTNC_PAYLOAD_SIZE);
139  handle->frame.size = tsize + 17; // Modified to +17 from +19 (FCS no longer needed)
140  memcpy(handle->frame.part.payload, data, tsize);
141 
142  // No FCS required for MixW, MIXW TNC generates outgoing FCS
143  // fcs = mixwtnc_calc_fcs(data, tsize);
144  // handle->frame.part.payload[tsize] = fcs%256;
145  // handle->frame.part.payload[tsize+1] = fcs>>8;
146  // handle->frame.part.payload[tsize+2] = AX25_FLAG;
147 
148  return (tsize);
149 }
int i
Definition: rw_test.cpp:37
#define MIXWTNC_PAYLOAD_SIZE
Definition: mixwtnc_lib.h:50
struct mixwtnc_frame::@18::@20 part
uint8_t flag
Definition: mixwtnc_lib.h:92
uint16_t size
Definition: mixwtnc_lib.h:85
mixwtnc_frame frame
Definition: mixwtnc_lib.h:91
#define AX25_NOLAYER3
Definition: kisstnc_lib.h:55
int32_t mixwtnc_loadframe ( mixwtnc_handle handle,
vector< uint8_t >  data 
)
152 {
153  uint16_t tsize; //, fcs;
154 
155  handle->frame.part.header.flag = handle->flag;
156  handle->frame.part.header.protocol_id = AX25_NOLAYER3;
157  memcpy(handle->frame.part.header.destination_address,(char *)"ABCDEFG",7);
158  memcpy(handle->frame.part.header.source_address,(char *)"GROUND ",7);
159  for (uint16_t i=0; i<7; ++i)
160  {
161  handle->frame.part.header.destination_address[i] <<= 1;
162  handle->frame.part.header.source_address[i] <<= 1;
163  }
164  tsize = (data.size() <= MIXWTNC_PAYLOAD_SIZE?data.size():MIXWTNC_PAYLOAD_SIZE);
165  handle->frame.size = tsize + 17; // Modified to +17 from +19 (FCS no longer needed)
166  memcpy(handle->frame.part.payload, &data[0], tsize);
167 
168  // No FCS required for MixW, MIXW TNC generates outgoing FCS
169  // fcs = mixwtnc_calc_fcs(&data[0], tsize);
170  // handle->frame.part.payload[tsize] = fcs%256;
171  // handle->frame.part.payload[tsize+1] = fcs>>8;
172  // handle->frame.part.payload[tsize+2] = AX25_FLAG;
173 
174  return (tsize);
175 }
int i
Definition: rw_test.cpp:37
#define MIXWTNC_PAYLOAD_SIZE
Definition: mixwtnc_lib.h:50
struct mixwtnc_frame::@18::@20 part
uint8_t flag
Definition: mixwtnc_lib.h:92
uint16_t size
Definition: mixwtnc_lib.h:85
mixwtnc_frame frame
Definition: mixwtnc_lib.h:91
#define AX25_NOLAYER3
Definition: kisstnc_lib.h:55
int32_t mixwtnc_unloadframe ( mixwtnc_handle handle,
uint8_t *  data,
uint16_t  size 
)
178 {
179  uint16_t tsize;
180 
181  tsize = (handle->frame.size-17 <= maxsize?handle->frame.size-17:maxsize);
182  memcpy(data, handle->frame.part.payload, tsize);
183  data[tsize] = 0;
184  return (tsize);
185 }
struct mixwtnc_frame::@18::@20 part
uint16_t size
Definition: mixwtnc_lib.h:85
mixwtnc_frame frame
Definition: mixwtnc_lib.h:91
int32_t mixwtnc_unloadframe ( mixwtnc_handle handle,
vector< uint8_t > &  data 
)
188 {
189  uint16_t tsize;
190 
191  if (handle->frame.size >= 17)
192  {
193  tsize = handle->frame.size-17;
194  data.resize(tsize);
195  memcpy(&data[0], handle->frame.part.payload, tsize);
196  }
197  else
198  {
199  tsize = 0;
200  data.resize(tsize);
201  }
202  return (tsize);
203 }
struct mixwtnc_frame::@18::@20 part
uint16_t size
Definition: mixwtnc_lib.h:85
mixwtnc_frame frame
Definition: mixwtnc_lib.h:91
int32_t mixwtnc_unloadframe ( mixwtnc_frame frame,
vector< uint8_t > &  data 
)
206 {
207  uint16_t tsize;
208 
209  if (frame->size >= 17)
210  {
211  tsize = frame->size-17;
212  data.resize(tsize);
213  memcpy(&data[0], frame->part.payload, tsize);
214  }
215  else
216  {
217  tsize = 0;
218  data.resize(tsize);
219  }
220  return (tsize);
221 }
struct mixwtnc_frame::@18::@20 part
uint16_t size
Definition: mixwtnc_lib.h:85
uint16_t mixwtnc_calc_fcs ( uint8_t *  data,
uint16_t  length 
)
68 { uint16_t fcs;
69 
70  fcs = 0xffff;
71  while (length--)
72  { fcs = (fcs >> 8) ^ mixw_fcstab[(fcs ^ ((uint16_t)*data)) & 0xff];
73  data++;
74  }
75  return (~fcs);
76 }
uint16_t mixw_fcstab[256]
Definition: mixwtnc_lib.cpp:32
png_uint_32 length
Definition: png.c:2173
int32_t mixwtnc_exitkiss ( mixwtnc_handle handle)
224 {
225  cssl_putchar(handle->serial, 0xc0);
226  cssl_putchar(handle->serial, 0xff);
227  cssl_putchar(handle->serial, 0xc0);
228  return 0;
229 }
int32_t cssl_putchar(cssl_t *serial, uint8_t c)
Definition: cssl_lib.cpp:505
cssl_t * serial
Definition: mixwtnc_lib.h:90
int32_t mixwtnc_enterkiss ( mixwtnc_handle handle)
232 {
233  cssl_putstring(handle->serial, (char *)"INTFACE KISS\r");
234  cssl_putstring(handle->serial, (char *)"RESET\r");
235  return 0;
236 }
int32_t cssl_putstring(cssl_t *serial, char *str)
Definition: cssl_lib.cpp:535
cssl_t * serial
Definition: mixwtnc_lib.h:90