private static bool SetNetworkDnsServers(ControlSystemConfig.NetworkProperties config) { if (config != null & config.dnsServers != null) { //Get the local DNS servers string[] localDnsServers = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_DNS_SERVER, config.adapterId).Split(','); if (localDnsServers.Length != config.dnsServers.Length) { //There's definetly a change - we'll simply override the servers DNS recods OverrideDnsServers(config, localDnsServers); return(true); } else { for (int i = 0; i < localDnsServers.Length; i++) { //If any of the records is differnet, simply override all and return true if (String.Compare(localDnsServers[i], config.dnsServers[i], true) != 0) { OverrideDnsServers(config, localDnsServers); return(true); } } } } return(false); }
public FusionAssetBase Add(CrestronControlSystem controlSystem) { uint newId = 0; for (uint id = 1; id <= 249; id++) { if (!this.Fusion.Room.Fusion.FusionRoom.UserConfigurableAssetDetails.Contains(id)) { newId = id; break; } } if (newId > 0) { this.Fusion.Room.Fusion.FusionRoom.AddAsset(eAssetType.StaticAsset, newId, controlSystem.ControllerPrompt, "Control Processor", Guid.NewGuid().ToString()); Assets[newId] = this.Fusion.Room.Fusion.FusionRoom.UserConfigurableAssetDetails[newId].Asset; ((FusionStaticAsset)Assets[newId]).AddSig(eSigType.String, 1, "IP Address", eSigIoMask.InputSigOnly); ((FusionStaticAsset)Assets[newId]).FusionGenericAssetSerialsAsset3.StringInput[1].StringValue = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, CrestronEthernetHelper.GetAdapterdIdForSpecifiedAdapterType(EthernetAdapterType.EthernetLANAdapter)); return(Assets[newId]); } return(null); }
private static bool SetNetworkIpInfo(ControlSystemConfig.NetworkProperties config) { bool reboot = false; if (config != null) { //Check to see if IP address needs to be updated if (String.Compare(config.staticIpAddress, CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_STATIC_IPADDRESS, config.adapterId)) != 0) { reboot = CrestronEthernetHelper.SetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_SET.SET_STATIC_IPADDRESS, config.adapterId, config.staticIpAddress); } //Check to see if Net mask address needs to be updated if (String.Compare(config.staticNetMask, CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_STATIC_IPMASK, config.adapterId)) != 0) { reboot = CrestronEthernetHelper.SetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_SET.SET_STATIC_IPMASK, config.adapterId, config.staticNetMask); } //Check to see if Def router needs to be updated if (String.Compare(config.staticNetMask, CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_STATIC_ROUTER, config.adapterId), true) != 0) { reboot = CrestronEthernetHelper.SetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_SET.SET_STATIC_DEFROUTER, config.adapterId, config.staticDefRouter); } } return(reboot); }
// Monitor a random relay on the server control system. // This monitor can only subscribe to one relay at a time public void Monitor(string serverHostname) { try { if (monitor != null) { CrestronConsole.ConsoleCommandResponse("Already subscribed: " + monitor + "\r\n"); return; } string myHostname = ""; // adapterID 0 usually represents the outbound LAN port myHostname = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_HOSTNAME, 0).ToLower(); monitor = new RelayMonitor(myHostname); monitor.Subscribe(serverHostname); CrestronConsole.ConsoleCommandResponse("Now monitoring: " + monitor); } catch (Exception e) { if (monitor != null) { monitor.Dispose(); monitor = null; } CrestronConsole.ConsoleCommandResponse("Could not start client: {0}\r\n", e.Message); } finally { } }
public static short GetAdapterIdForAddress(this IPAddress address) { if (address == null) { throw new ArgumentNullException("address"); } if (address.Equals(IPAddress.Broadcast) || address.Equals(IPAddress.Any) || address.Equals(IPAddress.Loopback) || address.Equals(IPAddress.None) || address.IsIPv4Multicast()) { return(-1); } var numAdapters = InitialParametersClass.NumberOfEthernetInterfaces; for (short ix = 0; ix < numAdapters; ++ix) { var addr = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, ix); var mask = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_MASK, ix); var ipAddr = IPAddress.Parse(addr); var ipMask = IPAddress.Parse(mask); if (address.IsInSameSubnet(ipAddr, ipMask)) { return(ix); } } return(CrestronEthernetHelper.GetAdapterdIdForSpecifiedAdapterType(EthernetAdapterType.EthernetLANAdapter)); }
/// <summary> /// Create a CodecSshClient /// </summary> internal CiscoSshClient(string address, int port, string username, string password) { _address = address; _port = port; _username = username; _password = password; CrestronEnvironment.ProgramStatusEventHandler += type => { _programRunning = type != eProgramStatusEventType.Stopping; if (_programRunning) { return; } _threadWait.Set(); _reconnect = false; if (!Connected) { return; } CloudLog.Info("Program stopping, Sending bye to {0} at {1}", GetType().Name, _address); Send("bye"); }; _heartbeatId = CrestronEthernetHelper.GetEthernetParameter( CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_MAC_ADDRESS, CrestronEthernetHelper.GetAdapterdIdForSpecifiedAdapterType(EthernetAdapterType.EthernetLANAdapter)); }
public override void InitializeSystem() { try { testRoku = new Roku("172.22.3.4", 8060, "Test Roku", CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, 0)); testRoku.onResponseProcessed += new EventHandler <RokuEventArgs>(testRokue_onResponseProcessed); testPanel = new Ts1542(0x03, this); if (testPanel.Register() != eDeviceRegistrationUnRegistrationResponse.Success) { ErrorLog.Notice("Error Registering Panel, Reason: {0}", testPanel.RegistrationFailureReason); } else { testPanel.LoadSmartObjects(string.Format(@"{0}\Test UI.sgd", Directory.GetApplicationDirectory())); testPanel.SigChange += new SigEventHandler(testPanel_SigChange); foreach (var so in testPanel.SmartObjects) { so.Value.SigChange += new SmartObjectSigChangeEventHandler(Value_SigChange); } } } catch (Exception e) { ErrorLog.Error("Error in InitializeSystem: {0}", e.Message); } }
private static string Post(string method, object args) { var system = new { mac_address = CrestronEthernetHelper.GetEthernetParameter( CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_MAC_ADDRESS, CrestronEthernetHelper.GetAdapterdIdForSpecifiedAdapterType(EthernetAdapterType.EthernetLANAdapter)), ip_address = CrestronEthernetHelper.GetEthernetParameter( CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, CrestronEthernetHelper.GetAdapterdIdForSpecifiedAdapterType(EthernetAdapterType.EthernetLANAdapter)), host_name = CrestronEthernetHelper.GetEthernetParameter( CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_HOSTNAME, CrestronEthernetHelper.GetAdapterdIdForSpecifiedAdapterType(EthernetAdapterType.EthernetLANAdapter)), model = InitialParametersClass.ControllerPromptName, version = InitialParametersClass.FirmwareVersion, ram_free = SystemMonitor.RAMFree * 1000 }; var app = new { index = InitialParametersClass.ApplicationNumber, name = InitialParametersClass.ProgramIDTag, version = _assembly.GetName().Version.ToString(), last_start_time = _startupTime, build_date = _programInfo["App Build Date"], programmer = _programInfo["Programmer Name"], simpl_sharp_version = _programInfo["SIMPLSharp Version"], include_4_dat_version = _programInfo["Include4.dat Version"] }; var requestObject = new { method, @params = args, project_key = _projectKey, system, app }; var request = new HttpsClientRequest { RequestType = RequestType.Post, ContentSource = ContentSource.ContentString, ContentString = JsonConvert.SerializeObject(requestObject, Formatting.Indented, new IsoDateTimeConverter()), Header = { ContentType = "application/json" }, KeepAlive = false, Url = new Crestron.SimplSharp.Net.Http.UrlParser(@"https://crestroncloudlogger.appspot.com/api") }; using (var client = new HttpsClient { IncludeHeaders = false }) { var response = client.Dispatch(request); CrestronConsole.PrintLine("Logger response: {0}", response.Code); CrestronConsole.PrintLine("Logger rx:\r\n{0}", response.ContentString); return(response.ContentString); } }
public void HostName(string Name) { if (!CheckHostName(Name)) { return; } CrestronEthernetHelper.SetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_SET.SET_HOSTNAME, AdapterId, Name); }
public void RemoveDNS_Server(string Address) { if (!CheckIP(Address)) { return; } CrestronEthernetHelper.SetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_SET.REMOVE_DNS_SERVER, AdapterId, Address); }
public void SecureWebPort(string Port) { if (!CheckCrestronPort(Port)) { return; } CrestronEthernetHelper.SetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_SET.SET_SECURE_WEB_PORT, AdapterId, Port); }
public void StaticDefaultRouter(string Address) { if (!CheckIP(Address)) { return; } CrestronEthernetHelper.SetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_SET.SET_STATIC_DEFROUTER, AdapterId, Address); }
public void StaticNetMask(string Address) { if (!CheckIP(Address)) { return; } CrestronEthernetHelper.SetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_SET.SET_STATIC_IPMASK, AdapterId, Address); }
public void DomainName(string Name) { if (!CheckDomainName(Name)) { return; } CrestronEthernetHelper.SetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_SET.SET_DOMAINNAME, AdapterId, Name); }
void CheckStatus(object o) { try { bool commsOk = false; try { //#if DEBUG CrestronConsole.PrintLine("CiscoCodec Sending Heatbeat..."); //#endif CommandArgs args = new CommandArgs(); args.Add("ID", CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_MAC_ADDRESS, CrestronEthernetHelper.GetAdapterdIdForSpecifiedAdapterType(this.FeedbackServer.AdapterForIPAddress))); XDocument response = this.SendCommand("Peripherals/HeartBeat", args); //#if DEBUG try { if (response.Element("Command").Element("PeripheralsHeartBeatResult").Attribute("status").Value == "OK") { CrestronConsole.PrintLine("HeatBeat OK"); } else { CrestronConsole.PrintLine("status = {0}", response.Element("Command").Element("PeripheralsHeartBeatResult").Attribute("status").Value); } } catch (Exception e) { ErrorLog.Exception("Error reading result from Heartbeat Send", e); } //#endif this.DeviceCommunicating = true; commsOk = true; } catch (Exception e) { ErrorLog.Error("Error checking in with CiscoCodec, {0}", e.Message); CrestronConsole.PrintLine("Error Sending CiscoCodec Heartbeat ..."); CrestronConsole.PrintLine(e.StackTrace); CrestronConsole.PrintLine("Stopping CheckStatus Timer and calling CiscoCodec.Initialize()..."); this.DeviceCommunicating = false; _CheckStatusTimer.Stop(); _CheckStatusTimer.Dispose(); this.Initialize(); } if (commsOk && !this.FeedbackServer.Registered) { ErrorLog.Warn("The CiscoCodec was not registered for feedback on CheckStatusThread. Codec could have unregistered itself due to Post errors or connectivity problems"); this.Registerfeedback(); } } catch (Exception e) { ErrorLog.Exception("Error occured in CiscoCodec.CheckStatus() timer callback", e); } }
public InfoConfig() { Name = ""; Date = DateTime.Now; Type = ""; Version = ""; Comment = ""; HostName = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_HOSTNAME, 0); AppNumber = InitialParametersClass.ApplicationNumber; RuntimeInfo = new RuntimeInfo(); }
private static bool SetNetworkDomainName(ControlSystemConfig.NetworkProperties config) { if (config != null) { if (String.Compare(config.domainName, CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_DOMAIN_NAME, config.adapterId), true) != 0) { return(CrestronEthernetHelper.SetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_SET.SET_DOMAINNAME, config.adapterId, config.hostName)); } } return(false); }
/// <summary> /// Gets either the custom URL, a local-to-processor URL, or null if it's a default logo /// </summary> public string GetUrl() { if (Type == "url") { return(Url); } if (Type == "system") { return(string.Format("http://{0}:8080/logo.png", CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, 0))); } return(null); }
public static EthernetAdapterType GetAdapterTypeForAddress(this IPAddress address) { if (address == null) { throw new ArgumentNullException("address"); } if (address.Equals(IPAddress.Broadcast) || address.Equals(IPAddress.Any) || address.Equals(IPAddress.Loopback) || address.Equals(IPAddress.None) || address.IsIPv4Multicast()) { return(EthernetAdapterType.EthernetUnknownAdapter); } return(CrestronEthernetHelper.GetAdapterTypeForSpecifiedId(address.GetAdapterIdForAddress())); }
private static void OverrideDnsServers(ControlSystemConfig.NetworkProperties config, string[] oldServers) { //Remove current servers foreach (string ds in oldServers) { CrestronEthernetHelper.SetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_SET.REMOVE_DNS_SERVER, config.adapterId, ds); } //Add new servers foreach (string ds in config.dnsServers) { CrestronEthernetHelper.SetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_SET.ADD_DNS_SERVER, config.adapterId, ds); } }
//SSMono.IO.FileSystemWatcher ListWatcher; public DevicePresetsModel(string key, ISetTopBoxNumericKeypad setTopBox, string fileName) : base(key) { PulseTime = 150; DigitSpacingMS = 150; try { // Grab the digit functions from the device // If any fail, the whole thing fails peacefully DialFunctions = new Dictionary <char, Action <bool> >(10) { { '1', setTopBox.Digit1 }, { '2', setTopBox.Digit2 }, { '3', setTopBox.Digit3 }, { '4', setTopBox.Digit4 }, { '5', setTopBox.Digit5 }, { '6', setTopBox.Digit6 }, { '7', setTopBox.Digit7 }, { '8', setTopBox.Digit8 }, { '9', setTopBox.Digit9 }, { '0', setTopBox.Digit0 }, { '-', setTopBox.Dash } }; } catch { Debug.Console(0, "DevicePresets '{0}', not attached to INumericKeypad device. Ignoring", key); DialFunctions = null; return; } EnterFunction = setTopBox.KeypadEnter; UseLocalImageStorage = true; ImagesLocalHostPrefix = "http://" + CrestronEthernetHelper.GetEthernetParameter( CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, 0); ImagesPathPrefix = @"/presets/images.zip/"; ListPathPrefix = @"/html/presets/lists/"; SetFileName(fileName); //ListWatcher = new FileSystemWatcher(@"\HTML\presets\lists"); //ListWatcher.NotifyFilter = NotifyFilters.LastWrite; //ListWatcher.EnableRaisingEvents = true; //ListWatcher.Changed += ListWatcher_Changed; InitSuccess = true; }
public TemplateEngine(Assembly assembly, string resourcePath, string title, bool loggedIn) { _templateContents = GetResourceContents(assembly, resourcePath); while (Regex.IsMatch(_templateContents, @"{% extends ([\.\w]+) %}")) { var contents = _templateContents; var block = GetResourceContents(assembly, Regex.Match(_templateContents, @"{% extends ([\.\w]+) %}").Groups[1].Value); _templateContents = Regex.Replace(block, @"{{ block_content }}", match => Regex.Replace(contents, @"{% extends ([\.\w]+) %}", string.Empty)); } _context = new Dictionary <string, object> { { "page_title", title }, { "processor_prompt", InitialParametersClass.ControllerPromptName }, { "processor_ip_address", CrestronEthernetHelper.GetEthernetParameter( CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, CrestronEthernetHelper.GetAdapterdIdForSpecifiedAdapterType( EthernetAdapterType.EthernetLANAdapter)) }, { "processor_hostname", CrestronEthernetHelper.GetEthernetParameter( CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_HOSTNAME, CrestronEthernetHelper.GetAdapterdIdForSpecifiedAdapterType( EthernetAdapterType.EthernetLANAdapter)).ToUpper() }, { "authentication_enabled", InitialParametersClass.IsAuthenticationEnabled }, { "login_logout_button_name", loggedIn ? "Logout" : "Login" }, { "login_logout_link", loggedIn ? "/logout" : "/login" } }; var domain = CrestronEthernetHelper.GetEthernetParameter( CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_DOMAIN_NAME, CrestronEthernetHelper.GetAdapterdIdForSpecifiedAdapterType( EthernetAdapterType.EthernetLANAdapter)); domain = domain.Length > 0 ? domain : "local"; _context.Add("processor_domain", domain); _context.Add("processor_fqdn", _context["processor_hostname"] + "." + domain); _context.Add("system_name", _context["processor_hostname"]); }
public void Get() { try { var roomId = 1; var host = CrestronEthernetHelper.GetEthernetParameter( CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, CrestronEthernetHelper.GetAdapterdIdForSpecifiedAdapterType( EthernetAdapterType.EthernetLANAdapter)); try { roomId = int.Parse(Request.QueryString["room"]); } catch { HandleNotFound(); return; } uint ipId = 4; try { var controllers = System.UIControllers.Where( ui => ui is RoomUIController && ui.DefaultRoom != null && ui.DefaultRoom.Id == roomId).ToArray(); if (controllers.Any()) { ipId = controllers.First().Device.ID; } Redirect(string.Format("/static/xpanel/Core3XPanel.html?host={0}&ipid={1}", host, ipId.ToString("X2"))); } catch (Exception e) { HandleError(e); } } catch (Exception e) { HandleError(e); } }
private static bool SetNetworkWebServer(ControlSystemConfig.NetworkProperties config) { if (config != null & config.webServer != null) { //Webserver is off, but should be set to on if ((bool)config.webServer & CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_WEBSERVER_STATUS, config.adapterId) == "OFF") { return(CrestronEthernetHelper.SetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_SET.SET_WEBSERVER_STATE, config.adapterId, "ON")); } //Webserver is on, but should be set to off if (!(bool)config.webServer & CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_WEBSERVER_STATUS, config.adapterId) == "ON") { return(CrestronEthernetHelper.SetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_SET.SET_WEBSERVER_STATE, config.adapterId, "OFF")); } } return(false); //We didn't change anything }
internal void Stop() { _listening = false; ConsoleConnection[] clients; lock (_connections) { clients = _connections.Values.ToArray(); } if (_listeningThread != null && _listeningThread.ThreadState == ThreadState.Running) { _listeningThread.Abort(); } foreach (var client in clients) { client.Dispose(); } if (string.IsNullOrEmpty(_csPortForwardIp)) { return; } try { Logger.Log("Attempting to remove port forwarding for Logger..."); var result = CrestronEthernetHelper.RemovePortForwarding((ushort)Port, (ushort)Port, _csPortForwardIp, CrestronEthernetHelper.ePortMapTransport.TCP); if (result == CrestronEthernetHelper.PortForwardingUserPatRetCodes.NoErr) { Logger.Log("Port forwarding removed ok!"); return; } Logger.Warn($"Could not remove port forwarding for Logger, result = {result}"); _csPortForwardIp = null; } catch (Exception e) { Logger.Error(e); } }
object systemStart(object userObject) { while (ServerIP.Length < 7) { ServerIP = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, 0); CrestronConsole.PrintLine("ServerIP: Retry Until LAN Ready: {0}", ServerIP); Thread.Sleep(1000); } if (this.SupportsIROut) { IR1.LoadIRDriver("\\USER\\Samsung UE40J5100AK.ir"); IR1.Register(); } Xpan = new Xpanel(0x03, this); Xpan.SigChange += new SigEventHandler(MyXPanSigChangeHandler); Xpan.Register(); return(null); }
private static bool SetNetworkDhcp(ControlSystemConfig.NetworkProperties config) { if (config != null) { //DHCP is currently off, but should be set to on if (config.dhcp & CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_DHCP_STATE, config.adapterId) == "OFF") { return(CrestronEthernetHelper.SetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_SET.SET_DHCP_STATE, config.adapterId, "ON")); } //DHCP is currently on, but should be set to off if (!config.dhcp & CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_DHCP_STATE, config.adapterId) == "ON") { return(CrestronEthernetHelper.SetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_SET.SET_DHCP_STATE, config.adapterId, "ON")); } } return(false); //We didn't change anything }
/// <summary> /// Read local network propertis of the control system and saves them to the config file /// </summary> private void SyncDeviceNetworkProperties() { short adapterId = CrestronEthernetHelper.GetAdapterdIdForSpecifiedAdapterType(EthernetAdapterType.EthernetLANAdapter); //Mac Address _deviceConfig.networkProperties.macAddress = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_MAC_ADDRESS, adapterId); //DHCP _deviceConfig.networkProperties.dhcp = (CrestronEthernetHelper.GetEthernetParameter( CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_DHCP_STATE, adapterId).Equals("ON", StringComparison.OrdinalIgnoreCase)) ? true : false; //Webserver status _deviceConfig.networkProperties.webServer = (CrestronEthernetHelper.GetEthernetParameter( CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_WEBSERVER_STATUS, adapterId).Equals("ON", StringComparison.OrdinalIgnoreCase)) ? true : false; //Static IP Info _deviceConfig.networkProperties.staticIpAddress = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_STATIC_IPADDRESS, adapterId); _deviceConfig.networkProperties.staticNetMask = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_STATIC_IPMASK, adapterId); _deviceConfig.networkProperties.staticDefRouter = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_STATIC_ROUTER, adapterId); //HostName _deviceConfig.networkProperties.hostName = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_HOSTNAME, adapterId); //Domain Name _deviceConfig.networkProperties.domainName = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_DOMAIN_NAME, adapterId); //DNS Servers _deviceConfig.networkProperties.dnsServers = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_DNS_SERVER, adapterId).Split(','); //DNS server comes in the following format - x.x.x.x (static/DHCP) - Since we force the data to be in ipv4, we remove the (static/DHCP) section int i; foreach (string ds in _deviceConfig.networkProperties.dnsServers) { i = ds.IndexOf('('); if (i > 0) { ds.Substring(0, i).Trim(); } } }
internal void Start(int portNumber) { Port = portNumber; if (_listeningThread != null && _listeningThread.ThreadState == ThreadState.Running) { throw new Exception("Logger already running"); } try { if (InitialParametersClass.NumberOfExternalEthernetInterfaces > 0) { Logger.Log("Control system has external ethernet interfaces, will attempt to map port to internal IP"); var id = CrestronEthernetHelper.GetAdapterdIdForSpecifiedAdapterType(EthernetAdapterType.EthernetCSAdapter); var controlSubnetIp = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, id); Logger.Log($"CS IP Address is: {controlSubnetIp}"); var result = CrestronEthernetHelper.AddPortForwarding((ushort)portNumber, (ushort)portNumber, controlSubnetIp, CrestronEthernetHelper.ePortMapTransport.TCP); if (result == CrestronEthernetHelper.PortForwardingUserPatRetCodes.NoErr) { _csPortForwardIp = controlSubnetIp; Logger.Log( $"Port Fowarding result = {result}, forwarded TCP port {portNumber} to internal IP: {controlSubnetIp}"); } else { Logger.Warn($"Could not create port forwarding for Logger, result = {result}"); } } } catch (Exception e) { Logger.Error(e); } _listeningThread = new Thread(ListenProcess) { Name = "LoggerRx" + InitialParametersClass.ApplicationNumber }; _listeningThread.Start(); Logger.Highlight($"Logger started console on port {portNumber}"); }
/// <summary> /// Method to handle the processor's ethernet adapter events. /// </summary> /// <param name="ethernetEventArgs">Information about the event being raised.</param> void CrestronEnvironment_EthernetEventHandler(EthernetEventArgs ethernetEventArgs) { // only process the main ehternet adapter's events if (ethernetEventArgs.EthernetAdapter != EthernetAdapterType.EthernetLANAdapter) { return; } // determine what type of event has been raised switch (ethernetEventArgs.EthernetEventType) { case eEthernetEventType.LinkUp: // get the processor's ip address var enetInfo = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, 0); break; case eEthernetEventType.LinkDown: default: break; } }