HMRSSI.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using System.Xml;
  2. namespace System.Net.HomeMatic {
  3. public class HMRSSI : HMElement {
  4. //device="PEQ0470160" rx="-75" tx="-67"
  5. private HMDevice _device;
  6. private string _deviceString;
  7. private int _rx;
  8. private int _tx;
  9. /*public override bool Equals(object o) {
  10. if (o == null) return false;
  11. if (((HMRSSI)o).Device.IseID == this._device.IseID)
  12. return true;
  13. else
  14. return false;
  15. }
  16. public static bool operator ==(HMRSSI c1, HMRSSI c2) {
  17. if (c1 == null || c2 == null) return c1 == null && c2 == null;
  18. return c1.Equals(c2);
  19. }
  20. public static bool operator !=(HMRSSI c1, HMRSSI c2) {
  21. if (c1 == null || c2 == null) return (c1 != null || c2 != null);
  22. return !c1.Equals(c2);
  23. }*/
  24. public override string ToString() {
  25. return "[System.Net.HomeMatic.HMRSSI[" + this.ValuesToString() + "]]";
  26. }
  27. private string ValuesToString() {
  28. return this._device.IseID + ";" +
  29. this._deviceString + ";" +
  30. this._rx.ToString() + ";" +
  31. this._tx.ToString() + ";";
  32. }
  33. public HMRSSI(HMApi Api, HMDevice Device):base(Api) {
  34. this._device = Device;
  35. //this._deviceString = this._device;
  36. //this.Update();
  37. }
  38. public HMRSSI(HMApi Api, HMDevice Device, XmlNode Data) : base(Api) {
  39. this._device = Device;
  40. this.Init(Data);
  41. }
  42. public HMRSSI(HMApi Api, HMDevice Device, string DeviceName) : base(Api) {
  43. this._device = Device;
  44. }
  45. public HMDevice Device {
  46. get { return this._device; }
  47. }
  48. public string DeviceString {
  49. get { return this.DeviceString; }
  50. }
  51. public int RX {
  52. get {
  53. if (this.UpdateRequired())
  54. this.Update();
  55. return this._rx;
  56. }
  57. }
  58. public int TX {
  59. get {
  60. if (this.UpdateRequired())
  61. this.Update();
  62. return this._tx;
  63. }
  64. }
  65. private void Init(XmlNode Data) {
  66. this._deviceString = this.Attr_String(Data, "device");
  67. this._rx = this.Attr_Int32(Data, "rx");
  68. this._tx = this.Attr_Int32(Data, "tx");
  69. this.lastUpdate = DateTime.Now;
  70. }
  71. private DateTime lastUpdate;
  72. private bool UpdateRequired() {
  73. return DateTime.Now.Ticks - this.lastUpdate.Ticks > 10000000;
  74. }
  75. public void Update() {
  76. if (this._deviceString == "")
  77. return;
  78. XmlDocument doc = this._api.GetApiData(ApiMethode.RSSIList);
  79. XmlNodeList childs = doc.ChildNodes[1].ChildNodes;
  80. int c = childs.Count;
  81. if (c > 0) {
  82. for (int i = 0; i < c; i++) {
  83. if (childs[i].Name == "rssi") {
  84. string xname = this.Attr_String(childs[i], "device");
  85. if (xname == this._deviceString) {
  86. this.Init(childs[i]);
  87. }
  88. }
  89. }
  90. }
  91. }
  92. }
  93. }