Exemplo n.º 1
0
static void sms_version_proc(char *p, u8 *number)
{
    MSG_THREAD *msg = NULL;
    SMS_SEND_INFO *data = NULL;
    char msgLen = 0;
    char *ptr1;
    char ack_message[ACK_MESSAGE_LEN]= {0};

    ptr1 = string_bypass(p, "VERSION?");
    if(NULL != ptr1)
    {
        snprintf(ack_message, ACK_MESSAGE_LEN, "VER:%s\r\nCORE:%s", VERSION_STR, eat_get_version());
        msgLen = sizeof(MSG_THREAD) + sizeof(SMS_SEND_INFO) + strlen(ack_message);
        msg = allocMsg(msgLen);
        if (!msg)
        {
            LOG_ERROR("alloc sms msg failed!");
            return;
        }

        msg->cmd = CMD_THREAD_SMS;
        msg->length = sizeof(SMS_SEND_INFO) + strlen(ack_message);

        data = (SMS_SEND_INFO*)msg->data;
        strncpy(data->number,number,TEL_NO_LENGTH + 1);
        data->type = SMS_SEND_DIRECT;
        data->smsLen = strlen(ack_message);
        strncpy(data->content,ack_message,ACK_MESSAGE_LEN);

        sendMsg(THREAD_MAIN, msg, msgLen);
    }

    return;
}
Exemplo n.º 2
0
static void sms_seek_proc(char *p, u8 *number)
{
    MSG_THREAD *msg = NULL;
    SMS_SEND_INFO *data = NULL;
    char msgLen = 0;
    char *ptr1;
    int result = -1;
    char ack_message[ACK_MESSAGE_LEN]= {0};

    ptr1 = string_bypass(p, "SEEK 1");
    if(NULL != ptr1)
    {
        snprintf(ack_message, ACK_MESSAGE_LEN, "SEEK ON OK");
        result = SUCCESS;
    }

    ptr1 = string_bypass(p, "SEEK 0");
    if(NULL != ptr1)
    {
        snprintf(ack_message, ACK_MESSAGE_LEN, "SEEK OFF OK");
        result = SUCCESS;
    }

    if(SUCCESS == result)
    {
        msgLen = sizeof(MSG_THREAD) + sizeof(SMS_SEND_INFO) + strlen(ack_message);
        msg = allocMsg(msgLen);
        if (!msg)
        {
            LOG_ERROR("alloc sms msg failed!");
            return;
        }

        msg->cmd = CMD_THREAD_SMS;
        msg->length = sizeof(SMS_SEND_INFO) + strlen(ack_message);

        data = (SMS_SEND_INFO*)msg->data;
        strncpy(data->number,number,TEL_NO_LENGTH + 1);
        data->type = SMS_SEND_DIRECT;
        data->smsLen = strlen(ack_message);
        strncpy(data->content,ack_message,ACK_MESSAGE_LEN);

        sendMsg(THREAD_MAIN, msg, msgLen);
    }

    return;
}
Exemplo n.º 3
0
static void sms_factory_proc(char *p, u8 *number)
{
    MSG_THREAD *msg = NULL;
    SMS_SEND_INFO *data = NULL;
    char msgLen = 0;
    char *ptr1;
    char ack_message[ACK_MESSAGE_LEN]= {0};
    int rc = 0;

    ptr1 = string_bypass(p, "Factory");
    if(NULL != ptr1)
    {
        rc = fs_factory();
        if(0 > rc)
        {
            snprintf(ack_message, ACK_MESSAGE_LEN, "Factory default error");
        }
        else
        {
            snprintf(ack_message, ACK_MESSAGE_LEN, "Factory default ok");
        }
        msgLen = sizeof(MSG_THREAD) + sizeof(SMS_SEND_INFO) + strlen(ack_message);
        msg = allocMsg(msgLen);
        if (!msg)
        {
            LOG_ERROR("alloc sms msg failed!");
            return;
        }

        msg->cmd = CMD_THREAD_SMS;
        msg->length = sizeof(SMS_SEND_INFO) + strlen(ack_message);

        data = (SMS_SEND_INFO*)msg->data;
        strncpy(data->number,number,TEL_NO_LENGTH + 1);
        data->type = SMS_SEND_DIRECT;
        data->smsLen = strlen(ack_message);
        strncpy(data->content,ack_message,ACK_MESSAGE_LEN);

        sendMsg(THREAD_MAIN, msg, msgLen);

        //ResetFlag = EAT_TRUE;
    }

    return;
}
Exemplo n.º 4
0
static EBBRC 
MsgMgrPrim_msg0(MsgMgrRef _self, EvntLoc loc, MsgHandlerId id)
{
  MsgMgrPrimRef self = (MsgMgrPrimRef)_self;
  MsgStore *msg;  
  MsgMgrPrimRef target;
  EBBRC rc;

  rc = MsgMgrPrim_findTarget(self, loc, &target);
  if (rc == EBBRC_NOTFOUND) return rc;

  LRT_RCAssert(rc);

  msg = allocMsg(self);
  msg->id = id;
  msg->numargs = 0;
  
  MsgMgrPrim_enqueueMsg(target, msg);
  return EBBRC_OK;
}
Exemplo n.º 5
0
static eat_bool vibration_sendAlarm(void)
{
    u8 msgLen = sizeof(MSG_THREAD) + sizeof(ALARM_INFO);
    MSG_THREAD *msg = NULL;
    ALARM_INFO *msg_data = NULL;

    Add_AlarmCount();
    if(Get_AlarmCount() < 2)
    {
        msg = allocMsg(msgLen);
        msg_data = (ALARM_INFO*)msg->data;

        msg->cmd = CMD_THREAD_ALARM;
        msg->length = sizeof(ALARM_INFO);
        msg_data->alarm_type = ALARM_VIBRATE;

        LOG_DEBUG("vibration alarm:cmd(%d),length(%d),data(%d)", msg->cmd, msg->length, msg_data->alarm_type);
        return sendMsg(THREAD_MAIN, msg, msgLen);
    }

    return EAT_FALSE;
}
Exemplo n.º 6
0
static EBBRC 
MsgMgrPrim_msg3(MsgMgrRef _self, EvntLoc loc, MsgHandlerId id, 
		uintptr_t a1, uintptr_t a2, uintptr_t a3)
{
  MsgMgrPrimRef self = (MsgMgrPrimRef)_self;
  MsgStore *msg;  
  MsgMgrPrimRef target;
  EBBRC rc;

  rc = MsgMgrPrim_findTarget(self, loc, &target);
  if (rc == EBBRC_NOTFOUND) return rc;

  LRT_RCAssert(rc);

  msg = allocMsg(self);
  msg->id = id;
  msg->numargs = 3;
  msg->args[0] = a1;
  msg->args[1] = a2;
  msg->args[2] = a3;
  MsgMgrPrim_enqueueMsg(target, msg);
  return EBBRC_OK;
};
Exemplo n.º 7
0
static eat_bool vivration_AutolockStateSend(eat_bool state)
{
    eat_bool ret;
    u8 msgLen = sizeof(MSG_THREAD) + sizeof(AUTOLOCK_INFO);
    MSG_THREAD* msg = allocMsg(msgLen);
    AUTOLOCK_INFO* msg_state = 0;

    if (!msg)
    {
        LOG_ERROR("alloc msg failed!");
        return EAT_FALSE;
    }

    msg->cmd = CMD_THREAD_AUTOLOCK;
    msg->length = sizeof(AUTOLOCK_INFO);

    msg_state = (AUTOLOCK_INFO*)msg->data;
    msg_state->state = state;

    LOG_DEBUG("send autolock state msg to main thread!");
    ret = sendMsg(THREAD_MAIN, msg, msgLen);

    return ret;
}
Exemplo n.º 8
0
/**********************************************************************
														SEND

	Invia un messaggio come richiesto dal sender al destinatario
	specificato nel registro a1 (receiver), col payload specificato
	al registro	a2 (payload).
	Operazione NON BLOCCANTE.

**********************************************************************/
int send (tcb_t *sender, tcb_t *target, U32 payload){

	msg_t *msg;
	tcb_t *_sender_;

	/* Protezione SSI */
	if (sender == SSI_tcb)
		_sender_ = (tcb_t *)MAGIC_SSI;
	else 
		_sender_ = sender;

	/* Destinatario in ready_queue o thread corrente */
	if ( ((thereIsThread(&ready_queue, target)) != NULL ) || (current_thread == target) ) {
		if ((msg = allocMsg()) == NULL) PANIC();
		/* Creazione e compilazione messaggio */

		msg->m_sender = _sender_;
		msg->m_message = payload;

		/* Priorità allo Pseudo Clock Tick -> Messaggio in testa */
		if (_sender_ == (tcb_t*)BUS_INTERVALTIMER)
			pushMessage(&(target->t_inbox), msg);
		/* Trattamento normale -> Messaggio in coda */
		else insertMessage(&(target->t_inbox), msg);

		return (MSGGOOD);
	}
	
	/* Destinatario in wait_queue */
	else if ((thereIsThread(&wait_queue, target)) != NULL ) {

		/* 
				Se sta aspettando un messaggio da questo thread 
				o da chiunque sveglio il thread dest togliendolo 
				dalla wait_queue e lo inserisco nella ready_queue
				passandogli il payload dove mi aveva richiesto e 
				che avevo salvato nel TCB nel	campo "reply".
		*/
		if ((target->waiting_for == _sender_) || (target->waiting_for == ANYMESSAGE)) {
			*(target->reply) = payload;

			/* Risveglio il thread */
			insertThread(&ready_queue, outThread(&wait_queue, target));

			/* Risettaggio campi per message passing */
			target->waiting_for = (tcb_t *)-1;
			target->reply = (U32 *)-1;

			/* Decremento soft block count se caso SSI e restituisco sender al destinatario */
			if (_sender_ == SSI_tcb)
				soft_block_count--;

			target->t_state.reg_v0 = (U32)_sender_;
			
			return (MSGGOOD);
		}

		/* Destinatario momentaneamente in attesa di un altro mittente */
		else {
			/* Tutto come sopra */
			if ((msg = allocMsg()) == NULL) PANIC();

			msg->m_sender = _sender_;
			msg->m_message = payload;

			if (sender == (tcb_t *)BUS_INTERVALTIMER)
				pushMessage(&(target->t_inbox), msg);

			else insertMessage(&(target->t_inbox), msg);

			return (MSGGOOD);
		}

	}

	/* Nessuno dei casi precedenti --> potrebbe essere stato terminato il thread */
	return (MSGNOGOOD);
	
}
Exemplo n.º 9
0
static void sms_server_proc(char *p, u8 *number)
{
    MSG_THREAD *msg = NULL;
    SMS_SEND_INFO *data = NULL;
    char msgLen = 0;
    char *ptr1;
    char ack_message[ACK_MESSAGE_LEN]= {0};
    char domainORip[MAX_DOMAIN_NAME_LEN] = {0};
    char domain[MAX_DOMAIN_NAME_LEN] = {0};
    u32 ip[4] = {0};
    u32 port = 0;
    int count = 0;
    int result = -1;

    ptr1 = string_bypass(p, "SERVER?");
    if(NULL != ptr1)
    {
        if(setting.addr_type == ADDR_TYPE_IP)
        {
            snprintf(ack_message, ACK_MESSAGE_LEN, "SERVER %d.%d.%d.%d:%d",setting.ipaddr[0],setting.ipaddr[1],setting.ipaddr[2],setting.ipaddr[3],setting.port);
        }
        else if(setting.addr_type == ADDR_TYPE_DOMAIN)
        {
            snprintf(ack_message, ACK_MESSAGE_LEN, "SERVER %s:%d",setting.domain,setting.port);
        }
        result = SUCCESS;
    }

    ptr1 = string_bypass(p, "SERVER ");
    if(NULL != ptr1)
    {
        count = sscanf(ptr1, "%[^:]:%u", domainORip, &port);
        if(2 == count)
        {
            count = sscanf(domainORip, "%u.%u.%u.%u", &ip[0], &ip[1], &ip[2], &ip[3]);
            if(4 == count)
            {
                if(ip[0] <= 255 && ip[1] <= 255 && ip[2] <= 255 && ip[3] <= 255)
                {
                    setting.addr_type = ADDR_TYPE_IP;
                    setting.ipaddr[0] = (char)ip[0];
                    setting.ipaddr[1] = (char)ip[1];
                    setting.ipaddr[2] = (char)ip[2];
                    setting.ipaddr[3] = (char)ip[3];
                    setting.port = (u16)port;

                    setting_save();
                    ResetFlag = EAT_TRUE;

                    snprintf(ack_message, ACK_MESSAGE_LEN, "%s:%u OK", domainORip, port);
                }
                else
                {
                    snprintf(ack_message, ACK_MESSAGE_LEN, "%s:%u ERROR", domainORip, port);
                }
            }
            else
            {
                count = sscanf(domainORip, "%[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.]", domain);
                if(1 == count)
                {
                    setting.addr_type = ADDR_TYPE_DOMAIN;
                    strncpy(setting.domain, domainORip,MAX_DOMAIN_NAME_LEN);
                    setting.port = (u16)port;

                    setting_save();
                    ResetFlag = EAT_TRUE;

                    snprintf(ack_message, ACK_MESSAGE_LEN, "%s:%u OK", domain, port);
                }
                else
                {
                    snprintf(ack_message, ACK_MESSAGE_LEN, "%s:%u ERROR", domainORip, port);
                }
            }

            //ResetFlag = EAT_TRUE;
        }
        else
        {
            snprintf(ack_message, ACK_MESSAGE_LEN, "%s ERROR", ptr1);
        }

        result = SUCCESS;
    }

    if(SUCCESS == result)
    {
        msgLen = sizeof(MSG_THREAD) + sizeof(SMS_SEND_INFO) + strlen(ack_message);
        msg = allocMsg(msgLen);
        if (!msg)
        {
            LOG_ERROR("alloc sms msg failed!");
            return;
        }

        msg->cmd = CMD_THREAD_SMS;
        msg->length = sizeof(SMS_SEND_INFO) + strlen(ack_message);

        data = (SMS_SEND_INFO*)msg->data;
        strncpy(data->number,number,TEL_NO_LENGTH + 1);
        data->type = SMS_SEND_DIRECT;
        data->smsLen = strlen(ack_message);
        strncpy(data->content,ack_message,ACK_MESSAGE_LEN);

        sendMsg(THREAD_MAIN, msg, msgLen);
    }

    return;
}