示例#1
0
/**
 * Runs the at_task loop.  This loop listens for incomming messages and
 * handles them appropriately, checks for timeouts and handles them if
 * needed, handles quiet periods between AT commands and submits AT
 * commands that have been queued up.
 */
void at_task(struct at_info *ati, const size_t ms_delay)
{
        char *msg = serial_buffer_rx(ati->sb, ms_delay);

        if (msg)
                at_task_run_bytes_read(ati, lstrip_inline(msg));
        else
                at_task_run_no_bytes(ati);

        at_task_quiet_period_handler(ati);
        at_task_cmd_handler(ati);
}
size_t serial_buffer_rx_msgs(struct serial_buffer *sb, const size_t ms_delay,
                             const char *msgs[], size_t msgs_len)
{
        size_t msgs_rx = 0;

        for (; msgs_len; --msgs_len, ++msgs_rx) {
                const char* msg = serial_buffer_rx(sb, ms_delay);

                if (!msg)
                        break;

                *msgs++ = msg;
        }

        return msgs_rx;
}
size_t serial_buffer_rx_msgs(struct serial_buffer *sb, const size_t ms_delay,
                             const char *msgs[], size_t msgs_len)
{
        size_t rx_bytes = 0;
        size_t msgs_rx = 0;

        for (; msgs_len; --msgs_len, ++msgs_rx) {
                const size_t read = serial_buffer_rx(sb, ms_delay);

                if (0 == read)
                        break;

                *msgs++ = sb->buffer + rx_bytes;
                rx_bytes += read;
        }

        return msgs_rx;
}
static bool sim900_stop_direct_mode(struct serial_buffer *sb)
{
        /* Must delay min 1000ms before stopping direct mode */
	delayMs(2000);

        /*
         * Using straight serial buffer logic here instead of
         * the AT command system because we can get data intended for
         * the JSON parser while we do this. Also because we don't
         * want the \r at the end of the command.
         */
        serial_buffer_reset(sb);
        serial_buffer_append(sb, "+++");
        serial_buffer_tx(sb);
        for (size_t events = STOP_DM_RX_EVENTS; events; --events) {
                serial_buffer_reset(sb);
                if (serial_buffer_rx(sb, STOP_DM_RX_TIMEOUT_MS) &&
                    is_rsp_ok((const char**) &(sb->buffer), 1))
                        return true;
        }

        return false;
}