Example #1
0
DWORD CClientNet::MsgHandler(TS_PEER_MESSAGE& inputMsg) {			// 创建新的客户端WSClient
    TS_UINT64 uid = getUid(inputMsg.msg);
    if (uid == SelfUID) {
        return 0;
    }

    TS_MESSAGE_HEAD *head = (TS_MESSAGE_HEAD*) &inputMsg.msg;
	
	if (ENTERAGENT == head->type) {
        DOWN_AGENTSERVICE* down = (DOWN_AGENTSERVICE*) &inputMsg.msg;
        if (SuccessEnterClass == down->result) {
            setTimeDiff(down->head.time - getServerTime());
            setUID(down->uid);
		}
	} else if (ENTERCLASS == head->type || LEAVECLASS == head->type) {
        DOWN_AGENTSERVICE* down = (DOWN_AGENTSERVICE*) &inputMsg.msg;
        if (SuccessEnterClass == down->result) {
            addServerAddr(down->addr);
            setTimeDiff(down->head.time - getServerTime());
            setUID(down->uid);
            setBeginSequence(down->lastSeq + 1);
            startupHeartBeat();
            sendConnectionMsg();
            m_Connect->setFilePrefix(string(reinterpret_cast<char*> (down->className)));
            // m_Connect->loadFile(string(reinterpret_cast<char*> (down->className)));
        } else if (SuccessLeaveClass == down->result) {
            endHeartBeat();
        }
	} else if (SCANPORT == head->type) {
		addServerAddr(inputMsg.peeraddr);
	}

    sendToUp(inputMsg.msg, 0, 0, true);
	return 0;
}
Example #2
0
static void mainThread(void *args)
{
    setTimeDiff();
    while (1) {
        //get data
        //getting data should trigger a flag
        //if flag == 1 then
        Xacc = XGforce * 9.81;
        Zacc = (ZGforce - 1) * 9.81;
        speed = calcSpeed(Xacc, Zacc, &distance);
        uartBuf = "test";
        uart_write(uartBuf, strlen(uartBuf));
        if (distance < 200 && Xacc < 0) {
            //send data
        }
        //clear flag
        //end if
    }
}