// FormatCollection: convert the Relay collection to a string
            // representing the 'items' property of the Collection+JSON response
            public string FormatCollection(CrestronCollection <Relay> collec, string collecUrl)
            {
                JArray items = new JArray();

                foreach (Relay r in collec)
                {
                    JObject item = new JObject();
                    item["href"] = collecUrl + "/" + r.ID;

                    JObject ID = new JObject();
                    ID["name"]  = "ID";
                    ID["value"] = r.ID;

                    JObject State = new JObject();
                    State["name"]  = "State";
                    State["value"] = (r.State) ? "Closed" : "Open";

                    JArray data = new JArray();
                    data.Add(ID);
                    data.Add(State);

                    item["data"] = data;

                    items.Add(item);
                }

                return(JsonConvert.SerializeObject(items));
            }
Exemplo n.º 2
0
 public static Relays8Card GetRelay8Card(CrestronCollection <Relay> Relays)
 {
     if (Relays.Count != 8)
     {
         return(null);
     }
     return(_Relay8Card ?? (_Relay8Card = new Relays8Card(Relays)));
 }
 public static IOs8AnalogInputCard GetIO8AnalogInputCard(CrestronCollection <Versiport> Versiports)
 {
     if (Versiports.Count != 8)
     {
         return(null);
     }
     return(_IO8AnalogInputCard ?? (_IO8AnalogInputCard = new IOs8AnalogInputCard(Versiports)));
 }
 public static DigitalInputs2Card GetSlot2DigitalInputs(CrestronCollection <DigitalInput> DigitalInputs)
 {
     if (DigitalInputs.Count != 2)
     {
         return(null);
     }
     return(_Slot2DigitalInputs ?? (_Slot2DigitalInputs = new DigitalInputs2Card(DigitalInputs)));
 }
Exemplo n.º 5
0
 private Relays2Card(CrestronCollection <Relay> Relays)
 {
     if (Relays.Count != 2)
     {
         return;
     }
     _Relays = Relays;
     CreateRelays();
     SubscribeRelayChanged();
 }
 private IOs8AnalogInputCard(CrestronCollection <Versiport> Versiports)
 {
     _Versiports = Versiports;
     CreateIOPorts();
     SubscribeInDigitalOutChanged();
     SubscribeInPUDisableChanged();
     SubscribeInDigitalInChanged();
     SubscribeInMinChangeChanged();
     SubscribeInAnalogInChanged();
 }
        public IRPortController(ControlSystem cs)
        {
            myIRPorts = cs.IROutputPorts;

            if (cs.ControllerIROutputSlot.Register() != eDeviceRegistrationUnRegistrationResponse.Success)
            {
                ErrorLog.Error("Error Registering IR Slot {0}", cs.ControllerIROutputSlot.DeviceRegistrationFailureReason);
            }
            else
            {
                LoadIRDrivers();
            }
        }
        public ComPortController(ControlSystem cs)
        {
            myComPorts = cs.ComPorts;

            for (uint i = 1; i <= 2; i++)
            {
                myComPorts[i].SerialDataReceived += new ComPortDataReceivedEvent(ControlSystem_SerialDataReceived);
                if (myComPorts[i].Register() != eDeviceRegistrationUnRegistrationResponse.Success)
                {
                    ErrorLog.Error("Error registering comport {0}", myComPorts[i].DeviceRegistrationFailureReason);
                }
                else
                {
                    myComPorts[i].SetComPortSpec(ComPort.eComBaudRates.ComspecBaudRate19200,
                                                 ComPort.eComDataBits.ComspecDataBits8,
                                                 ComPort.eComParityType.ComspecParityNone,
                                                 ComPort.eComStopBits.ComspecStopBits1,
                                                 ComPort.eComProtocolType.ComspecProtocolRS232,
                                                 ComPort.eComHardwareHandshakeType.ComspecHardwareHandshakeNone,
                                                 ComPort.eComSoftwareHandshakeType.ComspecSoftwareHandshakeNone,
                                                 false);
                }
            }
        }
Exemplo n.º 9
0
        private void TestAvSwitch()
        {
            string rawConfig = JsonHelper.ReadJsonData(@"\NVRAM\SystemConfig.json");
            SystemConfiguration configData = JsonHelper.ParseConfigJson(rawConfig);

            AvSwitchController avSwitch = new AvSwitchController(configData.AvSwitcher, this);

            if (avSwitch.Initialize())
            {
                CrestronConsole.PrintLine("avSwitch successfully initialized.");
                avSwitch.DeviceOnlineStatusEvent      += new EventHandler <SspCertificationTest.Utilities.GenericEventArgs <bool> >(avSwitch_DeviceOnlineStatusEvent);
                avSwitch.AudioOutputSourceChangeEvent += new EventHandler <SspCertificationTest.Utilities.GenericEventArgs <uint, uint> >(avSwitch_AudioOutputSourceChangeEvent);
                avSwitch.VideoOutputSourceChangeEvent += new EventHandler <SspCertificationTest.Utilities.GenericEventArgs <uint, uint> >(avSwitch_VideoOutputSourceChangeEvent);
                avSwitch.InputVideoSyncEvent          += new EventHandler <SspCertificationTest.Utilities.GenericEventArgs <uint, bool> >(avSwitch_InputVideoSyncEvent);

                CrestronConsole.PrintLine("Result of build:");
                CrestronConsole.PrintLine("Switch type: {0}", avSwitch.SwitchType);
                CrestronConsole.PrintLine("Number of inputs: {0}", avSwitch.NumInputs);
                CrestronConsole.PrintLine("Number of outputs: {0}", avSwitch.NumOutputs);
                CrestronConsole.PrintLine("Online status: {0}", avSwitch.Online);
                CrestronConsole.PrintLine("GUID: {0}", avSwitch.GUID);

                CrestronCollection <ComPort> rmcCom = avSwitch.GetEndpointComports(1);
                CrestronConsole.PrintLine("Output 1 com ports:");
                foreach (var c in rmcCom)
                {
                    CrestronConsole.PrintLine("\tIs registered: {0}", c.Registered);
                    CrestronConsole.PrintLine("\tBaud: {0}", c.BaudRate);
                    CrestronConsole.PrintLine("\tProtocol: {0}", c.Protocol);
                }

                CrestronConsole.PrintLine(string.Empty);
                avSwitch.Route(1, 1);
                CrestronConsole.PrintLine("result of route(): out {0} -- A{1} V{2}", avSwitch.GetCurrentAudioRoute(1), avSwitch.GetCurrentAudioRoute(1));
            }
        }
Exemplo n.º 10
0
 private Relays8Card(CrestronCollection <Relay> Relays)
 {
     _Relays = Relays;
     CreateRelays();
     SubscribeRelayChanged();
 }
        public RestfulRelayServer(CrestronCollection <Relay> relay_collection, string hostname)
        {
            try
            {
                _numberOfRelays = relay_collection.Count;
                _relays         = relay_collection;
                _root           = "http://" + hostname;
                notifier        = new HttpClient();

                // To ensure that the template.json file appears in the control system's application directory,
                // set "Build Action" to "Content" and "Copy to Output Directory" to "Copy always" in the file's Properties menu
                _cjTemplate = File.ReadToEnd(Directory.GetApplicationDirectory() + "\\template.json", Encoding.UTF8);

                // set up subscription lists for the Relay collection and for each Relay
                sublists = new List <Dictionary <string, Subscription> >(NumberOfRelays + 1); // Both the collection and each relay gets its own subscription dictionary
                for (int i = 0; i < NumberOfRelays + 1; i++)
                {
                    sublists.Add(new Dictionary <string, Subscription>()); // client will use a GuID to locate the subscription resource if it wants to DELETE it.
                }

                // start up the server
                server = new HttpCwsServer("/api");

                /*
                 * URL Routing table:
                 *  /relays
                 *  /relays/web-hooks
                 *  /relays/web-hooks/{subid}
                 *  /relays/{id}
                 *  /relays/{id}/web-hooks
                 *  /relays/{id}/web-hooks/{subid}
                 */

                // subscribe to events
                server.ReceivedRequestEvent += new HttpCwsRequestEventHandler(server_ReceivedRequestEvent);
                server.HttpRequestHandler    = new DefaultHandler(this); // This is the default handler. It will process unrouted requests.
                foreach (Relay r in relay_collection)
                {
                    r.StateChange += new RelayEventHandler(r_StateChange);
                }

                // Add each route to server's routing table: In this example, each route is
                // associated with its own RouteHandler class, which will process the HTTP request and write its response.
                // Other designs might use a single route handler that interprets the full requested path and performs the
                // route handling in this handler's ProcessRequest method

                // The order in which you add the routes matters. The HttpCwsServer will search in this order for a route matching
                // the requested URL, stopping at the first match it finds and calling the corresponding handler's
                // ProcessRequest method, or that of the HttpRequestHandler (called "DefaultHandler" in this example)
                // if no route-specific handler exists.
                HttpCwsRoute route = new HttpCwsRoute("relays")
                {
                    Name = "relay_collection"
                };                                                                             // do not include the leading '/' in the HttpCwsRoute constructor
                route.RouteHandler = new RelaysHandler(this);
                server.Routes.Add(route);

                route = new HttpCwsRoute("relays/web-hooks")
                {
                    Name = "relay_collection_subscriptions"
                };
                route.RouteHandler = new RelaysWebhooksHandler(this);
                server.Routes.Add(route);

                route = new HttpCwsRoute("relays/web-hooks/{subid}")
                {
                    Name = "relay_collection_subscription"
                };
                route.RouteHandler = new RelaysWebhooksSubidHandler(this);
                server.Routes.Add(route);

                route = new HttpCwsRoute("relays/{id}")
                {
                    Name = "individual_relay"
                };
                route.RouteHandler = new RelaysIdHandler(this);
                server.Routes.Add(route);

                route = new HttpCwsRoute("relays/{id}/web-hooks")
                {
                    Name = "individual_relay_subscriptions"
                };
                route.RouteHandler = new RelaysIdWebhooksHandler(this);
                server.Routes.Add(route);

                route = new HttpCwsRoute("relays/{id}/web-hooks/{subid}")
                {
                    Name = "individual_relay_subscription"
                };
                route.RouteHandler = new RelaysIdWebhooksSubidHandler(this);
                server.Routes.Add(route);

                // Start receiving HTTP requests
                server.Register();
            }
            catch (Exception e)
            {
                CrestronConsole.PrintLine("Error in the RestfulRelayServer constructor: " + e.Message);
            }
            finally
            {
            }
        }
 private DigitalInputs2Card(CrestronCollection <DigitalInput> DigitalInputs)
 {
     _CrestronDigitalInputPorts = DigitalInputs;
     CreateDigitalInputPorts();
     SubscribeDigitalInputPortStateChanged();
 }
Exemplo n.º 13
0
 static public void LoadIRDrivers(CrestronCollection <IROutputPort> myIRPorts)
 {
     // IROutputPorts[1].LoadIRDriver(String.Format(@"{0}\IR\AppleTV.ir", Directory.GetApplicationDirectory()));
     myIRPorts[1].LoadIRDriver(@"\NVRAM\AppleTV.ir");
 }