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.

SerialPipe.cpp

Committer:
mazgch
Date:
2013-11-14
Revision:
11:b084552b03fe
Parent:
9:e7a5959ffae1
Child:
12:684b31d5482b

File content as of revision 11:b084552b03fe:

#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);
}

SerialPipe::~SerialPipe(void)
{
    attach(NULL, RxIrq);
    attach(NULL, TxIrq);
}

// tx channel
int SerialPipe::put(const char* b, int n, bool t)    
{ 
    int c = n;
    while (c && t)
    {
        int i = _pipeTx.put(b, c, false);
        b += i;
        c -= i;
        // give a chance to start tx
        __disable_irq();
        txIrqBuf();
        __enable_irq();
    }
    return (n - c);
}

void SerialPipe::txIrqBuf(void)
{
    while (serial_writable(&_serial) && _pipeTx.readable())
    {
        char ch = _pipeTx.getc();
        serial_putc(&_serial, ch);
    }
}

// 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())
            _pipeRx.putc(ch);
        else 
            /* 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 = _pipeRx.next();
        i ++;
        if (t == '\r')     // terminate commands with carriage return
        {
             _pipeRx.done();
             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;
}