C027_SupportTest_xively_locationで使用しているC027用ライブラリ

Fork of C027_Support by u-blox

下記のプログラムC027_SupportTest_xively_locationで使用しているC027用ライブラリです。

Import programC027_SupportTest_xively_location

インターフェース2014年10月号のu-blox C027で3G通信する記事で使用したプログラム。   CQ publishing Interface 2014.10 issue, C027 3G test program.

オリジナルのライブラリは下記を参照してください。

Import libraryC027_Support

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.

Committer:
mazgch
Date:
Fri Jan 31 09:49:51 2014 +0000
Revision:
17:296d94a006b4
Parent:
16:4a7ba1887e81
Child:
18:e5697801df29
update with flow apis

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mazgch 9:e7a5959ffae1 1 #pragma once
mazgch 9:e7a5959ffae1 2
mazgch 9:e7a5959ffae1 3 #include "SerialPipe.h"
mazgch 9:e7a5959ffae1 4
mazgch 15:5eda64e5b9d1 5 SerialPipe::SerialPipe(PinName tx, PinName rx, int rxSize, int txSize)
mazgch 15:5eda64e5b9d1 6 : _SerialPipeBase(tx,rx), _pipeRx(rxSize), _pipeTx(txSize)
mazgch 9:e7a5959ffae1 7 {
mazgch 9:e7a5959ffae1 8 attach(this, &SerialPipe::rxIrqBuf, RxIrq);
mazgch 9:e7a5959ffae1 9 attach(this, &SerialPipe::txIrqBuf, TxIrq);
mazgch 9:e7a5959ffae1 10 }
mazgch 9:e7a5959ffae1 11
mazgch 17:296d94a006b4 12 SerialPipe::SerialPipe(PinName tx, PinName rx, PinName rts, PinName cts,
mazgch 17:296d94a006b4 13 int rxSize, int txSize)
mazgch 17:296d94a006b4 14 : _SerialPipeBase(tx,rx), _pipeRx(rxSize), _pipeTx(txSize)
mazgch 17:296d94a006b4 15 {
mazgch 17:296d94a006b4 16 attach(this, &SerialPipe::rxIrqBuf, RxIrq);
mazgch 17:296d94a006b4 17 attach(this, &SerialPipe::txIrqBuf, TxIrq);
mazgch 17:296d94a006b4 18
mazgch 17:296d94a006b4 19 set_flow_control(RTSCTS, rts, cts);
mazgch 17:296d94a006b4 20 }
mazgch 17:296d94a006b4 21
mazgch 9:e7a5959ffae1 22 SerialPipe::~SerialPipe(void)
mazgch 9:e7a5959ffae1 23 {
mazgch 9:e7a5959ffae1 24 attach(NULL, RxIrq);
mazgch 9:e7a5959ffae1 25 attach(NULL, TxIrq);
mazgch 9:e7a5959ffae1 26 }
mazgch 9:e7a5959ffae1 27
mazgch 9:e7a5959ffae1 28 // tx channel
mazgch 13:e2446fcdc246 29 int SerialPipe::writeable(void)
mazgch 13:e2446fcdc246 30 {
mazgch 13:e2446fcdc246 31 return _pipeTx.free();
mazgch 13:e2446fcdc246 32 }
mazgch 13:e2446fcdc246 33
mazgch 13:e2446fcdc246 34 int SerialPipe::putc(int c)
mazgch 13:e2446fcdc246 35 {
mazgch 15:5eda64e5b9d1 36 c = _pipeTx.putc(c);
mazgch 15:5eda64e5b9d1 37 txStart();
mazgch 15:5eda64e5b9d1 38 return c;
mazgch 13:e2446fcdc246 39 }
mazgch 13:e2446fcdc246 40
mazgch 13:e2446fcdc246 41 int SerialPipe::put(const void* buffer, int length, bool blocking)
mazgch 9:e7a5959ffae1 42 {
mazgch 13:e2446fcdc246 43 int count = length;
mazgch 13:e2446fcdc246 44 const char* ptr = (const char*)buffer;
mazgch 15:5eda64e5b9d1 45 if (count)
mazgch 9:e7a5959ffae1 46 {
mazgch 15:5eda64e5b9d1 47 do
mazgch 15:5eda64e5b9d1 48 {
mazgch 15:5eda64e5b9d1 49 int written = _pipeTx.put(ptr, count, false);
mazgch 15:5eda64e5b9d1 50 ptr += written;
mazgch 15:5eda64e5b9d1 51 count -= written;
mazgch 15:5eda64e5b9d1 52 txStart();
mazgch 15:5eda64e5b9d1 53 }
mazgch 15:5eda64e5b9d1 54 while (count && blocking);
mazgch 9:e7a5959ffae1 55 }
mazgch 13:e2446fcdc246 56 return (length - count);
mazgch 13:e2446fcdc246 57 }
mazgch 13:e2446fcdc246 58
mazgch 9:e7a5959ffae1 59 void SerialPipe::txIrqBuf(void)
mazgch 9:e7a5959ffae1 60 {
mazgch 15:5eda64e5b9d1 61 while (_SerialPipeBase::writeable() && _pipeTx.readable())
mazgch 11:b084552b03fe 62 {
mazgch 13:e2446fcdc246 63 char c = _pipeTx.getc();
mazgch 15:5eda64e5b9d1 64 _SerialPipeBase::_base_putc(c);
mazgch 11:b084552b03fe 65 }
mazgch 9:e7a5959ffae1 66 }
mazgch 9:e7a5959ffae1 67
mazgch 13:e2446fcdc246 68 void SerialPipe::txStart(void)
mazgch 13:e2446fcdc246 69 {
mazgch 13:e2446fcdc246 70 __disable_irq();
mazgch 13:e2446fcdc246 71 txIrqBuf();
mazgch 13:e2446fcdc246 72 __enable_irq();
mazgch 13:e2446fcdc246 73 }
mazgch 13:e2446fcdc246 74
mazgch 9:e7a5959ffae1 75 // rx channel
mazgch 9:e7a5959ffae1 76 int SerialPipe::readable(void)
mazgch 9:e7a5959ffae1 77 {
mazgch 9:e7a5959ffae1 78 return _pipeRx.readable();
mazgch 9:e7a5959ffae1 79 }
mazgch 9:e7a5959ffae1 80
mazgch 9:e7a5959ffae1 81 int SerialPipe::getc(void)
mazgch 9:e7a5959ffae1 82 {
mazgch 15:5eda64e5b9d1 83 if (!_pipeRx.readable())
mazgch 15:5eda64e5b9d1 84 return EOF;
mazgch 15:5eda64e5b9d1 85 return _pipeRx.getc();
mazgch 13:e2446fcdc246 86 }
mazgch 13:e2446fcdc246 87
mazgch 13:e2446fcdc246 88 int SerialPipe::get(void* buffer, int length, bool blocking)
mazgch 13:e2446fcdc246 89 {
mazgch 13:e2446fcdc246 90 return _pipeRx.get((char*)buffer,length,blocking);
mazgch 13:e2446fcdc246 91 }
mazgch 13:e2446fcdc246 92
mazgch 9:e7a5959ffae1 93 void SerialPipe::rxIrqBuf(void)
mazgch 9:e7a5959ffae1 94 {
mazgch 15:5eda64e5b9d1 95 while (_SerialPipeBase::readable())
mazgch 9:e7a5959ffae1 96 {
mazgch 15:5eda64e5b9d1 97 char c = _SerialPipeBase::_base_getc();
mazgch 9:e7a5959ffae1 98 if (_pipeRx.writeable())
mazgch 13:e2446fcdc246 99 _pipeRx.putc(c);
mazgch 9:e7a5959ffae1 100 else
mazgch 9:e7a5959ffae1 101 /* overflow */;
mazgch 9:e7a5959ffae1 102 }
mazgch 9:e7a5959ffae1 103 }
mazgch 9:e7a5959ffae1 104
mazgch 9:e7a5959ffae1 105 // -----------------------------------------------------------------------
mazgch 9:e7a5959ffae1 106
mazgch 13:e2446fcdc246 107 int SerialPipeEx::getLine(char* buffer, int length)
mazgch 9:e7a5959ffae1 108 {
mazgch 14:69c3e57ef0f5 109 return getLine(buffer, length, &_pipeRx);
mazgch 14:69c3e57ef0f5 110 }
mazgch 14:69c3e57ef0f5 111
mazgch 14:69c3e57ef0f5 112 int SerialPipeEx::getLine(char* buffer, int length, Pipe<char>* pipe)
mazgch 14:69c3e57ef0f5 113 {
mazgch 9:e7a5959ffae1 114 int o = 0;
mazgch 9:e7a5959ffae1 115 int i = 0;
mazgch 14:69c3e57ef0f5 116 int l = pipe->start();
mazgch 13:e2446fcdc246 117 while ((i < l) && (o < length))
mazgch 9:e7a5959ffae1 118 {
mazgch 14:69c3e57ef0f5 119 int t = pipe->next();
mazgch 9:e7a5959ffae1 120 i ++;
mazgch 9:e7a5959ffae1 121 if (t == '\r') // terminate commands with carriage return
mazgch 9:e7a5959ffae1 122 {
mazgch 14:69c3e57ef0f5 123 pipe->done();
mazgch 13:e2446fcdc246 124 if (length > o)
mazgch 13:e2446fcdc246 125 buffer[o] = '\0';
mazgch 12:684b31d5482b 126 return o; // if enter send the zero char
mazgch 9:e7a5959ffae1 127 }
mazgch 9:e7a5959ffae1 128 else if (t == '\n') // skip/filter new line
mazgch 9:e7a5959ffae1 129 /* skip */;
mazgch 9:e7a5959ffae1 130 else if (t != '\b') // normal char (no backspace)
mazgch 13:e2446fcdc246 131 buffer[o++] = t;
mazgch 9:e7a5959ffae1 132 else if (o > 0) // backspace
mazgch 9:e7a5959ffae1 133 o --; // remove it
mazgch 9:e7a5959ffae1 134 }
mazgch 9:e7a5959ffae1 135 o = 0;
mazgch 13:e2446fcdc246 136 if (length > 0)
mazgch 13:e2446fcdc246 137 buffer[0] = '\0';
mazgch 9:e7a5959ffae1 138 return WAIT;
mazgch 9:e7a5959ffae1 139 }
mazgch 16:4a7ba1887e81 140
mazgch 16:4a7ba1887e81 141 int SerialPipeEx::getResp(char* buffer, int length)
mazgch 16:4a7ba1887e81 142 {
mazgch 16:4a7ba1887e81 143 return getResp(buffer, length, &_pipeRx);
mazgch 16:4a7ba1887e81 144 }
mazgch 16:4a7ba1887e81 145
mazgch 16:4a7ba1887e81 146 int SerialPipeEx::getResp(char* buffer, int length, Pipe<char>* pipe)
mazgch 16:4a7ba1887e81 147 {
mazgch 16:4a7ba1887e81 148 int o = 0;
mazgch 16:4a7ba1887e81 149 int i = 0;
mazgch 16:4a7ba1887e81 150 int l = pipe->start();
mazgch 16:4a7ba1887e81 151 static const char erTxt[] = "ERROR\r\n";
mazgch 16:4a7ba1887e81 152 static const char okTxt[] = "OK\r\n";
mazgch 16:4a7ba1887e81 153 int er = 0;
mazgch 16:4a7ba1887e81 154 int ok = 0;
mazgch 16:4a7ba1887e81 155 while ((i < pipe->size()) && (o < length))
mazgch 16:4a7ba1887e81 156 {
mazgch 16:4a7ba1887e81 157 int t = pipe->next();
mazgch 16:4a7ba1887e81 158 i ++;
mazgch 16:4a7ba1887e81 159 buffer[o++] = t;
mazgch 16:4a7ba1887e81 160 ok = (t == okTxt[ok]) ? ok + 1 : 0;
mazgch 16:4a7ba1887e81 161 er = (t == erTxt[er]) ? er + 1 : 0;
mazgch 16:4a7ba1887e81 162 if ((okTxt[ok] == '\0') || (erTxt[er] == '\0'))
mazgch 16:4a7ba1887e81 163 {
mazgch 16:4a7ba1887e81 164 pipe->done();
mazgch 16:4a7ba1887e81 165 if (length > o)
mazgch 16:4a7ba1887e81 166 buffer[o] = '\0';
mazgch 16:4a7ba1887e81 167 return o;
mazgch 16:4a7ba1887e81 168 }
mazgch 16:4a7ba1887e81 169 }
mazgch 16:4a7ba1887e81 170 o = 0;
mazgch 16:4a7ba1887e81 171 if (length > 0)
mazgch 16:4a7ba1887e81 172 buffer[0] = '\0';
mazgch 16:4a7ba1887e81 173 return WAIT;
mazgch 16:4a7ba1887e81 174 }