/// <summary> /// Retrievess data from message body. populates property dependant on data type /// </summary> private void GetData() { try { int dataTypePosition = TraciDataHelper.GetTraciInteger(_traciResponse.MessageBody, _traciResponse.MessageStart + 1) + _traciResponse.MessageStart + 5; switch (TraciDataHelper.GetTraciDataType(_traciResponse.MessageBody, dataTypePosition)) { case TraciConstants.DataType.TYPE_DOUBLE: DoubleResponse = TraciDataHelper.GetTraciDouble(_traciResponse.MessageBody, dataTypePosition + 1); break; case TraciConstants.DataType.TYPE_STRINGLIST: StringListResponse = TraciDataHelper.GetTracStringList(_traciResponse.MessageBody, dataTypePosition + 1); break; case TraciConstants.DataType.TYPE_STRING: StringResponse = TraciDataHelper.GetTraciString(_traciResponse.MessageBody, dataTypePosition + 1); break; } } catch (Exception ex) { throw new SumoControllerException("Error retrieving data from Variable Traci data response", ex); } }
/// <summary> /// Initialises class, retrieves header and main body from message /// </summary> /// <param name="response">Traci response message</param> public TraciResponseMessage(byte[] response) { MessageLength = TraciDataHelper.GetTraciInteger(response, 0); Command = TraciDataHelper.GetTraciCommand(response, 5); ReadStatusHeader(response); SetMessageBody(response); SetMessageStart(); }
/// <summary> /// Sets Body for variable action Traci message /// </summary> protected override void SetBody() { try { _commandBody = new List <byte>(); _commandBody.Add((byte)_variableName); _commandBody = TraciDataHelper.AddToByteList(_commandBody, TraciDataHelper.CreateTraciString(_variableValue)); } catch (Exception ex) { throw new SumoControllerException("Error setting body of Traci variable message", ex); } }
/// <summary> /// Creates the Traci message from the command queue /// </summary> /// <returns>Traci Message</returns> public byte[] GetMessage() { try { List <byte> messageBodyBytes = BuildMessageBody(); int messageSize = messageBodyBytes.Count + 4; List <byte> header = TraciDataHelper.CreateTraciIntBytes(messageSize); return(header.Concat(messageBodyBytes).ToArray()); } catch (Exception ex) { throw new SumoControllerException("Error creating Traci Message", ex); } }
/// <summary> /// Creates the Traci message body /// </summary> /// <returns>Traci message body in bytes</returns> private List <byte> BuildMessageBody() { try { List <byte> sectionBytes = new List <byte>(); foreach (KeyValuePair <TraciConstants.Command, List <byte> > command in _commandQueue) { sectionBytes = TraciDataHelper.AddToByteList(sectionBytes, BuildCommandBytes(command)); } return(sectionBytes); } catch (Exception ex) { throw new SumoControllerException("Error buiding Traci Message body", ex); } }