📄 gsm.c
字号:
break;
case 0x03:
switch (GSMSendCommType) {
case ATpCSQ: GSMProcAnalyseCSQ(); break;
case ATpCPMS: GSMProcAnalyseCPMS(); break;
case ATpCPAS: GSMProcAnalyseCPAS(); break;
case ATpCMGR: GSMProcAnalyseCMGR(); break;
case ATpCGDCONTq: GSMProcAnalyseCGDC(); break;
}
GSMSendCommStep = STATE_OK;
break;
case STATE_OK:
#ifdef SUPPORT_USART_SHOW
switch (GSMModemReply) {
case OK: psprintf(LineBuffer, "OK,"); DBusEditShowText(LineBuffer); break;
case ERROR: psprintf(LineBuffer, "ERROR,"); DBusEditShowText(LineBuffer); break;
case CMGS: psprintf(LineBuffer, "CMGS,"); DBusEditShowText(LineBuffer); break;
case CONNECT: psprintf(LineBuffer, "CONNECT,"); DBusEditShowText(LineBuffer); break;
case NOCARRIER: psprintf(LineBuffer, "NO CARRIER,"); DBusEditShowText(LineBuffer); break;
}
#endif
GSMProcModemReply();
GSMSendCommStep = STATE_IDLE; return GSMModemReply;
break;
case STATE_TIMEOUT:
#ifdef SUPPORT_USART_SHOW
psprintf(LineBuffer, "CMD-TimeOut,");
DBusEditShowText(LineBuffer);
#endif
InitReadBuff();
InitSendBuff();
GSMSendCommStep = STATE_IDLE; return TIMEOUT;
break;
}
return IDLE;
}
/************************************************************************
* GSM Proc Read Command *
* Proc Read Command's response *
************************************************************************/
BYTE GSMProcReadComm(void)
{
GSMFuncReturn = GSMReadModemSense();
switch (GSMFuncReturn) {
case RING:
GSMPhonePhase = GSM_PHONE_RING;
GSMPhoneTimer = TIMER_xS(5);
break;
case CMTI:
if (GSMReadCommPara >= 1 && GSMReadCommPara <= 20) {
if (FIFO_READ_FULL) { FIFO_READ_FF; }
FIFO_READ_FI(GSMReadCommPara);
}
break;
case CLIP:
if (GSMPhonePhase == GSM_PHONE_RING) {
// if (strstr(StrGSMDailerTXT, "3686267") != NULL) {
if (strstr(StrGSMDailerTXT, DBusTELCNum) != NULL) {
GSMPhoneTooth = TRUE;
}
}
break;
case ECAV:
if (GSMPhonePhase == GSM_PHONE_RING) {
if (GSMPhoneValue == 0)
GSMPhoneTimer = 0;
}
break;
}
return GSMFuncReturn;
}
/************************************************************************
* GSM Setup *
* Setup to the GSM module *
************************************************************************/
BYTE GSMProcSetup(void)
{
switch (GSMSetupState) {
case STATE_IDLE:
GSMRetryCount = 20;
GSMSetupState++;
break;
case 0x01:
GSMRetryCount--;
if (GSMRetryCount == 0) {
GSMSetupState = STATE_ERROR;
}
else {
GSMDelayTimer = TIMER_xS(3);
GSMSetupState++;
}
break;
case 0x02:
if (GSMDelayTimer == 0) {
GSMSetupState++;
}
break;
case 0x03:
GSMSendCommType = AT;
GSMSetupState++;
break;
case 0x05:
GSMSendCommType = ATpCNMI;
GSMSetupState++;
break;
case 0x07:
GSMSendCommType = ATpCPMS;
GSMSetupState++;
break;
case 0x09:
GSMSendCommType = ATpCLIPe1;
GSMSetupState++;
break;
case 0x0B:
GSMSendCommType = ATmECAMe1;
GSMSetupState++;
break;
case 0x0D:
GSMSendCommType = ATmE2EAMS;
GSMSetupState++;
break;
case 0x0F:
GSMSendCommType = ATpCGDCONTq;
GSMSetupState++;
break;
case 0x04:
case 0x06:
case 0x08:
case 0x0A:
case 0x0C:
case 0x0E:
case 0x10:
case 0x14:
GSMFuncReturn = GSMProcSendComm();
if (GSMFuncReturn != IDLE) {
if (GSMFuncReturn == OK) GSMSetupState++;
else GSMSetupState = 0x01;
}
break;
case 0x11:
CGDCountIndex = 1;
CGDCountRetry = FALSE;
GSMSetupState++;
break;
case 0x12:
if (CGDCountState[CGDCountIndex - 1]) {
GSMSetupState += 3;
}
else {
CGDCountRetry = TRUE;
GSMSetupState++;
}
break;
case 0x13:
GSMSendCommType = ATpCGDCONT;
GSMSendCommPara = CGDCountIndex;
GSMSetupState++;
break;
case 0x15:
CGDCountIndex++;
if (CGDCountIndex > CGD_COUNT_MAX) {
CGDCountIndex = 1;
GSMSetupState++;
}
else {
GSMSetupState -= 3;
}
break;
case 0x16:
if (CGDCountRetry) {
GSMSetupState -= 7;
}
else {
GSMSetupState++;
}
break;
case 0x17:
GSMSetupState = STATE_OK;
break;
case STATE_OK:
GSMSetupState = STATE_IDLE; return OK;
break;
case STATE_ERROR:
GSMSetupState = STATE_IDLE; return ERROR;
break;
}
return IDLE;
}
/************************************************************************
* GSM Power On *
* Power On the GSM module *
************************************************************************/
BYTE GSMProcPower(void)
{
switch (GSMPowerState) {
case STATE_IDLE:
GSM_POWER_LO;
GSM_DTR_LO;
GSMDelayTimer = TIMER_xS(1) / 2;
GSMPowerState++;
break;
case 0x01:
if (GSMDelayTimer == 0) {
GSM_POWER_HI;
GSM_DTR_HI;
GSMDelayTimer = TIMER_xS(5);
GSMPowerState++;
}
break;
case 0x02:
if (GSMDelayTimer == 0) {
GSMPowerState++;
}
break;
case 0x03:
GSMFuncReturn = GSMProcSetup();
if (GSMFuncReturn == OK) GSMPowerState++;
else if (GSMFuncReturn == ERROR) GSMPowerState = STATE_ERROR;
break;
case 0x04:
// GSMSendCommType = ATpCMGD14;
GSMPowerState++;
GSMPowerState++;
break;
case 0x05:
GSMFuncReturn = GSMProcSendComm();
if (GSMFuncReturn != IDLE) {
if (GSMFuncReturn == OK) GSMPowerState++;
else GSMPowerState = STATE_ERROR;
}
break;
case 0x06:
GSMPowerState = STATE_OK;
break;
case STATE_OK:
GSMPowerState = STATE_IDLE; return OK;
break;
case STATE_ERROR:
GSMPowerState = STATE_IDLE; return ERROR;
break;
}
return IDLE;
}
/************************************************************************
* GSM Power Off *
* Power Off the GSM module *
************************************************************************/
BYTE GSMProcSleep(void)
{
switch (GSMSleepState) {
case STATE_IDLE:
GSM_POWER_LO;
GSMDelayTimer = TIMER_xS(3);
GSMSleepState++;
break;
case 0x01:
if (GSMDelayTimer == 0) {
GSM_POWER_HI;
GSMDelayTimer = TIMER_xS(9);
GSMSleepState++;
}
break;
case 0x02:
if (GSMDelayTimer == 0) {
InitUserBuff();
GSMSleepState = STATE_OK;
}
break;
case STATE_OK:
GSMSleepState = STATE_IDLE; return OK;
break;
}
return IDLE;
}
/************************************************************************
* GSM Reset *
* Reset GSM module *
************************************************************************/
BYTE GSMProcReset(void)
{
switch (GSMResetState) {
case STATE_IDLE:
GSM_POWER_HI;
GSMDelayTimer = TIMER_xS(1);
GSMResetState++;
break;
case 0x01:
if (GSMDelayTimer == 0) {
GSMDelayTimer = TIMER_xS(5);
GSMResetState++;
}
break;
case 0x02:
if (GSMDelayTimer == 0) {
GSMResetState++;
}
break;
case 0x03:
GSMFuncReturn = GSMProcSetup();
if (GSMFuncReturn == OK) GSMResetState++;
else if (GSMFuncReturn == ERROR) GSMResetState = STATE_ERROR;
break;
case 0x04:
GSMResetState = STATE_OK;
break;
case STATE_OK:
GSMResetState = STATE_IDLE; return OK;
break;
case STATE_ERROR:
GSMResetState = STATE_IDLE; return ERROR;
break;
}
return IDLE;
}
/************************************************************************
* GSM Hello *
* Hello process to the GSM module *
************************************************************************/
BYTE GSMProcHello(void)
{
switch (GSMHelloState) {
case STATE_IDLE:
GSMRetryCount = 3;
GSMHelloState++;
break;
case 0x01:
GSMSendCommType = ATmE2IPA1;
GSMSendCommPara = CGDCountIndex;
GSMHelloState++;
break;
case 0x02:
GSMFuncReturn = GSMProcSendComm();
if (GSMFuncReturn != IDLE) {
if (GSMFuncReturn == OK) GSMHelloState++;
else GSMHelloState = 0x90;
}
break;
case 0x03:
GSMHelloState = STATE_OK;
break;
case 0x90:
GSMRetryCount--;
if (GSMRetryCount) GSMHelloState++;
else GSMHelloState = STATE_ERROR;
break;
case 0x91:
GSMDelayTimer = TIMER_xS(1);
GSMHelloState++;
break;
case 0x92:
if (GSMDelayTimer == 0) {
CGDCountIndex++;
if (CGDCountIndex > CGD_COUNT_MAX) {
CGDCountIndex = 1;
}
GSMHelloState = 0x01;
}
break;
case STATE_OK:
GSMHelloState = STATE_IDLE; return OK;
break;
case STATE_ERROR:
GSMHelloState = STATE_IDLE; return ERROR;
break;
}
return IDLE;
}
/************************************************************************
* GSM Enter *
* Enter process to the GSM module *
************************************************************************/
BYTE GSMProcEnter(void)
{
switch (GSMEnterState) {
case STATE_IDLE:
GSMRetryCount = 3;
GSMEnterState++;
break;
case 0x01:
GSMSendCommType = ATmE2IPO;
GSMEnterState++;
break;
case 0x02:
GSMFuncReturn = GSMProcSendComm();
if (GSMFuncReturn != IDLE) {
if (GSMFuncReturn == CONNECT) GSMEnterState++;
else GSMEnterState = 0x90;
}
break;
case 0x03:
GSMDelayTimer = TIMER_xS(1);
GSMEnterState++;
case 0x04:
if (GSMDelayTimer == 0) GSMEnterState = STATE_OK;
break;
case 0x90:
GSMRetryCount--;
if (GSMRetryCount) GSMEnterState++;
else GSMEnterState = STATE_ERROR;
break;
case 0x91:
GSMDelayTimer = TIMER_xS(1);
GSMEnterState++;
break;
case 0x92:
if (GSMDelayTimer == 0) GSMEnterState = 0x01;
break;
case STATE_OK:
DBusMakeGPRSLink();
GSMEnterState = STATE_IDLE; return OK;
break;
case STATE_ERROR:
GSMEnterState = STATE_IDLE; return ERROR;
break;
}
return IDLE;
}
/************************************************************************
* GSM Leave *
* Leave process to the GSM module *
************************************************************************/
BYTE GSMProcLeave(void)
{
switch (GSMLeaveState) {
case STATE_IDLE:
GSMRetryCount = 3;
GSMLeaveState++;
break;
case 0x01:
GSM_DTR_LO;
GSMDelayTimer = TIMER_xS(3) / 10;
GSMLeaveState++;
break;
case 0x02:
if (GSMDelayTimer == 0) GSMLeaveState++;
break;
case 0x03:
GSM_DTR_HI;
GSMDelayTimer = TIMER_xS(5) / 10;
GSMLeaveState++;
break;
case 0x04:
if (!GSM_DSR_IN) GSMLeaveState++;
else if (GSMDelayTimer == 0) GSMLeaveState = 0x90;
break;
case 0x05:
GSMDelayTimer = TIMER_xS(2);
GSMLeaveState++;
break;
case 0x06:
if (GSMProcReadComm() == OK) GSMLeaveState++;
else if (GSMDelayTimer == 0) GSMLeaveState++;
break;
case 0x07:
GSMLeaveState = STATE_OK;
break;
case 0x90:
GSMRetryCount--;
if (GSMRetryCount) GSMLeaveState++;
else GSMLeaveState = STATE_ERROR;
break;
case 0x91:
GSMDelayTimer = TIMER_xS(1);
GSMLeaveState++;
break;
case 0x92:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -