GSM port multiplexer class. More...
#include <Gsm0710Mux.h>
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 |
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.
enum Gsm0710Mux::StopType [protected] |
Gsm0710Mux::Gsm0710Mux | ( | ) |
Class constructor.
Initializes the GSM serial port multiplexer object.
Gsm0710Mux::~Gsm0710Mux | ( | ) | [virtual] |
Class destructor.
Terminates the GSM serial port multiplexer object.
bool Gsm0710Mux::closeVirtualPort | ( | int | portNumber | ) | [protected] |
Closes the virtual port Closes the specified virtual port.
portNumber | Virtual port number to close |
int Gsm0710Mux::getPendingFds | ( | int * | readyFds, | |
int | timeout | |||
) | [protected] |
Get opened file descriptors Get the list of opened file descriptors within timeout.
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 |
void Gsm0710Mux::handleCommand | ( | Gsm0710Frame * | pFrame, | |
StopType & | stopRequest | |||
) | [protected] |
Handle command retrieved from frame Handle the command stored in the GSM 07.10 frame.
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.
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.
inBuf | Address of the buffer where the frames are stored | |
stopRequest | Stop type flag requested to process |
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.
buf | Pointer to the buffer to store virtual data | |
count | Buffer size | |
port | Virtual port number to read data from |
void Gsm0710Mux::handleVirtualInput | ( | int | fd | ) | [protected] |
Handle data coming from virtual input device Handles the data stored in virtual input device.
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.
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.
fd | File descriptor that is polled | |
timeOut | Timeout in milliseconds the polling waits the file descriptor to be ready |
bool Gsm0710Mux::openPhysicalPort | ( | const char * | port | ) | [protected] |
Opens the modem physical serial port Opens the serial port of the physical modem device.
port | Pointer to the null-terminated string with port name |
bool Gsm0710Mux::openVirtualPort | ( | int | portNumber | ) | [protected] |
Opens the virtual port Opens the specified virtual serial port.
portNumber | Virtual port number to open |
bool Gsm0710Mux::sendAT | ( | const char * | cmd, | |
int | tout | |||
) | [protected] |
Send the appropriate AT command Sends the AT commands to physical modem device.
cmd | Pointer to null-terminated command being sent | |
tout | Timeout for waiting the command to be processed |
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.
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.
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. |
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.
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.
channel | Channel number that will be used for data transmission | |
input | Data being sent | |
count | Data length | |
type | Frame type to be sent |
size_t Gsm0710Mux::writeToVirtual | ( | unsigned char * | buf, | |
size_t | count, | |||
int | channel | |||
) | [protected] |
Write data to virtual port Writes data into multiplexer virtual port.
buf | Pointer to buffer that contains data being written | |
count | Buffer length | |
channel | Channel number where to send the data |
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