cornelluniversity::vetserial::base_command Class Reference

A pure virtual abstraction which serves as the basis of the vet serial protocol command structure. More...

#include <vetprot.h>

Inheritance diagram for cornelluniversity::vetserial::base_command:

cornelluniversity::vetserial::control_request cornelluniversity::vetserial::mp3_play_request cornelluniversity::vetserial::mp3_stop_request cornelluniversity::vetserial::status_request cornelluniversity::vetserial::status_response List of all members.

Public Member Functions

 base_command (const cmnd_id cid)
 constructor The object must be initialized with a COMMAND_ID
 base_command (const uint8_ *in_pkt, uint32_ nbytes)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Constructor overloaded for receiving packets rather than creating one.
virtual ~base_command (void)
 Destructor; frees any dynamic memory that was used in during the objects life cycle (two internal buffers).
const uint8_packet (void) const
 Internal packet buffer accessor.
const int packet_size (void) const
 Accessor for the internall managed buffer byte count (i.e.
const uint8_ flags (void) const
 Accessor to the packet flags byte (the full bit field).
void set_flag (const uint8_ f)
 mutator for the packet flags byte; enables one or more flags by ORing in the supplied parameter into the current value.
void clr_flag (const flag_t f)
 Toggles off a single bit in the flags bit field.
bool flag_enabled (const flag_t f) const
 Determines if a single flag within the flags byte is enabled or not.
void error_code (const err_code id)
 mutator for the packet error code byte; Sets the byte to a supplied ERROR_CODE defined value.
const err_code error_code (void) const
 accessor to the packet error code byte.
void data_id (const uint8_ id)
 mutator for the internally stored data-id field.
const unsigned char data_id (void) const
 accessor to the internally stored data-id field.
void payload_size (const uint16_ sz)
 mutator for the internally stored payload size field.
const uint16_ payload_size (void) const
 accessor of the internally stored payload size field.
virtual void execute (void)=0
 pure virtual function that must be over-ridden in all objects inheriting from base_command.

Static Public Attributes

static const unsigned int PKT_HEADER_SZ
static const unsigned int PKT_TAIL_SZ
static const unsigned int PKT_MAX_SZ

Protected Member Functions

uint16_ crc16 (const uint8_ *indata, const uint32_ nbytes)
 generates the CCITT CRC 16 polynomial X^16 + X^12 + X^5 + 1
bool verify_crc16 (const uint8_ *full_packet, const uint32_ nbytes)
 validates the accuracy of a supplied packet against its included CRC(s) pass the FULL packet, the routine will determine what validations to perform.
void header (void)
 When called, this will reinitialize the internal buffers, essentially wiping out any previous data.
void tail (const uint8_ *payload, const uint32_ payload_sz=0)
 Appends a protocol defined trailer to the end of the packet currently in the interal buffer.

Protected Attributes

uint8_buffer_
uint8_packet_
uint32_ buffersz_
uint32_ pktsz_

Detailed Description

A pure virtual abstraction which serves as the basis of the vet serial protocol command structure.

This handles packet management, dissecting incoming packets or creating new ones as needed. How the packets are assembled is determined in the pure virtual function execute() which must be over-ridden by any class inheriting from base_command.

Definition at line 134 of file vetprot.h.


Constructor & Destructor Documentation

cornelluniversity::vetserial::base_command::base_command ( const cmnd_id  cid  ) 

constructor The object must be initialized with a COMMAND_ID

Parameters:
cid - the COMMAND_ID defined command being initialized
See also:
COMMAND_ID

base_command(const uint8_ * in_pkt, uint32_ nbytes)

cornelluniversity::vetserial::base_command::base_command ( const uint8_ in_pkt,
uint32_  nbytes 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Constructor overloaded for receiving packets rather than creating one.

Parameters:
in_pkt - pointer to a unisigned char array that comprises an in-coming protocol conforming packet
nbytes - the size of the packet in bytes
Exceptions:
cornelluniversity::vetexcept data out-of-bounds
cornelluniversity::vetexcept NULLPTR encountered where data is required
std::bad_alloc standard memory allocation failure
See also:
base_command(const cmnd_id cid)


Member Function Documentation

void cornelluniversity::vetserial::base_command::clr_flag ( const flag_t  f  )  [inline]

Toggles off a single bit in the flags bit field.

Parameters:
f - FLAG_TYPE defined value of the bit to be disabled
See also:
FLAG_TYPE

Definition at line 187 of file vetprot.h.

uint16_ cornelluniversity::vetserial::base_command::crc16 ( const uint8_ indata,
const uint32_  nbytes 
) [protected]

generates the CCITT CRC 16 polynomial X^16 + X^12 + X^5 + 1

Parameters:
indata - pointer to an unsigned char based c-style string
nbytes - int size of the indata array
Returns:
unsigned short - 16 bit integer making up the CRC of the supplied byte string
Exceptions:
cornelluniversity::vetexcept NULLPTR encountered where data is required

const unsigned char cornelluniversity::vetserial::base_command::data_id ( void   )  const [inline]

accessor to the internally stored data-id field.

Returns:
unsigned char - the 8 bit integer currently stored in the packet
See also:
void data_id(const uint8_ id)

Definition at line 219 of file vetprot.h.

void cornelluniversity::vetserial::base_command::data_id ( const uint8_  id  )  [inline]

mutator for the internally stored data-id field.

This fields value is arbitrary and supplied to support debugging and more advanced packet tracking schemes. The value of the Id is limited to 8-bit values.

Parameters:
id - 8 bit integer to be stored in the packet

Definition at line 213 of file vetprot.h.

const err_code cornelluniversity::vetserial::base_command::error_code ( void   )  const [inline]

accessor to the packet error code byte.

Returns:
ERROR_CODE - a defined error id
See also:
ERROR_CODE

Definition at line 206 of file vetprot.h.

void cornelluniversity::vetserial::base_command::error_code ( const err_code  id  )  [inline]

mutator for the packet error code byte; Sets the byte to a supplied ERROR_CODE defined value.

Parameters:
id - ERROR_CODE defined error id
See also:
ERROR_CODE

Definition at line 200 of file vetprot.h.

virtual void cornelluniversity::vetserial::base_command::execute ( void   )  [pure virtual]

pure virtual function that must be over-ridden in all objects inheriting from base_command.

This function should be developed to implement the assembly (or dissection if necessary) of packets for the command in question. The end result should be to have a fully formed packet in buffer_ (for outgoing) or for an incoming packet parsed into its appropriate members.

Implemented in cornelluniversity::vetserial::control_request, cornelluniversity::vetserial::status_request, cornelluniversity::vetserial::status_response, cornelluniversity::vetserial::mp3_play_request, and cornelluniversity::vetserial::mp3_stop_request.

bool cornelluniversity::vetserial::base_command::flag_enabled ( const flag_t  f  )  const [inline]

Determines if a single flag within the flags byte is enabled or not.

Parameters:
f - FLAG_TYPE defined value of the bit to interrogate
Returns:
bool - true if enabled, false otherwise
See also:
FLAG_TYPE

Definition at line 194 of file vetprot.h.

const uint8_ cornelluniversity::vetserial::base_command::flags ( void   )  const [inline]

Accessor to the packet flags byte (the full bit field).

Returns:
const unsigned char - flags bit field

Definition at line 176 of file vetprot.h.

void cornelluniversity::vetserial::base_command::header ( void   )  [protected]

When called, this will reinitialize the internal buffers, essentially wiping out any previous data.

The 10-byte packet header is then rebuilt based on the current values stored in the objects private members. The header is left in the buffer for you to use or append additional data.

Exceptions:
cornelluniversity::vetexcept data out-of-bounds
std::bad_alloc standard memory allocation failure

const uint8_* cornelluniversity::vetserial::base_command::packet ( void   )  const [inline]

Internal packet buffer accessor.

The intrnal buffer is where new packets are managed.

Returns:
unsigned char * - complete packet ready for delivery

Definition at line 166 of file vetprot.h.

const int cornelluniversity::vetserial::base_command::packet_size ( void   )  const [inline]

Accessor for the internall managed buffer byte count (i.e.

packet size).

Returns:
const int number of bytes in the currently stored out-going packet

Definition at line 171 of file vetprot.h.

const uint16_ cornelluniversity::vetserial::base_command::payload_size ( void   )  const [inline]

accessor of the internally stored payload size field.

The payload size is the size of the packet minus header and trailer.

Returns:
unsigned short - 16 bit integer indicating the byte size of the packets data payload

Definition at line 231 of file vetprot.h.

void cornelluniversity::vetserial::base_command::payload_size ( const uint16_  sz  )  [inline]

mutator for the internally stored payload size field.

The payload size is the size of the packet minus header and trailer.

Parameters:
sz - 16 bit integer indicating the byte size of the packets data payload

Definition at line 225 of file vetprot.h.

void cornelluniversity::vetserial::base_command::set_flag ( const uint8_  f  )  [inline]

mutator for the packet flags byte; enables one or more flags by ORing in the supplied parameter into the current value.

Parameters:
f - unsigned char flag(s) to be enabled

Definition at line 181 of file vetprot.h.

void cornelluniversity::vetserial::base_command::tail ( const uint8_ payload,
const uint32_  payload_sz = 0 
) [protected]

Appends a protocol defined trailer to the end of the packet currently in the interal buffer.

This routine does not question the contents of the buffer, it simply appends three additional bytes. Two of those bytes are the CRC checksum for the data payload, so you'll have to pass those (payload) bytes into this routine.

Parameters:
payload - pointer to an unsigned char based c-style string that comprises the data payload (and oly the payload, no part of the header should be included)
payload_sz - (optional) int size of the payload array. Because this value is stored internally for header purposes, you can ignore the second argument and the value in the appropriate private member will be used instead.
Exceptions:
cornelluniversity::vetexcept data out-of-bounds
cornelluniversity::vetexcept NULLPTR encountered where data is required
Warning:
there must be three (3) bytes of free space in the buffer

bool cornelluniversity::vetserial::base_command::verify_crc16 ( const uint8_ full_packet,
const uint32_  nbytes 
) [protected]

validates the accuracy of a supplied packet against its included CRC(s) pass the FULL packet, the routine will determine what validations to perform.

In the case of just a header being present, this routine will return after that check. If the packet also has a data payload, the this routine will return only after validating both CRCs. Both must be valid for the routine to return true.

Parameters:
indata - pointer to an unsigned char based c-style string
nbytes - int size of the indata array
Returns:
bool - true is CRC is valid, false otherwise
Exceptions:
cornelluniversity::vetexcept data out-of-bounds
cornelluniversity::vetexcept NULLPTR encountered where data is required
std::bad_alloc standard memory allocation failure


Member Data Documentation

uint8_* cornelluniversity::vetserial::base_command::buffer_ [protected]

internal memory for building new packets

Definition at line 242 of file vetprot.h.

uint32_ cornelluniversity::vetserial::base_command::buffersz_ [protected]

byte count of any built packet

Definition at line 244 of file vetprot.h.

uint8_* cornelluniversity::vetserial::base_command::packet_ [protected]

raw data storage for imported packets

Definition at line 243 of file vetprot.h.

const unsigned int cornelluniversity::vetserial::base_command::PKT_HEADER_SZ [static]

byte count of a packet's header structure

Definition at line 136 of file vetprot.h.

const unsigned int cornelluniversity::vetserial::base_command::PKT_MAX_SZ [static]

miximum allowable byte count of any complete packet

Definition at line 138 of file vetprot.h.

const unsigned int cornelluniversity::vetserial::base_command::PKT_TAIL_SZ [static]

byte count of a packet's tail (trailer) structure

Definition at line 137 of file vetprot.h.

uint32_ cornelluniversity::vetserial::base_command::pktsz_ [protected]

byte count of any imported packet

Definition at line 245 of file vetprot.h.


The documentation for this class was generated from the following file:
Generated on Thu Sep 27 11:11:48 2012 for VetSim by  doxygen 1.4.7