static int8_t gsmAutobaud(void) { char buff[8]; int8_t try; int8_t resp; // A HEX string such as “00 49 49 49 49 FF FF FF FF” will be sent out // through serial port at the baud rate of 115200 immediately after // SIM900 is powered on. // Send AT command for autobaud gsmDebug("Autobauding...\n"); for(try=3; try; try--) { _gsmWriteLine("AT"); _gsmRead(buff, 8); if (buff[0] == '0') { gsmDebug("DONE\n"); // The GSM has been already configured: // return error to avoid re-configuration return ERROR; } resp = _gsmReadResult(); if (resp == OK) { gsmDebug("DONE\n"); return resp; } gsmDebug("FAILED\n"); } return ERROR; } #else # define gsmAutobaud() OK #endif static int8_t gsmConfigure(void) { char buff[8]; int8_t resp; // Load configuration _gsmWriteLine("ATE0"); _gsmRead(buff, 8); resp = _gsmReadResult(); if (resp != OK) { return resp; } // Configure TA Response Format _gsmWriteLine("ATV0"); resp = _gsmReadResult(); if (resp != OK) { return resp; } return OK; } int8_t gsmPowerOn(void) { int8_t result; // TODO: check if the modem is already on // either using the STATUS line or by sending an AT command if (gsm_status()) { #if 0 // Modem already ON... checking AT command _gsmWriteLine("AT"); result = _gsmReadResult(); if (result == OK) return result; // Not responding to AT comand... shut-down gsm_powerOff(); DELAY(10000); #endif // Resetting the modem LOG_INFO("GSM: Resetting...\n"); gsm_reset(); } else { LOG_INFO("GSM: Powering-on...\n"); gsm_on(); } // When DCE powers on with the autobauding enabled, it is recommended // to wait 2 to 3 seconds before sending the first AT character. LOG_INFO("Wait (20s) for network attachment\n"); DELAY(20000); result = gsmAutobaud(); if (result != OK) return result; result = gsmConfigure(); return result; } void gsmPowerOff(void) { LOG_INFO("GSM: Powering-off...\n"); gsm_off(); LED_GSM_OFF(); }
void GSMTask (void *arg) { static const char fname[] = "GSMTask"; void *msg; phn_syshdr_t *syshdr; boolean release_msg = TRUE; /* * Get the GSM message queue handle * A hack until the tasks in irx are * CPRized. */ gsm_msg_queue = (cprMsgQueue_t) arg; if (!gsm_msg_queue) { GSM_ERR_MSG(GSM_F_PREFIX"invalid input, exiting\n", fname); return; } if (platThreadInit("GSMTask") != 0) { return; } /* * Adjust relative priority of GSM thread. */ (void) cprAdjustRelativeThreadPriority(GSM_THREAD_RELATIVE_PRIORITY); /* * Initialize all the GSM modules */ lsm_init(); fsm_init(); fim_init(); gsm_init(); dcsm_init(); cc_init(); fsmutil_init_shown_calls_ci_map(); /* * On Win32 platform, the random seed is stored per thread; therefore, * each thread needs to seed the random number. It is recommended by * MS to do the following to ensure randomness across application * restarts. */ cpr_srand((unsigned int)time(NULL)); /* * Cache random numbers for SRTP keys */ gsmsdp_cache_crypto_keys(); while (1) { release_msg = TRUE; msg = cprGetMessage(gsm_msg_queue, TRUE, (void **) &syshdr); if (msg) { switch (syshdr->Cmd) { case TIMER_EXPIRATION: gsm_process_timer_expiration(msg); break; case GSM_SIP: case GSM_GSM: release_msg = gsm_process_msg(syshdr->Cmd, msg); break; case DP_MSG_INIT_DIALING: case DP_MSG_DIGIT_STR: case DP_MSG_STORE_DIGIT: case DP_MSG_DIGIT: case DP_MSG_DIAL_IMMEDIATE: case DP_MSG_REDIAL: case DP_MSG_ONHOOK: case DP_MSG_OFFHOOK: case DP_MSG_UPDATE: case DP_MSG_DIGIT_TIMER: case DP_MSG_CANCEL_OFFHOOK_TIMER: dp_process_msg(syshdr->Cmd, msg); break; case SUB_MSG_B2BCNF_SUBSCRIBE_RESP: case SUB_MSG_B2BCNF_NOTIFY: case SUB_MSG_B2BCNF_TERMINATE: sub_process_b2bcnf_msg(syshdr->Cmd, msg); break; case SUB_MSG_FEATURE_SUBSCRIBE_RESP: case SUB_MSG_FEATURE_NOTIFY: case SUB_MSG_FEATURE_TERMINATE: sub_process_feature_msg(syshdr->Cmd, msg); break; case SUB_MSG_KPML_SUBSCRIBE: case SUB_MSG_KPML_TERMINATE: case SUB_MSG_KPML_NOTIFY_ACK: case SUB_MSG_KPML_SUBSCRIBE_TIMER: case SUB_MSG_KPML_DIGIT_TIMER: kpml_process_msg(syshdr->Cmd, msg); break; case REG_MGR_STATE_CHANGE: gsm_reset(); break; case THREAD_UNLOAD: destroy_gsm_thread(); break; default: GSM_ERR_MSG(GSM_F_PREFIX"Unknown message\n", fname); break; } cprReleaseSysHeader(syshdr); if (release_msg == TRUE) { cprReleaseBuffer(msg); } /* Check if there are pending messages for dcsm * if it in the right state perform its operation */ dcsm_process_jobs(); } } }
void gsmReset(void) { LOG_INFO("GSM: Reset\n"); gsm_reset(); }