libNbiotCore/src/modems/BG96MA-R02A07M1G/network.cpp
// TODO: not really required, should be refactored
not really required, should be refactored
not really required should be refactored
int Network::ipRead(nbiot::CircularBuffer<READ_BUFFER_SIZE>& data, int len, unsigned short timeout_ms)
{
    int avail = -1;
    int rb = 0;
    nbiot::Timer timer(timeout_ms);
    if(m_cmd.sendCommand(nbiot::string::Printf(cmdQIRD_arg, m_connectionNumber, len)))
    {
        if(m_cmd.readUntil(respQIRD, timer.remaining()))
        {
            nbiot::string response = m_cmd.getResponse();
            if(!(response == "ERROR"))
            {
                size_t pos = response.find(':');
                if(nbiot::string::npos != pos)
                {
                    pos++;
                    while (' ' == response.at(pos)) 
                    {
                        pos++;
                    }
                    if (pos < response.size())
                    {
                        nbiot::string number = response.substr(pos, response.size());
                        avail = atoi(number.c_str());
                    }
                }
            }
            if(0 < avail)
            {
                for(int i = 0; i < avail; ++i)
                {
                    unsigned char c = -1;
                    if(m_cmd.serial.readRaw(&c, static_cast<unsigned short>(timer.remaining())))
                    {
                        data.put(c);
                        rb++;
                    }
                }
                m_cmd.readResponse(REPLY_OK, static_cast<unsigned short>(timer.remaining()));
            }
        }
    }
    m_cmd.readResponse(REPLY_IGNORE, static_cast<unsigned short>(timer.remaining()));
    return rb;
}
int Network :: ipRead ( nbiot :: CircularBuffer < READ_BUFFER_SIZE > & data , int len , unsigned short timeout_ms ) { int avail = -1 ; int rb = 0 ; nbiot :: Timer timer ( timeout_ms ) ; if ( m_cmd . sendCommand ( nbiot :: string :: Printf ( cmdQIRD_arg , m_connectionNumber , len ) ) ) { if ( m_cmd . readUntil ( respQIRD , timer . remaining ( ) ) ) { nbiot :: string response = m_cmd . getResponse ( ) ; if ( ! ( response == " " ) ) { size_t pos = response . find ( ' ' ) ; if ( nbiot :: string :: npos != pos ) { pos ++ ; while ( ' ' == response . at ( pos ) ) { pos ++ ; } if ( pos < response . size ( ) ) { nbiot :: string number = response . substr ( pos , response . size ( ) ) ; avail = atoi ( number . c_str ( ) ) ; } } } if ( 0 < avail ) { for ( int i = 0 ; i < avail ; ++ i ) { unsigned char c = -1 ; if ( m_cmd . serial . readRaw ( & c , static_cast < unsigned short > ( timer . remaining ( ) ) ) ) { data . put ( c ) ; rb ++ ; } } m_cmd . readResponse ( REPLY_OK , static_cast < unsigned short > ( timer . remaining ( ) ) ) ; } } } m_cmd . readResponse ( REPLY_IGNORE , static_cast < unsigned short > ( timer . remaining ( ) ) ) ; return rb ; }
TODO: not really required, should be refactored
TODO : not really required should be refactored
// eat up spaces if there are any