mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-15 10:29:47 +00:00
Merge pull request #3621 from cesanta/tests
add tests for ATcmd driver, fix some warnings
This commit is contained in:
8 files changed
+266
-56
No files matched your search
@@ -9,7 +9,9 @@
|
||||
|
||||
static size_t print_atcmd(void (*out)(char, void *), void *arg, va_list *ap) {
|
||||
struct mg_str s = va_arg(*ap, struct mg_str);
|
||||
for (size_t i = 0; i < s.len; i++) out(s.buf[i] < 0x20 ? '.' : s.buf[i], arg);
|
||||
size_t i;
|
||||
for (i = 0; i < s.len; i++)
|
||||
out((char) (s.buf[i] < 0x20 ? '.' : s.buf[i]), arg);
|
||||
return s.len;
|
||||
}
|
||||
|
||||
@@ -27,7 +29,7 @@ static bool mg_atcmd_handle(struct mg_tcpip_if *ifp) {
|
||||
if (dd->script_index % 2 == 0) { // send AT command
|
||||
const char *cmd = dd->script[dd->script_index];
|
||||
MG_DEBUG(("send AT[%d]: %M", dd->script_index, print_atcmd, mg_str(cmd)));
|
||||
while (*cmd) dd->tx(dd->usart, *cmd++);
|
||||
while (*cmd != '\0') dd->tx(dd->usart, (uint8_t) *cmd++);
|
||||
dd->script_index++;
|
||||
ifp->recv_queue.head = 0;
|
||||
} else { // check AT command response
|
||||
@@ -43,7 +45,7 @@ static bool mg_atcmd_handle(struct mg_tcpip_if *ifp) {
|
||||
return false; // FAIL
|
||||
}
|
||||
if ((c = dd->rx(dd->usart)) < 0) return false; // no data
|
||||
q->buf[q->head++] = c;
|
||||
q->buf[q->head++] = (char) c;
|
||||
if (mg_match(mg_str_n(q->buf, q->head), mg_str(expect), NULL)) {
|
||||
MG_DEBUG(("recv AT[%d]: %M", dd->script_index, print_atcmd,
|
||||
mg_str_n(q->buf, q->head)));
|
||||
@@ -84,7 +86,7 @@ static size_t mg_atcmd_rx(void *buf, size_t len, struct mg_tcpip_if *ifp) {
|
||||
}
|
||||
}
|
||||
if (!dd->no_byte_stuff && !byte_unstuff(dd, &b)) continue;
|
||||
q->buf[q->head++] = b;
|
||||
q->buf[q->head++] = (char) b;
|
||||
}
|
||||
len = (q->head <= len) ? q->head : 0;
|
||||
memmove(buf, q->buf, len);
|
||||
@@ -130,7 +132,7 @@ struct mg_tcpip_driver mg_tcpip_driver_atcmd = {mg_atcmd_init, mg_atcmd_tx, mg_a
|
||||
static void byte_stuff(struct mg_tcpip_driver_atcmd_data *dd, uint8_t b) {
|
||||
if ((b < 0x20) || (b == MG_HDLC_ESC) || (b == MG_HDLC_FLAG)) {
|
||||
dd->tx(dd->usart, MG_HDLC_ESC);
|
||||
dd->tx(dd->usart, b ^ 0x20);
|
||||
dd->tx(dd->usart, (uint8_t) (b ^ 0x20));
|
||||
} else {
|
||||
dd->tx(dd->usart, b);
|
||||
}
|
||||
|
||||
+1
-1
@@ -1278,7 +1278,7 @@ static size_t tx_tcp_ctrlresp(struct mg_tcpip_if *ifp, struct pkt *pkt,
|
||||
}
|
||||
|
||||
static size_t tx_tcp_rst(struct mg_tcpip_if *ifp, struct pkt *pkt, bool toack) {
|
||||
return tx_tcp_ctrlresp(ifp, pkt, toack ? TH_RST : (TH_RST | TH_ACK),
|
||||
return tx_tcp_ctrlresp(ifp, pkt, (uint8_t)(toack ? TH_RST : (TH_RST | TH_ACK)),
|
||||
toack ? pkt->tcp->ack : 0);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user