Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: M2X_dev axeda_wrapper_dev MTS_M2x_Example1 MTS_Cellular_Connect_Example ... more
io/MTSSerialFlowControl.cpp@152:9a2c7ed27744, 2014-09-02 (annotated)
- Committer:
- mfiore
- Date:
- Tue Sep 02 18:38:55 2014 +0000
- Revision:
- 152:9a2c7ed27744
- Parent:
- 144:52cb5b6667cc
Wifi: fix compatibility break with old shields by checking for both old and new style responses to "show connection" command
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| kranjan | 141:571e0ef6c8dc | 1 | /* Universal Socket Modem Interface Library |
| kranjan | 141:571e0ef6c8dc | 2 | * Copyright (c) 2013 Multi-Tech Systems |
| kranjan | 141:571e0ef6c8dc | 3 | * |
| kranjan | 141:571e0ef6c8dc | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| kranjan | 141:571e0ef6c8dc | 5 | * you may not use this file except in compliance with the License. |
| kranjan | 141:571e0ef6c8dc | 6 | * You may obtain a copy of the License at |
| kranjan | 141:571e0ef6c8dc | 7 | * |
| kranjan | 141:571e0ef6c8dc | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| kranjan | 141:571e0ef6c8dc | 9 | * |
| kranjan | 141:571e0ef6c8dc | 10 | * Unless required by applicable law or agreed to in writing, software |
| kranjan | 141:571e0ef6c8dc | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| kranjan | 141:571e0ef6c8dc | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| kranjan | 141:571e0ef6c8dc | 13 | * See the License for the specific language governing permissions and |
| kranjan | 141:571e0ef6c8dc | 14 | * limitations under the License. |
| kranjan | 141:571e0ef6c8dc | 15 | */ |
| kranjan | 141:571e0ef6c8dc | 16 | |
| jengbrecht | 0:563b70517320 | 17 | #include "MTSSerialFlowControl.h" |
| jengbrecht | 0:563b70517320 | 18 | |
| mfiore | 39:6e94520a3217 | 19 | using namespace mts; |
| mfiore | 39:6e94520a3217 | 20 | |
| jengbrecht | 140:bf0c8288eb78 | 21 | MTSSerialFlowControl::MTSSerialFlowControl(PinName TXD, PinName RXD, PinName RTS, PinName CTS, int txBufSize, int rxBufSize) |
| jengbrecht | 140:bf0c8288eb78 | 22 | : MTSSerial(TXD, RXD, txBufSize, rxBufSize) |
| jengbrecht | 140:bf0c8288eb78 | 23 | , rxReadyFlag(false) |
| jengbrecht | 140:bf0c8288eb78 | 24 | , rts(RTS) |
| jengbrecht | 140:bf0c8288eb78 | 25 | , cts(CTS) |
| jengbrecht | 0:563b70517320 | 26 | { |
| mfiore | 10:2bd727a4b329 | 27 | notifyStartSending(); |
| jengbrecht | 45:40745c2036cf | 28 | |
| sgodinez | 84:77c5ab16534d | 29 | highThreshold = MAX(rxBufSize - 10, rxBufSize * 0.85); |
| mfiore | 2:8d3ea0dfce39 | 30 | lowThreshold = rxBufSize * 0.3; |
| jengbrecht | 45:40745c2036cf | 31 | |
| sgodinez | 86:186bbf974c7c | 32 | rxBuffer.attach(this, &MTSSerialFlowControl::notifyStartSending, lowThreshold, Vars::LESS); |
| mfiore | 2:8d3ea0dfce39 | 33 | } |
| mfiore | 2:8d3ea0dfce39 | 34 | |
| jengbrecht | 45:40745c2036cf | 35 | MTSSerialFlowControl::~MTSSerialFlowControl() |
| jengbrecht | 45:40745c2036cf | 36 | { |
| mfiore | 2:8d3ea0dfce39 | 37 | |
| jengbrecht | 45:40745c2036cf | 38 | } |
| jengbrecht | 45:40745c2036cf | 39 | |
| jengbrecht | 140:bf0c8288eb78 | 40 | void MTSSerialFlowControl::rxClear() |
| jengbrecht | 140:bf0c8288eb78 | 41 | { |
| sgodinez | 101:27bb34e23304 | 42 | MTSBufferedIO::rxClear(); |
| jengbrecht | 140:bf0c8288eb78 | 43 | notifyStartSending(); |
| sgodinez | 101:27bb34e23304 | 44 | } |
| sgodinez | 101:27bb34e23304 | 45 | |
| jengbrecht | 45:40745c2036cf | 46 | void MTSSerialFlowControl::notifyStartSending() |
| jengbrecht | 45:40745c2036cf | 47 | { |
| sgodinez | 101:27bb34e23304 | 48 | if(!rxReadyFlag) { |
| sgodinez | 101:27bb34e23304 | 49 | rts.write(0); |
| sgodinez | 101:27bb34e23304 | 50 | rxReadyFlag = true; |
| sgodinez | 110:8f3149c99112 | 51 | //printf("RTS LOW: READY - RX[%d/%d]\r\n", rxBuffer.size(), rxBuffer.capacity()); |
| sgodinez | 101:27bb34e23304 | 52 | } |
| mfiore | 2:8d3ea0dfce39 | 53 | } |
| mfiore | 2:8d3ea0dfce39 | 54 | |
| jengbrecht | 45:40745c2036cf | 55 | void MTSSerialFlowControl::notifyStopSending() |
| jengbrecht | 45:40745c2036cf | 56 | { |
| sgodinez | 101:27bb34e23304 | 57 | if(rxReadyFlag) { |
| sgodinez | 101:27bb34e23304 | 58 | rts.write(1); |
| sgodinez | 101:27bb34e23304 | 59 | rxReadyFlag = false; |
| sgodinez | 110:8f3149c99112 | 60 | //printf("RTS HIGH: NOT-READY - RX[%d/%d]\r\n", rxBuffer.size(), rxBuffer.capacity()); |
| sgodinez | 101:27bb34e23304 | 61 | } |
| mfiore | 2:8d3ea0dfce39 | 62 | } |
| mfiore | 2:8d3ea0dfce39 | 63 | |
| jengbrecht | 45:40745c2036cf | 64 | void MTSSerialFlowControl::handleRead() |
| jengbrecht | 45:40745c2036cf | 65 | { |
| jengbrecht | 144:52cb5b6667cc | 66 | char byte = serial.getc(); |
| jengbrecht | 144:52cb5b6667cc | 67 | if(rxBuffer.write(byte) != 1) { |
| jengbrecht | 144:52cb5b6667cc | 68 | printf("[ERROR] Serial Rx Byte Dropped [%c][0x%02X]\r\n", byte, byte); |
| jengbrecht | 144:52cb5b6667cc | 69 | } |
| jengbrecht | 144:52cb5b6667cc | 70 | if (rxBuffer.size() > highThreshold) { |
| jengbrecht | 144:52cb5b6667cc | 71 | notifyStopSending(); |
| mfiore | 2:8d3ea0dfce39 | 72 | } |
| mfiore | 2:8d3ea0dfce39 | 73 | } |
| mfiore | 2:8d3ea0dfce39 | 74 | |
| jengbrecht | 45:40745c2036cf | 75 | void MTSSerialFlowControl::handleWrite() |
| jengbrecht | 45:40745c2036cf | 76 | { |
| sgodinez | 86:186bbf974c7c | 77 | while(txBuffer.size() != 0) { |
| sgodinez | 86:186bbf974c7c | 78 | if (serial.writeable() && cts.read() == 0) { |
| jengbrecht | 77:d7b14688a704 | 79 | char byte; |
| sgodinez | 86:186bbf974c7c | 80 | if(txBuffer.read(byte) == 1) { |
| jengbrecht | 144:52cb5b6667cc | 81 | serial.attach(NULL, Serial::RxIrq); |
| sgodinez | 86:186bbf974c7c | 82 | serial.putc(byte); |
| jengbrecht | 144:52cb5b6667cc | 83 | serial.attach(this, &MTSSerialFlowControl::handleRead, Serial::RxIrq); |
| mfiore | 2:8d3ea0dfce39 | 84 | } |
| jengbrecht | 77:d7b14688a704 | 85 | } else { |
| jengbrecht | 77:d7b14688a704 | 86 | return; |
| mfiore | 2:8d3ea0dfce39 | 87 | } |
| mfiore | 2:8d3ea0dfce39 | 88 | } |
| mfiore | 2:8d3ea0dfce39 | 89 | } |
| kranjan | 141:571e0ef6c8dc | 90 |
uIP Socket Modem Shield (Outdated - see below)