man pcomm (Fonctions bibliothèques) - The Primitive Communications Object.

NAME

PComm - The Primitive Communications Object.

SYNOPSIS



#include <pcomm.h>

Public Members

PComm (char *pcrDev, tcflag_t baudRate=B9600, const char *name=0)

The PComm Constructor.

~PComm ()

The PComm Destructor.

bool PCOpen (const char *pcrDev=PCRDEV, tcflag_t baudRate=B9600)

Opens another file descriptor to the serial device.

void PCClose ()

Closes the currently active file descriptor.

size_pc PCTell (char *)

Issue a command string to the radio.

size_pc PCAsk (char *)

Issue a status request from the radio.

size_pc PCHear (char *)

Receive a repsonse from the radio.

size_pc PCRawWrite (char *)

writes directly to the current socket.

size_pc PCRawRead (char *)

reads directly from the current socket.

Private Members

size_pc Write (char *)

Internal function to write to the socket.

size_pc Read (char *)

Internal function to read from the socket.

void resetCall ()

resets the radio and port.

void countCall ()

function to keep track on the number of calls.

int callCount

Counter for number of times the radio has been written to.

char callBuf [256]

Internal buffer for radio reset.

struct timeval* timeOut

Used in the select for timeout(s).

fd_set* FDSet

Socket set used in the select.

int retVal

Select()'s return value.

struct termios* oldtio

Stores the port's original settings.

struct termios* newtio

Port settings to be applied for current session.

int fd

Socket descriptor used for current session.

char pcrDevice [256]

Current serial/comm device.

tcflag_t pcrSpeed

Current baud rate.

bool errRead

Was there an error reading?

bool errWrite

Was there an error writing?

char askBuf [256]

Buffer for sending data in PCAsk.

char hearBuf [256]

Buffer for receiving data in PCHear.

char writeBuf [256]

Buffer for writing data used in wrapper Write().

char readBuf [256]

Buffer for reading data used in wrapper Read().

char int_name [256]

Internal object name. Warning: not necessarily populated.

size_pc writeCtr

Send bytecount used in wrapper function Write().

size_pc readCtr

Receive bytecount used in wrapper function Read().

size_pc askCtr

Receive bytecount used in PCAsk.

size_pc tellCtr

Send bytecount used in PCTell.

size_pc hearCtr

Receive bytecount used in PCHear.

DETAILED DESCRIPTION

The Primitive Communications Object.

PComm object is the serial i/o object. It facilitates the low level grunt work for reading and writing to the serial device(s). It handles the string manipulation necessary for communication with the radio.

Definition at line 47 of file pcomm.h.

MEMBER FUNCTION DOCUMENTATION

PComm::PComm (char * pcrDev, tcflag_t baudRate = B9600, const char * name = 0)

The PComm Constructor.

Parameters:

pcrDev name of device to be opened (char string)
baudRate speed of device to be opened
name internal object name (for your use)

This is the easiest way to open the serial device for communications with the radio. If the serial device cannot be opened for processing the object will abort with a -1 status code to the operating system.

You must send it at least the device name which is to be opened as the first argument. Optionally, you can send it an initial baudrate and an internal object name.

PComm::~PComm ()

The PComm Destructor.

Destroys the object, and closes any open file descriptors to the serial device. It also restores any old (initial) settings to the serial device.

Definition at line 62 of file pcomm.cpp.

PComm::PCOpen (const char * pcrDev = PCRDEV, tcflag_t baudRate = B9600)

Opens another file descriptor to the serial device.

Parameters:

pcrDev Serial port device to be opened.
baudRate Initial serial speed.

Opens a file descriptor to the device pcrDev (which is by default your system's PCRDEV define) at the speed baudRate (which is by default as delinated in your termios.h set to 9600 baud).

Warning: You can only call this as long as the object is alive. If you do destry the object remember to call this function only after setting up the port configuration correctly.

Returns: true or false based on success value.

Definition at line 79 of file pcomm.cpp.

PComm::PCClose ()

Closes the currently active file descriptor.

Used in conjunction with PCOpen(...) so that you can release and regain the socket after an initialization procedure.

Definition at line 173 of file pcomm.cpp.

PComm::PCTell (char * mesg)

Issue a command string to the radio.

Parameters:

mesg command string from pcrdef.h.

Sends a command to the radio via the custom made wrapper function Write() . This doesnt really alter the message at all for reading and writing to the radio.

Returns: number of bytes actually written gets returned, or (-1) on error.

See also: pcrdef.h

Definition at line 194 of file pcomm.cpp.

PComm::PCAsk (char * mesg)

Issue a status request from the radio.

Parameters:

mesg a query command string

This function makes sure that mesg isnt empty, as well as making sure that mesg is two bytes long. Any queries sent to the radio should be the header of the information requested to be returned.

It then zero's out the ask buffer, and copies the message into the ask buffer. Then it concatenates the PCRQST command terminator, and calls Write() sending it the ask buffer.

Returns: the number of bytes asked minus the PCRQST command terminator.

See also: PCRQST() pcrdef.h

Definition at line 217 of file pcomm.cpp.

PComm::PCHear (char * mesg)

Receive a repsonse from the radio.

Parameters:

mesg a character string long enough to hold a reply

This function makes sure that mesg is pointing to a valid address (ie: is malloc'd) then it zero's out the message string and hearBuffer. It then calls Read()... remembering the number of bytes read, it cuts out the end-of-command marker read in (CR-LF) and copies what it heard into the message string.

If the radio kept spitting out LF chars, it checks for the err bool.

Returns: the number of bytes read, or -1 on err.

See also: pcrdef.h

Definition at line 251 of file pcomm.cpp.

PComm::PCRawWrite (char * mesg)

writes directly to the current socket.

Parameters:

mesg the character string which it will write

Sends a command directly to the socket without any preprocessing

Returns: number of bytes actually written

See also: pcrdef.h PCRawRead(char *mesg)

Definition at line 304 of file pcomm.cpp.

PComm::PCRawRead (char * mesg)

reads directly from the current socket.

Parameters:

mesg malloc'd char string big enough to hold a reply

Reads directly from the socket without any preprocessing

Returns: number of bytes read.

See also: pcrdef.h PCRawWrite(char *mesg)

Definition at line 337 of file pcomm.cpp.

PComm::Write (char * submesg) [private]

Internal function to write to the socket.

Parameters:

submesg character string to write out to

sends a command to the radio/socket.

It zero's out the internal class's write buffer, and copies the message passed in called submesg into the write buffer. It appends the special end-of-command marker to the write buffer, and exec's write(). Select() is used to see if we are ready to write to the socket in the FDSet.

Returns: what was actually written minus two. Since the minus two is to account for the end-of-command marker. On error we return -2

See also: Read()

Definition at line 370 of file pcomm.cpp.

PComm::Read (char * submesg) [private]

Internal function to read from the socket.

Parameters:

submesg a character string long enough to hold data

It reset's the read counter, and loopbreaker. The read counter keeps track of the number of bytes read in. The loop breaker makes sure that read doesnt get stuck reading New Lines from the radio for ever and ever. Since we are ignoring newlines when we read. The radio has a tendency of sending newlines even when it has nothing to say.

it executes read() into the internal variable read buffer, and increments the loop breaker. If the number of bytes read is greater than 1, then some useful data was read in... no need to re-loop. When good data is read, it is copied into the submesg string from the read buffer. Select() will determine if the socket in FDSet is ready to read data.

Returns: If after five times, the read() read in anything less than 1, then break, and set errRead to true, while returning the number of bytes read. If after five seconds fd says that it's still not ready, then it will return, setting the read counter to a negative value.

See also: Write()

Definition at line 416 of file pcomm.cpp.

PComm::resetCall () [private]

resets the radio and port.

This function reset's the radio and the port when called. It is necessary to reset the radio after a certain number of read() and write()'s. In this case we have made it after 200 write() calls.

It closes the port, and reopens the port. Zero's out the call buffer, and copy's the poweron/ecmd command strings into the call buffer. It then select()'s to see if we are ready to write to the buffer. After which it writes to the radio to tell it, that we are back online and want it to come up. Then it bzero's the call buffer and reads what the radio has to say. It loops in that mode if it received only one character of data (the radio likes to send nothing but newlines sometimes) AND the number of loops is less than 10. We dont want to get stuck there.

Warning: this function is necessary for the radio to operate properly under the manual update mode. If you override this function make sure to run the radio in auto-update mode.

See also: countCall()

Definition at line 496 of file pcomm.cpp.

PComm::countCall () [private]

function to keep track on the number of calls.

this function keeps track of the number of calls that were sent to the radio before the last reset. it calls resetCall() every 200 calls, otherwise it increments the call count.

See also: resetCall()

Definition at line 564 of file pcomm.cpp.

MEMBER DATA DOCUMENTATION

int PComm::callCount [private]

Counter for number of times the radio has been written to.

Definition at line 68 of file pcomm.h.

char PComm::callBuf[256] [private]

Internal buffer for radio reset.

Definition at line 70 of file pcomm.h.

struct timeval* PComm::timeOut [private]

Used in the select for timeout(s).

Definition at line 73 of file pcomm.h.

fd_set* PComm::FDSet [private]

Socket set used in the select.

Definition at line 75 of file pcomm.h.

int PComm::retVal [private]

Select()'s return value.

Definition at line 77 of file pcomm.h.

struct termios* PComm::oldtio [private]

Stores the port's original settings.

Definition at line 79 of file pcomm.h.

struct termios* PComm::newtio [private]

Port settings to be applied for current session.

Definition at line 81 of file pcomm.h.

int PComm::fd [private]

Socket descriptor used for current session.

Definition at line 83 of file pcomm.h.

char PComm::pcrDevice[256] [private]

Current serial/comm device.

Definition at line 85 of file pcomm.h.

tcflag_t PComm::pcrSpeed [private]

Current baud rate.

Definition at line 87 of file pcomm.h.

bool PComm::errRead [private]

Was there an error reading?

Definition at line 90 of file pcomm.h.

bool PComm::errWrite [private]

Was there an error writing?

Definition at line 92 of file pcomm.h.

char PComm::askBuf[256] [private]

Buffer for sending data in PCAsk.

Definition at line 94 of file pcomm.h.

char PComm::hearBuf[256] [private]

Buffer for receiving data in PCHear.

Definition at line 96 of file pcomm.h.

char PComm::writeBuf[256] [private]

Buffer for writing data used in wrapper Write().

Definition at line 98 of file pcomm.h.

char PComm::readBuf[256] [private]

Buffer for reading data used in wrapper Read().

Definition at line 100 of file pcomm.h.

char PComm::int_name[256] [private]

Internal object name. Warning: not necessarily populated.

Definition at line 102 of file pcomm.h.

size_pc PComm::writeCtr [private]

Send bytecount used in wrapper function Write().

Definition at line 104 of file pcomm.h.

size_pc PComm::readCtr [private]

Receive bytecount used in wrapper function Read().

Definition at line 106 of file pcomm.h.

size_pc PComm::askCtr [private]

Receive bytecount used in PCAsk.

Definition at line 108 of file pcomm.h.

size_pc PComm::tellCtr [private]

Send bytecount used in PCTell.

Definition at line 110 of file pcomm.h.

size_pc PComm::hearCtr [private]

Receive bytecount used in PCHear.

Definition at line 112 of file pcomm.h.

AUTHOR

Generated automatically by Doxygen for Icom PCR-1000 Library from the source code.