如何编辑SIM800l库以确保建立呼叫 [英] How to edit SIM800l library to ensure that a call is established

查看:155
本文介绍了如何编辑SIM800l库以确保建立呼叫的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用SIM800l通过 AT命令与arduino UNO进行通话.通过使用此,我可以使用gprsTest.callUp(number)函数进行调用.问题在于,即使数字错误或没有信用,它也会返回true.

I use SIM800l to make calls with arduino UNO with AT commands. By using this library I make calls with gprsTest.callUp(number) function. The problem is that it returns true even the number is wrong or there is no credit.

GPRS_Shield_Arduino.cpp库为什么会这样.它不检查ATDnumberhere;

It is clear on this part code from GPRS_Shield_Arduino.cpp library why it is happening. It doesnt check the return of ATDnumberhere;

bool GPRS::callUp(char *number)
{
    //char cmd[24];
    if(!sim900_check_with_cmd("AT+COLP=1\r\n","OK\r\n",CMD)) {
        return false;
    }
    delay(1000);
    //HACERR quitar SPRINTF para ahorar memoria ???
    //sprintf(cmd,"ATD%s;\r\n", number);
    //sim900_send_cmd(cmd);
    sim900_send_cmd("ATD");
    sim900_send_cmd(number);
    sim900_send_cmd(";\r\n");
    return true;
}

ATDnumberhere;在软件串行通信中的返回为:

The return of ATDnumberhere; on software serial communication is:

如果号码错误 ERROR

If number is wrong ERROR

如果没有积分

 `MO CONNECTED  //instant response

  +COLP: "003069XXXXXXXX",129,"",0,"" // after 3 sec

  OK`

如果正在呼叫并且没有应答

If it is calling and no answer

MO RING //instant response, it is ringing

NO ANSWER // after some sec

如果正在通话并挂断

MO RING //instant response

NO CARRIER // after some sec

如果接收方没有载波

ATD6985952400;

NO CARRIER

如果正在通话,请接听并挂断

If it is calling , answer and hang up

MO RING

MO CONNECTED

+COLP: "69XXXXXXXX",129,"",0,""

OK

NO CARRIER

问题是该函数gprsTest.callUp(number)如何在每种情况下使用不同的收益,或者至少在振铃时如何返回true?

The question is how to use different returns for every case by this function gprsTest.callUp(number) , or at least how to return true if it is ringing ?

推荐答案

该库代码似乎比我乍看之下最糟糕的代码要好,但是它仍然存在一些问题.最严重的是其最终结果代码处理.

This library code seems better than the worst I have seen at first glance, but it still have some issues. The most severe is its Final result code handling.

sim900_check_with_cmd函数在概念上几乎存在,但是绝不接受仅检查OK.它应该检查调制解调器可能发送的每一个可能的最终结果代码. 在输出示例中,您将获得以下最终结果代码

The sim900_check_with_cmd function is conceptually almost there, however only checking for OK is in no way acceptable. It should check for every single possible final result code the modem might send. From your output examples you have the following final result codes

  • 确定
  • 错误
  • 没有载体
  • 没有答案

,但还有更多.您可以查看 atinout 的代码is_final_result_code函数的示例(您还可以在

but there exists a few more as well. You can look at the code for atinout for an example of a is_final_result_code function (you can also compare to isFinalResponseError and isFinalResponseSuccess1 in ST-Ericsson's U300 RIL).

GPRS::callUp末尾的无条件return true;是一个错误,但由于缺乏实现更好的API的想法而可能是有意的,以便调用客户端可以检查中间结果代码.但这是一种错误的方法. 该库确实应该无例外地执行所有有状态命令行调用和最终结果代码解析.仅在库中执行部分操作,然后将其中的一部分留给客户端,这是错误的设计.

The unconditional return true; at the end of GPRS::callUp is an error, but it might be deliberate due to lack of ideas for implementing a better API so that the calling client could check the intermediate result codes. But that is such a wrong way to do it. The library really should do all the stateful command line invocation and final result code parsing with no exceptions. Just doing parts of that in the library and leaving some of it up to the client is just bad design.

当客户端要检查命令行或最终结果代码之间的中间结果代码或信息文本时,或采取行动时,正确的方法是让库将从调制解调器接收的所有内容分解"为单独的完整行,对于不是最终结果代码的所有内容,都通过回调函数将其提供给客户端.

When clients want to inspect or act on intermediate result codes or information text that comes between the command line and the final result code, the correct way to do it is to let the library "deframe" everything it receives from the modem into individual complete lines, and for everything that is not a final result code provide this to the client through a callback function.

以下是我atinout程序的未完成更新:

The following is from an unfinished update to my atinout program:

bool send_commandline(
        const char *cmdline,
        const char *prefix,
        void (*handler)(const char *response_line, void *ptr),
        void *ptr,
        FILE *modem)
{
        int res;
        char response_line[1024];

        DEBUG(DEBUG_MODEM_WRITE, ">%s\n", cmdline);
        res = fputs(cmdline, modem);
        if (res < 0) {
                error(ERR "failed to send '%s' to modem (res = %d)", cmdline, res);
                return false;
        }

        /*
         * Adding a tiny delay here to avoid losing input data which
         * sometimes happens when immediately jumping into reading
         * responses from the modem.
         */
        sleep_milliseconds(200);

        do {
                const char *line;
                line = fgets(response_line, (int)sizeof(response_line), modem);
                if (line == NULL) {
                        error(ERR "EOF from modem");
                        return false;
                }
                DEBUG(DEBUG_MODEM_READ, "<%s\n", line);
                if (prefix[0] == '\0') {
                        handler(response_line, ptr);
                } else if (STARTS_WITH(response_line, prefix)) {
                        handler(response_line + strlen(prefix) + strlen(" "), ptr);
                }
        } while (! is_final_result(response_line));

        return strcmp(response_line, "OK\r\n") == 0;
}

您可以将其用作实施适当处理的基础.如果你想 从函数中获取错误响应,添加其他回调参数,然后更改为

You can use that as a basis for implementing proper handling. If you want to get error responses out of the function, add an additional callback argument and change to

        success = strcmp(response_line, "OK\r\n") == 0;
        if (!success) {
                error_handler(response_line, ptr);
        }
        return success;


提示:阅读 V.250 规范,它将教您几乎需要了解的有关命令行,结果代码和响应处理的所有信息.例如,命令行也应使用\r 而不是\r\n-


Tip: Read all of chapter 5 in the V.250 specification, it will teach you almost everything you need to know about command lines, result codes and response handling. Like for instance that a command line should also be terminated with \r only, not \r\n-

1 请注意,CONNECT不是最终结果代码,它是中间结果代码,因此严格来说,名称isFinalResponseSuccess并非100%正确.

1 Note that CONNECT is not a final result code, it is an intermediate result code, so the name isFinalResponseSuccess is strictly speaking not 100% correct.

这篇关于如何编辑SIM800l库以确保建立呼叫的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆