Ejemplo n.º 1
0
        public override void OnNotification(string roleName, string opName, IList<VParamType> retVals, VPort senderPort)
        {
            string message;
            string sensorData;
            string sensorTag = senderPort.GetInfo().GetFriendlyName() + roleName;

            lock (this)
            {
                if (roleName.Contains(RoleSensor.RoleName) && opName.Equals(RoleSensor.OpGetName))
                {
                        byte rcvdNum = (byte) (int) retVals[0].Value();
                        sensorData = rcvdNum.ToString();

                }
                else if (roleName.Contains(RoleSensorMultiLevel.RoleName) && opName.Equals(RoleSensorMultiLevel.OpGetName))
                {
                    double rcvdNum = (double) retVals[0].Value();
                    sensorData = rcvdNum.ToString();
                }
                else
                {
                    sensorData = String.Format("Invalid role->op {0}->{1} from {2}", roleName, opName, sensorTag);
                }
            }

            //Write to the stream
            WriteToStream(sensorTag, sensorData);
            //Create local list of alerts for display
            message = String.Format("{0} {1},{2}", DateTime.Now, sensorTag, sensorData);
            this.receivedMessageList.Add(message);
            //Log
            logger.Log("{0},{1}", this.ToString(), message);
        }
Ejemplo n.º 2
0
        public override void PortRegistered(VPort port)
        {
            lock (this)
            {
                if (Role.ContainsRole(port, RoleSensor.RoleName))
                {
                    VCapability capability = GetCapability(port, Constants.UserSystem);

                    if (registeredSensors.ContainsKey(port))
                        registeredSensors[port] = capability;
                    else
                        registeredSensors.Add(port, capability);

                    if (capability != null)
                    {
                        port.Subscribe(RoleSensor.RoleName, RoleSensor.OpGetName,
                               this.ControlPort, capability, this.ControlPortCapability);
                    }
                }
                if (Role.ContainsRole(port, RoleActuator.RoleName))
                {
                    VCapability capability = GetCapability(port, Constants.UserSystem);

                    if (registeredActuators.ContainsKey(port))
                        registeredActuators[port] = capability;
                    else
                        registeredActuators.Add(port, capability);

                    if (capability != null)
                    {
                        port.Subscribe(RoleActuator.RoleName, RoleActuator.OpPutName, this.ControlPort, capability, this.ControlPortCapability);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Does the given port contain the given role
        /// </summary>
        /// <param name="port"></param>
        /// <param name="roleName"></param>
        /// <returns></returns>
        public static bool ContainsRole(VPort port, string roleName)
        {
            foreach (VRole role in port.GetInfo().GetRoles())
            {
                if (ContainsRole(role.Name(), roleName))
                    return true;
            }

            return false;
        }
Ejemplo n.º 4
0
 public override void PortDeregistered(VPort port)
 {
     lock (this)
     {
         if (accessibleDummyPorts.Contains(port))
         {
             accessibleDummyPorts.Remove(port);
             logger.Log("{0} deregistered port {1}", this.ToString(), port.GetInfo().ModuleFacingName());
         }
     }
 }
Ejemplo n.º 5
0
 public override void OnNotification(string roleName, string opName, IList<VParamType> retVals, VPort senderPort)
 {
     logger.Log("Notitification from {0} for {0}", roleName, opName);
     if (retVals.Count >= 1)
     {
         this.Temperature = (int)retVals[0].Value();
     }
     else
     {
         logger.Log("{0}: got unexpected retvals [{1}] from {2}", ToString(), retVals.Count.ToString(), senderPort.ToString());
     }
 }
Ejemplo n.º 6
0
        public sealed override void PortDeregisteredWithHooks(HomeOS.Hub.Platform.Views.VPort port)
        {
            lock (capabilityStore)
            {
                if (capabilityStore.ContainsKey(port))
                {
                    capabilityStore.Remove(port);
                }
            }

            platform.UpdateState(this, new HomeOS.Hub.Common.ModuleState(ModuleState.SimpleState.EnterPortDeregistered, DateTime.Now));
            PortDeregistered(port);
            platform.UpdateState(this, new HomeOS.Hub.Common.ModuleState(ModuleState.SimpleState.ExitPortDeregistered, DateTime.Now));
        }
 public override void PortDeregistered(VPort port)
 {
     lock (this)
     {
         if (Role.ContainsRole(port, RoleSensor.RoleName))
         {
             if (registeredValves.ContainsKey(port))
             {
                 registeredValves.Remove(port);
                 logger.Log("{0} removed valve port {1}", this.ToString(), port.ToString());
             }
         }
     }
 }
Ejemplo n.º 8
0
        /// <summary>
        ///  Called when a new port is registered with the platform
        /// </summary>
        public override void PortRegistered(VPort port)
        {

            logger.Log("{0} got registeration notification for {1}", ToString(), port.ToString());

            lock (this)
            {
                if (!accessibleWeatherPorts.Contains(port) && 
                    Role.ContainsRole(port, RoleWeather.RoleName) && 
                    GetCapabilityFromPlatform(port) != null)
                {
                    accessibleWeatherPorts.Add(port);

                    logger.Log("{0} added port {1}", this.ToString(), port.ToString());
                }
            }
        }
Ejemplo n.º 9
0
        internal static IPort V2C(VPort view)
        {
            if (view == null)
            {
                return null;
            }

            if (!System.Runtime.Remoting.RemotingServices.IsObjectOutOfAppDomain(view) &&
                (view.GetType().Equals(typeof(PortC2V))))
            {
                return ((PortC2V)(view)).GetSourceContract();
            }
            else
            {
                return new PortV2C(view);
            }
        }
Ejemplo n.º 10
0
        public override void OnNotification(string roleName, string opName, IList<VParamType> retVals, VPort senderPort)
        {
            string message;
            lock (this)
            {
                switch (opName.ToLower())
                {
                    case RoleDummy2.OpEchoSubName:
                        int rcvdNum = (int)retVals[0].Value();

                        message = String.Format("async echo response from {0}. rcvd = {1}", senderPort.ToString(), rcvdNum.ToString());
                        this.receivedMessageList.Add(message);
                        break;
                    default:
                        message = String.Format("Invalid async operation return {0} from {1}", opName.ToLower(), senderPort.ToString());
                        break;
                }
            }
            logger.Log("{0} {1}", this.ToString(), message);
        }
Ejemplo n.º 11
0
 public override void OnNotification(string roleName, string opName, IList<VParamType> retVals, VPort senderPort)
 {
     string message;
     lock (this)
     {
         switch (opName.ToLower())
         {
             case "echosub":
                 string rcvdData = (string)retVals[0].Value();
                 irDataList.Add(rcvdData);
                 //ProcessData(rcvdData);
                 message = String.Format("async echo response from {0}. rcvd = {1}", senderPort.ToString(), rcvdData.ToString());
                 this.receivedMessageList.Add(message);
                 break;
             default:
                 message = String.Format("Invalid async operation return {0} from {1}", opName.ToLower(), senderPort.ToString());
                 break;
         }
     }
     //logger.Log("{0} {1}", this.ToString(), message);
 }
Ejemplo n.º 12
0
        /// <summary>
        ///  Called when a new port is registered with the platform
        /// </summary>
        public override void PortRegistered(VPort port)
        {
            logger.Log("{0} got registeration notification for {1}", ToString(), port.ToString());

            lock (this)
            {
                if (!accessibleDummyPorts.Contains(port) &&
                    Role.ContainsRole(port, RoleDummy2.RoleName) &&
                    GetCapabilityFromPlatform(port) != null)
                {
                    accessibleDummyPorts.Add(port);

                    logger.Log("{0} added port {1}", this.ToString(), port.ToString());

                    if (Subscribe(port, RoleDummy2.Instance, RoleDummy2.OpEchoSubName))
                        logger.Log("{0} subscribed to port {1}", this.ToString(), port.ToString());
                    else
                        logger.Log("failed to subscribe to port {1}", this.ToString(), port.ToString());
                }
            }
        }
Ejemplo n.º 13
0
 public override void AsyncReturn(string roleName, string opName, IList<VParamType> retVals, VPort p, VCapability respCap)
 {
     _contract.AsyncReturn(roleName, opName,
                           CollectionAdapters.ToIListContract<VParamType, IParamType>(retVals, BaseTypeAdapter.V2C, BaseTypeAdapter.C2V),
                           PortAdapter.V2C(p), CapabilityAdapter.V2C(respCap));
 }
Ejemplo n.º 14
0
 public abstract int InstallCapability(VCapability capability, VPort targetPort);
Ejemplo n.º 15
0
 public virtual void PortDeregisteredWithHooks(VPort port) { }
Ejemplo n.º 16
0
        public override void OnNotification(string roleName, string opName, IList<VParamType> retVals, VPort senderPort)
        {
            string message;
            string sensorData;
            string sensorTag = senderPort.GetInfo().GetFriendlyName() + roleName;

            lock (this)
            {
                if (roleName.Contains(RoleSensor.RoleName) && opName.Equals(RoleSensor.OpGetName))
                {
                    byte rcvdNum = (byte)(int)retVals[0].Value();
                    sensorData = rcvdNum.ToString();

                }
                else if (roleName.Contains(RoleSensorMultiLevel.RoleName) && opName.Equals(RoleSensorMultiLevel.OpGetName))
                {
                    double rcvdNum = (double)retVals[0].Value();
                    sensorData = rcvdNum.ToString();
                }
                else
                {
                    sensorData = String.Format("Sensor: Invalid role->op {0}->{1} from {2}", roleName, opName, sensorTag);
                }

                try
                {
                    //Write to the stream
                    WriteToStream(sensorTag, sensorData);
                }
                catch (Exception exp)
                {
                    logger.Log("Sensor:{0}: WriteToStream failed. Exception caught.");
                    logger.Log(exp.ToString());
                }
            }

            //Create local list of alerts for display
            message = String.Format("{0}\t{1}\t{2}", DateTime.Now, sensorTag, sensorData);
            this.receivedMessageList.Enqueue(message);
            if (this.receivedMessageList.Count > gNumStringstoShow)
                this.receivedMessageList.Dequeue();
            logger.Log("Sensor\t{0}", message);

            //if applicable write the information to a local file.
            if (this.writingToLocalFile)
                WriteToLocalFile(message);

            //record latest data in our monitoring dictionary
            if (monitorDataValues.ContainsKey(sensorTag))
            {
                (monitorDataValues[sensorTag]).UpdateDataVal(sensorData);
            }
            else
            {
                monitorDataValues.Add(sensorTag, new MonitorDataVal(sensorData));
            }
        }
Ejemplo n.º 17
0
 public abstract void PortDeregistered(VPort port);
Ejemplo n.º 18
0
 public override void PortRegistered(VPort port)
 {
     _contract.PortRegistered(PortAdapter.V2C(port));
 }
Ejemplo n.º 19
0
 public override int InstallCapability(VCapability capability, VPort targetPort)
 {
     return _contract.InstallCapability(CapabilityAdapter.V2C(capability), PortAdapter.V2C(targetPort));
 }
Ejemplo n.º 20
0
 /// <summary>
 /// Invoke an operation exported by the port
 /// </summary>
 /// <param name="roleName">The name of the role that contains the operation</param>
 /// <param name="opName">The name of the operation being subscribed to</param>
 /// <param name="parameters">The list of parameters to call the operation with</param>
 /// <param name="fromPort">The port from which subscription is being issued (usually the ControlPort of the calling module) </param>
 /// <param name="reqCap">The capability for the port to which subscription is being issued</param>
 /// <param name="respCap">The capability that the notifications should use</param>
 /// <returns>The list of return values</returns>
 public abstract IList<VParamType> Invoke(string roleName, string opName, IList<VParamType> parameters, 
                                               VPort fromPort, VCapability reqCap, VCapability respCap);
Ejemplo n.º 21
0
 /// <summary>
 /// Unsubscribe from an operation exported by this port. Somebody else cannot unsubscribe 
 /// you unless they have the same response capability that was used to create the subscription.
 /// </summary>
 /// <param name="roleName">The name of the role that contains the operation</param>
 /// <param name="opName">The name of the operation being subscribed to</param>
 /// <param name="fromPort">The port to unsubscribe</param>
 /// <param name="respCap">The response capability that was used in the subscription</param>
 /// <returns>true if the port was subscribed and is now unsubscribed,
 /// false if the port was not subscribed</returns>
 public abstract bool Unsubscribe(string roleName, string opName, VPort fromPort, VCapability respCap);
Ejemplo n.º 22
0
        private void WriteObjectImage(VPort cameraPort, Bitmap image, Rectangle rectSrc, bool center)
        {
            Rectangle rectTarget = rectSrc;
            int srcPixelShiftX = 0;
            int srcPixelShiftY = 0;

            if (rectSrc.Width == 0 && rectSrc.Height == 0)
            {
                logger.Log("Write Object Image Called with Rect with zero height and width!");
                return;
            }

            if (center)
            {
                rectTarget.X = (int)((image.Width - rectSrc.Width) / 2.0);
                rectTarget.Y = (int)((image.Height - rectSrc.Height) / 2.0);
                srcPixelShiftX = rectTarget.X - rectSrc.X;
                srcPixelShiftY = rectTarget.Y - rectSrc.Y;
            }

            // create the destination based upon layer one
            BitmapData bmpData = image.LockBits(new Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
            int stride = bmpData.Stride;
            image.UnlockBits(bmpData);

            WriteableBitmap composite = new WriteableBitmap(image.Width, image.Height, 96, 96, System.Windows.Media.PixelFormats.Rgb24, null);
            Int32Rect sourceRect = new Int32Rect(0, 0, (int)image.Width, (int)image.Height);
            byte[] pixels = new byte[stride * image.Height];

            for (int x = 0; x < image.Width; ++x)
            {
                for (int y = 0; y < image.Height; ++y)
                {
                    if (rectSrc.Contains(x, y))
                    {
                        Color clr = image.GetPixel(x, y);
                        pixels[stride * (y + srcPixelShiftY) + 3 * (x + srcPixelShiftX)] = clr.R;
                        pixels[stride * (y + srcPixelShiftY) + 3 * (x + srcPixelShiftX) + 1] = clr.G;
                        pixels[stride * (y + srcPixelShiftY) + 3 * (x + srcPixelShiftX) + 2] = clr.B;
                    }
                    else if (!rectTarget.Contains(x, y))
                    {
                        pixels[stride * y + 3 * x] = 0x00;
                        pixels[stride * y + 3 * x + 1] = 0x00;
                        pixels[stride * y + 3 * x + 2] = 0x00;
                    }
                }
            }
            composite.WritePixels(sourceRect, pixels, stride, 0);

            // encode the bitmap to the output file
            JpegBitmapEncoder encoder = new JpegBitmapEncoder();
            encoder.Frames.Add(BitmapFrame.Create(composite));
            string filepath = GetMediaFileName(cameraPort.GetInfo().GetFriendlyName(), MediaType.MediaType_Image_JPEG);

            if (null == filepath)
            {
                logger.Log("GetMediaFileName failed to get a file name, are there more than 10 files of the same name?");
                return;
            }

            using (var stream = new FileStream(filepath, FileMode.Create, FileAccess.ReadWrite, FileShare.Read))
            {
                encoder.Save(stream);
            }
        }
Ejemplo n.º 23
0
        public override void OnNotification(string roleName, string opName, IList<VParamType> retVals, VPort senderPort)
        {
            string message;
            string sensorData;
            string sensorTag = senderPort.GetInfo().GetFriendlyName() + roleName;

            lock (this)
            {
                if (roleName.Contains(RoleSensor.RoleName) && opName.Equals(RoleSensor.OpGetName))
                {
                    byte rcvdNum = (byte)(int)retVals[0].Value();
                    sensorData = rcvdNum.ToString();

                }
                else if (roleName.Contains(RoleSensorMultiLevel.RoleName) && opName.Equals(RoleSensorMultiLevel.OpGetName))
                {
                    double rcvdNum = (double)retVals[0].Value();
                    sensorData = rcvdNum.ToString();
                }
                else
                {
                    sensorData = String.Format("Sensor: Invalid role->op {0}->{1} from {2}", roleName, opName, sensorTag);
                }

                     //log to the azure sql db via azure mobile services
                    WriteToDB(sensorTag, Convert.ToSingle(sensorData));

              }

            //Create local list of alerts for display
            message = String.Format("{0}\t{1}\t{2}", DateTime.Now, sensorTag, sensorData);
            this.receivedMessageList.Enqueue(message);
            if (this.receivedMessageList.Count > gNumStringstoShow)
                this.receivedMessageList.Dequeue();
            logger.Log("Sensor\t{0}", message);

            //if applicable write the information to a local file.
            if (this.writingToLocalFile)
                WriteToLocalFile(message);

 
        }
Ejemplo n.º 24
0
        public void SendEchoRequest(VPort port, int counter)
        {
            try
            {
                DateTime requestTime = DateTime.Now;

                var retVals = Invoke(port, RoleDummy2.Instance, RoleDummy2.OpEchoName, new ParamType(counter));

                double diffMs = (DateTime.Now - requestTime).TotalMilliseconds;

                if (retVals[0].Maintype() != (int)ParamType.SimpleType.error)
                {

                    int rcvdNum = (int) retVals[0].Value();

                    logger.Log("echo success to {0} after {1} ms. sent = {2} rcvd = {3}", port.ToString(), diffMs.ToString(), counter.ToString(), rcvdNum.ToString());
                }
                else
                {
                    logger.Log("echo failure to {0} after {1} ms. sent = {2} error = {3}", port.ToString(), diffMs.ToString(), counter.ToString(), retVals[0].Value().ToString());
                }

            }
            catch (Exception e)
            {
                logger.Log("Error while calling echo request: {0}", e.ToString());
            }
        }
Ejemplo n.º 25
0
        private void AddFrameToVideo(Bitmap image, VPort cameraPort, long sampleTime)
        {
            // Lock the bitmap's bits.  
            Rectangle rect = new Rectangle(0, 0, image.Width, image.Height);
            BitmapData bmpData = image.LockBits(rect, ImageLockMode.ReadOnly, image.PixelFormat);

            // Get the address of the first line.
            IntPtr ptr = bmpData.Scan0;

            int result;

            unsafe
            {
                result = registeredCameras[cameraPort].VideoWriter.AddFrame((byte*)ptr, 3 * image.Width * image.Height, image.Width, image.Height, sampleTime);
            }

            image.UnlockBits(bmpData);

            if (result != 0)
            {
                string message = String.Format("Failed to add frame for {0}. ResultCode: {1:x}", cameraPort.GetInfo().GetFriendlyName(), ((uint)result));
                logger.Log(message);

            }
        }
Ejemplo n.º 26
0
 public PortV2C(VPort view)
 {
     _view = view;
 }
Ejemplo n.º 27
0
 public override IList<VParamType> Invoke(string roleName, string opName, IList<VParamType> parameters, VPort p, VCapability reqCap, VCapability respCap)
 {
     return CollectionAdapters.ToIList<IParamType, VParamType>(_contract.Invoke(roleName, opName,
                                                                                            CollectionAdapters.ToIListContract<VParamType, IParamType>(parameters, BaseTypeAdapter.V2C, BaseTypeAdapter.C2V),
                                                                                            PortAdapter.V2C(p),
                                                                                            CapabilityAdapter.V2C(reqCap),
                                                                                            CapabilityAdapter.V2C(respCap)),
                                                                           BaseTypeAdapter.C2V, BaseTypeAdapter.V2C);
 }
Ejemplo n.º 28
0
 public override bool Subscribe(string roleName, string opName, VPort fromPort, VCapability reqCap, VCapability respCap)
 {
     return _contract.Subscribe(roleName, opName, PortAdapter.V2C(fromPort), CapabilityAdapter.V2C(reqCap), CapabilityAdapter.V2C(respCap));
 }
 /// <summary>
 ///  Called when a new port is deregistered with the platform
 ///        the dummy driver does not care about other ports in the system
 /// </summary>
 public override void PortDeregistered(VPort port) { }
Ejemplo n.º 30
0
 ///// <summary>
 ///// Invoke an operation exported by the port
 ///// </summary>
 ///// <param name="roleName">The name of the role that contains the operation</param>
 ///// <param name="opName">The name of the operation being subscribed to</param>
 ///// <param name="parameters">The list of parameters to call the operation with</param>
 ///// <param name="fromPort">The port from which subscription is being issued (usually the ControlPort of the calling module) </param>
 ///// <param name="reqCap">The capability for the port to which subscription is being issued</param>
 ///// <param name="respCap">The capability that the notifications should use</param>
 ///// <returns>The list of return values</returns>
 //public abstract IList<object> Invoke(string roleName, string opName,
 //                                              VPort fromPort, VCapability reqCap, VCapability respCap, params object[] parameters);
 /// <summary>
 /// The function that is called when a notification is issued in response to subscriptions
 /// </summary>
 /// <param name="roleName">The name of the role for which the notification is issued</param>
 /// <param name="opName">The name of the operation for which the notification is issued</param>
 /// <param name="retVals">The list of return values that are part of the notification</param>
 /// <param name="srcPort">The port from which the notification is being sent</param>
 /// <param name="respCap">The capability that the notification was sent with</param>
 public abstract void AsyncReturn(string roleName, string opName, IList<VParamType> retVals, VPort srcPort, VCapability respCap);
Ejemplo n.º 31
0
        /// <summary>
        ///  Called when a new port is registered with the platform
        /// </summary>
        public override void PortRegistered(VPort port)
        {

            logger.Log("Sensor:{0} got registeration notification for {1}", ToString(), port.ToString());

            lock (this)
            {
                if (!accessibleSensorPorts.Contains(port) &&
                    GetCapabilityFromPlatform(port) != null &&
                    (Role.ContainsRole(port, RoleSensor.RoleName) || Role.ContainsRole(port, RoleSensorMultiLevel.RoleName)))
                {
                    accessibleSensorPorts.Add(port);

                    logger.Log("Sensor:{0} added port {1}", this.ToString(), port.ToString());

                    if (Role.ContainsRole(port, RoleSensor.RoleName))
                    {
                        if (Subscribe(port, RoleSensor.Instance, RoleSensor.OpGetName))
                            logger.Log("Sensor:{0} subscribed to sensor port {1}", this.ToString(), port.ToString());
                        else
                            logger.Log("Sensor:{0} failed to subscribe to sensor  port {1}", this.ToString(), port.ToString());
                    }

                    if (Role.ContainsRole(port, RoleSensorMultiLevel.RoleName))
                    {
                        if (Subscribe(port, RoleSensorMultiLevel.Instance, RoleSensorMultiLevel.OpGetName))
                            logger.Log("Sensor:{0} subscribed to multi-level sensor port {1}", this.ToString(), port.ToString());
                        else
                            logger.Log("Sensor: {0} failed to subscribe to multi-level port {1}", this.ToString(), port.ToString());
                    }

                }
            }
        }
Ejemplo n.º 32
0
 public sealed override void PortRegisteredWithHooks(HomeOS.Hub.Platform.Views.VPort port)
 {
     platform.UpdateState(this, new HomeOS.Hub.Common.ModuleState(ModuleState.SimpleState.EnterPortRegistered, DateTime.Now));
     PortRegistered(port);
     platform.UpdateState(this, new HomeOS.Hub.Common.ModuleState(ModuleState.SimpleState.ExitPortRegistered, DateTime.Now));
 }