示例#1
0
void mqttcallback(char* topic, byte* payload, unsigned int len) {
  skipSleep=true; // don't go to sleep if we receive mqtt message
  char tmp[200];
  strncpy(tmp, (char*)payload, len);
  tmp[len] = 0x00;
  handleMsg(tmp);
}
void Net::visit(Renderer *renderer, const kmMat4& parentTransform, bool parentTransformUpdated)
{
	if(!msgQueue.empty())
	{
		handleMsg();
	}
}
示例#3
0
void ScriptResolver::readStdout()
{
    qDebug() << Q_FUNC_INFO << m_proc.bytesAvailable();
    if( m_msgsize == 0 )
    {
        if( m_proc.bytesAvailable() < 4 ) return;
        quint32 len_nbo;
        m_proc.read( (char*) &len_nbo, 4 );
        m_msgsize = qFromBigEndian( len_nbo );
        qDebug() << Q_FUNC_INFO << "msgsize" << m_msgsize;
    }

    if( m_msgsize > 0 )
    {
        m_msg.append( m_proc.read( m_msgsize - m_msg.length() ) );
    }

    if( m_msgsize == (quint32) m_msg.length() )
    {
        handleMsg( m_msg );
        m_msgsize = 0;
        m_msg.clear();
        if( m_proc.bytesAvailable() ) QTimer::singleShot( 0, this, SLOT(readStdout()) );
    }
}
int main(int argc, const char *argv[])
{
	int serfile,i;
	char pid_str[10];
	char buf[5000];
	if(argc<2)
	{
		fprintf(stderr, "You need to give atleast one user as command line argumnet\n");
		exit(0);
	}
	pid_t p = getpid();
	initialize();
	identifyActiveUsers(argc,argv);	
	if((serfile=open("ser.txt",O_CREAT|O_EXCL|0666))==-1)
	{	
		perror("Error in opening. File already exists");
		exit(1);
	}
	signal(SIGINT,destroy);
	sprintf(pid_str,"%d",p);
	write(serfile,pid_str,strlen(pid_str));
	releaseMessageSem(semid,MSG_SEM);
	while(1)
	{
		blockMessageSem(semid,MSG_SEM);
		printf("--- Received Message :\"%s\"\n",msg);
		strcpy(buf,msg);
		handleMsg(buf);
		releaseMessageSem(semid,MSG_SEM);
	}
	return 0;
}
示例#5
0
void GUIVTermDevice::loop() {
	ulong buf[IPC_DEF_SIZE / sizeof(ulong)];
	while(!isStopped()) {
		msgid_t mid;
		int fd = getwork(id(),&mid,buf,sizeof(buf),_rbufPos > 0 ? GW_NOBLOCK : 0);
		if(EXPECT_FALSE(fd < 0)) {
			/* just log that it failed. maybe a client has sent a message that was too big */
			if(fd != -EINTR && fd != -ENOCLIENT)
				printe("getwork failed");

			/* append the buffer now to reduce delays */
			if(_rbufPos > 0) {
				{
					std::lock_guard<std::mutex> guard(*_vt.mutex);
					_rbuffer[_rbufPos] = '\0';
					vtout_puts(&_vt,_rbuffer,_rbufPos,true);
					_sh->update();
					_rbufPos = 0;
				}
				checkPending();
			}
			continue;
		}

		esc::IPCStream is(fd,buf,sizeof(buf),mid);
		handleMsg(mid,is);
		_sh->update();
	}
}
示例#6
0
Connection::Connection( Servent* parent )
    : QObject()
    , m_sock( 0 )
    , m_peerport( 0 )
    , m_servent( parent )
    , m_ready( false )
    , m_onceonly( true )
    , m_do_shutdown( false )
    , m_actually_shutting_down( false )
    , m_peer_disconnected( false )
    , m_tx_bytes( 0 )
    , m_tx_bytes_requested( 0 )
    , m_rx_bytes( 0 )
    , m_id( "Connection()" )
    , m_statstimer( 0 )
    , m_stats_tx_bytes_per_sec( 0 )
    , m_stats_rx_bytes_per_sec( 0 )
    , m_rx_bytes_last( 0 )
    , m_tx_bytes_last( 0 )
{
    moveToThread( m_servent->thread() );
    qDebug() << "CTOR Connection (super)" << thread();

    connect( &m_msgprocessor_out, SIGNAL( ready( msg_ptr ) ),
             SLOT( sendMsg_now( msg_ptr ) ), Qt::QueuedConnection );

    connect( &m_msgprocessor_in,  SIGNAL( ready( msg_ptr ) ),
             SLOT( handleMsg( msg_ptr ) ), Qt::QueuedConnection );

    connect( &m_msgprocessor_in, SIGNAL( empty() ),
             SLOT( handleIncomingQueueEmpty() ), Qt::QueuedConnection );
}
示例#7
0
void AutomaticController::run()
{
	while(running_)
	{
		unsigned long id;
		osapi::Message* msg = mq_.receive(id);
		handleMsg(msg,id);
		delete msg;
	}
}
示例#8
0
 void LogSystem::run()
 {
   while(running_)
   {
     unsigned long id;
     Message* msg = mq_.receive(id);
     handleMsg(id, msg);
     delete msg;
   }
 }
示例#9
0
void commParser::newBytes(uint8_t*bytes,int len,uint32_t millis){
  for(int k = 0;k<len;k++){
    int8_t out = esp_parse_byte(bytes[k],msg);
    if (out > 0){
      //we got a new message: handle it
      handleMsg();
      // save the time
      last_message_millis = millis;
    }
    if (out == -2){//increment the bad checksum counter
      bad_checksums++;
    }
  }
}
示例#10
0
void Subscriber::run()
{
  OSAPI_LOG_DBG("Preparing for loop...");

  while(running_)
  {
    unsigned long id;
    osapi::Message* m = mq_.receive(id);
    handleMsg(id, m);
    delete m;
  }

  OSAPI_LOG_DBG("Thread terminating...");
}
示例#11
0
/*
 * This function loops through all messages this robot has received since the last call
 * to check messages.
 * For each message, it populates an irMsg struct and calls handleMsg with it.
 */
static void checkMessages(void){
	irMsg msgStruct;	
	ATOMIC_BLOCK(ATOMIC_RESTORESTATE){ //We want to make sure that this block doesn't get interrupted by stuff trying to add more messages to the buffer.
		uint16_t crc;
		while(incMsgHead != NULL){
			MsgNode* node = (MsgNode*)incMsgHead;
			if(node->length==0){
				printf_P(PSTR("ERROR: Message length 0 for msg_node.\r\n"));
			}
			char msgData[node->length];
			memcpy(msgData, node->msg, node->length);
			msgStruct.msg			= msgData;
			msgStruct.arrivalTime	= node->arrivalTime;
			msgStruct.senderID		= node->senderID;
			msgStruct.length		= node->length;
			crc						= node->crc;
			/*
			 * At this point everything relevant has been copied out of the buffer. To avoid
			 * problems caused by the changes to the queue while handling the message, we
			 * remove the current node and update the structure before calling handleMsg.
			 */
			MsgNode* tmp = node;
			MsgNode* deleteMe;
			while(tmp->next !=NULL){
				uint8_t crcMatches = (tmp->next->crc == crc);
				uint8_t closeTimes = (abs((int32_t)(tmp->next->arrivalTime) - (int32_t)(msgStruct.arrivalTime))) < 30;
				if(crcMatches && closeTimes){
					deleteMe = tmp->next;
					tmp->next = tmp->next->next;
					myFree(deleteMe);
					memoryConsumedByMsgBuffer -= (sizeof(MsgNode) + msgStruct.length);
					numWaitingMsgs--;
				}else{
					tmp = tmp->next;
				}
			}
			incMsgHead = (volatile MsgNode*)(node->next);
			memoryConsumedByMsgBuffer -= (sizeof(MsgNode) + msgStruct.length);
			numWaitingMsgs--;
			myFree(node);

			//While we let user code handle the message we want interrupts to be back on. 
			NONATOMIC_BLOCK(NONATOMIC_RESTORESTATE){ 
				handleMsg(&msgStruct);
			}
		}
	}
}
示例#12
0
Connection::Connection( Servent* parent )
    : QObject()
    , d_ptr( new ConnectionPrivate( this, parent ) )
{
    moveToThread( parent->thread() );
    tDebug( LOGVERBOSE ) << "CTOR Connection (super)" << thread();

    connect( &d_func()->msgprocessor_out, SIGNAL( ready( msg_ptr ) ),
             SLOT( sendMsg_now( msg_ptr ) ), Qt::QueuedConnection );

    connect( &d_func()->msgprocessor_in,  SIGNAL( ready( msg_ptr ) ),
             SLOT( handleMsg( msg_ptr ) ), Qt::QueuedConnection );

    connect( &d_func()->msgprocessor_in, SIGNAL( empty() ),
             SLOT( handleIncomingQueueEmpty() ), Qt::QueuedConnection );
}
示例#13
0
void Mobile::run()
{
  
  // Opret timer objekt.
  timer_ = osapi::createNewTimer(&mq_, ID_STOP_MOBILE);
  
  while(running_)
  {
    unsigned long id;
    osapi::Message* msg = mq_.receive(id);
    handleMsg(msg,id);
    delete msg;
  }
  
  timer_->disArm();
}
示例#14
0
int main()
{
    uint8_t *buf;
    char str[] = "hello";
    int len;
    Msg msg;
    msg.msgtype = MSG_in;
    msg.bodylen = 4;
    len = 4 + 4 + 4;
    strncpy(msg.msgbody, str, 4);
    buf = (uint8_t *)&msg;
    registHandleFunc(MSG_in, handle_in, 0);
    registHandleFunc(MSG_out, handle_out, 0);
    handleMsg(1, buf, len);
    return 0;
}
void CAccessLinkDevice::handleMsg()
{
  uchar len = (uchar)msg[0];

  //! check if we have enough data for at least one message
  if( msg.length() < len) return;

  uchar cmd = (uchar)msg[1];

  //! be sure that the message is tag detection or tag standart read
  if(cmd != 0x90 && cmd != 0x92)
  {
    msg.remove(0,len);
    return;
  }

  uchar tagStatus = (uchar)msg[2] & 0x07;

  //! wait, no information, timeout
  if(tagStatus == 0 || tagStatus == 0x04 || tagStatus == 0x05)
  {
    msg.remove(0,len);
    return;
  }

  //! more data will comming
  if(tagStatus == 0x01 || tagStatus == 0x02)
  {
    if(cmd == 0x90)
      keyDetection << msg.left(len);
    msg.remove(0,len);
    handleMsg();
    return;
  }

  //! all data are received
  if(tagStatus == 0x03 || tagStatus == 0x07)
  {
    if(cmd == 0x90)
      keyDetection << msg.left(len);
    msg.remove(0,len);

    handleKey();

    return;
  }
}
示例#16
0
int receive_all(int s, char *buf, int *len, int first) {
	int total = 0; // how many bytes we've received
	size_t bytesleft = *len; // how many we have left to receive
	int n;
	int endOfMsg = 0;
	int index = 0;
	int beforeFirst = 1;
	while (endOfMsg == 0) {//case we get bad packet, we check manually.
		char rBuff[400];
		if (beforeFirst == 0){
			n = recv(s, rBuff + total, 400, 0);
			strcat(buf, rBuff);
		}
		else{
			n = recv(s, buf + total, bytesleft, 0);
			beforeFirst = 0;
		}
		//checkForZeroValue(n,s);
		if (n == -1) { break; }
		total += n;
		bytesleft -= n;
		const char *ptr = strchr(buf, '}');
		while (ptr) {
			index = ptr - buf + 1;
			// Handle msg!!!
			if (first == 1){
				endOfMsg = 1;
				handleFirstMsg(buf);
				ptr = NULL;
				continue;
			}
			char currBuf[BUF_SIZE];
			strcpy(currBuf, buf);
			currBuf[index] = '\0';
			handleMsg(currBuf);
			strcpy(buf, currBuf);
			endOfMsg = 1;
			break;
		}
		if (first == 1){
			break;
		}
	}
	*len = total; // return number actually sent here
	return n == -1 ? -1 : 0; //-1 on failure, 0 on success
}
示例#17
0
void RPeninputServerImpl::DimUiLayoutL(TBool aFlag)
    {
    TInt priority = iPriority;

    TPckgC<TBool> msg(aFlag);
    TIpcArgs arg;    
    arg.Set(KMsgSlot0,&msg);

    TPckgC<TInt> prioriryMsg(priority);//p
    arg.Set(KMsgSlot1,&prioriryMsg);
    
    TInt bmpHandle = -1;
    TPckg<TInt> handleMsg(bmpHandle);
    arg.Set(KMsgSlot2,&handleMsg);
    
    TRect extend;
    TPckg<TRect> posMsg(extend);  
    arg.Set(KMsgSlot3,&posMsg);
    
    if (iInternalPopup)
        {
        SendReceive(EPeninputRequestInternalDimLayout,arg);    
        }
    else
        {
        SendReceive(EPeninputRequestDimLayout,arg);    
        }
   
    if(aFlag)
        {
        //show the background control
        if(!iBackgroundCtrl)
            {
            iBackgroundCtrl = CPenUiBackgroundWnd::NewL(CCoeEnv::Static()->RootWin(),bmpHandle);
            }
        if(iBackgroundCtrl)
            iBackgroundCtrl->Show(extend, iGlobalNotes, 
                iInternalPopup,priority, iResourceChange);    
        }
    else //undim the window
        {
        if(iBackgroundCtrl)
            iBackgroundCtrl->Hide();    
        }
    }
示例#18
0
bool PreGame::read(
		std::shared_ptr<TBSystem::network::sockets::ITcpSocket> &socket)
{
	char msg[155];
	int ret;

	try {
		ret = socket->recv(msg, 154);
	} catch (std::runtime_error &e) {
		TBSystem::log::err << e.what() << TBSystem::log::endl;
		return (false);
	}
	if (!ret) {
		return (false);
	}
	handleMsg(std::string(msg));
	return (true);
}
示例#19
0
void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length) {
  switch(type) {
      case WStype_DISCONNECTED:
          //USE_SERIAL.printf("[%u] Disconnected!\n", num);
          wsConcount--;
          sprintf(str,"ws disconnect count=%d",wsConcount);
          if (useMQTT) mqtt.publish(mqttpub,str);
          break;
      case WStype_CONNECTED:
          {
              IPAddress ip = webSocket.remoteIP(num);
              sprintf(str,"[%u] connected from %d.%d.%d.%d url: %s\n", num, ip[0], ip[1], ip[2], ip[3], payload);
              //USE_SERIAL.println();
              // send message to client
              sprintf(str,"Connection #%d.", num);
              webSocket.sendTXT(num, str);
              sprintf(str, "name=%s", nodename);
              webSocket.sendTXT(num, str);
              //webSocket.sendTXT(num, mqttpub);
              //webSocket.sendTXT(num, mqttsub);
              if (timeStatus() == timeSet) webSocket.sendTXT(num, "Time is set.");
              else webSocket.sendTXT(num, "Time not set.");
              //mqtt.publish(mqttpub, str);
              //wsSendlabels();
              newWScon = num + 1;
              wsConcount++;
              sprintf(str,"ws connect count=%u new=%u",wsConcount,newWScon);
              if (useMQTT) mqtt.publish(mqttpub,str);
          }
          break;
      case WStype_TEXT:
          payload[length] = '\0'; // null terminate
          handleMsg((char *)payload);

          break;
      case WStype_BIN:
         // USE_SERIAL.printf("[%u] get binary lenght: %u\n", num, length);
          hexdump(payload, length);

          // send message to client
          // webSocket.sendBIN(num, payload, lenght);
          break;
  }
}
示例#20
0
文件: car.hpp 项目: bjarkevad/I3ISU
void Car::run() {
//Send req msg to entryguard
//enter
	running_ = true;
	while(running_)
	{
		unsigned long id;
		osapi::Message* msg = _msgQueue.receive(id);
		handleMsg(msg, id);
		delete msg;
	}

	//sleep for a while to stay in 
	//send req msg to exitguard
	//handlemessage
	//delete msg;
	//exit
	running_ = false;
}
示例#21
0
int receive_all(int s, char *buf, int *len, int first) {
	int total = 0; /* how many bytes we've received */
	size_t bytesleft = *len; /* how many we have left to receive */
	int n;
	//
	while (total < *len) {
		n = recv(s, buf + total, bytesleft, 0);
		checkForZeroValue(n, s);
		if (n == -1) { break; }
		total += n;
		bytesleft -= n;
	}
	if (first == 1){
		handleFirstMsg(buf);
	}
	else {
		handleMsg(buf);
	}
	*len = total; /* return number actually sent here */
	return n == -1 ? -1 : 0; /*-1 on failure, 0 on success */
}
示例#22
0
int main(int argc, char *argv[]){
    if (argc != 2)         /* Test for correct number of parameters */
    {
        fprintf(stderr,"Usage:  %s <UDP SERVER PORT>\n", argv[0]);
        return 1;
    }
    // assigan the port number
    servPort = atoi(argv[1]);
    
   
    /* Create socket for sending/receiving datagrams */
    if ((sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
        dieWithError("socket() failed");
    
    /* Construct local address structure */
    memset(&servAddr, 0, sizeof(servAddr));   /* Zero out structure */
    servAddr.sin_family = AF_INET;                /* Internet address family */
    servAddr.sin_addr.s_addr = htonl(INADDR_ANY); /* Any incoming interface */
    servAddr.sin_port = htons(servPort);      /* Local port */
    
    /* Bind to the local address */
    if (bind(sock, (struct sockaddr *) &servAddr, sizeof(servAddr)) < 0)
        dieWithError("bind() failed");
    
   for (;;) /* Run forever */
   {
        /* Set the size of the in-out parameter */
        cliAddrLen = sizeof(clntAddr);
        //receive();
    
    
    handleMsg();

    
   }
    return 0;
}
示例#23
0
void MIDIMsgHandler::handlePacket(MIDIPacket *pkt) {
    UInt8 *buff = (UInt8 *)pkt->data;
    
    UInt8 off = 0;
    while(off < pkt->length) {
        UInt8 *buf = &buff[off];
        
        bool found = false;
        for(int i=0;i<sizeof(MsgTypes)/2;++i) {
            const struct MIDIMsgHandler::MsgType &t = MIDIMsgHandler::MsgTypes[i];
            
            if((buf[0] & 0xf0) == t.status) {
                UInt8 goodLen = !t.length ? pkt->length - off : t.length;
                handleMsg(buf, goodLen);
                off += goodLen;
                found = true;
            }
        }
        if(found)
            found = false;
        else
            off++;
    }
}
示例#24
0
static void handleBuffer(int sockfd, char *buf, int len)
{
    handleMsg(sockfd, (uint8_t *)buf, len);
}
示例#25
0
void CommandHandler::handleCommand(const std::string &command, ChatTab *tab)
{
    std::string::size_type pos = command.find(' ');
    std::string type(command, 0, pos);
    std::string args(command, pos == std::string::npos ? command.size() : pos + 1);

    if (type == "help") // Do help before tabs so they can't override it
    {
        handleHelp(args, tab);
    }
    else if (tab->handleCommand(type, args))
    {
        // Nothing to do
    }
    else if (type == "announce")
    {
        handleAnnounce(args, tab);
    }
    else if (type == "where")
    {
        handleWhere(args, tab);
    }
    else if (type == "who")
    {
        handleWho(args, tab);
    }
    else if (type == "msg" || type == "whisper" || type == "w")
    {
        handleMsg(args, tab);
    }
    else if (type == "query" || type == "q")
    {
        handleQuery(args, tab);
    }
    else if (type == "ignore")
    {
        handleIgnore(args, tab);
    }
    else if (type == "unignore")
    {
        handleUnignore(args, tab);
    }
    else if (type == "join")
    {
        handleJoin(args, tab);
    }
    else if (type == "list")
    {
        handleListChannels(args, tab);
    }
    else if (type == "clear")
    {
        handleClear(args, tab);
    }
    else if (type == "party")
    {
        handleParty(args, tab);
    }
    else if (type == "me")
    {
        handleMe(args, tab);
    }
    else if (type == "record")
    {
        handleRecord(args, tab);
    }
    else if (type == "toggle")
    {
        handleToggle(args, tab);
    }
    else if (type == "present")
    {
        handlePresent(args, tab);
    }
    else
    {
        tab->chatLog(_("Unknown command."));
    }
}