char DoCommand() { switch(rxbuffer[0]) { case CMD_EMPTY: return 1; case CMD_READ_BATTERY_VOLTAGE: SendWord(BatteryValue); return 1; case CMD_SET_ACCELERATION_VAR: Acceleration = rxbuffer[4]; return 1; case CMD_SET_PWM_ENABLED: TMR2ON = rxbuffer[4] > 0; return 1; case CMD_SET_MOTORS_ENABLED: Enable1pin = rxbuffer[4] > 0; Enable2pin = rxbuffer[4] > 0; return 1; case CMD_SET_PWMSPEED_A_VAR: PWMSpeedA.hi = rxbuffer[3]; PWMSpeedA.lo = rxbuffer[4]; return 1; case CMD_SET_PWMSPEED_B_VAR: PWMSpeedB.hi = rxbuffer[3]; PWMSpeedB.lo = rxbuffer[4]; return 1; case CMD_GET_TOTALTICKS_A: SendLong(AbsolutTickCountA); return 1; case CMD_GET_TOTALTICKS_B: SendLong(AbsolutTickCountB); return 1; case CMD_GET_TICKSPEED_A: SendWord(CurrentTickSpeedA); return 1; case CMD_GET_TICKSPEED_B: SendWord(CurrentTickSpeedB); return 1; case CMD_GET_CURRENT_A: SendWord(SenseValueA); return 1; case CMD_GET_CURRENT_B: SendWord(SenseValueB); return 1; case CMD_SET_SERVOA_POS: ServoAPos = rxbuffer[4]; return 1; case CMD_SET_SERVOB_POS: ServoBPos = rxbuffer[4]; return 1; case CMD_SET_SERVOC_POS: ServoCPos = rxbuffer[4]; return 1; default: return 0; } }
bool s13WXWServer::SendLongToAll (long lLong, std::vector<unsigned int> aryExcept) { unsigned int uiSocketsLength = aryClientSockets.size (); for (unsigned int uiIdx = 0; uiIdx < uiSocketsLength; uiIdx++) { bool bContinue = false; for (unsigned int uiJdx = 0; uiJdx < aryExcept.size (); uiJdx++) { if (uiIdx == aryExcept.at (uiJdx)) { bContinue = true; break; } } if (bContinue == true) continue; if (SendLong (aryClientSockets.at (uiIdx), lLong) == false) continue; } return (true); }
bool NetSocket::SendPacket(NetAddress *to, const void *data, int length) { struct sockaddr addr; int ret; if (m_Network->m_FakeLoss && RandomFloat(0, 1) < m_Network->m_FakeLoss) { return true; } if (length <= 0 || !data || !to) { return true; } to->ToSockadr(&addr); if (length > MAX_ROUTEABLE_PACKET) { ret = SendLong((const char *)data, length, 0, &addr, sizeof(addr)); } else { if (length < sizeof(addr)) ret = SendShort((const char *)data, length, 0, &addr, sizeof(addr)); else ret = sendto(m_Socket, (const char *)data, length, 0, &addr, sizeof(addr)); } if (ret == -1) { int err = m_Network->GetLastErrorCode(); // wouldblock is silent if (err == WSAEWOULDBLOCK) return true; if (err == WSAECONNREFUSED || err == WSAECONNRESET) return true; // some PPP links dont allow broadcasts if (err == WSAEADDRNOTAVAIL) return true; m_System->Printf("WARNING! NetSocket::SendPacket: %s\n", m_Network->GetErrorText(err)); return false; } m_BytesOut += ret + UDP_HEADER_SIZE; return true; }