/// <summary> /// Delete the device in HomeSeer. Clear the set INI settings. Delete the thread. /// </summary> /// <param name="refIdStr">The device reference identifier (as string) for HomeSeer.</param> /// <returns><c>true</c> if device was found and deleted, <c>false</c> otherwise.</returns> public bool DeleteDevice(string refIdStr) { int refId; bool success = true; // delete the device from HomeSeer if (!Int32.TryParse(refIdStr, out refId)) { success = false; } else { Scheduler.Classes.DeviceClass hsDevice = (Scheduler.Classes.DeviceClass)hs.GetDeviceByRef(refId); if ((hsDevice == null) || (!hs.DeleteDevice(refId))) { success = false; } } // delete the info from the INI file hs.ClearINISection("Camera" + refIdStr, INI_File); // delete the thread HikAlarmThreadManager.DeleteDevice(refId); return(success); }
/// <summary> /// Creates a device from the configuration information. Save the information in the INI file. /// </summary> /// <param name="name">The name for the device.</param> /// <param name="ipAddress">The ip address for the device.</param> /// <param name="username">The username for the device.</param> /// <param name="password">The password for the device.</param> /// <returns>The device reference identifier from HomeSeer.</returns> public int CreateDeviceFromConfig(string name, string ipAddress, string username, string password) { Console.WriteLine("Name: {0}", name); Console.WriteLine("IpAddress: {0}", ipAddress); Console.WriteLine("Username: {0}", username); Console.WriteLine("Password: {0}", password); // create the device in HomeSeer int refId; Scheduler.Classes.DeviceClass hsDevice = CreateDevice(out refId, name); if (hsDevice == null) { return(-1); } // save the settings hs.SaveINISetting("Camera" + refId, "IpAddress", ipAddress, INI_File); hs.SaveINISetting("Camera" + refId, "Username", username, INI_File); hs.SaveINISetting("Camera" + refId, "Password", password, INI_File); // start a new thread HikAlarmThreadManager.AddDevice(this, refId, ipAddress, username, password); return(refId); }
/// <summary> /// Updates the device parameters in the INI file. It is necessary to restart the thread for the new values to take effect. /// </summary> /// <param name="refIdStr">The device reference identifier (as string) for HomeSeer.</param> /// <param name="ipAddress">The ip address.</param> /// <param name="username">The username.</param> /// <param name="password">The password.</param> /// <returns><c>true</c> if the update was successful, <c>false</c> otherwise.</returns> public bool UpdateDevice(string refIdStr, string ipAddress, string username, string password) { int refId; if (!Int32.TryParse(refIdStr, out refId)) { return(false); } Scheduler.Classes.DeviceClass hsDevice = (Scheduler.Classes.DeviceClass)hs.GetDeviceByRef(refId); if (hsDevice == null) { return(false); } // save the settings hs.SaveINISetting("Camera" + refIdStr, "IpAddress", ipAddress, INI_File); hs.SaveINISetting("Camera" + refIdStr, "Username", username, INI_File); if (password != "") { hs.SaveINISetting("Camera" + refIdStr, "Password", password, INI_File); } HikAlarmThreadManager.DeleteDevice(refId); HikAlarmThreadManager.AddDevice(this, refId, ipAddress, username, password); return(true); }
public Scheduler.Classes.DeviceClass getHSRootDevice() { // Don't cache hsDevice directly - but we cache HS refId. // We can invalidate root dev by setting hsRootDevRefId to 0 if (hsRootDevRefId == 0) { var hsDev = getHSDevice(EnOceanDeviceType.Controller, this.getPortName()); if (hsDev != null) { hsRootDevRefId = hsDev.get_Ref(null); return(hsDev); } Console.WriteLine(" No EnOcean controller HS device - creating."); var newDev = createHSDevice("EnOcean controller: " + getPortName(), EnOceanDeviceType.Controller, getPortName()); newDev.set_Device_Type_String(HS, "EnOcean Controller"); // newDev.MISC_Set(HS, Enums.dvMISC.NO_LOG); newDev.MISC_Set(HS, Enums.dvMISC.SHOW_VALUES); HS.SaveEventsDevices(); return(newDev); } Scheduler.Classes.DeviceClass rootDev = (Scheduler.Classes.DeviceClass)HS.GetDeviceByRef(hsRootDevRefId); return(rootDev); }
public SiidDevice(InstanceHolder I, Scheduler.Classes.DeviceClass Dev) { this.Instance = I; this.Ref = Dev.get_Ref(Instance.host); this.Device = Dev; this.Extra = Dev.get_PlugExtraData_Get(Instance.host); }
/// <summary> /// Name of the HomeSeer device. /// </summary> /// <param name="refId">The device reference identifier for HomeSeer.</param> public string DeviceName(int refId) { string name = "RefId_" + refId.ToString(); Scheduler.Classes.DeviceClass hsDevice = (Scheduler.Classes.DeviceClass)hs.GetDeviceByRef(refId); if (hsDevice != null) { name = hsDevice.get_Name(hs); } return(name); }
public string MakeNewRule() { var dv = Instance.host.NewDeviceRef("R"); Scheduler.Classes.DeviceClass newDevice = (Scheduler.Classes.DeviceClass)Instance.host.GetDeviceByRef(dv); newDevice.set_InterfaceInstance(Instance.host, Instance.name); newDevice.set_Name(Instance.host, "Type Meter Calc " + dv); //newDevice.set_Location2(Instance.host, "ScratchpadRule"); newDevice.set_Location(Instance.host, "Utilities"); newDevice.set_Location2(Instance.host, "Calcs"); //newDevice.set_Interface(Instance.host, "Modbus Configuration");//Put here the registered name of the page for what we want in the Modbus tab!!! So easy! newDevice.set_Interface(Instance.host, Util.IFACE_NAME); //Needed to link device to plugin, so the tab calls back to the correct hardcoded homeseer function //newDevice.set_InterfaceInstance()'' SET INTERFACE INSTANCE newDevice.set_Relationship(Instance.host, Enums.eRelationship.Not_Set); newDevice.MISC_Set(Instance.host, Enums.dvMISC.NO_LOG); newDevice.MISC_Set(Instance.host, Enums.dvMISC.SHOW_VALUES); // newDevice.MISC_Set(Instance.host, Enums.dvMISC.HIDDEN); HomeSeerAPI.PlugExtraData.clsPlugExtraData EDO = new PlugExtraData.clsPlugExtraData(); // EDO = newDevice.get_PlugExtraData_Get(Instance.host); string ruleString = makeNewRules(); string userNote = newDevice.get_UserNote(Instance.host); userNote = userNote.Split("PLUGIN EXTRA DATA:".ToCharArray())[0]; userNote += "PLUGIN EXTRA DATA:" + ruleString.ToString(); newDevice.set_UserNote(Instance.host, userNote); EDO.AddNamed("SSIDKey", ruleString); newDevice.set_PlugExtraData_Set(Instance.host, EDO); // newDevice.set_Device_Type_String(Instance.host, makeNewModbusGateway()); var DevINFO = new DeviceTypeInfo_m.DeviceTypeInfo(); DevINFO.Device_API = DeviceTypeInfo_m.DeviceTypeInfo.eDeviceAPI.Plug_In; newDevice.set_DeviceType_Set(Instance.host, DevINFO); Instance.Devices.Add(new SiidDevice(Instance, newDevice)); MakeStewardVSP(dv); return("refresh"); }
public void Initialize() { Dictionary <int, Scheduler.Classes.DeviceClass> device_map = new Dictionary <int, Scheduler.Classes.DeviceClass>(); Dictionary <int, bool> processed = new Dictionary <int, bool>(); Scheduler.Classes.clsDeviceEnumeration devenum = HS.GetDeviceEnumerator() as Scheduler.Classes.clsDeviceEnumeration; while (!devenum.Finished) { Scheduler.Classes.DeviceClass dev = devenum.GetNext(); if (dev.get_Interface(null) != Constants.PLUGIN_STRING_NAME) { continue; // Not ours! } var extraData = dev.get_PlugExtraData_Get(HS); if (extraData == null) { extraData = new PlugExtraData.clsPlugExtraData(); } var typeStr = (string)extraData.GetNamed("EnOcean Type"); if (typeStr == null) { continue; // No type - continue } if (typeStr != "Controller") { continue; // Not a controller } var dataStr = (string)extraData.GetNamed("EnOcean Cfg"); if (dataStr == null) { Console.WriteLine("No json data on device - skipping"); // extraData.AddNamed("EnOcean Cfg", config.ToString()); // rootDev.set_PlugExtraData_Set(HS, extraData); continue; // Skip interface } else { var config = JObject.Parse(dataStr); Console.WriteLine("Loaded config: {0}", config.ToString()); var ctrlInstance = new EnOceanController(HS, HSCB, hspiInst, config); ctrlInstance.Initialize(); AddInterface(ctrlInstance); } } }
protected void GetHSDevice() { hsDevice = Controller.getHSDevice(EnOceanController.EnOceanDeviceType.SimpleDevice, DeviceId); if (hsDevice == null) { if (deviceConfig["node_name"] == null) { deviceConfig["node_name"] = DeviceId; } hsDevice = Controller.createHSDevice((string)deviceConfig["node_name"], EnOceanController.EnOceanDeviceType.SimpleDevice, DeviceId); hsDevice.set_Device_Type_String(HS, "EnOcean " + EnOceanController.EnOceanDeviceType.SimpleDevice.ToString()); hsDevice.set_Relationship(HS, Enums.eRelationship.Parent_Root); // hsDevice.MISC_Set(HS, Enums.dvMISC.NO_LOG); hsDevice.MISC_Set(HS, Enums.dvMISC.SHOW_VALUES); AddOrUpdateHSDeviceProperties(); SaveConfiguration(); } }
/// <summary> /// Create a new device and set the names for the status display. /// </summary> /// <param name="refId">The device reference identifier for HomeSeer.</param> /// <param name="name">The name for the device.</param> /// <returns>Scheduler.Classes.DeviceClass.</returns> private Scheduler.Classes.DeviceClass CreateDevice(out int refId, string name = "HikVision Camera") { Scheduler.Classes.DeviceClass dv = null; refId = hs.NewDeviceRef(name); if (refId > 0) { dv = (Scheduler.Classes.DeviceClass)hs.GetDeviceByRef(refId); dv.set_Address(hs, "Camera" + refId); dv.set_Device_Type_String(hs, "HikVision Camera Alarm"); DeviceTypeInfo_m.DeviceTypeInfo DT = new DeviceTypeInfo_m.DeviceTypeInfo(); DT.Device_API = DeviceTypeInfo_m.DeviceTypeInfo.eDeviceAPI.Security; DT.Device_Type = (int)DeviceTypeInfo_m.DeviceTypeInfo.eDeviceType_Security.Zone_Interior; dv.set_DeviceType_Set(hs, DT); dv.set_Interface(hs, IFACE_NAME); dv.set_InterfaceInstance(hs, ""); dv.set_Last_Change(hs, DateTime.Now); dv.set_Location(hs, "Camera"); // room dv.set_Location2(hs, "HikVision"); // floor VSVGPairs.VSPair Pair = new VSVGPairs.VSPair(HomeSeerAPI.ePairStatusControl.Status); Pair.PairType = VSVGPairs.VSVGPairType.SingleValue; Pair.Value = -1; Pair.Status = "Unknown"; Default_VS_Pairs_AddUpdateUtil(refId, Pair); Pair = new VSVGPairs.VSPair(HomeSeerAPI.ePairStatusControl.Status); Pair.PairType = VSVGPairs.VSVGPairType.SingleValue; Pair.Value = 0; Pair.Status = "No Motion"; Default_VS_Pairs_AddUpdateUtil(refId, Pair); Pair = new VSVGPairs.VSPair(HomeSeerAPI.ePairStatusControl.Status); Pair.PairType = VSVGPairs.VSVGPairType.SingleValue; Pair.Value = 1; Pair.Status = "Motion"; Default_VS_Pairs_AddUpdateUtil(refId, Pair); dv.MISC_Set(hs, Enums.dvMISC.STATUS_ONLY); dv.MISC_Set(hs, Enums.dvMISC.SHOW_VALUES); dv.set_Status_Support(hs, true); } return(dv); }
public string ConfigDevice(int dvRef, string user, int userRights, bool newDevice) { //OK, I think if we do a switch here based on Device Type String, this will work. For Modbus I'm setting the string to "Modbus". //Of course the user can change this string and mess this up so we'll see Scheduler.Classes.DeviceClass ourDevice = (Scheduler.Classes.DeviceClass)Instance.host.GetDeviceByRef(dvRef); var EDO = ourDevice.get_PlugExtraData_Get(Instance.host); var parts = HttpUtility.ParseQueryString(EDO.GetNamed("SSIDKey").ToString()); switch (parts["Type"]) { case ("Modbus Gateway"): { return(Instance.modPage.BuildModbusGatewayTab(dvRef)); } case ("Modbus Device"): { return(Instance.modPage.BuildModbusDeviceTab(dvRef)); } case ("BACnet Device"): case ("BACnet Object"): { return(Instance.bacnetDevices.BuildBACnetDeviceTab(dvRef)); } case ("Scratchpad"): //???? { return(Instance.scrPage.BuildScratchDeviceTab(dvRef)); } } return("ERROR"); }
public Scheduler.Classes.DeviceClass getHSDevice(EnOceanDeviceType type, string id = "") { Scheduler.Classes.clsDeviceEnumeration devenum = HS.GetDeviceEnumerator() as Scheduler.Classes.clsDeviceEnumeration; while (!devenum.Finished) { Scheduler.Classes.DeviceClass dev = devenum.GetNext(); if (dev.get_Interface(null) != Constants.PLUGIN_STRING_NAME) { continue; // Not ours! } if (dev.get_Device_Type_String(null) == "EnOcean " + type.ToString()) { string hsAddr = dev.get_Address(null); //FIXME: Should probably not use address but a plugin value! if (id == hsAddr) { return(dev); } } } return(null); }
/// <summary> /// Initialize the plugin and associated hardware/software, start any threads /// </summary> /// <param name="port">The COM port for the plugin if required.</param> /// <returns>Warning message or empty for success.</returns> public override string InitIO(string port) { // initialize everything here, return a blank string only if successful, or an error message try { Scheduler.Classes.clsDeviceEnumeration EN = (Scheduler.Classes.clsDeviceEnumeration)hs.GetDeviceEnumerator(); if (EN == null) { throw new Exception(IFACE_NAME + " failed to get a device enumerator from HomeSeer."); } do { Scheduler.Classes.DeviceClass dv = EN.GetNext(); if ((dv != null) && (dv.get_Interface(hs) != null) && (dv.get_Interface(hs).Trim() == IFACE_NAME)) { //Console.WriteLine("Found device: refId = {0}", dv.get_Ref(hs)); int refId = dv.get_Ref(hs); string ipAddress = hs.GetINISetting("Camera" + refId, "IpAddress", "", INI_File); string username = hs.GetINISetting("Camera" + refId, "Username", "", INI_File); string password = hs.GetINISetting("Camera" + refId, "Password", "", INI_File); Console.WriteLine("Camera: RefId: {0}, IpAddress: {1}, Username: {2}, Password: {3}", refId, ipAddress, username, password); HikAlarmThreadManager.AddDevice(this, refId, ipAddress, username, password); } } while (!EN.Finished); } catch (Exception ex) { hs.WriteLog(IFACE_NAME + " Error", "Exception in Find_Create_Devices/Enumerator: " + ex.Message); } // Create and register the web pages - only need one for configuration configPage = new HikAlarmConfig(this); RegisterWebPage(configPage.Name); return(""); }
void LoadChildDevices() { Scheduler.Classes.clsDeviceEnumeration devenum = HS.GetDeviceEnumerator() as Scheduler.Classes.clsDeviceEnumeration; while (!devenum.Finished) { Scheduler.Classes.DeviceClass hsDev = devenum.GetNext(); if (hsDev.get_Interface(null) != Constants.PLUGIN_STRING_NAME) { continue; // Not ours! } var extraData = hsDev.get_PlugExtraData_Get(HS); if (extraData == null) { extraData = new PlugExtraData.clsPlugExtraData(); } var typeStr = (string)extraData.GetNamed("EnOcean Type"); // if (typeStr == null) // Console.WriteLine("Warning: No device type set on child device"); var dataStr = (string)extraData.GetNamed("EnOcean Cfg"); var childConfig = new JObject(); if (dataStr != null) { childConfig = JObject.Parse(dataStr); } if (hsDev.get_Address(null).StartsWith(ControllerId)) { // Console.WriteLine("DT : {0} vs {1}", hsDev.get_Device_Type_String(null), EnOceanDeviceType.SimpleDevice.ToString()); if (hsDev.get_Device_Type_String(null) != "EnOcean " + EnOceanDeviceType.SimpleDevice.ToString()) { continue; } DeviceTypes.CreateDeviceInstance(HS, this, hsDev.get_Address(null), (string)childConfig["device_type"], childConfig); Console.WriteLine("Found child device: {0}", hsDev.get_Address(null)); } } }
public void GenericDeviceStuff(SiidDevice SiidDev) { Scheduler.Classes.DeviceClass Device = SiidDev.Device; Values["ID"] = SiidDev.Ref; Values["Name"] = Device.get_Name(Instance.host); Values["Floor"] = Device.get_Location2(Instance.host); Values["Room"] = Device.get_Location(Instance.host); Values["code"] = Device.get_Code(Instance.host); Values["address"] = Device.get_Address(Instance.host); Values["statusOnly"] = Device.get_Status_Support(Instance.host); Values["CanDim"] = Device.get_Can_Dim(Instance.host); Values["doNotLog"] = Instance.host.DeviceNoLog(SiidDev.Ref); // voiceC=AllInstances[InstanceFriendlyName].host.DeviceProperty_Boolean(DeviceID", HomeSeerAPI.Enums.eDeviceProperty.Prop; // includeInPower=AllInstances[InstanceFriendlyName].host.; // usePopUp=Device.use; //doNotUp = HomeSeerAPI.Enums.eCapabilities; Values["userAccess"] = Device.get_UserAccess(Instance.host); Values["notes"] = Device.get_UserNote(Instance.host); var DeviceType = Device.get_DeviceType_Get(Instance.host); Values["DeviceType"] = DeviceType.Device_API.ToString() + "?" + DeviceType.Device_API_Description.ToString() + "?" + DeviceType.Device_SubType.ToString() + "?" + DeviceType.Device_SubType_Description.ToString() + "?" + DeviceType.Device_Type.ToString() + "?" + DeviceType.Device_Type_Description.ToString(); Values["deviceTypeString"] = Device.get_Device_Type_String(Instance.host); Values["RelationshipStatus"] = Device.get_Relationship(Instance.host); Values["associatedDevicesList"] = Device.get_AssociatedDevices_List(Instance.host); HomeSeerAPI.VSVGPairs.VSPair[] AllStatus = Instance.host.DeviceVSP_GetAllStatus(SiidDev.Ref); Values["vsp"] = EncodeVSPairs(AllStatus); Values["vgp"] = EncodeVGPairs(AllStatus, SiidDev.Ref); // Values["vgp"] =; // Values["associatedDevices"]=Device.get_AssociatedDevices(Instance.host); }
public Boolean Initialize() { Dictionary<int, Scheduler.Classes.DeviceClass> device_map = new Dictionary<int, Scheduler.Classes.DeviceClass>(); // Dictionary<int, JObject> json_map = new Dictionary<int, JObject>(); Dictionary<int, bool> processed = new Dictionary<int, bool>(); //config = new JObject(); rootDev = getHSRootDevice(); var extraData = rootDev.get_PlugExtraData_Get(HS); if (extraData == null) extraData = new PlugExtraData.clsPlugExtraData(); var typeStr = (string)extraData.GetNamed("EnOcean Type"); if (typeStr == null) { Console.WriteLine("No type on device - adding"); extraData.AddNamed("EnOcean Type", "Controller"); rootDev.set_PlugExtraData_Set(HS, extraData); } if (config["nodes"] == null) { config.Add("nodes", new JObject()); } setControllerStatus("Initializing ctrl instance on port " + getPortName()); controller = new EnOceanFrameLayer(); if (controller.Open(getPortName())) { controller.PacketEventHandler += controller_PacketEvent; setControllerStatus("Active"); } else { setControllerStatus("Port open error!"); // GetHSDeviceByAddress(0x1234abcd); return false; } var p = EnOceanPacket.MakePacket_CO_RD_VERSION(); controller.Send(p, (EnOceanPacket recvPacket) => { if (recvPacket.getType() != PacketType.RESPONSE) return false; var br = new BinaryReader(new MemoryStream(recvPacket.GetData())); Console.WriteLine("Ret Code = {0}", br.ReadByte()); Console.WriteLine("App Version {0}", br.ReadUInt32()); Console.WriteLine("API Version {0}", br.ReadUInt32()); var uniqueControllerId = br.ReadUInt32().ToString("x8"); this.UniqueControllerId = uniqueControllerId; Console.WriteLine("Chip ID {0}", uniqueControllerId); Console.WriteLine("Chip Version {0}", br.ReadUInt32()); var d = Encoding.UTF8.GetString(br.ReadBytes(16), 0, 16); Console.WriteLine("APP NAME: {0}", d); //TODO: Parse app description return true; }); int timeout = 30; while (timeout-- > 0 && this.UniqueControllerId == "Unknown") { Console.WriteLine("Waiting for controller id!"); Thread.Sleep(100); } // GetHSDeviceByAddress(0x1234abcd); if (UniqueControllerId == "Unknown") { Console.WriteLine("USB Device did not respond!"); setControllerStatus("Initialization error!"); return false; } LoadChildDevices(); return true; }
public Boolean Initialize() { Dictionary <int, Scheduler.Classes.DeviceClass> device_map = new Dictionary <int, Scheduler.Classes.DeviceClass>(); // Dictionary<int, JObject> json_map = new Dictionary<int, JObject>(); Dictionary <int, bool> processed = new Dictionary <int, bool>(); //config = new JObject(); rootDev = getHSRootDevice(); var extraData = rootDev.get_PlugExtraData_Get(HS); if (extraData == null) { extraData = new PlugExtraData.clsPlugExtraData(); } var typeStr = (string)extraData.GetNamed("EnOcean Type"); if (typeStr == null) { Console.WriteLine("No type on device - adding"); extraData.AddNamed("EnOcean Type", "Controller"); rootDev.set_PlugExtraData_Set(HS, extraData); } if (config["nodes"] == null) { config.Add("nodes", new JObject()); } setControllerStatus("Initializing ctrl instance on port " + getPortName()); controller = new EnOceanFrameLayer(); if (controller.Open(getPortName())) { controller.PacketEventHandler += controller_PacketEvent; setControllerStatus("Active"); } else { setControllerStatus("Port open error!"); // GetHSDeviceByAddress(0x1234abcd); return(false); } var p = EnOceanPacket.MakePacket_CO_RD_VERSION(); controller.Send(p, (EnOceanPacket recvPacket) => { if (recvPacket.getType() != PacketType.RESPONSE) { return(false); } var br = new BinaryReader(new MemoryStream(recvPacket.GetData())); Console.WriteLine("Ret Code = {0}", br.ReadByte()); Console.WriteLine("App Version {0}", br.ReadUInt32()); Console.WriteLine("API Version {0}", br.ReadUInt32()); var uniqueControllerId = br.ReadUInt32().ToString("x8"); this.UniqueControllerId = uniqueControllerId; Console.WriteLine("Chip ID {0}", uniqueControllerId); Console.WriteLine("Chip Version {0}", br.ReadUInt32()); var d = Encoding.UTF8.GetString(br.ReadBytes(16), 0, 16); Console.WriteLine("APP NAME: {0}", d); //TODO: Parse app description return(true); }); int timeout = 30; while (timeout-- > 0 && this.UniqueControllerId == "Unknown") { Console.WriteLine("Waiting for controller id!"); Thread.Sleep(100); } // GetHSDeviceByAddress(0x1234abcd); if (UniqueControllerId == "Unknown") { Console.WriteLine("USB Device did not respond!"); setControllerStatus("Initialization error!"); return(false); } LoadChildDevices(); return(true); }
public SIIDDevice(SiidDevice SiidDev, InstanceHolder instance) : base(SiidDev, instance) { Instance = instance; Scheduler.Classes.DeviceClass Device = SiidDev.Device; var EDO = SiidDev.Extra; System.Collections.Specialized.NameValueCollection parts = HttpUtility.ParseQueryString(EDO.GetNamed("SSIDKey").ToString()); //Need to grab the key order from somewhere string[] Orderlist = null; switch (parts["Type"]) { case ("Modbus Gateway"): { Orderlist = ModbusMaster.Attributes; break; } case ("Modbus Device"): { Orderlist = ModbusDevice.Attributes; break; } case ("BACnet Device"): case ("BACnet Object"): { //Need to export everything that we would need in order to import. All of bacnetNodeData, essentially. //To this end, maybe it would be easiest to also store device-level stuff in object nodes - i.e. device IP address Orderlist = BACnetObject.Attributes; System.Collections.Specialized.NameValueCollection bacnetNodeData = BACnetDevices.ParseJsonString(parts["BACnetNodeData"]); // HttpUtility.ParseQueryString(parts["BACnetNodeData"]); foreach (var Ent in Orderlist) { listOfAttributes.Add(Ent); switch (Ent) { case "Type": Values[Ent] = parts[Ent]; break; case "NetworkIPAddress": Values[Ent] = bacnetNodeData["ip_address"]; break; case "DeviceIPAddress": Values[Ent] = bacnetNodeData["device_ip_address"]; break; case "DeviceUDPPort": Values[Ent] = bacnetNodeData["device_udp_port"]; break; case "DeviceInstance": Values[Ent] = bacnetNodeData["device_instance"]; break; case "ObjectType": Values[Ent] = bacnetNodeData["object_type_string"]; break; case "ObjectInstance": Values[Ent] = bacnetNodeData["object_instance"]; break; case "ObjectName": Values[Ent] = bacnetNodeData["object_name"]; break; case "PollInterval": Values[Ent] = bacnetNodeData["polling_interval"]; break; case "RawValue": case "ProcessedValue": Values[Ent] = parts[Ent]; break; } } return; //Orderlist = BACnetDevice.Attributes; //break; } case ("Scratchpad"): { Orderlist = ScratchpadDevice.Attributes; break; } } foreach (var Ent in Orderlist) { Values[Ent] = parts[Ent]; listOfAttributes.Add(Ent); } }
public bool ProcessCommand(EnOceanPacket packet, Scheduler.Classes.DeviceClass hsDev) { Console.WriteLine("Processing command : {0}", packet.getType().ToString()); return(true); }
protected void GetHSDevice() { hsDevice = Controller.getHSDevice(EnOceanController.EnOceanDeviceType.SimpleDevice, DeviceId); if (hsDevice == null) { if (deviceConfig["node_name"] == null) deviceConfig["node_name"] = DeviceId; hsDevice = Controller.createHSDevice((string)deviceConfig["node_name"], EnOceanController.EnOceanDeviceType.SimpleDevice, DeviceId); hsDevice.set_Device_Type_String(HS, "EnOcean " + EnOceanController.EnOceanDeviceType.SimpleDevice.ToString()); hsDevice.set_Relationship(HS, Enums.eRelationship.Parent_Root); // hsDevice.MISC_Set(HS, Enums.dvMISC.NO_LOG); hsDevice.MISC_Set(HS, Enums.dvMISC.SHOW_VALUES); AddOrUpdateHSDeviceProperties(); SaveConfiguration(); } }
public static string GetValues(InstanceHolder Instance, string ScratchPadString) { ScratchPadString = ScratchPadString.Replace("(^p^)", "+"); List <int> Raws = new List <int>(); List <int> Processed = new List <int>(); Match m = Regex.Match(ScratchPadString, @"(\$\()+(\d+)(\))+"); while (m.Success) { if (!Raws.Contains(int.Parse(m.Groups[2].ToString()))) { Raws.Add(int.Parse(m.Groups[2].ToString())); } m = m.NextMatch(); } m = Regex.Match(ScratchPadString, @"(\#\()+(\d+)(\))+"); while (m.Success) { if (!Processed.Contains(int.Parse(m.Groups[2].ToString()))) { Processed.Add(int.Parse(m.Groups[2].ToString())); } m = m.NextMatch(); } StringBuilder FinalString = new StringBuilder(ScratchPadString); foreach (int dv in Raws) { SiidDevice TempDev = SiidDevice.GetFromListByID(Instance.Devices, dv); if (TempDev == null) { try { Scheduler.Classes.DeviceClass newDevice = (Scheduler.Classes.DeviceClass)Instance.host.GetDeviceByRef(dv); //If the device exists and is a SIID device, adds it into the list var E = newDevice.get_PlugExtraData_Get(Instance.host); if (E.GetNamed("SSIDKey") != null) { TempDev = new SiidDevice(Instance, newDevice); Instance.Devices.Add(TempDev); } } catch { //Device reference either incorrect or not a SIID device. } } if (TempDev != null) { //OK the extradata store in the SIID device list is outdated. grab from the device... //var TempEDO = TempDev.Extra; var TempEDO = TempDev.Device.get_PlugExtraData_Get(Instance.host); var Tempparts = HttpUtility.ParseQueryString(TempEDO.GetNamed("SSIDKey").ToString()); try { Double results = 0; Double.TryParse(Tempparts["RawValue"], out results); string Rep = results.ToString("0.#####################################################################################################################################################################################################################################################################################################################################"); if (Rep == null) { throw new Exception(); } FinalString.Replace("$(" + dv + ")", Rep); } catch { try { string Rep = Instance.host.DeviceValueEx(dv).ToString("0.#####################################################################################################################################################################################################################################################################################################################################"); //Problem, device values return as int if (Rep == null) { throw new Exception(); } FinalString.Replace("$(" + dv + ")", Rep); } catch { } } } else //Not an SIID device, use the device value { try { string Rep = Instance.host.DeviceValueEx(dv).ToString(); //Fails for BACnet devices because the status does not reflect the displayed value if (Rep == null) { throw new Exception(); } Double results = 0; Double.TryParse(Rep, out results); Rep = results.ToString("0.#####################################################################################################################################################################################################################################################################################################################################"); FinalString.Replace("$(" + dv + ")", Rep); } catch (Exception E) { Instance.hspi.Log("Error parsing scratchpad string: Could not retrive device value for device: " + dv, 2); } } } foreach (int dv in Processed) { SiidDevice TempDev = SiidDevice.GetFromListByID(Instance.Devices, dv);// (Scheduler.Classes.DeviceClass)Instance.host.GetDeviceByRef(dv); if (TempDev != null) { var TempEDO = TempDev.Extra; var Tempparts = HttpUtility.ParseQueryString(TempEDO.GetNamed("SSIDKey").ToString()); try { string Rep = Tempparts["ProcessedValue"]; if (Rep == null) { throw new Exception(); } FinalString.Replace("#(" + dv + ")", Rep); } catch { try { string Rep = Instance.host.DeviceValueEx(dv).ToString(); if (Rep == null) { throw new Exception(); } FinalString.Replace("#(" + dv + ")", Rep); } catch { } } } else { try { string Rep = Instance.host.DeviceValueEx(dv).ToString(); if (Rep != null) { FinalString.Replace("#(" + dv + ")", Rep); } } catch { } } } return(FinalString.ToString()); }
public string addSubrule(string data) { //Make a new rule, but make it in service to an existing rule: var dv = Instance.host.NewDeviceRef("R"); Scheduler.Classes.DeviceClass newDevice = (Scheduler.Classes.DeviceClass)Instance.host.GetDeviceByRef(dv); newDevice.set_InterfaceInstance(Instance.host, Instance.name); newDevice.set_Name(Instance.host, "Type Meter Rate" + dv); // newDevice.set_Location2(Instance.host, "ScratchpadSubRule"); newDevice.set_Location(Instance.host, "Utilities"); newDevice.set_Location2(Instance.host, "Rates"); //newDevice.set_Interface(Instance.host, "Modbus Configuration");//Put here the registered name of the page for what we want in the Modbus tab!!! So easy! newDevice.set_Interface(Instance.host, Util.IFACE_NAME); //Needed to link device to plugin, so the tab calls back to the correct hardcoded homeseer function //newDevice.set_InterfaceInstance()'' SET INTERFACE INSTANCE newDevice.set_Relationship(Instance.host, Enums.eRelationship.Not_Set); newDevice.MISC_Set(Instance.host, Enums.dvMISC.NO_LOG); newDevice.MISC_Set(Instance.host, Enums.dvMISC.SHOW_VALUES); // newDevice.MISC_Set(Instance.host, Enums.dvMISC.HIDDEN); HomeSeerAPI.PlugExtraData.clsPlugExtraData EDO = new PlugExtraData.clsPlugExtraData(); // EDO = newDevice.get_PlugExtraData_Get(Instance.host); string ruleString = makeNewRules(); string userNote = newDevice.get_UserNote(Instance.host); userNote = userNote.Split("PLUGIN EXTRA DATA:".ToCharArray())[0]; userNote += "PLUGIN EXTRA DATA:" + ruleString.ToString(); newDevice.set_UserNote(Instance.host, userNote); EDO.AddNamed("SSIDKey", ruleString); newDevice.set_PlugExtraData_Set(Instance.host, EDO); // newDevice.set_Device_Type_String(Instance.host, makeNewModbusGateway()); var DevINFO = new DeviceTypeInfo_m.DeviceTypeInfo(); DevINFO.Device_API = DeviceTypeInfo_m.DeviceTypeInfo.eDeviceAPI.Plug_In; newDevice.set_DeviceType_Set(Instance.host, DevINFO); Instance.Devices.Add(new SiidDevice(Instance, newDevice)); MakeStewardVSP(dv); StringBuilder stb = new StringBuilder(); var page = this; string GatewayID = data.Split("_".ToCharArray())[1]; SiidDevice GateWay = SiidDevice.GetFromListByID(Instance.Devices, Convert.ToInt32(GatewayID)); Scheduler.Classes.DeviceClass Gateway = GateWay.Device; //Should keep in gateway a list of devices Gateway.AssociatedDevice_Add(Instance.host, dv); //This is totally working actually return("refresh"); stb.Append("<meta http-equiv=\"refresh\" content = \"0; URL='/deviceutility?ref=" + dv + "&edit=1'\" />"); // stb.Append("<a id = 'LALA' href='/deviceutility?ref=" + dv + "&edit=1'/><script>LALA.click()</script> "); page.AddBody(stb.ToString()); return(page.BuildPage()); }