Implementation of 3G USB Modem Huawei E372
Diff: USBSerialStream.cpp
- Revision:
- 2:61ac95f0af72
- Parent:
- 0:67daedd6f74f
diff -r fbf17fb09581 -r 61ac95f0af72 USBSerialStream.cpp --- a/USBSerialStream.cpp Fri Feb 20 17:15:55 2015 +0000 +++ b/USBSerialStream.cpp Tue Apr 14 13:27:07 2015 +0000 @@ -17,10 +17,15 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include <stdio.h> +#include <cstdio> #include "USBSerialStream.h" +#define __DEBUG__ 0 +#ifndef __MODULE__ +#define __MODULE__ "USBSerialStream.cpp" +#endif +#include "MyDebug.h" USBSerialStream::USBSerialStream(IUSBHostSerial& serial) : m_serial(serial), m_serialTxFifoEmpty(true), m_availableSphre(1), m_spaceSphre(1), m_inBuf() @@ -39,11 +44,11 @@ //0 for non-blocking (returns immediately), -1 for infinite blocking /*virtual*/ int USBSerialStream::read(uint8_t* buf, size_t* pLength, size_t maxLength, uint32_t timeout/*=osWaitForever*/) { - USB_DBG("Trying to read at most %d chars", maxLength); + DBG("Trying to read at most %d chars", maxLength); int ret = waitAvailable(timeout); if(ret) { - USB_WARN("Error %d while waiting for incoming data", ret); + WARN("Error %d while waiting for incoming data", ret); return ret; } int a = available(); //Prevent macro issues @@ -57,7 +62,7 @@ buf++; } setupReadableISR(true); - USB_DBG("Read %d chars successfully", *pLength); + DBG("Read %d chars successfully", *pLength); return OK; } @@ -78,19 +83,19 @@ return OK; } - USB_DBG("Waiting for data availability %d ms (-1 is infinite)", timeout); + DBG("Waiting for data availability %d ms (-1 is infinite)", timeout); ret = m_availableSphre.wait(timeout); //Wait for data to arrive or for abort if(ret <= 0) { - USB_DBG("Timeout"); + DBG("Timeout"); return NET_TIMEOUT; } if(!m_inBuf.available()) //Even if abort has been called, return that data is available { - USB_DBG("Aborted"); + DBG("Aborted"); return NET_INTERRUPTED; } - USB_DBG("Finished waiting"); + DBG("Finished waiting"); while( m_availableSphre.wait(0) > 0 ); //Clear the queue as data is available return OK; } @@ -103,7 +108,7 @@ } else { - USB_DBG("Serial is readable"); ; + DBG("Serial is readable"); ; } return OK; } @@ -126,18 +131,18 @@ //0 for non-blocking (returns immediately), -1 for infinite blocking /*virtual*/ int USBSerialStream::write(uint8_t* buf, size_t length, uint32_t timeout/*=-1*/) { - USB_DBG("Trying to write %d chars", length); + DBG("Trying to write %d chars", length); do { int ret = waitSpace(timeout); if(ret) { - USB_WARN("Error %d while waiting for space", ret); + WARN("Error %d while waiting for space", ret); return ret; } int s = space(); //Prevent macro issues int writeLen = MIN( s, length ); - USB_DBG("Writing %d chars", writeLen); + DBG("Writing %d chars", writeLen); setupWriteableISR(false); while(writeLen) { @@ -154,7 +159,7 @@ setupWriteableISR(true); } while(length); - USB_DBG("Write successful"); + DBG("Write successful"); return OK; } @@ -175,16 +180,16 @@ return OK; } - USB_DBG("Waiting for data space %d ms (-1 is infinite)", timeout); + DBG("Waiting for data space %d ms (-1 is infinite)", timeout); ret = m_spaceSphre.wait(timeout); //Wait for space to be made or for abort if(ret <= 0) { - USB_DBG("Timeout"); + DBG("Timeout"); return NET_TIMEOUT; } if(!space()) //Even if abort has been called, return that space is available { - USB_DBG("Aborted"); + DBG("Aborted"); return NET_INTERRUPTED; } while( m_spaceSphre.wait(0) > 0); //Clear the queue as space is available