public void ValidateResponse(IROCResponseMessage response) { var opCode139Response = response as OpCode139Response; Debug.Assert(opCode139Response != null, "Argument response should be of type OpCode139Response."); switch (Command) { case 0: if (opCode139Response.Command != 0) { throw new FormatException("Command requested does not equal command recieved"); } break; case 1: { if (opCode139Response.Command != 1) { throw new FormatException("Command requested does not equal command recieved"); } if (opCode139Response.NumberOfPoints != RequestedHistoryPoints.Count) { throw new FormatException("Number of history points recieved does not equal number of history points requested."); } if (opCode139Response.NumberOfTimePeriods != NumberOfTimePeriods) { throw new FormatException("Number of history points recieved does not equal number of history points requested."); } if (opCode139Response.NumberOfPoints > 0) { var meterHistory = opCode139Response.MeterHistory; if (meterHistory.First().HistoryPointNumber != RequestedHistoryPoints.First()) { throw new FormatException("Starting history point recieved does not equal starting history point requested."); } if (meterHistory.First().Index != HistoryIndex) { throw new FormatException("Starting history record index recieved does not equal starting history record index requested."); } } } break; default: throw new Exception("Unsupported Command"); } }
public void ValidateResponse(IROCResponseMessage response) { var opCode126Response = response as OpCode126Response; Debug.Assert(opCode126Response != null, "Argument response should be of type OpCode126Response."); var meterHistory = opCode126Response.MeterHistory; if (opCode126Response.HistoryPointNumber != this.HistoryPointNumber) { throw new Exception("History point recieved not the same as history point requested"); } }
public void ValidateResponse(IROCResponseMessage response) { var opCode180Response = response as OpCode180Response; Debug.Assert(opCode180Response != null, "Argument response should be of type OpCode180Response."); var expectedByteCount = (parameters.Sum(p => p.Data.Length) + parameters.Sum(t => t.Tlp.ToArray().Length)) + 1; if (expectedByteCount != opCode180Response.Data.Length) { throw new FormatException(String.Format(CultureInfo.InvariantCulture, "Unexpected byte count. Expected {0}, received {1}.", expectedByteCount, opCode180Response.Data.Length)); } }
public void ValidateResponse(IROCResponseMessage response) { var opCode122Response = response as OpCode122Response; Debug.Assert(opCode122Response != null, "Argument response should be of type OpCode122Response."); var meterEvents = opCode122Response.MeterEvents; if (meterEvents.Count != NumberOfEventsRequested) { throw new FormatException("Number of events recieved does not equal number of events requested."); } if (meterEvents.First().Index != StartingEventIndexPointer) { throw new FormatException("Starting event index recieved does not equal starting event index requested."); } }
public void ValidateResponse(IROCResponseMessage response) { var opCode130Response = response as OpCode130Response; Debug.Assert(opCode130Response != null, "Argument response should be of type OpCode130Response."); var meterHistory = opCode130Response.MeterHistory; if (meterHistory.Count != NumberOfHistoryRecordsRequested) { throw new FormatException("Number of history records recieved does not equal number of history records requested."); } if (meterHistory.First().Index != StartingHistoryIndexPointer) { throw new FormatException("Starting history record index recieved does not equal starting history record index requested."); } }
internal void ValidateResponse(IROCRequestMessage request, IROCResponseMessage response) { if (request.OpCode != response.OpCode) { throw new IOException(String.Format(CultureInfo.InvariantCulture, "Received response with unexpected OpCode. Expected {0}, received {1}.", request.OpCode, response.OpCode)); } if (request.DestinationUnit != response.SourceUnit) { throw new IOException(String.Format(CultureInfo.InvariantCulture, "Response source unit does not match request. Expected {0}, received {1}.", response.DestinationUnit, request.SourceUnit)); } if (request.DestinationGroup != response.SourceGroup) { throw new IOException(String.Format(CultureInfo.InvariantCulture, "Response source group does not match request. Expected {0}, received {1}.", response.DestinationGroup, request.SourceGroup)); } request.ValidateResponse(response); }
public void ValidateResponse(IROCResponseMessage response) { var opCode118Response = response as OpCode118Response; Debug.Assert(opCode118Response != null, "Argument response should be of type OpCode118Response."); if (opCode118Response.NumberOfAlarms != NumberOfAlarmsRequested) { throw new FormatException("Number of alarms recieved does not equal number of alarms requested."); } var meterAlarms = opCode118Response.ROCPlusAlarms; if (meterAlarms.Count > 0) { if (meterAlarms.First().Index != StartingAlarmIndexPointer) { throw new FormatException("Starting alarm index recieved does not equal starting alarm index requested."); } } }
public void ValidateResponse(IROCResponseMessage response) { var opCode136Response = response as OpCode136Response; Debug.Assert(opCode136Response != null, "Argument response should be of type OpCode136Response."); if (opCode136Response.NumberOfDataElements != ((NumberOfHistoryPoints + 1) * NumberOfTimePeriods)) { throw new FormatException("Number of history records recieved does not equal number of history records requested."); } var meterHistory = opCode136Response.MeterHistory; if (meterHistory.First().HistoryPointNumber != StartingHistoryPoint) { throw new FormatException("Starting history point recieved does not equal starting history point requested."); } if (meterHistory.First().Index != HistoryIndex) { throw new FormatException("Starting history record index recieved does not equal starting history record index requested."); } }
public void ValidateResponse(IROCResponseMessage response) { var opCode007Response = response as OpCode007Response; Debug.Assert(opCode007Response != null, "Argument response should be of type OpCode007Response."); }
internal virtual TResponseMessage UnicastMessage <TResponseMessage>(IROCRequestMessage requestMessage) where TResponseMessage : IROCResponseMessage, new() { if (TracingEnabled) { Trace.WriteLine(string.Format("ROCMaster.Transport,WriteDelay,{0},{1}", requestMessage.OpCode.ToString(), DateTime.Now.ToString("O"), "Transport")); } var lastException = (Exception)null; var transactionStopWatch = Stopwatch.StartNew(); IROCResponseMessage responseMessage = default(TResponseMessage); int attempt = 0; bool success = false; object channelLock = Channel.LockObject; lock (channelLock) { do { try { attempt++; if (RequestWriteDelayMilliseconds > 0) { if (TracingEnabled) { Trace.WriteLine(string.Format("ROCMaster.Transport,WriteDelay,{0},{1}", requestMessage.OpCode.ToString(), RequestWriteDelayMilliseconds.ToString("0.0"))); } TimedThreadBlocker.Wait(RequestWriteDelayMilliseconds); } Write(requestMessage); if (ResponseReadDelayMilliseconds > 0) { if (TracingEnabled) { Trace.WriteLine(string.Format("ROCMaster.Transport,ReadDelay,{0},{1}", requestMessage.OpCode.ToString(), ResponseReadDelayMilliseconds.ToString("0.0"))); } TimedThreadBlocker.Wait(RequestWriteDelayMilliseconds); } responseMessage = ReadResponse <TResponseMessage>(requestMessage); if (responseMessage.OpCode == 255) { var opCode255Response = responseMessage as OpCode255Response; if (opCode255Response != null) { throw new OpCode255Exception(opCode255Response); } } else { ValidateResponse(requestMessage, responseMessage); transactionStopWatch.Stop(); if (TracingEnabled) { Trace.WriteLine(string.Format("ROCMaster.Transport,Read,{0},{1},{3},{4}", requestMessage.OpCode.ToString(), transactionStopWatch.Elapsed.TotalMilliseconds.ToString(), HexConverter.ToHexString(requestMessage.ProtocolDataUnit), HexConverter.ToHexString(responseMessage.ProtocolDataUnit), "")); } return((TResponseMessage)responseMessage); } } catch (Exception e) { lastException = e; Trace.WriteLine(string.Format("ROCMaster.Transport.Error,{0},{1}", requestMessage.OpCode.ToString(), e.Message), "Transport"); if (e is FormatException || e is NotImplementedException || e is TimeoutException || e is IOException) { if (attempt > NumberOfRetries) { goto Finish; } else { TimedThreadBlocker.Wait(WaitToRetryMilliseconds); } } else { throw; } } if (TracingEnabled) { Trace.WriteLine(string.Format("ROCMaster.Transport.Warning,Retry,{0},{1}", requestMessage.OpCode.ToString(), attempt.ToString())); } } while (!success && NumberOfRetries > attempt); } Finish: throw new TimeoutException("Device not responding to requests", lastException); }