#include <pcomm.h>
Public Members | |||
PComm (char *pcrDev, tcflag_t baudRate=B9600, const char *name=0) | |||
The PComm Constructor. More... | |||
~PComm () | |||
The PComm Destructor. More... | |||
bool | PCOpen (const char *pcrDev=PCRDEV, tcflag_t baudRate=B9600) | ||
Opens another file descriptor to the serial device. More... | |||
void | PCClose () | ||
Closes the currently active file descriptor. More... | |||
size_pc | PCTell (char *) | ||
Issue a command string to the radio. More... | |||
size_pc | PCAsk (char *) | ||
Issue a status request from the radio. More... | |||
size_pc | PCHear (char *) | ||
Receive a repsonse from the radio. More... | |||
size_pc | PCRawWrite (char *) | ||
writes directly to the current socket. More... | |||
size_pc | PCRawRead (char *) | ||
reads directly from the current socket. More... | |||
Private Members | |||
size_pc | Write (char *) | ||
Internal function to write to the socket. More... | |||
size_pc | Read (char *) | ||
Internal function to read from the socket. More... | |||
void | resetCall () | ||
resets the radio and port. More... | |||
void | countCall () | ||
function to keep track on the number of calls. More... | |||
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. |
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.
PComm::PComm (char * pcrDev, tcflag_t baudRate = B9600, const char * name = 0) |
The PComm Constructor.
pcrDev | name of device to be opened (char string) |
baudRate | speed of device to be opened |
name |
internal object name (for your use)
|
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.
PComm::PCOpen (const char * pcrDev = PCRDEV, tcflag_t baudRate = B9600) |
Opens another file descriptor to the serial device.
pcrDev | Serial port device to be opened. |
baudRate |
Initial serial speed.
|
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.
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.
PComm::PCTell (char * mesg) |
Issue a command string to the radio.
mesg |
command string from pcrdef.h.
|
PComm::PCAsk (char * mesg) |
Issue a status request from the radio.
mesg |
a query command string
|
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.
PComm::PCHear (char * mesg) |
Receive a repsonse from the radio.
mesg |
a character string long enough to hold a reply
|
If the radio kept spitting out LF chars, it checks for the err bool.
PComm::PCRawWrite (char * mesg) |
writes directly to the current socket.
mesg |
the character string which it will write
|
PComm::PCRawRead (char * mesg) |
reads directly from the current socket.
mesg |
malloc'd char string big enough to hold a reply
|
PComm::Write (char * submesg) [private]
|
Internal function to write to the socket.
submesg |
character string to write out to
|
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.
PComm::Read (char * submesg) [private]
|
Internal function to read from the socket.
submesg |
a character string long enough to hold data
|
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.
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.
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.
int PComm::callCount [private]
|
char PComm::callBuf[256] [private]
|
struct timeval* PComm::timeOut [private]
|
fd_set* PComm::FDSet [private]
|
int PComm::retVal [private]
|
struct termios* PComm::oldtio [private]
|
struct termios* PComm::newtio [private]
|
int PComm::fd [private]
|
char PComm::pcrDevice[256] [private]
|
tcflag_t PComm::pcrSpeed [private]
|
bool PComm::errRead [private]
|
bool PComm::errWrite [private]
|
char PComm::askBuf[256] [private]
|
char PComm::hearBuf[256] [private]
|
char PComm::writeBuf[256] [private]
|
char PComm::readBuf[256] [private]
|
char PComm::int_name[256] [private]
|
size_pc PComm::writeCtr [private]
|
size_pc PComm::readCtr [private]
|
size_pc PComm::askCtr [private]
|
size_pc PComm::tellCtr [private]
|
size_pc PComm::hearCtr [private]
|