예제 #1
0
파일: lirc.cpp 프로젝트: BrandRegard/gnash
Lirc::~Lirc()
{
//    GNASH_REPORT_FUNCTION;
    if (_button != 0) {
	delete _button;
    }
    closeNet();
}
예제 #2
0
파일: gsm.c 프로젝트: ChangXiaodong/manhole
uint8_t openNet()
{
    uint16_t timeout = 0;
    memset( GPRS.receive, 0, ( size_t )GPRS_RX_BUFFER_SIZE );
    GPRS.receive_count = 0;
    printf("AT+SAPBR=1,1\r\n");
    while(GPRS.receive_count < 0x14)
    {
        timeout++;
        delay_1ms();
        if(timeout>TIME_OUT)
        {
            return ERROR;
        }
    }
    for(uint8_t i=GPRS.receive_count;i>0;i--)
    {
        if((GPRS.receive[i]   == '\r') && 
           (GPRS.receive[i+1] == '\n') && 
           (GPRS.receive[i+2] == 'O') && 
           (GPRS.receive[i+3] == 'K') && 
           (GPRS.receive[i+4] == '\r') && 
           (GPRS.receive[i+5] == '\n')
           )
        {
            return OK;
        }
    }
    for(uint8_t i=GPRS.receive_count;i>0;i--)
    {
        if((GPRS.receive[i]   == '\r') && 
           (GPRS.receive[i+1] == '\n') && 
           (GPRS.receive[i+2] == 'E') && 
           (GPRS.receive[i+3] == 'R') && 
           (GPRS.receive[i+4] == 'R') && 
           (GPRS.receive[i+5] == 'O') &&
           (GPRS.receive[i+6] == 'R') && 
           (GPRS.receive[i+7] == '\r') && 
           (GPRS.receive[i+8] == '\n')
           )
        {
           if(closeNet())
           {
              openNet();
           }
           else
           {
               GPRS_Error();
           }
            
        }
    }
    
    return ERROR;
}
int initCellModem(Serial *serial)
{

    size_t success = 0;
    size_t attempts = 0;
    g_cellmodem_status = CELLMODEM_STATUS_NOT_INIT;

    while (!success && attempts++ < 3) {
        closeNet(serial);

        if (attempts > 1) {
            pr_debug("SIM900: power cycling\r\n");
            if (sendCommandOK(serial, "AT\r") == 1 && attempts > 1) {
                pr_debug("SIM900: powering down\r\n");
                powerCycleCellModem();
            }
            powerCycleCellModem();
        }

        if (sendCommandRetry(serial, "ATZ\r", "OK", 2, 2) != 1) continue;
        if (sendCommandRetry(serial, "ATE0\r", "OK", 2, 2) != 1) continue;
        sendCommand(serial, "AT+CIPSHUT\r", "OK");
        if (isNetworkConnected(serial, 60, 3) != 1) continue;
        getSignalStrength(serial);
        read_subscriber_number(serial);
        read_IMEI(serial);
        if (isDataReady(serial, 30, 2) != 1) continue;
        success = 1;
    }
    if ( success ) {
        g_cellmodem_status = CELLMODEM_STATUS_PROVISIONED;
        return 0;
    } else {
        g_cellmodem_status = CELLMODEM_STATUS_NO_NETWORK;
        return -1;
    }
}