Пример #1
0
static int event_timer(const EatEvent_st* event)
{
    switch (event->data.timer.timer_id)
    {
        case TIMER_LOOP:
            LOG_DEBUG("TIMER_LOOP expire.");
            fsm_run(EVT_LOOP);
            eat_timer_start(event->data.timer.timer_id, setting.main_loop_timer_period);
            break;

        case TIMER_SEEKAUTOOFF:
            LOG_DEBUG("TIMER_SEEKAUTOOFF expire!");
            setSeekMode(EAT_FALSE);
            break;

        case TIMER_GPS_SEND:
            cmd_GPSPack();
            eat_timer_start(event->data.timer.timer_id, setting.gps_send_period);
            break;

        case TIMER_MSG_RESEND:
            msg_resend();
            eat_timer_start(event->data.timer.timer_id, 60*1000);
            break;

        default:
            LOG_ERROR ("timer(%d) not processed!", event->data.timer.timer_id);
            break;
    }
    return 0;
}
Пример #2
0
int event_timer(const EatEvent_st* event)
{
    switch (event->data.timer.timer_id)
    {
        case TIMER_WATCHDOG:
            LOG_INFO("TIMER_WATCHDOG expire!");
            feedWatchdog();
            eat_timer_start(event->data.timer.timer_id, 50000);
            break;

        case TIMER_AT_CMD:
            LOG_INFO("TIMER_AT_CMD expire!");
            eat_modem_write("AT+CGATT?\n", 10);
            eat_timer_start(event->data.timer.timer_id, 5000);
            break;

        case TIMER_GPS_SEND:
            LOG_INFO("TIMER_GPS_SEND expire!");
            eat_timer_start(event->data.timer.timer_id, setting.gps_timer_period);
            client_loop();
            break;

        default:
            LOG_ERROR ("timer(%d) not processed", event->data.timer.timer_id);
            break;
    }
    return 0;
}
Пример #3
0
void app_vibration_thread(void *data)
{
	EatEvent_st event;
	bool ret;

	LOG_INFO("vibration thread start.");

	ret = mma8652_init();
	if (!ret)
	{
        //LED_off();
        LOG_ERROR("mma8652 init failed");
	}
	else
	{
	    mma8652_config();
	}

	eat_timer_start(TIMER_VIBRATION, setting.vibration_timer_period);

	while(EAT_TRUE)
	{
        eat_get_event_for_user(THREAD_VIBRATION, &event);
        switch(event.event)
        {
            case EAT_EVENT_TIMER:
                switch (event.data.timer.timer_id)
                {
                    case TIMER_VIBRATION:
                        vibration_timer_handler();
                        eat_timer_start(TIMER_VIBRATION, setting.vibration_timer_period);
                        break;
                    case TIMER_MOVE_ALARM:
                        move_alarm_timer_handler();
                        break;

                    default:
                        LOG_ERROR("timer(%d) expire!", event.data.timer.timer_id);
                        break;
                }
                break;

            default:
            	LOG_ERROR("event(%d) not processed!", event.event);
                break;
        }
    }
}
Пример #4
0
static void vibration_timer_handler(void)
{
    static eat_bool isFirstTime = EAT_TRUE;

    uint8_t transient_src = 0;

    mma8652_i2c_register_read(MMA8652_REG_TRANSIENT_SRC, &transient_src, sizeof(transient_src));
    if(transient_src & MMA8652_TRANSIENT_SRC_EA)
    {
        /* At the first time, the value of MMA8X5X_TRANSIENT_SRC is strangely 0x60.
         * Do not send alarm at the first time.
         */
        if(isFirstTime)
        {
            isFirstTime = EAT_FALSE;

            Vibration_setMoved(EAT_FALSE);
        }
        else
        {
            Vibration_setMoved(EAT_TRUE);
        }
    }
    else
    {
        Vibration_setMoved(EAT_FALSE);
    }

    //always to judge if need to alarm , just judge the defend state before send alarm
    if(Vibration_isMoved())
    {
        eat_timer_start(TIMER_MOVE_ALARM, MOVE_TIMER_PERIOD);
        //vibration_sendAlarm();  //bec use displacement judgement , there do not alarm
    }

    if(Vibration_isMoved())
    {
        ResetVibrationTime();
        LOG_DEBUG("shake!");
    }
    else
    {
        VibrationTimeAdd();

        if(getVibrationTime() * setting.vibration_timer_period >= (get_autodefend_period() * 60000))
        {
            if(get_autodefend_state())
            {
                if(EAT_FALSE == vibration_fixed())
                {
                    vivration_AutolockStateSend(EAT_TRUE);    //TODO:send autolock_msg to main thread
                    set_vibration_state(EAT_TRUE);
                }
            }                    
            Reset_AlarmCount();
        }
    }

    return;
}
Пример #5
0
/* 
 * ===  FUNCTION  ======================================================================
 *         Name: AtCmdDelayExe
 *  Description: dealy 10ms to execute at cmd 
 *        Input:
 *       Output:
 *       Return:
 *               eat_bool::
 *       author: Jumping create at 2014-1-13
 * =====================================================================================
 */
static eat_bool AtCmdDelayExe(u16 delay)
{
    eat_bool ret = FALSE;
    eat_trace("INFO: at cmd delay execute,%d",delay);
    if (delay == 0){
        delay = AT_CMD_EXECUTE_DELAY;
    }
    ret = eat_timer_start(EAT_TIMER_1,delay);
    if (ret)
        s_atExecute = 1;
    return ret;
}
Пример #6
0
static eat_bool AtCmdOverTimeStart(void)
{
    eat_bool ret = FALSE;
    ret = eat_timer_start(EAT_TIMER_2,AT_CMD_EXECUTE_OVERTIME);
    return ret;
}
Пример #7
0
static void move_alarm_timer_handler()
{
    unsigned char readbuf[3];
    int i;
    float tmp[3]={0};
    short temp;
    static float x_data[MAX_MOVE_DATA_LEN], y_data[MAX_MOVE_DATA_LEN], z_data[MAX_MOVE_DATA_LEN];
    float temp_data[MAX_MOVE_DATA_LEN];
    static int timerCount = 0;
    bool ret = mma8652_i2c_register_read(MMA8652_REG_OUT_X_MSB, readbuf, 3);
    temp = readbuf[0]<<8;
    x_data[timerCount] = temp/256;
     temp = readbuf[1]<<8;
    y_data[timerCount] = temp/256;
     temp = readbuf[2]<<8;
    z_data[timerCount] = temp/256;
    timerCount++;

    if(timerCount<MAX_MOVE_DATA_LEN)
    {
        eat_timer_start(TIMER_MOVE_ALARM, MOVE_TIMER_PERIOD);
    }
    else
    {
        timerCount = 0;
        for(i=0;i<MAX_MOVE_DATA_LEN;i++)
        {
            tmp[0] += (x_data[i]/MAX_MOVE_DATA_LEN);
            tmp[1] += (y_data[i]/MAX_MOVE_DATA_LEN);
            tmp[2] += (z_data[i]/MAX_MOVE_DATA_LEN);
        }
        for(i=0;i<MAX_MOVE_DATA_LEN;i++)
        {
            x_data[i] = x_data[i] - tmp[0];
            y_data[i] = y_data[i] - tmp[1];
            z_data[i] = z_data[i] - tmp[2];
        }
        DigitalIntegrate(x_data, temp_data, MAX_MOVE_DATA_LEN,MOVE_TIMER_PERIOD/1000.0);
        DigitalIntegrate(temp_data, x_data, MAX_MOVE_DATA_LEN,MOVE_TIMER_PERIOD/1000.0);
        for(i=0;i<MAX_MOVE_DATA_LEN;i++)
        {
            if(x_data[0]<abs(x_data[i]))
            {
                x_data[0] = abs(x_data[i]);
            }
            if(x_data[i] > MOVE_THRESHOLD)
            {
                if(EAT_TRUE == vibration_fixed())
                {
                    vibration_sendAlarm();
                    LOG_DEBUG("MOVE_TRESHOLD_Z[%d]   = %f",i, x_data[i]);
                }
                return;
            }

        }
        LOG_DEBUG("MAX_X  = %f", x_data[0]);
        DigitalIntegrate(y_data, temp_data, MAX_MOVE_DATA_LEN,MOVE_TIMER_PERIOD/1000.0);

        DigitalIntegrate(temp_data, y_data, MAX_MOVE_DATA_LEN,MOVE_TIMER_PERIOD/1000.0);
        for(i=0;i<MAX_MOVE_DATA_LEN;i++)
        {
            if(y_data[i] > MOVE_THRESHOLD)
            {
                if(EAT_TRUE == vibration_fixed())
                {
                    vibration_sendAlarm();
                    LOG_DEBUG("MOVE_TRESHOLD_Z[%d]   = %f",i, y_data[i]);
                }
                return;
            }
            if(y_data[0]<abs(y_data[i]))
            {
                y_data[0] = abs(y_data[i]);
            }

        }
        LOG_DEBUG("MAX_Y  = %f", y_data[0]);
        DigitalIntegrate(z_data, temp_data, MAX_MOVE_DATA_LEN,MOVE_TIMER_PERIOD/1000.0);
        DigitalIntegrate(temp_data, z_data, MAX_MOVE_DATA_LEN,MOVE_TIMER_PERIOD/1000.0);
        for(i=0;i<MAX_MOVE_DATA_LEN;i++)
        {
            if(z_data[i] > MOVE_THRESHOLD)
            {
                if(EAT_TRUE == vibration_fixed())
                {
                    vibration_sendAlarm();
                    LOG_DEBUG("MOVE_TRESHOLD_Z[%d]   = %f",i, z_data[i]);
                }
                return;
            }
            if(z_data[0]<abs(z_data[i]))
            {
                z_data[0] = abs(z_data[i]);
            }
        }
        LOG_DEBUG("MAX_z  = %f", z_data[0]);
    }


}
Пример #8
0
static void app_main(void *data)
{
    EatUartConfig_st uart_config;
    EatEvent_st event;
    int event_num = 0;

	APP_InitRegions(); //APP RAM initialize
    APP_init_clib(); //C library initialize

    if(eat_uart_open(eat_uart_app ) == EAT_FALSE)
    {
	    eat_trace("[%s] uart(%d) open fail!", __FUNCTION__, eat_uart_app);
    }
	
    uart_config.baud = EAT_UART_BAUD_115200;
    uart_config.dataBits = EAT_UART_DATA_BITS_8;
    uart_config.parity = EAT_UART_PARITY_NONE;
    uart_config.stopBits = EAT_UART_STOP_BITS_1;
    if(EAT_FALSE == eat_uart_set_config(eat_uart_app, &uart_config))
    {
        eat_trace("[%s] uart(%d) set config fail!", __FUNCTION__, eat_uart_app);
    }
    //eat_uart_set_send_complete_event(eat_uart_app, EAT_TRUE);
    eat_timer_start(EAT_TIMER_1, 10000);
    while(1)
    {
        event_num = eat_get_event_num();
get_event:
        if(event_num>0)
        {
            eat_get_event(&event);
            eat_trace("[%s] event_id=%d", __FUNCTION__, event.event);

            if (event.event == EAT_EVENT_NULL || event.event >= EAT_EVENT_NUM)
            {
                eat_trace("[%s] invalid event type", __FUNCTION__, event.event);
                continue;
            }

            switch (event.event)
            {
                case EAT_EVENT_TIMER :
                    {
                        //Restart timer
                        if(event.data.timer.timer_id == EAT_TIMER_2)
                        {
                            eat_timer_start(EAT_TIMER_2, 50);
                        }else 
                        {
                            if(eat_timer_process())
                                eat_timer_start(event.data.timer.timer_id, 6000);
                            else
                                eat_timer_start(EAT_TIMER_2, 50);
                        }
                        // eat_trace("Timer test 1, timer ID:%d", event.data.timer.timer_id);
                    }
                    break;
                case EAT_EVENT_MDM_READY_RD:
                    mdm_rx_proc(&event);
                    break;
                case EAT_EVENT_MDM_READY_WR:
                    eat_trace("[%s] uart(%d) event :%s", __FUNCTION__, event.data.uart, "EAT_EVENT_MDM_READY_WR");
                    break;
                case EAT_EVENT_UART_READY_RD:
                    uart_rx_proc(&event);
                    break;
                case EAT_EVENT_UART_READY_WR:
                    eat_trace("[%s] uart(%d) event :%s", __FUNCTION__, event.data.uart, "EAT_EVENT_UART_READY_WR");
                    uart_ready_wr_proc();
                    break;
                case EAT_EVENT_UART_SEND_COMPLETE:
                    uart_send_complete_proc(&event);
                    break;

                default:
                    break;
            }
            event_num = eat_get_event_num();
            if(event_num>0)
                goto get_event;
            else
                eat_sleep(50);
        }else
        {
            eat_sleep(50);
        }
    }	
}
Пример #9
0
Файл: main.c Проект: igou/com
void app_main(void *data)
{   
    EatEvent_st event;
    u16 len = 0;
    EatUartConfig_st uart_config;
    eat_bool ret;

    APP_InitRegions();//Init app RAM
    APP_init_clib(); //C library initialize, second step
    #if 0
   if(eat_uart_open(EAT_UART_1 ) == EAT_FALSE)
    {
	    eat_trace("[%s] uart(%d) open fail!", __FUNCTION__, EAT_UART_1);
    }
	
    uart_config.baud = EAT_UART_BAUD_115200;
    uart_config.dataBits = EAT_UART_DATA_BITS_8;
    uart_config.parity = EAT_UART_PARITY_NONE;
    uart_config.stopBits = EAT_UART_STOP_BITS_1;
    if(EAT_FALSE == eat_uart_set_config(EAT_UART_1, &uart_config))
    {
        eat_trace("[%s] uart(%d) set config fail!", __FUNCTION__, EAT_UART_1);
    }
 #endif
    log_0("app_main ENTRY");
    Gpio_init();
    ret = eat_mem_init(s_memPool,EAT_MEM_MAX_SIZE);
    if (!ret)
        log_0("ERROR: eat memory initial error!");
    
    eat_timer_start(TIMER_SOFT_RESET,600000);
    at_cluster();

    while(EAT_TRUE)
    {
        eat_get_event(&event);
        log_2("MSG id%x", event.event);
        switch(event.event)
        {
          case EAT_EVENT_TIMER :
           {
             EatTimer_enum timer_id = event.data.timer.timer_id;
             timer_hdlr(timer_id);
           } 
             break;
          case EAT_EVENT_INT :      
             log_0("INTERRUPT IS COMING");
             if(get_key())/*donw = 1 */
                key_hdlr();               
             break;
             
           case EAT_EVENT_USER_MSG:
            {
             u8 data = event.data.user_msg.data[0];
             set_debounce(data);
            }
              break;
           case EAT_EVENT_KEY:
           {
            eat_bool press = event.data.key.is_pressed;
            log_0("power key");
            pwrkey_hdlr(press);
           }
              break;
              
          case EAT_EVENT_MDM_READY_WR:
              break;
              
          case EAT_EVENT_UART_READY_RD:
            log_2("EAT_EVENT_UART_READY_RD");
              break;
          case EAT_EVENT_MDM_READY_RD:
              {        
                  len = 0;
                           /* boot info(such as:RDY ;+CFUN: 1  ;+CPIN: READY)
                            * will be sent to here(main task);
                            */
                  len = eat_modem_read(buf, 2048); /*necessary:Read it out*/ 
                  buf[len] = 0;
                  log_2("main task buf (%s)",buf);
                  #if 0
                 if(core_is_ready(buf))
                    {
                     eat_trace("core is ready");
                     eat_timer_start(TIMER_SOFT_RESET,600000);
                     at_cluster();
                   }  
                 #endif
               }
              break;    
          case EAT_EVENT_UART_SEND_COMPLETE :
              break;
          default:
              break;
        }

    }

}