Beispiel #1
0
static void bear_notify_cb(cbm_bearer_state_enum state, u8 ip_addr[4])
{
    LOG_DEBUG("bear_notify state: %s.", getStateDescription(state));

	switch (state)
	{
        case CBM_ACTIVATED:
            LOG_DEBUG("local ip is %d.%d.%d.%d", ip_addr[0], ip_addr[1], ip_addr[2], ip_addr[3]);

		    fsm_run(EVT_BEARER_HOLD);
            break;

        case CBM_DEACTIVATED:
            fsm_run(EVT_BEARER_DEACTIVATED);
            break;

        case CBM_GPRS_AUTO_DISC_TIMEOUT:
            LOG_ERROR("CBM_GPRS_AUTO_DISC_TIMEOUT happened!");
            eat_reset_module();
            break;

        case CBM_ACTIVATING:
        case CBM_DEACTIVATING:
            //no need to handle
            break;

        default:
            LOG_ERROR("BEAR_NOTIFY %d not handled", state);
            break;
	}
}
Beispiel #2
0
static void soc_notify_cb(s8 s,soc_event_enum event,eat_bool result, u16 ack_size)
{
    u8 buffer[1152] = {0};//1K + 128 for upgrade module
    s32 rc = 0;

    LOG_DEBUG("SOCKET notify:socketid(%d), event(%s).", s, getEventDescription(event));

    switch (event)
    {
        case SOC_READ:

            rc = eat_soc_recv(socket_id, buffer, 1152);//1K + 128 for upgrade module
            if (rc > 0)
            {
                client_proc(buffer, rc);
            }
            else
            {
                LOG_ERROR("eat_soc_recv error:rc=%d!", rc);
            }

            break;

        case SOC_CONNECT:
            if(result)
            {
                LOG_DEBUG("SOC_CONNECT success.");
                fsm_run(EVT_SOCKET_CONNECTED);
            }
            else
            {
                LOG_ERROR("SOC_CONNECT failed, maybe the server is OFF!");
                fsm_run(EVT_SOCKET_CONNECT_FAILED);
                eat_soc_close(s);
            }

            break;

        case SOC_CLOSE:
            LOG_INFO("SOC_CLOSE:socketid = %d", s);

            eat_soc_close(s);

            fsm_run(EVT_SOCKET_DISCONNECTED);

            break;

        case SOC_ACKED:
            LOG_DEBUG("acked size of send data: %d.", ack_size);
            break;

        default:
            LOG_INFO("SOC_NOTIFY %d not handled", event);
            break;
    }

}
Beispiel #3
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;
}
Beispiel #4
0
static int event_mod_ready_rd(const EatEvent_st* event)
{
	u8 buf[256] = {0};
	u16 len = 0;

	len = eat_modem_read(buf, 256);
	if (!len)
	{
	    LOG_ERROR("modem received nothing.");
	    return -1;
	}
    LOG_DEBUG("modem recv: %s", buf);
    if(get_manager_ATcmd_state())
    {
        set_manager_ATcmd_state(EAT_FALSE);
        cmd_get_AT(buf);
    }

    if (modem_IsCallReady(buf))
    {
        //diag_check();  // because diagnosis is not accurate, remove it

        fsm_run(EVT_CALL_READY);
    }

    if(modem_IsCCIDOK(buf))
    {
        cmd_SimInfo(buf + 9);//str(AT+CCID\r\n) = 9
    }


	return 0;
}
Beispiel #5
0
static void hostname_notify_cb(u32 request_id, eat_bool result, u8 ip_addr[4])
{
	if (result == EAT_TRUE)
	{
		LOG_DEBUG("hostname notify:%s -> %d.%d.%d.%d.", setting.domain, ip_addr[0], ip_addr[1], ip_addr[2], ip_addr[3], setting.port);

		socket_connect(ip_addr); //TODO:this should be done in function action_hostname2ip
		fsm_run(EVT_HOSTNAME2IP);
	}
	else
	{
	    LOG_ERROR("hostname_notify_cb error: request_id = %d", request_id);
	    fsm_run(EVT_HOSTNAME2IP_FAILED);
	}

    return;
}
Beispiel #6
0
void fsm( event_t *evt )
{
   /* Start with the init loop. */
   if (fsm_state == FSM_INIT) {
      fsm_init( evt );
      return;
   }
   else if (fsm_state == FSM_ERR) {
      LED0_ON();
      return;
   }

   /* Handle normal events. */
   switch (evt->type) {
      case EVENT_TYPE_TIMER:
         if (evt->timer.timer == 0) {
            LED0_TOGGLE();
            timer_start( 0, 500, NULL );
         }
         else if (evt->timer.timer == 1) {

            if (fsm_state == FSM_SEARCH)
               fsm_search();
            else if (fsm_state == FSM_RUN)
               fsm_run();
         }
         break;

      case EVENT_TYPE_ADC:
         fsm_adcBuf[ fsm_adc ]  = ADCL;
         fsm_adcBuf[ fsm_adc ] += ADCH<<8;
         /*printf( "adc %d: %u", fsm_adc, fsm_adcBuf[ fsm_adc ] );*/
         fsm_adc = 1-fsm_adc;
         adc_start( fsm_adc );
         break;

      default:
         break;
   }
}
Beispiel #7
0
int socket_sendData(void* data, s32 len)
{
    s32 rc;

    LOG_HEX((const char*)data, len);

    rc = eat_soc_send(socket_id, data, len);
    if (rc >= 0)
    {
        LOG_DEBUG("socket send data successful.");
    }
    else
    {
        if (rc == SOC_PIPE || rc == SOC_NOTCONN)
        {
            fsm_run(EVT_SOCKET_DISCONNECTED);       //这个地方仅为保护作用,正常的socket断链应该会通过soc_notify_cb来通知
        }
        LOG_ERROR("sokcet send data failed:%d!", rc);
    }


    return rc;
}
Beispiel #8
0
int axe_run(LIFE_S *self)
{
    DOTA_RETURN_IF_NULL(self, ERR_NULL_POINTER);

    return fsm_run(&axe_fsm, self);
}