Exemplo n.º 1
0
bool IGainSpan_CmdLib_Read(
    uint8_t *rxData,
    uint16_t dataLength,
    uint8_t blockFlag)
{
    bool got_data = false;

    /* Keep getting data if we have a number of bytes to fetch */
    while (dataLength) {
        /* Try to get a byte */
        if (GainSpan_SPI_ReceiveByte(GAINSPAN_SPI_CHANNEL, rxData)) {
//printf("|%02X|", *rxData);
            /* Got a byte, move up to the next position */
            rxData++;
            dataLength--;
            got_data = true;
        } else {
            /* Did not get a byte, are we block?  If not, stop here */
            if (!blockFlag)
                break;

            // TODO: Need some type of semaphore here!
        }
    }

    return got_data;
}
/*---------------------------------------------------------------------------*/
void TestGainSpan_ATCommands(void)
{
    bool send = true;
    const uint8_t match[] = "AT\r\r\nOK\r\n\n\r\n";
    uint8_t in[sizeof(match)];
    uint8_t pos;
    uint8_t c;
    uint32_t start;

    DisplayLCD(LCD_LINE2, "GS ATCmd");

    /* Reset the connection by flushing any waiting data */
    start = MSTimerGet();
    while (MSTimerDelta(start) < 500) {
        if (GainSpan_SPI_ReceiveByte(SPI_WIFI_CHANNEL, &c)) {
            Console_UART_SendByte(c);
            start = MSTimerGet();
        }
    }

    start = MSTimerGet();
    while (1) {
        /* Infitine loop */
        if (send) {
            /* Do AT commands as fast as possible. */
            GainSpan_SPI_SendData("AT\r\n", 4);
            send = false;
            pos = 0;
            start += 10;
        }
        if (GainSpan_SPI_ReceiveByte(SPI_WIFI_CHANNEL, &c)) {
            if (c != GAINSPAN_SPI_CHAR_IDLE) {
                in[pos++] = c;
                Console_UART_SendByte(c);
                if (pos == (sizeof(match) - 1)) {
                    if (memcmp(match, in, sizeof(match) - 1) != 0) {
                        Console_UART_SendByte('_');
                        ErrorCode(3);
                    }

                    send = true;
                }
            }
        }
    }
}
Exemplo n.º 3
0
 /*---------------------------------------------------------------------------*/
bool App_Read(uint8_t *rxData, uint16_t dataLength, uint8_t blockFlag)
{
#ifdef ATLIBGS_INTERFACE_SPI
    bool got_data = false;

    /* Keep getting data if we have a number of bytes to fetch */
    while (dataLength) {
        /* Try to get a byte */
        if (GainSpan_SPI_ReceiveByte(GAINSPAN_SPI_CHANNEL, rxData)) {
            /* Got a byte, move up to the next position */
            rxData++;
            dataLength--;
            got_data = true;
        } else {
            /* Did not get a byte, are we block?  If not, stop here */
            if (!blockFlag)
                break;
        }
    }

    return got_data;
#else
    bool got_data = false;

    /* Keep getting data if we have a number of bytes to fetch */
    while (dataLength) {
        /* Try to get a byte */
        if (GainSpan_UART_ReceiveByte(rxData)) {
            /* Got a byte, move up to the next position */
            rxData++;
            dataLength--;
            got_data = true;
        } else {
            /* Did not get a byte, are we block?  If not, stop here */
            if (!blockFlag)
            break;
        }
    }

    return got_data;
#endif
}