public static void setBusyPacketIds(ESPPacket newPacket) { m_busyPacketIds.Clear(); String log = ""; if (newPacket != null) { byte[] payload = newPacket.Payload; for (int i = 0; i < payload.Length; i++) { Byte newId = payload[i]; m_busyPacketIds.Add(newId); } /* * for (int i = 0; i < m_busyPacketIds.size(); i++) * { * log = log + "[" + Byte.toString(m_busyPacketIds.get(i)) + "] "; * } */ } if (ESPLibraryLogController.LOG_WRITE_INFO) { //Log.i("Valentine", log); } }
public static void pushInputPacketOntoQueue(ESPPacket packet) { lock (m_inlock) { m_inputQueue.AddLast(packet); } }
public static void pushOnToSendAfterBusyQueue(ESPPacket _packet) { lock (m_outlock) { bool addToQueue = true; for (int i = 0; i < m_toSendAfterBusyClear.Count; i++) { ESPPacket curPacket = m_toSendAfterBusyClear[i]; if (curPacket.PacketIdentifier.ToByteValue() == _packet.PacketIdentifier.ToByteValue()) { // This packet is already in the queue, so don't resend it after we are busy addToQueue = false; } } if (addToQueue) { for (int i = 0; i < m_busyPacketIds.Count; i++) { if (_packet.PacketIdentifier.ToByteValue() == m_busyPacketIds[i]) { // This packet is in the list of packets the V1 is working on, so don't add it to the queue addToQueue = false; } } } if (addToQueue) { m_toSendAfterBusyClear.Add(_packet); } } }
public static void sendAfterBusyQueue() { lock (m_outlock) { if (m_toSendAfterBusyClear.Count > 0) { //Log.i("Valentine", "V1 not busy. Trying to resend " + m_toSendAfterBusyClear.size() + " packets"); } for (int i = 0; i < m_toSendAfterBusyClear.Count; i++) { ESPPacket packet = m_toSendAfterBusyClear[i]; PacketQueue.pushOutputPacketOntoQueue(packet); } } m_toSendAfterBusyClear.Clear(); }
public static void pushOutputPacketOntoQueue(ESPPacket packet) { lock (m_outlock) { bool addPacketToQueue = true; for (int i = 0; i < m_outputQueue.Count; i++) { ESPPacket curPacket = m_outputQueue.ElementAt(i); if (packet.IsSamePacket(curPacket)) { // Don't put this packet into the queue addPacketToQueue = false; break; } } if (addPacketToQueue) { m_outputQueue.AddLast(packet); } } }
public static ESPPacket getNextOutputPacket() { ESPPacket rc = null; lock (m_outlock) { if (m_outputQueue.Count == 0) { // No packets to send or we don't have a V1 type yet rc = null; } else if (m_holdoffOutput) { rc = null; // Check for packets destined for the V1connection and allow them to override the holdoff for (int i = 0; i < m_outputQueue.Count; i++) { ESPPacket p = m_outputQueue.ElementAt <ESPPacket>(i); if (p.Destination == Devices.V1CONNECT && p.Origin == Devices.V1CONNECT) { rc = p; m_outputQueue.Remove(p); break; } } } else { //int location = 0; //bool found = false; while (rc == null && m_outputQueue.Count > 0) { rc = m_outputQueue.First.Value; m_outputQueue.RemoveFirst(); /*if (!found) * { * rc = m_outputQueue.remove(location); * } * else * { * location++; * } * * if (location == m_outputQueue.Count) * { * break; * }*/ } } if (rc != null) { // Change the packet type if it doesn't match the last type specified. // Don't change if the last type specified is UNKNOWN because there is not a valid type to change it to. if (rc.V1Type != m_v1Type && m_v1Type != Devices.UNKNOWN) { rc.SetNewV1Type(m_v1Type); } } } return(rc); }
public static void putLastWrittenPacketOfType(ESPPacket _packet) { m_lastSentPacket.Add(_packet.PacketIdentifier, _packet); }
public void sendPacket(ESPPacket packet) { throw new NotImplementedException(); }
public void handleDemoPacket(ESPPacket _packet) { switch (_packet.PacketIdentifier) { case PacketId.respVersion: m_versionPackets.Add(_packet.Origin, (ResponseVersion)_packet); break; case PacketId.respSerialNumber: m_V1SerialPackets.Add(_packet.Origin, (ResponseSerialNumber)_packet); break; case PacketId.respSavvyStatus: m_SavvyConfiguration = (ResponseSavvyStatus)_packet; break; case PacketId.respUserBytes: m_V1Configuration = (ResponseUserBytes)_packet; if ((m_V1ConfigObject != null) && (m_V1ConfigFunction != null)) { Utilities.Utilities.doCallback(m_V1ConfigObject, m_V1ConfigFunction, UserSettings.GetType(), (UserSettings)m_V1Configuration.getResponseData()); } break; case PacketId.respSweepSections: m_CustomSweepSections.Add((ResponseSweepSections)_packet); break; case PacketId.respSweepDefinition: m_ResponseSweepDefinitions.Add((ResponseSweepDefinitions)_packet); break; case PacketId.respMaxSweepIndex: m_MaximumCustomSweepIndex = (ResponseMaxSweepIndex)_packet; break; case PacketId.respBatteryVoltage: m_BatteryVoltage = (ResponseBatteryVoltage)_packet; break; case PacketId.respVehicleSpeed: m_VehicleSpeed = (ResponseVehicleSpeed)_packet; break; case PacketId.reqVersion: PacketQueue.pushInputPacketOntoQueue(m_versionPackets[_packet.Destination]); break; case PacketId.reqSerialNumber: PacketQueue.pushInputPacketOntoQueue(m_V1SerialPackets[_packet.Destination]); break; case PacketId.reqUserBytes: PacketQueue.pushInputPacketOntoQueue(m_V1Configuration); break; case PacketId.reqAllSweepDefinitions: case PacketId.reqSetSweepsToDefault: for (int i = 0; i < m_ResponseSweepDefinitions.Count; i++) { PacketQueue.pushInputPacketOntoQueue(m_ResponseSweepDefinitions[i]); } break; case PacketId.reqDefaultSweepDefinitions: case PacketId.respDefaultSweepDefinition: // Ignore these packets in the demo mode file. break; case PacketId.reqMaxSweepIndex: PacketQueue.pushInputPacketOntoQueue(m_MaximumCustomSweepIndex); break; case PacketId.reqSweepSections: for (int i = 0; i < m_CustomSweepSections.Count; i++) { PacketQueue.pushInputPacketOntoQueue(m_CustomSweepSections[i]); } break; case PacketId.reqBatteryVoltage: PacketQueue.pushInputPacketOntoQueue(m_BatteryVoltage); break; case PacketId.reqSavvyStatus: PacketQueue.pushInputPacketOntoQueue(m_SavvyConfiguration); break; case PacketId.reqVehicleSpeed: PacketQueue.pushInputPacketOntoQueue(m_VehicleSpeed); break; case PacketId.reqTurnOffMainDisplay: case PacketId.reqTurnOnMainDisplay: case PacketId.respDataReceived: case PacketId.reqStartAlertData: case PacketId.reqStopAlertData: case PacketId.reqChangeMode: case PacketId.reqMuteOn: case PacketId.reqMuteOff: case PacketId.reqFactoryDefault: case PacketId.reqWriteUserBytes: case PacketId.reqWriteSweepDefinition: case PacketId.reqOverrideThumbwheel: case PacketId.reqSetSavvyUnmuteEnable: case PacketId.respDataError: case PacketId.respUnsupportedPacket: case PacketId.respRequestNotProcessed: case PacketId.infV1Busy: case PacketId.respSweepWriteResult: break; case PacketId.respAlertData: case PacketId.infDisplayData: PacketQueue.pushInputPacketOntoQueue(_packet); break; case PacketId.unknownPacketType: // There is nothing to do with an unknown packet type in demo mode break; } }
public static ESPPacket getPacket(PacketId _id) { ESPPacket rc = null; if (_id != null) { switch (_id) { //basic data case PacketId.reqVersion: rc = new RequestVersion(Devices.UNKNOWN, Devices.UNKNOWN); break; case PacketId.respVersion: rc = new ResponseVersion(Devices.UNKNOWN); break; case PacketId.reqSerialNumber: rc = new RequestSerialNumber(Devices.UNKNOWN, Devices.UNKNOWN); break; case PacketId.respSerialNumber: rc = new ResponseSerialNumber(Devices.UNKNOWN); break; case PacketId.reqUserBytes: rc = new RequestUserBytes(Devices.UNKNOWN); break; case PacketId.respUserBytes: rc = new ResponseUserBytes(Devices.UNKNOWN); break; case PacketId.reqWriteUserBytes: rc = new RequestWriteUserBytes(null, Devices.UNKNOWN); break; case PacketId.reqFactoryDefault: rc = new RequestFactoryDefault(Devices.UNKNOWN, Devices.UNKNOWN); break; case PacketId.reqDefaultSweepDefinitions: rc = new RequestDefaultSweepDefinitions(Devices.UNKNOWN); break; case PacketId.respDefaultSweepDefinition: rc = new ResponseDefaultSweepDefinitions(Devices.UNKNOWN); break; //custom sweep data case PacketId.reqWriteSweepDefinition: rc = new RequestWriteSweepDefinition(null, Devices.UNKNOWN); break; case PacketId.reqAllSweepDefinitions: rc = new RequestAllSweepDefinitions(Devices.UNKNOWN); break; case PacketId.respSweepDefinition: rc = new ResponseSweepDefinitions(Devices.UNKNOWN); break; case PacketId.reqSetSweepsToDefault: rc = new RequestSetSweepsToDefault(Devices.UNKNOWN); break; case PacketId.reqMaxSweepIndex: rc = new RequestMaxSweepIndex(Devices.UNKNOWN); break; case PacketId.respMaxSweepIndex: rc = new ResponseMaxSweepIndex(Devices.UNKNOWN); break; case PacketId.respSweepWriteResult: rc = new ResponseSweepWriteResult(Devices.UNKNOWN); break; case PacketId.reqSweepSections: rc = new RequestSweepSections(Devices.UNKNOWN); break; case PacketId.respSweepSections: rc = new ResponseSweepSections(Devices.UNKNOWN); break; //informational packets case PacketId.infDisplayData: rc = new InfDisplayData(Devices.UNKNOWN); break; case PacketId.reqTurnOffMainDisplay: rc = new RequestTurnOffMainDisplay(Devices.UNKNOWN); break; case PacketId.reqTurnOnMainDisplay: rc = new RequestTurnOnMainDisplay(Devices.UNKNOWN); break; case PacketId.reqMuteOn: rc = new RequestMuteOn(Devices.UNKNOWN); break; case PacketId.reqMuteOff: rc = new RequestMuteOff(Devices.UNKNOWN); break; case PacketId.reqChangeMode: rc = new RequestChangeMode((byte)0, Devices.UNKNOWN); break; case PacketId.reqStartAlertData: rc = new RequestStartAlertData(Devices.UNKNOWN); break; case PacketId.reqStopAlertData: rc = new RequestStopAlertData(Devices.UNKNOWN); break; case PacketId.respAlertData: rc = new ResponseAlertData(Devices.UNKNOWN); break; case PacketId.respDataReceived: rc = new ResponseDataReceived(Devices.UNKNOWN); break; case PacketId.reqBatteryVoltage: rc = new RequestBatteryVoltage(Devices.UNKNOWN); break; case PacketId.respBatteryVoltage: rc = new ResponseBatteryVoltage(Devices.UNKNOWN); break; //unspported and error case PacketId.respUnsupportedPacket: rc = new ResponseUnsupported(Devices.UNKNOWN); break; case PacketId.respRequestNotProcessed: rc = new ResponseRequestNotProcessed(Devices.UNKNOWN); break; case PacketId.infV1Busy: rc = new InfV1Busy(Devices.UNKNOWN); break; case PacketId.respDataError: rc = new ResponseDataError(Devices.UNKNOWN); break; //Savvy case PacketId.reqSavvyStatus: rc = new RequestSavvyStatus(Devices.UNKNOWN, Devices.UNKNOWN); break; case PacketId.respSavvyStatus: rc = new ResponseSavvyStatus(Devices.UNKNOWN); break; case PacketId.reqVehicleSpeed: rc = new RequestVehicleSpeed(Devices.UNKNOWN, Devices.UNKNOWN); break; case PacketId.respVehicleSpeed: rc = new ResponseVehicleSpeed(Devices.UNKNOWN); break; case PacketId.reqOverrideThumbwheel: rc = new RequestOverrideThumbwheel(Devices.UNKNOWN, (byte)0, Devices.UNKNOWN); break; case PacketId.reqSetSavvyUnmuteEnable: rc = new RequestSetSavvyUnmute(Devices.UNKNOWN, false, Devices.UNKNOWN); break; default: rc = new UnknownPacket(Devices.UNKNOWN); break; } } return(rc); }