void WorkingStateMsgTransmit(unsigned char ClientNum, unsigned char RecTarget) { MsgHead[ClientNum].m_Status = WorkingStatus[ClientNum]; MsgHead[ClientNum].m_Total_Length = MessageHeaderLength+sizeof(Terminal_Working_State_MSG_BODY); MsgHead[ClientNum].m_Command_Id = TerminalWorkingStateCommand; MsgHead[ClientNum].m_Sequence_Id = SequenceId; SequenceId++; MessageHeader(ClientNum); MsgWorkStateBody[ClientNum].m_Current_Speed = CurrentSpeed[ClientNum]; // MsgWorkStateBody[ClientNum].m_Current_Speed = 0x55; MsgWorkStateBody[ClientNum].m_Total_Drip = TotalDrip[ClientNum]; // MsgWorkStateBody[ClientNum].m_Total_Drip = 0x77; MsgWorkStateBody[ClientNum].m_Terminal_Power = TerminalPowerPrecent[ClientNum]; MsgWorkStateBody[ClientNum].m_Max_Speed_Limited = MaxSpeedLimited[ClientNum]; MsgWorkStateBody[ClientNum].m_Min_Speed_Limited = MinSpeedLimited[ClientNum]; memset(&TxBuffer[0]+sizeof(MSG_HEAD),0,sizeof(Terminal_Working_State_MSG_BODY)); memcpy(&TxBuffer[0]+sizeof(MSG_HEAD),&MsgWorkStateBody[ClientNum],sizeof(Terminal_Working_State_MSG_BODY)); if(RecTarget == CC1101Target) { CC1101SendPacket( TxBuffer, MsgHead[ClientNum].m_Total_Length); } else if(RecTarget == CC3000Target) { CC3000SendPacket( TxBuffer, MsgHead[ClientNum].m_Total_Length); } }
void ClientConnection::send_action_message() { m_send_header = MessageHeader(); m_send_header.flag = miro::MessageHeader::Flag::action; m_send_header.len1 = m_send_buffer.size_headers(); m_send_header.len2 = m_send_buffer.size_data(); socket().send(buffer(m_send_header),[this](error_ref e) { if (check_error(e)) { send_action_headers(); } }); }
void LoginReqTransmit(unsigned char ClientNum,unsigned char RecTarget) { MsgHead[ClientNum].m_Status = LoginStatus[ClientNum]; MsgHead[ClientNum].m_Total_Length = MessageHeaderLength; MsgHead[ClientNum].m_Command_Id = TerminalLogin_ReqCommand ; MsgHead[ClientNum].m_Sequence_Id = SequenceId; SequenceId++; MessageHeader(ClientNum); if(RecTarget == CC1101Target) { CC1101SendPacket( TxBuffer, MsgHead[ClientNum].m_Total_Length); } else if(RecTarget == CC3000Target) { CC3000SendPacket( TxBuffer, MsgHead[ClientNum].m_Total_Length); } }
void ClientConnection::handle_handshake() { auto& alias = m_session.m_user_info.user_alias; m_send_header = MessageHeader(); m_send_header.flag = MessageHeader::Flag::handshake; m_send_header.len1 = alias.length() + 1; socket().send(buffer(m_send_header),[this](error_ref e) { if (check_error(e)) { auto& alias = m_session.m_user_info.user_alias; socket().send((void*)alias.data(),alias.length()+1,[this](error_ref e) { if (check_error(e)) { handle_outgoing(); handle_incomming(); } }); } }); }
void WorAckTransmit(unsigned char ClientNum,unsigned char RecTarget) { MsgHead[ClientNum].m_Status = LoginStatus[ClientNum]; MsgHead[ClientNum].m_Total_Length = MessageHeaderLength; MsgHead[ClientNum].m_Command_Id = TerminalWOR_AckCommand ; MsgHead[ClientNum].m_Sequence_Id = SequenceId; SequenceId++; MessageHeader(ClientNum); if(RecTarget == CC1101Target) { CC1101SendPacket( TxBuffer, MsgHead[ClientNum].m_Total_Length); } else if(RecTarget == CC3000Target) { CC3000SendPacket( TxBuffer, MsgHead[ClientNum].m_Total_Length); } // TxBuffer[0] = 0x01; // TxBuffer[1] = 0x02; // TxBuffer[2] = 0x03; // TxBuffer[3] = 0x04; // TxBuffer[4] = 0x05; // CC1101SendPacket(TxBuffer,1); }
void LoginTransmit(unsigned char ClientNum,unsigned char RecTarget) { MsgHead[ClientNum].m_Status = LoginStatus[ClientNum]; MsgHead[ClientNum].m_Total_Length = MessageHeaderLength+6; MsgHead[ClientNum].m_Command_Id = TerminalLoginCommand; MsgHead[ClientNum].m_Sequence_Id = SequenceId; SequenceId++; MessageHeader(ClientNum); TxBuffer[18] = ProtocolVersion[ClientNum]; TxBuffer[19] = ProtocolVersion[ClientNum]>>8; TxBuffer[20] = HardwareVersion[ClientNum]; TxBuffer[21] = HardwareVersion[ClientNum]>>8; TxBuffer[22] = Reversed; TxBuffer[23] = Reversed; if(RecTarget == CC1101Target) { CC1101SendPacket( TxBuffer, MsgHead[ClientNum].m_Total_Length); } else if(RecTarget == CC3000Target) { CC3000SendPacket( TxBuffer, MsgHead[ClientNum].m_Total_Length); } }
void VegaVoiceMessage::DoSend(gcc_unused fixed time, TCHAR *text) { /* // this ensures that if a repeated message is played, // and another message from XCSoar interrupts it, // and then it returns to this message type, it will // wait until the proper repeat time. if (id_active != id) { if (TimeReady(time)) { // need to send 'first' update id_active = id; } else { if (active) { // message was already active when it may have been // interrupted, so wait until time is ready for this message return; } else { // if message wasn't already active, it is now, // so it should be played immediately lastTime = time; } } } */ id_active = id; active = true; MessageHeader(); _tcscat(messageText,text); SendMessage(); }
bool FTcpMessageTransportConnection::SendMessages() { if (Outbox.IsEmpty() && bSentHeader) { return true; } if (!Socket->Wait(ESocketWaitConditions::WaitForWrite, FTimespan::Zero())) { return true; } if (!bSentHeader) { FArrayWriter HeaderData; FTcpMessageHeader MessageHeader(LocalNodeId); HeaderData << MessageHeader; if (!BlockingSend(HeaderData.GetData(), sizeof(FTcpMessageHeader))) { return false; } bSentHeader = true; TotalBytesSent += sizeof(FTcpMessageHeader); } else { FTcpSerializedMessagePtr Message; while (Outbox.Dequeue(Message)) { int32 BytesSent = 0; const TArray<uint8>& Payload = Message->GetDataArray(); // send the payload size FArrayWriter MessagesizeData = FArrayWriter(true); uint32 Messagesize = Payload.Num(); MessagesizeData << Messagesize; if (!BlockingSend(MessagesizeData.GetData(), sizeof(uint32))) { return false; } TotalBytesSent += sizeof(uint32); // send the payload if (!BlockingSend(Payload.GetData(), Payload.Num())) { return false; } TotalBytesSent += Payload.Num(); // return if the socket is no longer writable, or that was the last message if (Outbox.IsEmpty() || !Socket->Wait(ESocketWaitConditions::WaitForWrite, FTimespan::Zero())) { return true; } } } return true; }
template <class T> std::string pack_message(T type, const std::string& data) { return MessageHeader(type, data.size()).str() + data; }