public IEnumerable <byte[]> ReadLogs(DateTime startTime, LogDataLevel level) { if (LogStatus != LogStatus.Idle) { throw new InvalidOperationException("Cancel the current read op before starting a new one"); } LogStatus = LogStatus.InProgress; Vivo45LogPacket.Vivo45LogLevel v45Level = GetVivoLogLevel(level); if (!device.Messenger.StartLogDownload(v45Level, startTime, DateTime.Now, true)) { LogStatus = LogStatus.Idle; throw new Communication.CommunicationException("Error sending log start message"); } //start reading var logs = new List <byte[]>(); int expectedMessageNo = 0; int time = 0; int start = Environment.TickCount; LogStatus = LogStatus.InProgress; Vivo45LogPacket logPacket = null; while (time < Timeout) { if (LogStatus == LogStatus.Cancelled) { LogStatus = LogStatus.Idle; throw new LogException("Cancelled", LogStatus.Cancelled); } logPacket = device.Messenger.GetNextLogPacket(v45Level); if (logPacket == null || !logPacket.Ack) { LogStatus = LogStatus.Idle; throw new Communication.CommunicationException("Error reading log message"); } if (!ReadMessage(ref expectedMessageNo, logs, logPacket)) { LogStatus = LogStatus.Idle; throw new Communication.CommunicationException("Missed a log message"); } RaiseStatus(expectedMessageNo, expectedMessageNo); if (logPacket.LastPacket) { LogStatus = LogStatus.Completed; RaiseStatus(expectedMessageNo, expectedMessageNo); break; } time += Environment.TickCount - start; start = Environment.TickCount; } LogStatus = LogStatus.Idle; return(logs); }
public bool StartLogDownload(Vivo45LogPacket.Vivo45LogLevel level, DateTime startTimestamp, DateTime endTimestamp, bool storeSync) { bool rtn = false; V45Packet cmdResponse = HandleLogData(Vivo45LogPacket.Vivo45LogAction.sendLog, level, startTimestamp, endTimestamp, storeSync); if ((Vivo45LogPacket.Vivo45LogAction)cmdResponse.Payload[0] == Vivo45LogPacket.Vivo45LogAction.sendLog && (Vivo45LogPacket.Vivo45LogLevel)cmdResponse.Payload[1] == level) { rtn = true; } return(rtn); }
private V45Packet HandleLogData(Vivo45LogPacket.Vivo45LogAction action, Vivo45LogPacket.Vivo45LogLevel level, DateTime startTimestamp, DateTime endTimestamp, bool storeSync) { byte[] data = new byte[11]; int offset = 0; data.Add(ref offset, Convert.ToByte(action)); data.Add(ref offset, Convert.ToByte(level)); data.Add(ref offset, BitConverter.GetBytes(GetEpochSecondsFromDateTime(startTimestamp))); data.Add(ref offset, BitConverter.GetBytes(GetEpochSecondsFromDateTime(endTimestamp))); data.Add(ref offset, Convert.ToByte(storeSync)); V45Packet cmdPack = new V45Packet(V45Packet.V45Commands.cmdHandleLogData, data, sender, receiver); var packet = SendMessage(cmdPack); return(packet); }
public V45Packet StopLogDownload(Vivo45LogPacket.Vivo45LogLevel level) { V45Packet cmdResponse = HandleLogData(Vivo45LogPacket.Vivo45LogAction.stopLog, level, Device.Epoch, Device.Epoch, false); return(cmdResponse); }
public Vivo45LogPacket GetNextLogPacket(Vivo45LogPacket.Vivo45LogLevel level) { V45Packet cmdResponse = HandleLogData(Vivo45LogPacket.Vivo45LogAction.continueLog, level, Device.Epoch, Device.Epoch, false); return(new Vivo45LogPacket(cmdResponse.Payload, cmdResponse.Status)); }