Skip to content

Commit e58d6be

Browse files
committed
UPS_Device and WinNUT data polling cleanup
- Reorganized some lines in UPS_Device - Made Socket object access private, WinNUT now gets connection status from UPS_Device only. - Began implementation of max load calculation algorithm - Relocated static UPS device info display logic out of variable update function and into UPS initialization function. - Also cleaned up some unused code in WinNUT.vb.
1 parent 86b3d2e commit e58d6be

File tree

2 files changed

+27
-47
lines changed

2 files changed

+27
-47
lines changed

WinNUT_V2/WinNUT-Client/WinNUT.vb

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -300,12 +300,12 @@ Public Class WinNUT
300300
Dim upsConf = nutUps.Nut_Config
301301
LogFile.LogTracing(upsConf.UPSName & " has indicated it's ready to start sending data.", LogLvl.LOG_DEBUG, Me)
302302

303-
' Setup and begin polling data from UPS.
304-
' Polling_Interval = Arr_Reg_Key.Item("Delay")
305-
'With Update_Data
306-
' .Interval = Polling_Interval
307-
' ' .Enabled = True
308-
'End With
303+
With UPS_Device.UPS_Datas
304+
Lbl_VMfr.Text = .Mfr
305+
Lbl_VName.Text = .Model
306+
Lbl_VSerial.Text = .Serial
307+
Lbl_VFirmware.Text = .Firmware
308+
End With
309309

310310
Menu_UPS_Var.Enabled = True
311311
UpdateIcon_NotifyIcon()
@@ -542,7 +542,7 @@ Public Class WinNUT
542542
Dim Status As String = "Unknown"
543543
Select Case Reason
544544
Case Nothing, "Deconnected", "Lost Connect"
545-
If (UPS_Device IsNot Nothing) AndAlso Not UPS_Device.Nut_Socket.IsConnected Then
545+
If (UPS_Device IsNot Nothing) AndAlso Not UPS_Device.IsConnected Then
546546
PBox_Battery_State.Image = Nothing
547547
End If
548548
Status = "Unknown"
@@ -620,15 +620,7 @@ Public Class WinNUT
620620

621621
Private Sub Update_UPS_Data() Handles UPS_Device.DataUpdated
622622
LogFile.LogTracing("Updating UPS data for Form.", LogLvl.LOG_DEBUG, Me)
623-
With UPS_Device.UPS_Datas
624-
If Lbl_VMfr.Text = "" And Lbl_VName.Text = "" And Lbl_VSerial.Text = "" And Lbl_VFirmware.Text = "" Then
625-
LogFile.LogTracing("Retrieve UPS Informations", LogLvl.LOG_DEBUG, Me)
626-
Lbl_VMfr.Text = .Mfr
627-
Lbl_VName.Text = .Model
628-
Lbl_VSerial.Text = .Serial
629-
Lbl_VFirmware.Text = .Firmware
630-
End If
631-
End With
623+
632624
With UPS_Device.UPS_Datas.UPS_Value
633625
UPS_BattCh = .Batt_Charge
634626
UPS_BattV = .Batt_Voltage
@@ -638,7 +630,6 @@ Public Class WinNUT
638630
UPS_InputV = .Input_Voltage
639631
UPS_OutputV = .Output_Voltage
640632
UPS_Load = .Load
641-
'Me.UPS_Status = Me.Device_Data
642633
UPS_Status = "OL"
643634
UPS_OutPower = .Output_Power
644635

@@ -669,25 +660,6 @@ Public Class WinNUT
669660
Else
670661
Lbl_VOLoad.BackColor = Color.White
671662
End If
672-
'If Me.UPS_Status <> Nothing Then
673-
'If Me.UPS_Status.Trim().StartsWith("OL") Or StrReverse(Me.UPS_Status.Trim()).StartsWith("LO") Then
674-
' LogFile.LogTracing("UPS is plugged", LogLvl.LOG_DEBUG, Me)
675-
' Lbl_VOL.BackColor = Color.Green
676-
' Lbl_VOB.BackColor = Color.White
677-
' ActualAppIconIdx = AppIconIdx.IDX_OL
678-
'Else
679-
' LogFile.LogTracing("UPS is unplugged", LogLvl.LOG_DEBUG, Me)
680-
' Lbl_VOL.BackColor = Color.Yellow
681-
' Lbl_VOB.BackColor = Color.Green
682-
' ActualAppIconIdx = 0
683-
'End If
684-
685-
'If Me.UPS_Load > 100 Then
686-
' LogFile.LogTracing("UPS Overload", LogLvl.LOG_ERROR, Me)
687-
' Lbl_VOLoad.BackColor = Color.Red
688-
' Else
689-
' Lbl_VOLoad.BackColor = Color.White
690-
' End If
691663

692664
LogFile.LogTracing("Updating battery icons based on charge percent: " & UPS_BattCh & "%", LogLvl.LOG_DEBUG, Me)
693665

WinNUT_V2/WinNUT-Client_Common/UPS_Device.vb

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,17 @@ Public Class UPS_Device
6464
End Set
6565
End Property
6666

67+
Private _MaxLoad As Integer
68+
69+
Public ReadOnly Property MaxLoad As Integer
70+
Get
71+
Return _MaxLoad
72+
End Get
73+
End Property
74+
6775
#End Region
6876

6977
#Region "Events"
70-
71-
' Public Event Unknown_UPS()
7278
Public Event DataUpdated()
7379
Public Event Connected(sender As UPS_Device)
7480
Public Event ReConnected(sender As UPS_Device)
@@ -79,8 +85,6 @@ Public Class UPS_Device
7985
' Error encountered when trying to connect.
8086
Public Event ConnectionError(sender As UPS_Device, innerException As Exception)
8187
Public Event New_Retry()
82-
' Public Event Shutdown_Condition()
83-
' Public Event Stop_Shutdown()
8488

8589
''' <summary>
8690
''' Raised when the NUT server returns an error during normal communication and is deemed important for the client
@@ -90,6 +94,12 @@ Public Class UPS_Device
9094
''' <param name="nutEx">An exception detailing the error and cirucmstances surrounding it.</param>
9195
Public Event EncounteredNUTException(sender As UPS_Device, nutEx As NutException)
9296

97+
''' <summary>
98+
''' Raise an event when a status code is added to the UPS that wasn't there before.
99+
''' </summary>
100+
''' <param name="newStatuses">The bitmask of status flags that are currently set on the UPS.</param>
101+
Public Event StatusesChanged(sender As UPS_Device, newStatuses As UPS_States)
102+
93103
#End Region
94104

95105
Private Const CosPhi As Double = 0.6
@@ -107,7 +117,7 @@ Public Class UPS_Device
107117
' Public UPSData As New UPSData
108118

109119

110-
Public WithEvents Nut_Socket As Nut_Socket
120+
Private WithEvents Nut_Socket As Nut_Socket
111121

112122
Public Retry As Integer = 0
113123
Public MaxRetry As Integer = 30
@@ -118,12 +128,6 @@ Public Class UPS_Device
118128

119129
Private LogFile As Logger
120130

121-
''' <summary>
122-
''' Raise an event when a status code is added to the UPS that wasn't there before.
123-
''' </summary>
124-
''' <param name="newStatuses">The bitmask of status flags that are currently set on the UPS.</param>
125-
Public Event StatusesChanged(sender As UPS_Device, newStatuses As UPS_States)
126-
127131
Public Sub New(ByRef Nut_Config As Nut_Parameter, ByRef LogFile As Logger, pollInterval As Integer)
128132
Me.LogFile = LogFile
129133
Me.Nut_Config = Nut_Config
@@ -236,6 +240,10 @@ Public Class UPS_Device
236240
Return freshData
237241
End Function
238242

243+
Private Function FindMaxLoad() As Integer
244+
245+
End Function
246+
239247
Private oldStatusBitmask As Integer
240248

241249
Public Sub Retrieve_UPS_Datas() Handles Update_Data.Tick ' As UPSData

0 commit comments

Comments
 (0)