wat_status_t telit_start(wat_span_t *span) { wat_log_span(span, WAT_LOG_DEBUG, "Starting Telit module\n"); /* Section 2.1 of Telit AT Commands reference Guide recommends these options to be enabled */ wat_cmd_enqueue(span, "AT#SELINT=2", wat_response_selint, NULL, span->config.timeout_command); wat_cmd_enqueue(span, "AT#SMSMODE=1", wat_response_smsmode, NULL, span->config.timeout_command); /* From Telit AT commands reference guide, page 105: Set AT#REGMODE=1 * makes CREG behavior more formal */ wat_cmd_enqueue(span, "AT#REGMODE=1", NULL, NULL, span->config.timeout_command); wat_cmd_enqueue(span, "AT#DVI=1,1,0", wat_response_dvi, NULL, span->config.timeout_command); /* Enable Echo cancellation */ wat_cmd_enqueue(span, "AT#SHFEC=1", NULL, NULL, span->config.timeout_command); wat_cmd_enqueue(span, "AT#SHSEC=1", NULL, NULL, span->config.timeout_command); /* Disable Sidetone as it sounds like echo on calls with long delay (e.g SIP calls) */ wat_cmd_enqueue(span, "AT#SHSSD=0", wat_response_shssd, NULL, span->config.timeout_command); /* I guess we want full CPU power! */ wat_cmd_enqueue(span, "AT#CPUMODE=1", NULL, NULL, span->config.timeout_command); /* Enable codec notifications * (format = 1 is text, mode 2 is short mode to get notifications only including the codec in use) */ wat_cmd_enqueue(span, "AT#CODECINFO=1,2", wat_response_codecinfo, NULL, span->config.timeout_command); wat_cmd_register(span, "#CODECINFO", wat_notify_codec_info); /* Make sure the DIALMODE is set to 0 to receive an OK code as soon as possible * the option of using DIALMODE=2 is tempting as provides progress status * notifications (DIALING, RINGING, CONNECTED, RELEASED, DISCONNECTED), but the modem * will not accept any further commands in the meantime, which is not convenient */ wat_cmd_enqueue(span, "AT#DIALMODE=0", NULL, NULL, span->config.timeout_command); /* Enable automatic Band selection */ wat_cmd_enqueue(span, "AT+COPS=0", NULL, NULL, span->config.timeout_command); switch (span->config.band) { case WAT_BAND_900_1800: wat_cmd_enqueue(span, "AT#BND=0", NULL, NULL, span->config.timeout_command); break; case WAT_BAND_900_1900: wat_cmd_enqueue(span, "AT#BND=1", NULL, NULL, span->config.timeout_command); break; case WAT_BAND_850_1800: wat_cmd_enqueue(span, "AT#BND=2", NULL, NULL, span->config.timeout_command); break; case WAT_BAND_850_1900: wat_cmd_enqueue(span, "AT#BND=3", NULL, NULL, span->config.timeout_command); break; default: wat_log_span(span, WAT_LOG_CRIT, "Unsupported band value:%d\n", span->config.band); case WAT_BAND_AUTO: wat_cmd_enqueue(span, "AT#AUTOBND=2", NULL, NULL, span->config.timeout_command); break; } return WAT_SUCCESS; }
wat_status_t telit_wait_sim(wat_span_t *span) { wat_log_span(span, WAT_LOG_INFO, "Waiting for SIM acccess...\n"); wat_cmd_register(span, "#QSS", wat_notify_qss); wat_cmd_enqueue(span, "AT#QSS=2", wat_response_qss, NULL, span->config.timeout_command); wat_cmd_enqueue(span, "AT#QSS?", wat_response_qss, NULL, span->config.timeout_command); return WAT_SUCCESS; }
static wat_status_t wat_span_perform_start(wat_span_t *span) { memset(span->calls, 0, sizeof(span->calls)); memset(span->notifys, 0, sizeof(span->notifys)); memset(&span->net_info, 0, sizeof(span->net_info)); if (wat_queue_create(&span->event_queue, WAT_EVENT_QUEUE_SZ) != WAT_SUCCESS) { wat_log_span(span, WAT_LOG_CRIT, "Failed to create queue\n"); return WAT_FAIL; } if (wat_queue_create(&span->cmd_queue, WAT_CMD_QUEUE_SZ) != WAT_SUCCESS) { wat_log_span(span, WAT_LOG_CRIT, "Failed to create queue\n"); return WAT_FAIL; } if (wat_queue_create(&span->sms_queue, WAT_MAX_SMSS_PER_SPAN) != WAT_SUCCESS) { wat_log_span(span, WAT_LOG_CRIT, "Failed to create queue\n"); return WAT_FAIL; } if (wat_buffer_create(&span->buffer, WAT_BUFFER_SZ) != WAT_SUCCESS) { wat_log_span(span, WAT_LOG_CRIT, "Failed to create buffer\n"); return WAT_FAIL; } if (wat_sched_create(&span->sched, "span_schedule") != WAT_SUCCESS) { wat_log_span(span, WAT_LOG_CRIT, "Failed to create scheduler\n"); return WAT_FAIL; } wat_log_span(span, WAT_LOG_DEBUG, "Starting span\n"); wat_cmd_register(span, "+CRING", wat_notify_cring); wat_cmd_register(span, "+CMT", wat_notify_cmt); wat_cmd_register(span, "+CLIP", wat_notify_clip); wat_cmd_register(span, "+CREG", wat_notify_creg); #if 0 wat_cmd_register(span, "+CDIP", wat_notify_cdip); wat_cmd_register(span, "+CNAP", wat_notify_cnap); wat_cmd_register(span, "+CCWA", wat_notify_ccwa); #endif /* Module soft reset */ wat_cmd_enqueue(span, "ATZ", wat_response_atz, NULL, 60000); /* Disable echo mode */ wat_cmd_enqueue(span, "ATE0", wat_response_ate, NULL, span->config.timeout_command); wat_cmd_enqueue(span, "ATX4", NULL, NULL, span->config.timeout_command); /* Enable Mobile Equipment Error Reporting, numeric mode */ wat_cmd_enqueue(span, "AT+CMEE=1", NULL, NULL, span->config.timeout_command); /* Enable extended format reporting */ wat_cmd_enqueue(span, "AT+CRC=1", NULL, NULL, span->config.timeout_command); if (wat_test_flag(&span->module, WAT_MODFLAG_IS_CDMA)) { /* This is a CDMA module, no SIM here */ wat_log_span(span, WAT_LOG_DEBUG, "CDMA module does not require waiting for SIM ...\n"); if (span->state < WAT_SPAN_STATE_POST_START) { wat_span_set_state(span, WAT_SPAN_STATE_POST_START); } } else { span->module.wait_sim(span); wat_sched_timer(span->sched, "wait_sim", span->config.timeout_wait_sim, wat_scheduled_wait_sim, (void *) span, &span->timeouts[WAT_TIMEOUT_WAIT_SIM]); } return WAT_SUCCESS; }