support library for C027 helper functions for Buffer Pipes, Buffered Serial Port (rtos capable) and GPS parsing. It includes modem APIs for USSD, SMS and Sockets.

Dependents:   HTTPClient_Cellular_HelloWorld Cellular_HelloMQTT MbedSmartRestMain Car_Bon_car_module ... more

This library is intended to be used with u-blox products such as the C027 or a shield with u-blox cellular and GPS modules like the cellular and positioning shield from Embedded Artist.

For 2G/GSM and 3G/UMTS you need to:

  • have a SIM card and know its PIN number
  • need to know you network operators APN setting These setting should be passed to the connect or init and join functions. You can also extend the APN database in MDMAPN.h.

For CDMA products you need to make sure that you have provisioned and activated the modem with either Sprint or Verizon.



File content as of revision 9:e7a5959ffae1:

#pragma once 

#include "SerialPipe.h"

SerialPipe::SerialPipe(PinName tx, PinName rx, int rxSize, int txSize, const char* name) 
    : Serial(tx,rx,name), _pipeRx(rxSize), _pipeTx(txSize)
    attach(this, &SerialPipe::rxIrqBuf, RxIrq);
    attach(this, &SerialPipe::txIrqBuf, TxIrq);

    attach(NULL, RxIrq);
    attach(NULL, TxIrq);

// tx channel
int SerialPipe::put(const char* b, int s, bool t)    
    int c = 0;
    while (s && t)
        c += _pipeTx.put(b, s, false);
        b ++;
        s --;
        // give a chance to start tx
    return c;

void SerialPipe::txIrqBuf(void)
    while (serial_writable(&_serial) && _pipeTx.readable())
        serial_putc(&_serial, _pipeTx.getc());

// rx channel
int SerialPipe::readable(void)                      
    return _pipeRx.readable(); 

int SerialPipe::getc(void)                          
    return _pipeRx.getc(); 

int SerialPipe::get(char* b, int s, bool t) 
    return _pipeRx.get(b,s,t); 

void SerialPipe::rxIrqBuf(void)
    while (serial_readable(&_serial))
        char ch = serial_getc(&_serial);
        if (_pipeRx.writeable())
            /* overflow */;

// -----------------------------------------------------------------------

SerialPipeEx::SerialPipeEx(PinName tx, PinName rx, int rxSize, int txSize, const char* name) 
    : SerialPipe(tx,rx,rxSize,txSize,name)

int SerialPipeEx::getLine(char* b, int s)
    int o = 0;
    int i = 0;
    int l = _pipeRx.start();
    while ((i < l) && (o < s))
        int t =;
        i ++;
        if (t == '\r')     // terminate commands with carriage return
             return o;          // if enter send the zero char
        else if (t == '\n')     // skip/filter new line 
             /* skip */;
        else if (t != '\b')     // normal char (no backspace)
            b[o++] = t;
        else if (o > 0)         // backspace
            o --;               // remove it
    o = 0;
    return WAIT;