Esempio n. 1
0
 /// <summary>
 /// Initializes a new instance.
 /// </summary>
 /// <param name="targetDeviceId"></param>
 /// <param name="sourceDeviceId"></param>
 /// <param name="targetPath"></param>
 /// <param name="sourcePath"></param>
 public RnetEventMessage(RnetDeviceId targetDeviceId, RnetDeviceId sourceDeviceId, RnetPath targetPath,
     RnetPath sourcePath, RnetEvent evt, ushort timestamp, ushort data, RnetPriority priority)
     : base(targetDeviceId, sourceDeviceId, RnetMessageType.Event)
 {
     TargetPath = targetPath;
     SourcePath = sourcePath;
     Event = evt;
     Timestamp = timestamp;
     Data = data;
     Priority = priority;
 }
Esempio n. 2
0
 /// <summary>
 /// Sends an event to the path on the device and returns the data after the event was received.
 /// </summary>
 /// <param name="evt"></param>
 /// <param name="timestamp"></param>
 /// <param name="data"></param>
 /// <param name="priority"></param>
 /// <param name="cancellationToken"></param>
 /// <returns></returns>
 public override Task<byte[]> SendEvent(RnetEvent evt, ushort timestamp, ushort data, RnetPriority priority, CancellationToken cancellationToken)
 {
     throw new System.NotImplementedException();
 }
Esempio n. 3
0
        /// <summary>
        /// Sends an event to the path on the device and returns the value after the event was received.
        /// </summary>
        /// <param name="evt"></param>
        /// <param name="timestamp"></param>
        /// <param name="data"></param>
        /// <param name="priority"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public override async Task<byte[]> SendEvent(RnetEvent evt, ushort timestamp, ushort data, RnetPriority priority, CancellationToken cancellationToken)
        {
            return await RnetUtil.DefaultIfCancelled(async ct =>
            {
                using (await wait.EnterAsync(ct))
                {
                    // clear cached data
                    buffer = null;

                    // initiate event followed by request data message
                    await Device.SendEvent(Path, evt, timestamp, data, priority, ct);
                    await Device.SendRequestData(Path, ct);

                    // wait for new data value
                    while (buffer == null && !ct.IsCancellationRequested)
                        await wait.WaitAsync(ct);

                    return buffer;
                }
            }, cancellationToken, Device.EventTimeoutCancellationToken);
        }
Esempio n. 4
0
 /// <summary>
 /// Issues an event message to the device.
 /// </summary>
 /// <param name="path"></param>
 /// <param name="evt"></param>
 /// <param name="timestamp"></param>
 /// <param name="data"></param>
 /// <param name="priority"></param>
 /// <returns></returns>
 public Task SendEvent(RnetPath path, RnetEvent evt, ushort timestamp = 0, ushort data = 0, RnetPriority priority = RnetPriority.Low)
 {
     return SendEvent(path, evt, timestamp, data, priority, CancellationToken.None);
 }
Esempio n. 5
0
        /// <summary>
        /// Issues an event message to the device.
        /// </summary>
        /// <param name="path"></param>
        /// <param name="evt"></param>
        /// <param name="timestamp"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public async Task SendEvent(RnetPath path, RnetEvent evt, ushort timestamp, ushort data, RnetPriority priority, CancellationToken cancellationToken)
        {
            using (await send.LockAsync(cancellationToken))
            using (await handshake.EnterAsync(cancellationToken))
            {
                handshakeMessage = null;

                // send set data packet
                await Bus.Client.Send(new RnetEventMessage(
                    DeviceId,
                    Bus.LocalDevice.DeviceId,
                    path,
                    RnetPath.Empty,
                    evt,
                    timestamp,
                    data,
                    priority));

                // wait for handshake
                if (priority == RnetPriority.High)
                    while (handshakeMessage == null)
                        await handshake.WaitAsync(cancellationToken);
            }
        }