Gsm0710Mux Class Reference

GSM port multiplexer class. More...

#include <Gsm0710Mux.h>

List of all members.

Public Member Functions

 Gsm0710Mux ()
 Class constructor.
virtual ~Gsm0710Mux ()
 Class destructor.
bool startMux (const char *physicalPort, const char **muxPorts)
 Start port multiplexer.
bool stopMux ()
 Stop port multiplexer.

Protected Types

enum  StopType { STOPTYPE_NONE, STOPTYPE_NORMAL, STOPTYPE_SKIP_MODEM_CLEANUP }

Protected Member Functions

virtual void run ()
 Starts the multiplexer thread Starts the multiplexer thread, initializes the multiplexer, allocates the GSM 07.10 buffer and runs polling event loop.
bool initMux ()
 Initialize multiplexer Initializes the multiplexer by sending the appropriate AT commands and prepares the control channel and logical channels.
bool openPhysicalPort (const char *port)
 Opens the modem physical serial port Opens the serial port of the physical modem device.
bool openVirtualPort (int portNumber)
 Opens the virtual port Opens the specified virtual serial port.
bool closeVirtualPort (int portNumber)
 Closes the virtual port Closes the specified virtual port.
bool sendAT (const char *cmd, int tout)
 Send the appropriate AT command Sends the AT commands to physical modem device.
bool isOutputReady (int fd, int timeOut)
 Detect if the output file descriptor is ready or not Determines if the output file descriptor is ready or not within the timeOut period.
int getPendingFds (int *readyFds, int timeout)
 Get opened file descriptors Get the list of opened file descriptors within timeout.
size_t handleVirtualData (unsigned char *buf, size_t count, int port)
 Get the data from virtual port Read the data up to count from virtual port and write it to the buffer buf.
size_t handleSerialFrames (Gsm0710Buffer &inBuf, StopType &stopRequest)
 Handle data frames stored in buffer Handle frames stored GSM 07.10 buffer.
void handleCommand (Gsm0710Frame *pFrame, StopType &stopRequest)
 Handle command retrieved from frame Handle the command stored in the GSM 07.10 frame.
size_t writeToPhysical (int channel, unsigned char *input, size_t count, unsigned char type)
 Write data to physical port Writes data to the modem device physical port.
size_t writeToVirtual (unsigned char *buf, size_t count, int channel)
 Write data to virtual port Writes data into multiplexer virtual port.
void handlePhysicalInput (Gsm0710Buffer &inBuf, StopType &stopRequest)
 Handle data from physical modem device Handles data coming from physical modem device and stored in GSM 07.10 buffer.
void handleVirtualInput (int fd)
 Handle data coming from virtual input device Handles the data stored in virtual input device.

Protected Attributes

int muxedPortNum
int muxedPortHandles [VIRTUAL_PORTS_MAX]
char muxedPortMaster [VIRTUAL_PORTS_MAX][VIRTUAL_PATH_LEN]
int physicalHandle
char physicalPath [VIRTUAL_PATH_LEN]
VIRTUAL_CHANNEL channelState [VIRTUAL_PORTS_MAX+1]
Mutex mutex

Detailed Description

GSM port multiplexer class.

Implements the GSM 07.10 serial port multiplexer protocol. The class creates multiple serial ports that physically operate on a single serial port of the GPRS modem. The multiplexer class manages an internal worker thread that translates virtual serial port communication.

The port multiplexer is a power management aware class. When the mobile data terminal is suspended to a low power state, the port multiplexer is properly de-initialized to prepare the GPRS module for power saving.


Member Enumeration Documentation

enum Gsm0710Mux::StopType [protected]

Stopping types that can be requested

Enumerator:
STOPTYPE_NONE 

No stop requested

STOPTYPE_NORMAL 

Requested normal stop (with modem cleanup)

STOPTYPE_SKIP_MODEM_CLEANUP 

Requested stop without modem cleanup


Constructor & Destructor Documentation

Gsm0710Mux::Gsm0710Mux (  ) 

Class constructor.

Initializes the GSM serial port multiplexer object.

Gsm0710Mux::~Gsm0710Mux (  )  [virtual]

Class destructor.

Terminates the GSM serial port multiplexer object.


Member Function Documentation

bool Gsm0710Mux::closeVirtualPort ( int  portNumber  )  [protected]

Closes the virtual port Closes the specified virtual port.

Parameters:
portNumber Virtual port number to close
Returns:
Returns true if virtual port was closed successfully, false otherwise
int Gsm0710Mux::getPendingFds ( int *  readyFds,
int  timeout 
) [protected]

Get opened file descriptors Get the list of opened file descriptors within timeout.

Parameters:
readyFds Pointer to array where to store the available file descriptors
timeout Number of milliseconds the polling function will wait for file descriptor to be ready
Note:
If timeout is 0, there is no waiting. If timeout is -1, the polling request blocks until the event occurs.
Returns:
Returns number of file descriptor stored in readyFds
void Gsm0710Mux::handleCommand ( Gsm0710Frame pFrame,
StopType stopRequest 
) [protected]

Handle command retrieved from frame Handle the command stored in the GSM 07.10 frame.

Parameters:
pFrame Pointer to the frame that will be processed
stopRequest Stop type flag requested to process
void Gsm0710Mux::handlePhysicalInput ( Gsm0710Buffer inBuf,
StopType stopRequest 
) [protected]

Handle data from physical modem device Handles data coming from physical modem device and stored in GSM 07.10 buffer.

Parameters:
inBuf Address of the GSM 07.10 buffer where the data is stored
stopRequest Stop type flag requested to process
size_t Gsm0710Mux::handleSerialFrames ( Gsm0710Buffer inBuf,
StopType stopRequest 
) [protected]

Handle data frames stored in buffer Handle frames stored GSM 07.10 buffer.

Parameters:
inBuf Address of the buffer where the frames are stored
stopRequest Stop type flag requested to process
Returns:
Returns the number of frames extracted
size_t Gsm0710Mux::handleVirtualData ( unsigned char *  buf,
size_t  count,
int  port 
) [protected]

Get the data from virtual port Read the data up to count from virtual port and write it to the buffer buf.

Parameters:
buf Pointer to the buffer to store virtual data
count Buffer size
port Virtual port number to read data from
Returns:
Returns number of bytes written to the buffer
void Gsm0710Mux::handleVirtualInput ( int  fd  )  [protected]

Handle data coming from virtual input device Handles the data stored in virtual input device.

Parameters:
fd File descriptor to the virtual input device where the data is stored
bool Gsm0710Mux::initMux (  )  [protected]

Initialize multiplexer Initializes the multiplexer by sending the appropriate AT commands and prepares the control channel and logical channels.

Returns:
Returns true if initialization was successful, false otherwise
bool Gsm0710Mux::isOutputReady ( int  fd,
int  timeOut 
) [protected]

Detect if the output file descriptor is ready or not Determines if the output file descriptor is ready or not within the timeOut period.

Parameters:
fd File descriptor that is polled
timeOut Timeout in milliseconds the polling waits the file descriptor to be ready
Note:
If timeout is 0, there is no waiting. If timeout is -1, the polling request blocks until the event occurs.
Returns:
Returns true if the file descriptor is ready, false otherwise
bool Gsm0710Mux::openPhysicalPort ( const char *  port  )  [protected]

Opens the modem physical serial port Opens the serial port of the physical modem device.

Parameters:
port Pointer to the null-terminated string with port name
Returns:
Returns true if the physical port was opened successfully
bool Gsm0710Mux::openVirtualPort ( int  portNumber  )  [protected]

Opens the virtual port Opens the specified virtual serial port.

Parameters:
portNumber Virtual port number to open
Returns:
Returns true if virtual port was opened successfully, false otherwise
bool Gsm0710Mux::sendAT ( const char *  cmd,
int  tout 
) [protected]

Send the appropriate AT command Sends the AT commands to physical modem device.

Parameters:
cmd Pointer to null-terminated command being sent
tout Timeout for waiting the command to be processed
Note:
If timeout is 0, there is no waiting. If timeout is -1, the polling request blocks until the event occurs.
Returns:
Returns true if command was accepted, false otherwise
bool Gsm0710Mux::startMux ( const char *  physicalPort,
const char **  muxPorts 
)

Start port multiplexer.

Initializes and launches the serial port multiplexer. The GPRS module must be properly initialized before calling the multiplexer. Prior initialization must include the following steps.

  • Power up the module
  • Serial port setup
  • Initial handshake over serial port

The above procedure is implemented by following classes.

The virtual serial ports created by the multiplexer are accessible via /dev/ttyp0...ttyp3 devices. The opposite ends of these serial pipes must be passed to the multiplexer as a parameter, /dev/ptyp0...ptyp3.

Parameters:
physicalPort Points to the null-terminated string containing the name of the modem physical serial port.
muxPorts Points to a null-terminated array of null-terminated strings containing the names of the virtual serial ports. The application should specify at least one port.
Returns:
Returns true if the port multiplexer was started successfully.
bool Gsm0710Mux::stopMux (  ) 

Stop port multiplexer.

Stops the GSM serial port multiplexer and releases working thread. All virtual ports are closed, further communication is not possible.

Returns:
Returns true if the multiplexer was stopped successfully.
size_t Gsm0710Mux::writeToPhysical ( int  channel,
unsigned char *  input,
size_t  count,
unsigned char  type 
) [protected]

Write data to physical port Writes data to the modem device physical port.

Parameters:
channel Channel number that will be used for data transmission
input Data being sent
count Data length
type Frame type to be sent
Returns:
Returns number of bytes written
size_t Gsm0710Mux::writeToVirtual ( unsigned char *  buf,
size_t  count,
int  channel 
) [protected]

Write data to virtual port Writes data into multiplexer virtual port.

Parameters:
buf Pointer to buffer that contains data being written
count Buffer length
channel Channel number where to send the data
Returns:
Returns number of bytes written

Member Data Documentation

VIRTUAL_CHANNEL Gsm0710Mux::channelState[VIRTUAL_PORTS_MAX+1] [protected]

Array of virtual channel states

Mutex Gsm0710Mux::mutex [protected]

Mutex to protect the multiplexer thread

int Gsm0710Mux::muxedPortHandles[VIRTUAL_PORTS_MAX] [protected]

Array of handles for initialized multiplexer ports

char Gsm0710Mux::muxedPortMaster[VIRTUAL_PORTS_MAX][VIRTUAL_PATH_LEN] [protected]

Array of names for initialized multiplexer ports

int Gsm0710Mux::muxedPortNum [protected]

Number of initialized multiplexer ports

int Gsm0710Mux::physicalHandle [protected]

Handle to the physical modem port

char Gsm0710Mux::physicalPath[VIRTUAL_PATH_LEN] [protected]

Name of the physical modem port


The documentation for this class was generated from the following files:
Generated on Wed Oct 20 11:13:44 2010 for libspatha by  doxygen 1.6.3