/// <summary> /// The start channel message. /// </summary> /// <param name="Channelname"> /// The channelname. /// </param> /// <param name="gateWayChannelId"> /// The gate way channel id. /// </param> /// <returns> /// </returns> internal byte[] startChannelMessage(string Channelname, uint gateWayChannelId) { var mem = new MemoryStream(); var writer = new BinaryWriter(mem); var padding = 0; if (Channelname.Length % 8 == 0) { padding = 8; } else { padding = 8 - (Channelname.Length % 8); } mem.Capacity = 16 + Channelname.Length + padding; // add the versioning message writer.Write(NetworkByteConverter.ToByteArray(CommandID.CA_PROTO_CREATE_CHAN)); writer.Write(NetworkByteConverter.ToByteArray((UInt16)(Channelname.Length + padding))); writer.Write(new byte[4]); writer.Write(NetworkByteConverter.ToByteArray(gateWayChannelId)); writer.Write(NetworkByteConverter.ToByteArray((UInt32)CAConstants.CA_MINOR_PROTOCOL_REVISION)); writer.Write(NetworkByteConverter.ToByteArray(Channelname)); writer.Write(new byte[padding]); var buffer = mem.GetBuffer(); writer.Close(); mem.Dispose(); return(buffer); }
/// <summary> /// The monitor change message. /// </summary> /// <param name="subscriptionId"> /// The subscription id. /// </param> /// <param name="clientId"> /// The client id. /// </param> /// <param name="dataType"> /// The data type. /// </param> /// <param name="dataCount"> /// The data count. /// </param> /// <param name="data"> /// The data. /// </param> /// <returns> /// </returns> internal byte[] monitorChangeMessage(int subscriptionId, int clientId, EpicsType dataType, int dataCount, byte[] data) { var mem = new MemoryStream(); var writer = new BinaryWriter(mem); var padding = 0; if (data.Length % 8 == 0) { padding = 8; } else { padding = 8 - (data.Length % 8); } mem.Capacity = 16 + data.Length + padding; writer.Write(NetworkByteConverter.ToByteArray(CommandID.CA_PROTO_EVENT_ADD)); writer.Write(NetworkByteConverter.ToByteArray((UInt16)(data.Length + padding))); writer.Write(NetworkByteConverter.ToByteArray((UInt16)dataType)); writer.Write(NetworkByteConverter.ToByteArray((UInt16)dataCount)); writer.Write(NetworkByteConverter.ToByteArray((UInt32)clientId)); writer.Write(NetworkByteConverter.ToByteArray((UInt32)subscriptionId)); writer.Write(data); writer.Write(new byte[padding]); var buffer = mem.GetBuffer(); writer.Close(); mem.Dispose(); return(buffer); }
/// <summary> /// The get message. /// </summary> /// <param name="header"> /// The header. /// </param> /// <param name="jobId"> /// The job id. /// </param> /// <param name="iocId"> /// The ioc id. /// </param> /// <returns> /// </returns> internal byte[] getMessage(byte[] header, uint jobId, uint iocId) { Buffer.BlockCopy(NetworkByteConverter.ToByteArray(iocId), 0, header, 8, 4); Buffer.BlockCopy(NetworkByteConverter.ToByteArray(jobId), 0, header, 12, 4); return(header); }
/// <summary> /// The channel created message. /// </summary> /// <param name="clientId"> /// The client id. /// </param> /// <param name="serverId"> /// The server id. /// </param> /// <param name="dataType"> /// The data type. /// </param> /// <param name="dataCount"> /// The data count. /// </param> /// <param name="access"> /// The access. /// </param> /// <returns> /// </returns> internal byte[] channelCreatedMessage( int clientId, int serverId, EpicsType dataType, int dataCount, AccessRights access) { var mem = new MemoryStream(); var writer = new BinaryWriter(mem); mem.Capacity = 32; writer.Write(NetworkByteConverter.ToByteArray(CommandID.CA_PROTO_ACCESS_RIGHTS)); writer.Write(new byte[6]); writer.Write(NetworkByteConverter.ToByteArray((UInt32)clientId)); writer.Write(NetworkByteConverter.ToByteArray((UInt32)access)); writer.Write(NetworkByteConverter.ToByteArray(CommandID.CA_PROTO_CREATE_CHAN)); writer.Write(new byte[2]); writer.Write(NetworkByteConverter.ToByteArray((UInt16)dataType)); writer.Write(NetworkByteConverter.ToByteArray((UInt16)dataCount)); writer.Write(NetworkByteConverter.ToByteArray((UInt32)clientId)); writer.Write(NetworkByteConverter.ToByteArray((UInt32)serverId)); var buffer = mem.GetBuffer(); writer.Close(); mem.Dispose(); return(buffer); }
/// <summary> /// The set message. /// </summary> /// <param name="values"> /// The values. /// </param> /// <param name="type"> /// The type. /// </param> /// <param name="SID"> /// The sid. /// </param> /// <param name="CID"> /// The cid. /// </param> /// <param name="callBack"> /// The call back. /// </param> /// <typeparam name="dataType"> /// </typeparam> /// <returns> /// </returns> internal byte[] setMessage <dataType>(dataType[] values, EpicsType type, uint SID, uint CID, bool callBack) { var mem = new MemoryStream(); var writer = new BinaryWriter(mem); // possible max length = extended header (16byte) + count*40byte mem.Capacity = 16 + values.Length * 40; // jump to the end of the header. mem.Position = 16; foreach (var value in values) { writer.Write(NetworkByteConverter.objectToByte(value, type)); } // shrink to what we really need mem.Capacity = (int)mem.Position; // jump to the beginning mem.Position = 0; writer.Write(NetworkByteConverter.ToByteArray(callBack ? CommandID.CA_PROTO_WRITE_NOTIFY : CommandID.CA_PROTO_WRITE)); writer.Write(NetworkByteConverter.ToByteArray((UInt16)(mem.Capacity - 16))); writer.Write(NetworkByteConverter.ToByteArray((UInt16)type)); writer.Write(NetworkByteConverter.ToByteArray((UInt16)values.Length)); writer.Write(NetworkByteConverter.ToByteArray(SID)); writer.Write(NetworkByteConverter.ToByteArray(CID)); var buffer = mem.GetBuffer(); writer.Close(); mem.Dispose(); return(buffer); }
/// <summary> /// Generates a 16 byte MessageHeader containing the standard VersionMessage with /// Priority 1. /// It's only used in combination with other messages for this reason it's private. /// *cached* /// </summary> private static void versionMessage() { cVersionMessage = new byte[16] { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 }; Buffer.BlockCopy(NetworkByteConverter.ToByteArray(CAConstants.CA_MINOR_PROTOCOL_REVISION), 0, cVersionMessage, 6, 2); }
/// <summary> /// The channel creation fail message. /// </summary> /// <param name="clientId"> /// The client id. /// </param> /// <returns> /// </returns> internal byte[] channelCreationFailMessage(int clientId) { var msg = new byte[16] { 0, 26, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; Buffer.BlockCopy(NetworkByteConverter.ToByteArray(clientId), 0, msg, 8, 4); return(msg); }
/// <summary> /// The channel disconnection message. /// </summary> /// <param name="clientId"> /// The client id. /// </param> /// <returns> /// </returns> internal byte[] channelDisconnectionMessage(uint clientId) { var msg = new byte[16] { 0, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; Buffer.BlockCopy(NetworkByteConverter.ToByteArray(clientId), 0, msg, 8, 4); return(msg); }
/// <summary> /// The error message. /// </summary> /// <param name="ioId"> /// The io id. /// </param> /// <param name="header"> /// The header. /// </param> /// <param name="data"> /// The data. /// </param> /// <returns> /// </returns> internal byte[] errorMessage(uint ioId, byte[] header, byte[] data) { var message = new byte[header.Length + data.Length]; Buffer.BlockCopy(header, 0, message, 0, header.Length); Buffer.BlockCopy(NetworkByteConverter.ToByteArray(ioId), 0, message, 8, 4); Buffer.BlockCopy(data, 0, message, header.Length, data.Length); return(message); }
/// <summary> /// The put message. /// </summary> /// <param name="header"> /// The header. /// </param> /// <param name="payload"> /// The payload. /// </param> /// <param name="jobId"> /// The job id. /// </param> /// <param name="iocId"> /// The ioc id. /// </param> /// <returns> /// </returns> internal byte[] putMessage(byte[] header, byte[] payload, uint jobId, uint iocId) { var message = new byte[header.Length + payload.Length]; Buffer.BlockCopy(header, 0, message, 0, header.Length); Buffer.BlockCopy(NetworkByteConverter.ToByteArray(iocId), 0, message, 8, 4); Buffer.BlockCopy(NetworkByteConverter.ToByteArray(jobId), 0, message, 12, 4); Buffer.BlockCopy(payload, 0, message, header.Length, payload.Length); return(message); }
/// <summary> /// The monitor change message. /// </summary> /// <param name="subscriptionId"> /// The subscription id. /// </param> /// <param name="clientId"> /// The client id. /// </param> /// <param name="header"> /// The header. /// </param> /// <param name="data"> /// The data. /// </param> /// <returns> /// </returns> internal byte[] monitorChangeMessage(uint subscriptionId, uint clientId, byte[] header, byte[] data) { var message = new byte[header.Length + data.Length]; Buffer.BlockCopy(header, 0, message, 0, header.Length); Buffer.BlockCopy(NetworkByteConverter.ToByteArray(clientId), 0, message, 8, 4); Buffer.BlockCopy(NetworkByteConverter.ToByteArray(subscriptionId), 0, message, 12, 4); Buffer.BlockCopy(data, 0, message, header.Length, data.Length); return(message); }
/// <summary> /// The parse byte package. /// </summary> /// <param name="dataPipe"> /// The data pipe. /// </param> /// <param name="remoteEndPoint"> /// The remote end point. /// </param> /// <param name="maxPacketSize"> /// The max packet size. /// </param> internal void ParseBytePackage(Pipe dataPipe, EndPoint remoteEndPoint, int maxPacketSize) { var remoteAddress = remoteEndPoint.ToString(); uint readedBytes = 0; ushort cmdId, dataType; uint payloadSize, dataCount, param1, param2; byte[] payload = null; byte[] header = null; while (maxPacketSize == 0 || maxPacketSize >= (readedBytes + 16)) { header = dataPipe.Read(16); // Pipe destroyed if (header.Length == 0) { return; } cmdId = NetworkByteConverter.ToUInt16(header, 0); payloadSize = NetworkByteConverter.ToUInt16(header, 2); dataType = NetworkByteConverter.ToUInt16(header, 4); param1 = NetworkByteConverter.ToUInt32(header, 8); param2 = NetworkByteConverter.ToUInt32(header, 12); if (payloadSize == 0xFFFF) { payloadSize = NetworkByteConverter.ToUInt32(dataPipe.Read(4)); dataCount = NetworkByteConverter.ToUInt32(dataPipe.Read(4)); readedBytes += payloadSize + 24; } else { dataCount = NetworkByteConverter.ToUInt16(header, 6); readedBytes += payloadSize + 16; } payload = dataPipe.Read((int)payloadSize); this.HandleMessage( cmdId, dataType, ref payloadSize, ref dataCount, ref param1, ref param2, ref header, ref payload, ref remoteEndPoint); } }
/// <summary> /// Generates a EPICS-TCP-Greet Package, which is needed by establishing a new TCP-ServerConnection. /// It contains 3 Packages : CA_PROTO_VERSION,CA_PROTO_CLIENT_NAME and CA_PROTO_HOST_NAME /// /// *cached* /// </summary> private static void tcpGreetPackage() { var mem = new MemoryStream(); var writer = new BinaryWriter(mem); var userPadding = 0; var hostPadding = 0; // calc username padding if (Environment.UserName.Length % 8 == 0) { userPadding = 8; } else { userPadding = 8 - (Environment.UserName.Length % 8); } // calc hostpadding if (Environment.MachineName.Length % 8 == 0) { hostPadding = 8; } else { hostPadding = 8 - (Environment.MachineName.Length % 8); } // calc total length mem.Capacity = (3 * 16) + Environment.UserName.Length + userPadding + Environment.MachineName.Length + hostPadding; // add the version message first writer.Write(cVersionMessage); // add the username message writer.Write(NetworkByteConverter.ToByteArray(CommandID.CA_PROTO_CLIENT_NAME)); writer.Write(NetworkByteConverter.ToByteArray((UInt16)(Environment.UserName.Length + userPadding))); writer.Write(new byte[12]); writer.Write(NetworkByteConverter.ToByteArray(Environment.UserName)); writer.Write(new byte[userPadding]); // add the hostname message writer.Write(NetworkByteConverter.ToByteArray(CommandID.CA_PROTO_HOST_NAME)); writer.Write(NetworkByteConverter.ToByteArray((UInt16)(Environment.MachineName.Length + hostPadding))); writer.Write(new byte[12]); writer.Write(NetworkByteConverter.ToByteArray(Environment.MachineName)); writer.Write(new byte[hostPadding]); CTCPGreet = mem.GetBuffer(); writer.Close(); mem.Dispose(); }
private void RecordPropertyChanged(EpicsRecord sender, RecordProperty prop, object val, Setter setter) { if (prop == this.property) { var toUpdate = true; if (val is short || val is int || val is float || val is double) { var v = Convert.ToDouble(val); var l = Convert.ToDouble(this.lastValue); if (Math.Abs(v - l) > sender.MDEL) { this.lastValue = val; } else { toUpdate = false; } } else if (val is string) { if ((string)val == (string)this.lastValue) { toUpdate = false; } else { this.lastValue = val; } } else { if (val.ToString() == this.lastValue.ToString()) { toUpdate = false; } else { this.lastValue = val; } } if (toUpdate) { this.channel.sendMonitorChange( this.subscriptionId, this.type, this.dataCount, EpicsTransitionStatus.ECA_NORMAL, NetworkByteConverter.objectToByte(val, this.type, this.record)); } } }
/// <summary> /// Builds a EPICS-Package for Searching multiple Channel. /// it contains 2 types of messages: /// a leading CA_PROTO_VERSION and then for every channel a /// CA_PROTO_SEARCH /// </summary> /// <param name="channelList"> /// The channel List. /// </param> /// <returns> /// </returns> internal byte[] searchPackage(Queue <KeyValuePair <uint, string> > channelList) { var mem = new MemoryStream(); var writer = new BinaryWriter(mem); KeyValuePair <uint, string> pair; var padding = 0; var counter = 0; writer.Write(cVersionMessage); // it's something which should in 99% work but is not clean mem.Capacity = 65536; while (counter < this.GateWay.Config.ChannelSearchMaxPackageSize && channelList.Count > 0) { lock (channelList) { pair = channelList.Dequeue(); } counter++; if (pair.Value.Length % 8 == 0) { padding = 8; } else { padding = 8 - (pair.Value.Length % 8); } // add the versioning message writer.Write(NetworkByteConverter.ToByteArray(CommandID.CA_PROTO_SEARCH)); writer.Write(NetworkByteConverter.ToByteArray((UInt16)(pair.Value.Length + padding))); writer.Write(NetworkByteConverter.ToByteArray(CAConstants.DONT_REPLY)); writer.Write(NetworkByteConverter.ToByteArray(CAConstants.CA_MINOR_PROTOCOL_REVISION)); writer.Write(NetworkByteConverter.ToByteArray(pair.Key)); writer.Write(NetworkByteConverter.ToByteArray(pair.Key)); writer.Write(NetworkByteConverter.ToByteArray(pair.Value)); writer.Write(new byte[padding]); } mem.Capacity = (int)mem.Position; var buffer = mem.GetBuffer(); writer.Close(); mem.Dispose(); return(buffer); }
/// <summary> /// The close subscription message. /// </summary> /// <param name="iocId"> /// The ioc id. /// </param> /// <param name="subscriptionId"> /// The subscription id. /// </param> /// <returns> /// </returns> internal byte[] closeSubscriptionMessage(uint iocId, uint subscriptionId) { var mem = new MemoryStream(); var writer = new BinaryWriter(mem); mem.Capacity = 16; writer.Write(NetworkByteConverter.ToByteArray(CommandID.CA_PROTO_EVENT_CANCEL)); writer.Write(new byte[6]); writer.Write(NetworkByteConverter.ToByteArray(iocId)); writer.Write(NetworkByteConverter.ToByteArray(subscriptionId)); var buffer = mem.GetBuffer(); writer.Close(); mem.Dispose(); return(buffer); }
/// <summary> /// The close channel message. /// </summary> /// <param name="channelId"> /// The channel id. /// </param> /// <param name="iocId"> /// The ioc id. /// </param> /// <returns> /// </returns> internal byte[] closeChannelMessage(uint channelId, uint iocId) { var mem = new MemoryStream(); var writer = new BinaryWriter(mem); // add the versioning message mem.Capacity = 16; writer.Write(NetworkByteConverter.ToByteArray(CommandID.CA_PROTO_CLEAR_CHANNEL)); writer.Write(new byte[6]); writer.Write(NetworkByteConverter.ToByteArray(iocId)); writer.Write(NetworkByteConverter.ToByteArray(channelId)); var buffer = mem.GetBuffer(); writer.Close(); mem.Dispose(); return(buffer); }
/// <summary> /// The channel clear message. /// </summary> /// <param name="clientId"> /// The client id. /// </param> /// <param name="serverId"> /// The server id. /// </param> /// <returns> /// </returns> internal byte[] channelClearMessage(uint clientId, uint serverId) { var mem = new MemoryStream(); var writer = new BinaryWriter(mem); mem.Capacity = 16; writer.Write(NetworkByteConverter.ToByteArray(CommandID.CA_PROTO_CLEAR_CHANNEL)); writer.Write(new byte[6]); writer.Write(NetworkByteConverter.ToByteArray(serverId)); writer.Write(NetworkByteConverter.ToByteArray(clientId)); var buffer = mem.GetBuffer(); writer.Close(); mem.Dispose(); return(buffer); }
/// <summary> /// The get message. /// </summary> /// <param name="type"> /// The type. /// </param> /// <param name="count"> /// The count. /// </param> /// <param name="SID"> /// The sid. /// </param> /// <param name="CID"> /// The cid. /// </param> /// <returns> /// </returns> internal byte[] getMessage(EpicsType type, ushort count, uint SID, uint CID) { var mem = new MemoryStream(); var writer = new BinaryWriter(mem); mem.Capacity = 16; writer.Write(NetworkByteConverter.ToByteArray(CommandID.CA_PROTO_READ_NOTIFY)); writer.Write(new byte[2]); writer.Write(NetworkByteConverter.ToByteArray((UInt16)type)); writer.Write(NetworkByteConverter.ToByteArray(count)); writer.Write(NetworkByteConverter.ToByteArray(SID)); writer.Write(NetworkByteConverter.ToByteArray(CID)); var buffer = mem.GetBuffer(); writer.Close(); mem.Dispose(); return(buffer); }
/// <summary> /// The beacon message. /// </summary> /// <param name="port"> /// The port. /// </param> /// <param name="sequenceNumber"> /// The sequence number. /// </param> /// <param name="ip"> /// The ip. /// </param> /// <returns> /// </returns> internal static byte[] beaconMessage(int port, int sequenceNumber, uint ip) { var mem = new MemoryStream(); var writer = new BinaryWriter(mem); mem.Capacity = 16; writer.Write(NetworkByteConverter.ToByteArray(CommandID.CA_PROTO_RSRV_IS_UP)); writer.Write(new byte[2]); writer.Write(NetworkByteConverter.ToByteArray((UInt16)port)); writer.Write(new byte[2]); writer.Write(NetworkByteConverter.ToByteArray((UInt32)sequenceNumber)); writer.Write(NetworkByteConverter.ToByteArray(ip)); var buffer = mem.GetBuffer(); writer.Close(); mem.Dispose(); return(buffer); }
/// <summary> /// The monitor close message. /// </summary> /// <param name="dataType"> /// The data type. /// </param> /// <param name="serverId"> /// The server id. /// </param> /// <param name="subscriptionId"> /// The subscription id. /// </param> /// <returns> /// </returns> internal byte[] monitorCloseMessage(EpicsType dataType, int serverId, int subscriptionId) { var mem = new MemoryStream(); var writer = new BinaryWriter(mem); mem.Capacity = 16; writer.Write(NetworkByteConverter.ToByteArray(CommandID.CA_PROTO_EVENT_CANCEL)); writer.Write(new byte[2]); writer.Write(NetworkByteConverter.ToByteArray((UInt16)dataType)); writer.Write(new byte[2]); writer.Write(NetworkByteConverter.ToByteArray((UInt32)serverId)); writer.Write(NetworkByteConverter.ToByteArray((UInt32)subscriptionId)); var buffer = mem.GetBuffer(); writer.Close(); mem.Dispose(); return(buffer); }
/// <summary> /// The create subscription message. /// </summary> /// <param name="SID"> /// The sid. /// </param> /// <param name="SubscriptionID"> /// The subscription id. /// </param> /// <param name="type"> /// The type. /// </param> /// <param name="dataCount"> /// The data count. /// </param> /// <param name="mask"> /// The mask. /// </param> /// <returns> /// </returns> internal byte[] createSubscriptionMessage( uint SID, uint SubscriptionID, EpicsType type, ushort dataCount, MonitorMask mask) { var mem = new MemoryStream(); var writer = new BinaryWriter(mem); mem.Capacity = 32; writer.Write(NetworkByteConverter.ToByteArray(CommandID.CA_PROTO_EVENT_ADD)); writer.Write(NetworkByteConverter.ToByteArray((UInt16)16)); writer.Write(NetworkByteConverter.ToByteArray((UInt16)type)); writer.Write(NetworkByteConverter.ToByteArray(dataCount)); writer.Write(NetworkByteConverter.ToByteArray(SID)); writer.Write(NetworkByteConverter.ToByteArray(SubscriptionID)); writer.Write(new byte[12]); writer.Write(NetworkByteConverter.ToByteArray((UInt16)mask)); var buffer = mem.GetBuffer(); writer.Close(); mem.Dispose(); return(buffer); }
/// <summary> /// The set message. /// </summary> /// <param name="value"> /// The value. /// </param> /// <param name="type"> /// The type. /// </param> /// <param name="SID"> /// The sid. /// </param> /// <param name="CID"> /// The cid. /// </param> /// <param name="callBack"> /// The call back. /// </param> /// <returns> /// </returns> internal byte[] setMessage(object value, EpicsType type, uint SID, uint CID, bool callBack) { var mem = new MemoryStream(); var writer = new BinaryWriter(mem); var payload = NetworkByteConverter.objectToByte(value, type); var padding = 0; if (payload.Length % 8 == 0) { padding = 8; } else { padding = 8 - (payload.Length % 8); } mem.Capacity = 16 + payload.Length + padding; // add the versioning message writer.Write(NetworkByteConverter.ToByteArray(callBack ? CommandID.CA_PROTO_WRITE_NOTIFY : CommandID.CA_PROTO_WRITE)); writer.Write(NetworkByteConverter.ToByteArray((UInt16)(payload.Length + padding))); writer.Write(NetworkByteConverter.ToByteArray((UInt16)type)); writer.Write(new byte[2] { 0, 1 }); writer.Write(NetworkByteConverter.ToByteArray(SID)); writer.Write(NetworkByteConverter.ToByteArray(CID)); writer.Write(payload); writer.Write(new byte[padding]); var buffer = mem.GetBuffer(); writer.Close(); mem.Dispose(); return(buffer); }
/// <summary> /// The channel wrote message. /// </summary> /// <param name="clientId"> /// The client id. /// </param> /// <param name="ioId"> /// The io id. /// </param> /// <param name="dataType"> /// The data type. /// </param> /// <param name="dataCount"> /// The data count. /// </param> /// <param name="status"> /// The status. /// </param> /// <returns> /// </returns> internal byte[] channelWroteMessage( int clientId, int ioId, EpicsType dataType, int dataCount, EpicsTransitionStatus status) { var mem = new MemoryStream(); var writer = new BinaryWriter(mem); mem.Capacity = 16; writer.Write(NetworkByteConverter.ToByteArray(CommandID.CA_PROTO_WRITE_NOTIFY)); writer.Write(new byte[2]); writer.Write(NetworkByteConverter.ToByteArray((UInt16)dataType)); writer.Write(NetworkByteConverter.ToByteArray((UInt16)dataCount)); writer.Write(NetworkByteConverter.ToByteArray((UInt32)status)); writer.Write(NetworkByteConverter.ToByteArray((UInt32)ioId)); var buffer = mem.GetBuffer(); writer.Close(); mem.Dispose(); return(buffer); }
/// <summary> /// The channel found message. /// </summary> /// <param name="clientId"> /// The client id. /// </param> /// <returns> /// </returns> internal byte[] channelFoundMessage(uint clientId) { var mem = new MemoryStream(); var writer = new BinaryWriter(mem); mem.Capacity = 40; writer.Write(cVersionMessage); writer.Write(NetworkByteConverter.ToByteArray(CommandID.CA_PROTO_SEARCH)); writer.Write(NetworkByteConverter.ToByteArray((UInt16)8)); writer.Write(NetworkByteConverter.ToByteArray((UInt16)this.GateWay.Config.TCPListenPort)); writer.Write(new byte[2]); writer.Write(NetworkByteConverter.ToByteArray(0xFFFFFFFF)); writer.Write(NetworkByteConverter.ToByteArray(clientId)); writer.Write(NetworkByteConverter.ToByteArray(CAConstants.CA_MINOR_PROTOCOL_REVISION)); var buffer = mem.GetBuffer(); writer.Close(); mem.Dispose(); return(buffer); }
internal EpicsServerMonitor( EpicsRecord record, RecordProperty property, EpicsServerChannel channel, EpicsType type, int dataCount, MonitorMask monitorMask, int subscriptionId) { this.record = record; this.property = property; this.channel = channel; this.type = type; this.dataCount = dataCount; this.monitorMask = monitorMask; this.subscriptionId = subscriptionId; try { var val = this.record[this.property.ToString()]; if (val == null) { val = 0; } var realData = NetworkByteConverter.objectToByte(val, this.type, this.record); this.channel.sendMonitorChange( this.subscriptionId, this.type, this.dataCount, EpicsTransitionStatus.ECA_NORMAL, realData); this.StartMonitor(); } catch (Exception e) { this.channel.sendMonitorChange( this.subscriptionId, this.type, this.dataCount, EpicsTransitionStatus.ECA_ADDFAIL, new byte[0]); } }
/// <summary> /// The read value. /// </summary> /// <param name="ioId"> /// The io id. /// </param> /// <param name="type"> /// The type. /// </param> /// <param name="dataCount"> /// The data count. /// </param> internal void readValue(int ioId, EpicsType type, int dataCount) { byte[] val; var objVal = this.Record[this.Property.ToString()]; if (objVal == null) { objVal = 0; } try { if (dataCount == 1) { val = NetworkByteConverter.objectToByte(objVal, type, this.Record); } else { if (objVal.GetType().IsGenericType) { val = NetworkByteConverter.objectToByte(objVal, type, this.Record, dataCount); } else { return; } } this.Conn.Send(this.Server.Codec.channelReadMessage(this.ClientId, ioId, type, dataCount, val)); } catch (Exception e) { this.Conn.Send( this.Server.Codec.errorMessage(this.ClientId, EpicsTransitionStatus.ECA_BADTYPE, "WRONG TYPE", new byte[16])); } }
/// <summary> /// The channel created message. /// </summary> /// <param name="clientId"> /// The client id. /// </param> /// <param name="serverId"> /// The server id. /// </param> /// <param name="access"> /// The access. /// </param> /// <param name="header"> /// The header. /// </param> /// <returns> /// </returns> internal byte[] channelCreatedMessage(uint clientId, uint serverId, AccessRights access, byte[] header) { var mem = new MemoryStream(); var writer = new BinaryWriter(mem); mem.Capacity = 32; writer.Write(NetworkByteConverter.ToByteArray(CommandID.CA_PROTO_ACCESS_RIGHTS)); writer.Write(new byte[6]); writer.Write(NetworkByteConverter.ToByteArray(clientId)); writer.Write(NetworkByteConverter.ToByteArray((UInt32)access)); Buffer.BlockCopy(NetworkByteConverter.ToByteArray(clientId), 0, header, 8, 4); Buffer.BlockCopy(NetworkByteConverter.ToByteArray(serverId), 0, header, 12, 4); writer.Write(header); var buffer = mem.GetBuffer(); writer.Close(); mem.Dispose(); return(buffer); }
/// <summary> /// Builds a EPICS-Package for Searching a Channel. /// it contains 2 Messages: CA_PROTO_VERSION and CA_PROTO_SEARCH /// </summary> /// <param name="Channelname"> /// String Name of a searched Channel /// </param> /// <param name="CID"> /// CID of the given Channel /// </param> /// <returns> /// </returns> internal byte[] searchPackage(string Channelname, uint CID) { var mem = new MemoryStream(); var writer = new BinaryWriter(mem); var padding = 0; if (Channelname.Length % 8 == 0) { padding = 8; } else { padding = 8 - (Channelname.Length % 8); } mem.Capacity = 16 + 16 + Channelname.Length + padding; // add the versioning message writer.Write(cVersionMessage); writer.Write(NetworkByteConverter.ToByteArray(CommandID.CA_PROTO_SEARCH)); writer.Write(NetworkByteConverter.ToByteArray((UInt16)(Channelname.Length + padding))); writer.Write(NetworkByteConverter.ToByteArray(CAConstants.DONT_REPLY)); writer.Write(NetworkByteConverter.ToByteArray(CAConstants.CA_MINOR_PROTOCOL_REVISION)); writer.Write(NetworkByteConverter.ToByteArray(CID)); writer.Write(NetworkByteConverter.ToByteArray(CID)); writer.Write(NetworkByteConverter.ToByteArray(Channelname)); writer.Write(new byte[padding]); var buffer = mem.GetBuffer(); writer.Close(); mem.Dispose(); return(buffer); }
/// <summary> /// The error message. /// </summary> /// <param name="clientId"> /// The client id. /// </param> /// <param name="status"> /// The status. /// </param> /// <param name="errorMessage"> /// The error message. /// </param> /// <param name="header"> /// The header. /// </param> /// <returns> /// </returns> internal byte[] errorMessage(int clientId, EpicsTransitionStatus status, string errorMessage, byte[] header) { var mem = new MemoryStream(); var writer = new BinaryWriter(mem); mem.Capacity = 16 + 16 + errorMessage.Length + 1; writer.Write(NetworkByteConverter.ToByteArray(CommandID.CA_PROTO_ERROR)); writer.Write(NetworkByteConverter.ToByteArray(errorMessage.Length + 16)); writer.Write(new byte[4]); writer.Write(NetworkByteConverter.ToByteArray((UInt32)clientId)); writer.Write(NetworkByteConverter.ToByteArray((UInt32)status)); // emptyheader writer.Write(header); writer.Write(NetworkByteConverter.ToByteArray(errorMessage)); var buffer = mem.GetBuffer(); writer.Close(); mem.Dispose(); return(buffer); }