例子演示例子1(查询无线模组信号质量)- /** at_do_cmd 接口使用演示
- 查询GPRS模组信号质量命令
- => AT+CSQ
-
- <= +CSQ: 24, 0
- <= OK
- */
- /*
- * @brief 获取csq值
- */
- bool read_csq_value(at_obj_t *at, int *rssi, int *error_rate)
- {
- //接收缓冲区
- unsigned char recvbuf[32];
- //AT应答
- at_respond_t r = {"OK", recvbuf, sizeof(recvbuf), 3000};
- //
- if (at_do_cmd(at, &r, "AT+CSQ") != AT_RET_OK)
- return false;
- //提取出响应数据
- return (sscanf(recv, "%*[^+]+CSQ: %d,%d", rssi, error_rate) == 2);
- }
例子2(发送TCP数据)
- /** at_do_work 接口使用演示
- 参考自hl8518模组Socket 数据发送命令
- => AT+KTCPSND=<session_id>,<ndata>
-
- <= CONNECT
-
- => <data>
-
- <= OK
- */
- /*
- * @brief 数据发送处理
- * @retval none
- */
- static bool socket_send_handler(at_work_ctx_t *e)
- {
- struct socket_info *i = (struct socket_info *)e->params;
- struct ril_sock *s = i->s;
-
- if (s->type == SOCK_TYPE_TCP)
- e->printf(e, "AT+KTCPSND=%d,%d", s->session, i->bufsize);
- else
- e->printf(e, "AT+KUDPSND=%d,%s,%d,%d",s->session, s->host,
- s->port, i->bufsize);
- if (e->wait_resp(e, "CONNECT", 5000) != AT_RET_OK) { //等待提示符
- goto Error;
- }
- e->write(i->buf, i->bufsize); //发送数据
-
- e->write("--EOF--Pattern--", strlen("--EOF--Pattern--")); //发送结束符
- if (e->wait_resp(e, "OK", 5000) == AT_RET_OK)
- return true;
- else {
- Error:
- e->write("--EOF--Pattern--", strlen("--EOF--Pattern--"));
- return false;
- }
- }
- /**
- * @brief socket 数据发送
- * @param[in] s - socket
- * @param[in] buf - 数据缓冲区
- * @param[in] len - 缓冲区长度
- */
- static bool hl8518_sock_send(ril_obj_t *r, struct ril_sock *s, const void *buf,
- unsigned int len)
- {
- struct socket_info info = {s, (unsigned char *)buf, len, 0};
- if (len == 0)
- return false;
- return at_do_work(&r->at, (at_work)socket_send_handler, &info);
- }
|