Exemplo n.º 1
0
static int sim800_attach(struct cellular *modem)
{
    at_set_callbacks(modem->at, &sim800_callbacks, (void *) modem);

    at_set_timeout(modem->at, 2);

    /* Perform autobauding. */
    for (int i=0; i<SIM800_AUTOBAUD_ATTEMPTS; i++) {
        const char *response = at_command(modem->at, "AT");
        if (response != NULL)
            /* Modem replied. Good. */
            break;
    }

    /* Disable local echo. */
    at_command(modem->at, "ATE0");

    /* Disable local echo again; make sure it was disabled successfully. */
    at_command_simple(modem->at, "ATE0");

    /* Initialize modem. */
    static const char *const init_strings[] = {
//        "AT+IPR=0",                     /* Enable autobauding if not already enabled. */
        "AT+IFC=0,0",                   /* Disable hardware flow control. */
        "AT+CMEE=2",                    /* Enable extended error reporting. */
        "AT+CLTS=0",                    /* Don't sync RTC with network time, it's broken. */
        "AT+CIURC=0",                   /* Disable "Call Ready" URC. */
        "AT&W0",                        /* Save configuration. */
        "AT+BTSPPCFG=\"TT\",1",
        "AT+BTPAIRCFG=0",
        "AT+BTSPPGET=1",
        "AT+BTPOWER=1",
        NULL
    };
    for (const char *const *command=init_strings; *command; command++)
        at_command_simple(modem->at, "%s", *command);

    /* Configure IP application. */

//    /* Switch to multiple connections mode; it's less buggy. */
//    if (sim800_config(modem, "CIPMUX", "1", SIM800_CIPCFG_RETRIES) != 0)
//        return -1;
//    /* Receive data manually. */
//    if (sim800_config(modem, "CIPRXGET", "1", SIM800_CIPCFG_RETRIES) != 0)
//        return -1;
//    /* Enable quick send mode. */
//    if (sim800_config(modem, "CIPQSEND", "1", SIM800_CIPCFG_RETRIES) != 0)
//        return -1;

    return 0;
}
Exemplo n.º 2
0
static int telit2_attach(struct cellular *modem)
{
    at_set_callbacks(modem->at, &telit2_callbacks, (void *) modem);

    at_set_timeout(modem->at, 1);
    at_command(modem->at, "AT");        /* Aid autobauding. Always a good idea. */
    at_command(modem->at, "ATE0");      /* Disable local echo. */

    /* Initialize modem. */
    static const char *const init_strings[] = {
        "AT&K0",                        /* Disable hardware flow control. */
        "AT#SELINT=2",                  /* Set Telit module compatibility level. */
        "AT+CMEE=2",                    /* Enable extended error reporting. */
        NULL
    };
    for (const char *const *command=init_strings; *command; command++)
        at_command_simple(modem->at, "%s", *command);

    return 0;
}
Exemplo n.º 3
0
int main(int argc, char *argv[])
{
    assert(argc-1 == 1);
    const char *devpath = argv[1];

    printf("allocating channel...\n");
    struct at *at = at_alloc_unix(devpath, B115200);

    printf("opening port...\n");
    assert(at_open(at) == 0);

    printf("attaching callbacks\n");
    at_set_callbacks(at, &generic_modem_callbacks, NULL);

    const char *commands[] = {
        "AT",
        "ATE0",
        "AT+CGMR",
        "AT+CGSN",
        "AT+CCID",
        "AT+CMEE=0",
        "AT+BLAH",
        "AT+CMEE=2",
        "AT+BLAH",
        NULL
    };

    printf("sending commands...\n");
    at_set_timeout(at, 10);
    for (const char **command=commands; *command; command++) {
        const char *result = at_command(at, *command);
        printf("%s => %s\n", *command, result ? result : strerror(errno));
    }

    printf("freeing resources...\n");
    at_free(at);

    return 0;
}
Exemplo n.º 4
0
static int telit2_detach(struct cellular *modem)
{
    at_set_callbacks(modem->at, NULL, NULL);
    return 0;
}