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

Functions

uint16_t kisstnc_calc_fcs (uint8_t *data, uint16_t length)
 
int32_t kisstnc_connect (char *dev, kisstnc_handle *handle, uint8_t flag)
 
int32_t kisstnc_disconnect (kisstnc_handle *handle)
 
int32_t kisstnc_recvframe (kisstnc_handle *handle)
 
int32_t kisstnc_sendframe (kisstnc_handle *handle)
 
int32_t kisstnc_loadframe (kisstnc_handle *handle, uint8_t *data, uint16_t size)
 
int32_t kisstnc_loadframe (kisstnc_handle *handle, vector< uint8_t > data)
 
int32_t kisstnc_unloadframe (kisstnc_handle *handle, uint8_t *data, uint16_t size)
 
int32_t kisstnc_unloadframe (kisstnc_handle *handle, vector< uint8_t > &data)
 
int32_t kisstnc_exitkiss (kisstnc_handle *handle)
 
int32_t kisstnc_enterkiss (kisstnc_handle *handle)
 

Variables

uint16_t kisstnc_fcstab [256]
 

Function Documentation

uint16_t kisstnc_calc_fcs ( uint8_t *  data,
uint16_t  length 
)
68 { uint16_t fcs;
69 
70  fcs = 0xffff;
71  while (length--)
72  { fcs = (fcs >> 8) ^ kisstnc_fcstab[(fcs ^ ((uint16_t)*data)) & 0xff];
73  data++;
74  }
75  return (~fcs);
76 }
uint16_t kisstnc_fcstab[256]
Definition: kisstnc_lib.cpp:32
png_uint_32 length
Definition: png.c:2173
int32_t kisstnc_connect ( char *  dev,
kisstnc_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 KISSTNC_BAUD
Definition: kisstnc_lib.h:58
#define KISSTNC_BITS
Definition: kisstnc_lib.h:59
int32_t cssl_start()
Definition: cssl_lib.cpp:73
Definition: cssl_lib.h:62
int32_t cssl_setflowcontrol(cssl_t *serial, int rtscts, int xonxoff)
Definition: cssl_lib.cpp:389
uint8_t flag
Definition: kisstnc_lib.h:92
cssl_t * cssl_open(const char *fname, int baud, int bits, int parity, int stop)
Definition: cssl_lib.cpp:108
#define KISSTNC_PARITY
Definition: kisstnc_lib.h:60
int32_t cssl_settimeout(cssl_t *serial, int, double timeout)
Set read timeout.
Definition: cssl_lib.cpp:469
cssl_t * serial
Definition: kisstnc_lib.h:90
#define KISSTNC_STOPBITS
Definition: kisstnc_lib.h:61
int32_t kisstnc_disconnect ( kisstnc_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: kisstnc_lib.h:90
int32_t kisstnc_recvframe ( kisstnc_handle handle)
99 {
100  int32_t iretn;
101 
102  iretn = cssl_getslip(handle->serial, handle->frame.full, KISSTNC_FULL_SIZE);
103  if (iretn >= 0)
104  {
105 // int16_t ch = cssl_getchar(handle->serial);
106 // ch = cssl_getchar(handle->serial);
107  handle->frame.size = iretn;
108  }
109  else
110  {
111  handle->frame.size = 0;
112  }
113 
114  return iretn;
115 }
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: kisstnc_lib.h:85
uint8_t full[(254+19)]
Definition: kisstnc_lib.h:83
kisstnc_frame frame
Definition: kisstnc_lib.h:91
#define KISSTNC_FULL_SIZE
Definition: kisstnc_lib.h:53
cssl_t * serial
Definition: kisstnc_lib.h:90
int32_t kisstnc_sendframe ( kisstnc_handle handle)
118 {
119  int32_t iretn;
120 
121  handle->frame.part.header.flag = handle->flag;
122  iretn = cssl_putslip(handle->serial, handle->frame.full, handle->frame.size);
123 
124  return iretn;
125 }
struct kisstnc_frame::@6::@8 part
int iretn
Definition: rw_test.cpp:37
uint16_t size
Definition: kisstnc_lib.h:85
uint8_t full[(254+19)]
Definition: kisstnc_lib.h:83
uint8_t flag
Definition: kisstnc_lib.h:92
kisstnc_frame frame
Definition: kisstnc_lib.h:91
int32_t cssl_putslip(cssl_t *serial, uint8_t *buf, size_t size)
Definition: cssl_lib.cpp:586
cssl_t * serial
Definition: kisstnc_lib.h:90
int32_t kisstnc_loadframe ( kisstnc_handle handle,
uint8_t *  data,
uint16_t  size 
)
128 {
129  uint16_t tsize; //, fcs;
130 
131  handle->frame.part.header.flag = handle->flag;
132  handle->frame.part.header.protocol_id = AX25_NOLAYER3;
133  memcpy(handle->frame.part.header.destination_address,(char *)"ABCDEFG",7);
134  memcpy(handle->frame.part.header.source_address,(char *)"GROUND ",7);
135  for (uint16_t i=0; i<7; ++i)
136  {
137  handle->frame.part.header.destination_address[i] <<= 1;
138  handle->frame.part.header.source_address[i] <<= 1;
139  }
140  tsize = (size <= KISSTNC_PAYLOAD_SIZE?size:KISSTNC_PAYLOAD_SIZE);
141  handle->frame.size = tsize + 17; // Modified to +17 from +19 (FCS no longer needed)
142  memcpy(handle->frame.part.payload, data, tsize);
143 
144  // fcs = kisstnc_calc_fcs(data, tsize);
145 // handle->frame.part.payload[tsize] = fcs%256;
146 // handle->frame.part.payload[tsize+1] = fcs>>8;
147  // handle->frame.part.payload[tsize+2] = AX25_FLAG;
148 
149  return (tsize);
150 }
struct kisstnc_frame::@6::@8 part
int i
Definition: rw_test.cpp:37
uint16_t size
Definition: kisstnc_lib.h:85
#define KISSTNC_PAYLOAD_SIZE
Definition: kisstnc_lib.h:50
uint8_t flag
Definition: kisstnc_lib.h:92
#define AX25_NOLAYER3
Definition: kisstnc_lib.h:55
kisstnc_frame frame
Definition: kisstnc_lib.h:91
int32_t kisstnc_loadframe ( kisstnc_handle handle,
vector< uint8_t >  data 
)
153 {
154  uint16_t tsize; //, fcs;
155 
156  handle->frame.part.header.flag = handle->flag;
157  handle->frame.part.header.protocol_id = AX25_NOLAYER3;
158  memcpy(handle->frame.part.header.destination_address,(char *)"ABCDEFG",7);
159  memcpy(handle->frame.part.header.source_address,(char *)"GROUND ",7);
160  for (uint16_t i=0; i<7; ++i)
161  {
162  handle->frame.part.header.destination_address[i] <<= 1;
163  handle->frame.part.header.source_address[i] <<= 1;
164  }
165  tsize = (data.size() <= KISSTNC_PAYLOAD_SIZE?data.size():KISSTNC_PAYLOAD_SIZE);
166  handle->frame.size = tsize + 17; // Modified to +17 from +19 (FCS no longer needed)
167  memcpy(handle->frame.part.payload, &data[0], tsize);
168 
169 // fcs = kisstnc_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 }
struct kisstnc_frame::@6::@8 part
int i
Definition: rw_test.cpp:37
uint16_t size
Definition: kisstnc_lib.h:85
#define KISSTNC_PAYLOAD_SIZE
Definition: kisstnc_lib.h:50
uint8_t flag
Definition: kisstnc_lib.h:92
#define AX25_NOLAYER3
Definition: kisstnc_lib.h:55
kisstnc_frame frame
Definition: kisstnc_lib.h:91
int32_t kisstnc_unloadframe ( kisstnc_handle handle,
uint8_t *  data,
uint16_t  size 
)
178 {
179  uint16_t tsize;
180 
181  tsize = (handle->frame.size-17 <= size?handle->frame.size-17:size);
182  memcpy(data, handle->frame.part.payload, tsize);
183  data[tsize] = 0;
184  return (tsize);
185 }
struct kisstnc_frame::@6::@8 part
uint16_t size
Definition: kisstnc_lib.h:85
kisstnc_frame frame
Definition: kisstnc_lib.h:91
int32_t kisstnc_unloadframe ( kisstnc_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 kisstnc_frame::@6::@8 part
uint16_t size
Definition: kisstnc_lib.h:85
kisstnc_frame frame
Definition: kisstnc_lib.h:91
int32_t kisstnc_exitkiss ( kisstnc_handle handle)
206 {
207  cssl_putchar(handle->serial, 0xc0);
208  cssl_putchar(handle->serial, 0xff);
209  cssl_putchar(handle->serial, 0xc0);
210  return 0;
211 }
int32_t cssl_putchar(cssl_t *serial, uint8_t c)
Definition: cssl_lib.cpp:505
cssl_t * serial
Definition: kisstnc_lib.h:90
int32_t kisstnc_enterkiss ( kisstnc_handle handle)
214 {
215  cssl_putstring(handle->serial, (char *)"INTFACE KISS\r");
216  cssl_putstring(handle->serial, (char *)"RESET\r");
217  return 0;
218 }
int32_t cssl_putstring(cssl_t *serial, char *str)
Definition: cssl_lib.cpp:535
cssl_t * serial
Definition: kisstnc_lib.h:90

Variable Documentation

uint16_t kisstnc_fcstab[256]