COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
kisslib.h File Reference
#include "support/configCosmos.h"
#include "support/cosmos-errno.h"
#include "support/sliplib.h"
#include <cstring>
#include <iostream>
Include dependency graph for kisslib.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  KissHandle
 
struct  KissHandle::packet_content
 

Macros

#define PACKETMAX   1024
 

Functions

int kissEncode (uint8_t *input, uint32_t count, uint8_t *packet)
 
int kissDecode (uint8_t *kissed_input, uint32_t count, uint8_t *unload_packetd_payload)
 
int kissDecode (vector< uint8_t > kissed_input, KissHandle &handle)
 
KissHandle kissInspect (const unsigned char *input)
 
void print_ascii (unsigned char *packet, unsigned int count)
 
void print_hex (unsigned char *packet, unsigned int count)
 

Macro Definition Documentation

#define PACKETMAX   1024

Function Documentation

int kissEncode ( uint8_t *  input,
uint32_t  count,
uint8_t *  packet 
)
184 {
185  uint32_t payload_bytes = 0;
186 
187  //If payload is over 255 bytes indicate an error
188  if(count > 255)
189  {
190  printf("Error: Limit input to 255 8-bit character bytes\n");
191  return -1;
192  }
193 
194 //Build Packet Header
195 
196  //Frame End (1 Byte)
197  *packet = SLIP_FEND;
198  //Port number and command type (1Byte)
199  *(packet+1) = 0x10;
200  //Destination call sign(6Bytes)
201  *(packet+2) = ('W' << 1);
202  *(packet+3) = ('H' << 1);
203  *(packet+4) = ('7' << 1);
204  *(packet+5) = ('L' << 1);
205  *(packet+6) = ('G' << 1);
206  *(packet+7) = (0x20 << 1);
207  //Destination station ID (1Byte)
208  *(packet+8) = 0X60;
209  //Source call sign (6Bytes)
210  *(packet+9) = ('W' << 1);
211  *(packet+10) = ('H' << 1);
212  *(packet+11) = ('7' << 1);
213  *(packet+12) = ('L' << 1);
214  *(packet+13) = ('E' << 1);
215  *(packet+14) = (0x20 << 1);
216  //Source station ID (1Byte)
217  *(packet+15) = 0x61;
218  //Control(1Byte)
219  *(packet+16) = 0X31;
220  //Protocol ID (1Byte)
221  *(packet+17) = 0xF0; // 0xF0 = No layer 3 protocol
222 
223  packet += 18;
224 
225  for(uint32_t i=0; i<count; i++)
226  {
227  // Replace FEND with FESC TFEND
228  if (input[i] == SLIP_FEND)
229  {
230  *packet++ = SLIP_FESC;
231  *packet++ = SLIP_TFEND;
232  payload_bytes += 2; // Advance Payload Data Count 2 Bytes
233  }
234  // Replace FESC with FESC TFESC
235  else if (input[i] == SLIP_FESC)
236  {
237  *packet++ = SLIP_FESC;
238  *packet++ = SLIP_TFESC;
239  payload_bytes += 2; // Advance Payload Data Count 2 Bytes
240  }
241  // Copy Input
242  else
243  {
244  *packet++ = input[i];
245  payload_bytes++; // Advance Payload Data Count 1 Byte
246  }
247  }
248 
249  //Placing final frame-end
250  *packet= SLIP_FEND;
251 
252  //Keeping track of the count (payload bytes + header bytes + trailer)
253  payload_bytes += 19;
254 
255  return payload_bytes;
256 }
int i
Definition: rw_test.cpp:37
int count
Definition: rw_test.cpp:36
#define SLIP_FESC
SLIP Buffer Escape character.
Definition: sliplib.h:60
#define SLIP_TFEND
SLIP Buffer Escaped End character.
Definition: sliplib.h:64
#define SLIP_FEND
SLIP Buffer End character.
Definition: sliplib.h:56
#define SLIP_TFESC
SLIP Buffer Escaped Escape character.
Definition: sliplib.h:68
int kissDecode ( uint8_t *  kissed_input,
uint32_t  count,
uint8_t *  unload_packetd_payload 
)

Encoded payload will act as an intermediate packet holding the load_packetd data.

Frame end appended to packet after all the header is removed.

392 {
393  uint32_t i = 0;
394  uint32_t j = 0;
395  uint8_t load_packetd_payload[PACKETMAX];
396 
398  //It will be used to hold the load_packetd data while being decoding.
399  for(i=18; kissed_input[i] != SLIP_FEND; i++) // FEND = FEND
400  {
401  j = i - 18; // pointer to 0 in intermediate
402  load_packetd_payload[j] = kissed_input[i];
403  }
404 
406  //We do this to pinpoint where we can stop the decoding process.
407  load_packetd_payload[j+1]= SLIP_FEND;
408 
409 
410  //check the read in data
411  i = 0;
412  j = 0;
413 
414  for(;j <= PACKETMAX;)
415  {
416  //Function will return i once the appended FEND is read in
417  if(load_packetd_payload[j] == SLIP_FEND)
418  return i;
419 
420  if(load_packetd_payload[j] == SLIP_FESC) //if FESC
421  {
422  if(load_packetd_payload[j+1] == SLIP_TFEND) // Check for TFEND
423  {
424  load_packetd_payload[j] = SLIP_FEND;
425  unload_packetd_payload[i] = load_packetd_payload[j];
426  j+=2;
427  i++;
428  }
429 
430  else if(load_packetd_payload[j+1] == SLIP_TFESC) // Check for TFESC
431  {
432  load_packetd_payload[j] = SLIP_FESC;
433  unload_packetd_payload[i] = load_packetd_payload[j];
434  j+=2;
435  i++;
436  }
437 
438  else
439  {
440  printf("Invalid Transpose Error!!!\n"); //Error occurred if TFEND or TFESC does not follow a FESC
441  }
442  }
443 
444  else
445  {
446  unload_packetd_payload[i] = load_packetd_payload[j];
447  j++;
448  i++;
449  }
450  }
451 
452  return 0;
453 }
int i
Definition: rw_test.cpp:37
#define SLIP_FESC
SLIP Buffer Escape character.
Definition: sliplib.h:60
#define SLIP_TFEND
SLIP Buffer Escaped End character.
Definition: sliplib.h:64
#define SLIP_FEND
SLIP Buffer End character.
Definition: sliplib.h:56
#define PACKETMAX
Definition: ax25class.h:39
#define SLIP_TFESC
SLIP Buffer Escaped Escape character.
Definition: sliplib.h:68
int kissDecode ( vector< uint8_t >  kissed_input,
KissHandle handle 
)
KissHandle kissInspect ( const unsigned char *  input)
316  {
317 
318  //fill me up with goodness
319  KissHandle KKK;
320 
321 // uint8_t port_command;
322  unsigned char destination_call_sign[6];
323  uint8_t destination_station_id;//Changed this to an array of [1]
324  unsigned char source_call_sign[6];
325  uint8_t source_station_id;//changed this to an array of [1]
326  uint8_t control_id;//changed this to an array of [1]
327  uint8_t protocol_id;//changed this to an array of [1]
328 
329 
330  // First character of input is always FEND
331  // The next 17 characters we are interested in...
332 // port_command = input[1];
333  destination_station_id = input[8];
334  source_station_id = input[15];
335  control_id = input[16];
336  protocol_id = input[17];
337 
338 
339  //Extract destination call sign
340  //printf("Destination Call Sign = ");
341  for(int i=2;i<=7;i++)
342  {
343  destination_call_sign[i-2] = input[i] >> 1;
344  //printf("%c", destination_call_sign[i-2]);
345  }
346  //Copying destination callsign into KissHandle
347  KKK.set_destination_callsign((const char*) destination_call_sign);
348  //strcpy((char *)KKK.header.destination_callsign, (const char *) destination_call_sign);
349 
350  //Copying destination callsign ID into KissHandle
351  KKK.set_destination_stationID((uint8_t) destination_station_id);
352  //KKK.header.destination_stationID = destination_station_id;
353 
354  //printf("\n");
355 
356  //Extract source call sign
357  //printf("Source Call Sign = ");
358  for(int i=9;i<=14;i++)
359  {
360  source_call_sign[i-9] = input[i] >> 1;
361  //printf("%c", source_call_sign[i-9]);
362  }
363  //Copying source callsign into KissHandle
364  KKK.set_source_callsign((const char*) source_call_sign);
365  //strcpy((char *)KKK.header.source_callsign, (const char *) source_call_sign);
366 
367  //Copying source station ID into KissHandle
368  KKK.set_source_stationID((uint8_t) source_station_id);
369  //KKK.header.source_stationID = source_station_id;
370 
371  //Copying control into KissHandle
372  KKK.set_control((uint8_t) control_id);
373  //KKK.header.control = control_id;
374 
375  //Copying protocol ID into KissHandle
376  KKK.set_protocolID((uint8_t) protocol_id);
377  //KKK.header.protocolID = protocol_id;
378 
379 
380  //printf("\n");
381 
382  //printf("control id: %d", control_id[0]);
383  //printf("protocol id: %d", protocol_id[0]);
384 
385  return KKK;
386 }
int i
Definition: rw_test.cpp:37
void set_source_callsign(string source)
Definition: kisslib.cpp:106
void set_source_stationID(uint8_t ID)
Definition: kisslib.cpp:132
void set_protocolID(uint8_t protocol)
Definition: kisslib.cpp:154
void set_destination_callsign(string destination)
Definition: kisslib.cpp:69
Definition: kisslib.h:48
void set_control(uint8_t control_number)
Definition: kisslib.cpp:143
void set_destination_stationID(uint8_t ID)
Definition: kisslib.cpp:95
void print_ascii ( unsigned char *  packet,
unsigned int  count 
)
void print_hex ( unsigned char *  packet,
unsigned int  count 
)