A library for talking to Multi-Tech's Cellular SocketModem Devices.
Dependents: M2X_dev axeda_wrapper_dev MTS_M2x_Example1 MTS_Cellular_Connect_Example ... more
io/MTSSerialFlowControl.cpp
- Committer:
- sgodinez
- Date:
- 2013-12-30
- Revision:
- 101:27bb34e23304
- Parent:
- 96:27bdf4aa3a31
- Child:
- 110:8f3149c99112
File content as of revision 101:27bb34e23304:
#include "MTSSerialFlowControl.h" using namespace mts; MTSSerialFlowControl::MTSSerialFlowControl(PinName TXD, PinName RXD, PinName RTS, PinName CTS, int txBufSize, int rxBufSize) : MTSSerial(TXD, RXD, txBufSize, rxBufSize) , rxReadyFlag(false) , rts(RTS) , cts(CTS) { notifyStartSending(); highThreshold = MAX(rxBufSize - 10, rxBufSize * 0.85); lowThreshold = rxBufSize * 0.3; rxBuffer.attach(this, &MTSSerialFlowControl::notifyStartSending, lowThreshold, Vars::LESS); } MTSSerialFlowControl::~MTSSerialFlowControl() { } void MTSSerialFlowControl::rxClear() { MTSBufferedIO::rxClear(); notifyStartSending(); } void MTSSerialFlowControl::notifyStartSending() { if(!rxReadyFlag) { rts.write(0); rxReadyFlag = true; //printf("RTS LOW: START SENDING US BYTES - RX[%d/%d]\r\n", rxBuffer.size(), rxBuffer.capacity()); } } void MTSSerialFlowControl::notifyStopSending() { if(rxReadyFlag) { rts.write(1); rxReadyFlag = false; //printf("RTS HIGH: STOP SENDING US BYTES - RX[%d/%d]\r\n", rxBuffer.size(), rxBuffer.capacity()); } } void MTSSerialFlowControl::handleRead() { while (serial.readable()) { char byte = serial.getc(); if(rxBuffer.write(byte) != 1) { printf("[ERROR] Serial Rx Byte Dropped [%c][0x%02X]\r\n", byte, byte); notifyStopSending(); } if (rxBuffer.size() > highThreshold) { notifyStopSending(); } } } void MTSSerialFlowControl::handleWrite() { while(txBuffer.size() != 0) { if (serial.writeable() && cts.read() == 0) { char byte; if(txBuffer.read(byte) == 1) { serial.putc(byte); } } else { return; } } }