Completes MAXH2O-87 and MAXH2O-88. Increments driver version

This commit is contained in:
Patrick McDonagh
2018-01-16 16:53:50 -06:00
parent 4f076cae2f
commit 4a2ba7ff9d
8 changed files with 17940 additions and 17238 deletions

File diff suppressed because one or more lines are too long

View File

@@ -388,6 +388,62 @@
</div>
</div>
<div class="row row-flex">
<div class="col-md-12 text-center">
<h1>Motor Parameters</h1>
</div>
<div class="col-md-6 box-me entry-top-level" id="minvfdfrequency">
<div class="pad15">
<h2>Min Frequency</h2>
<form class="form-inline">
<div class="form-group">
<input class="form-control val_box"
type="number"
step="any"
value="<%=channels['advvfdipp.minvfdfrequency'].value %>">
</div>
<a href="#"
data-confirm-message="Are you sure you want to do this?"
data-refreshpause="1"
data-command=""
data-staticsend="{'tag': 'PowerFlex755.Cfg_MinSpdRef', 'val': <%=channels['advvfdipp.minvfdfrequency'].value %>}"
data-channelId="<%= channels["advvfdipp.writeplctag"].channelId %>"
data-techname="<%=channels["advvfdipp.writeplctag"].techName %>"
data-name="<%= channels["advvfdipp.writeplctag"].name%>"
data-nodechannelcurrentId="<%= channels["advvfdipp.writeplctag"].nodechannelcurrentId %>"
id="<%= channels["advvfdipp.writeplctag"].channelId %>"
class="btn btn-large btn-theme animated setstatic material-icons">send</a>
</form>
</div>
</div>
<div class="col-md-6 box-me entry-top-level" id="maxvfdfrequency">
<div class="pad15">
<h2>Max Frequency</h2>
<form class="form-inline">
<div class="form-group">
<input class="form-control val_box"
type="number"
step="any"
value="<%=channels['advvfdipp.maxvfdfrequency'].value %>">
</div>
<a href="#"
data-confirm-message="Are you sure you want to do this?"
data-refreshpause="1"
data-command=""
data-staticsend="{'tag': 'PowerFlex755.Cfg_MaxSpdRef', 'val': <%=channels['advvfdipp.minvfdfrequency'].value %>}"
data-channelId="<%= channels["advvfdipp.writeplctag"].channelId %>"
data-techname="<%=channels["advvfdipp.writeplctag"].techName %>"
data-name="<%= channels["advvfdipp.writeplctag"].name%>"
data-nodechannelcurrentId="<%= channels["advvfdipp.writeplctag"].nodechannelcurrentId %>"
id="<%= channels["advvfdipp.writeplctag"].channelId %>"
class="btn btn-large btn-theme animated setstatic material-icons">send</a>
</form>
</div>
</div>
</div>
<script>
$('.val_box').each(function(topLevel){

42
POCloud/HTML/Device.html Normal file
View File

@@ -0,0 +1,42 @@
<div class="row row-flex box-me">
<div class="col-md-6 text-center">
<h2 class="uppercase">Public IP Address</h2>
<p><%= channels["advvfdipp.public_ip_address"].value %><p>
</div>
</div>
<style>
.uppercase {
text-transform: uppercase;
font-size: 14px;
color: #666;
font-weight: 400;
letter-spacing: 1px;
z-index: 100;
}
.box-me {
position: relative;
padding: 0.5em;
padding-bottom: 1.5em;
border: 1px solid #eee;
/*margin: 1em 0;*/
}
.row-flex {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
flex-wrap: wrap;
}
.row-flex > [class*='col-'] {
display: flex;
flex-direction: column;
}
p {
font-size: 1.25em;
}
</style>

View File

@@ -1,9 +1,31 @@
"""Max Water System driver code."""
import threading
import sys
import logging
import time
from random import randint
from Channel import write_tag, read_tag
from device_base import deviceBase
from utilities import get_public_ip_address
import json
# LOGGING SETUP
from logging.handlers import RotatingFileHandler
log_formatter = logging.Formatter('%(asctime)s %(levelname)s %(funcName)s(%(lineno)d) %(message)s')
logFile = './advvfdipp.log'
my_handler = RotatingFileHandler(logFile, mode='a', maxBytes=500*1024, backupCount=2, encoding=None, delay=0)
my_handler.setFormatter(log_formatter)
my_handler.setLevel(logging.INFO)
logger = logging.getLogger('advvfdipp')
logger.setLevel(logging.INFO)
logger.addHandler(my_handler)
console_out = logging.StreamHandler(sys.stdout)
console_out.setFormatter(log_formatter)
logger.addHandler(console_out)
logger.info("advvfdipp startup")
PLC_IP_ADDRESS = "192.168.1.10"
WATCHDOG_SEND_PERIOD = 3600 # seconds
@@ -18,7 +40,7 @@ class start(threading.Thread, deviceBase):
deviceBase.__init__(self, name=name, number=number, mac=mac, Q=Q, mcu=mcu, companyId=companyId, offset=offset, mqtt=mqtt, Nodes=Nodes)
self.daemon = True
self.version = "7"
self.version = "8"
self.finished = threading.Event()
threading.Thread.start(self)
@@ -28,21 +50,38 @@ class start(threading.Thread, deviceBase):
def run(self):
"""Run the driver."""
wait_sec = 30
for i in range(0, wait_sec):
print("advvfdipp driver will start in {} seconds".format(wait_sec - i))
time.sleep(1)
logger.info("BOOM! Starting advvfdipp driver...")
self.nodes["advvfdipp_0199"] = self
public_ip_address = get_public_ip_address()
self.sendtodbDev(1, 'public_ip_address', public_ip_address, 0, 'advvfdipp')
watchdog = self.advvfdipp_watchdog()
self.sendtodbDev(1, 'watchdog', watchdog, 0)
self.sendtodbDev(1, 'watchdog', watchdog, 0, 'advvfdipp')
watchdog_send_timestamp = time.time()
watchdog_loops = 0
watchdog_check_after = 5000
while True:
self.nodes["advvfdipp_0199"] = self
watchdog_loops += 1
if (watchdog_loops >= watchdog_check_after):
test_watchdog = self.advvfdipp_watchdog()
if test_watchdog != watchdog or (time.time() - watchdog_send_timestamp) > WATCHDOG_SEND_PERIOD:
if not test_watchdog == watchdog or (time.time() - watchdog_send_timestamp) > WATCHDOG_SEND_PERIOD:
self.sendtodbDev(1, 'watchdog', test_watchdog, 0, 'advvfdipp')
watchdog_send_timestamp = time.time()
watchdog = test_watchdog
test_public_ip = get_public_ip_address()
if not test_public_ip == public_ip_address:
self.sendtodbDev(1, 'public_ip_address', test_public_ip, 0, 'advvfdipp')
public_ip_address = test_public_ip
watchdog_loops = 0
time.sleep(15)
def advvfdipp_watchdog(self):
"""Write a random integer to the PLC and then 1 seconds later check that it has been decremented by 1."""
@@ -54,3 +93,24 @@ class start(threading.Thread, deviceBase):
return (randval - 1) == watchdog_val[0]
except (KeyError, TypeError):
return False
def advvfdipp_sync(self, name, value):
"""Sync all data from the driver."""
self.forceSend = True
# self.sendtodb("log", "synced", 0)
return True
def advvfdipp_writeplctag(self, name, value):
"""Write a value to the PLC."""
try:
new_val = json.loads(str(value).replace("'", '"'))
tag_n = str(new_val['tag']) # "cmd_Start"
val_n = new_val['val']
w = write_tag(str(PLC_IP_ADDRESS), tag_n, val_n)
logger.warning("Result of advvfdipp_writeplctag(self, {}, {}) = {}".format(name, value, w))
if w is None:
w = "Error writing to PLC..."
return w
except Exception as e:
logger.warning("GOT EXCEPTION in advvfdipp_writeplctag(self, {}, {}) => {}".format(name, value, e))
return e

View File

@@ -1,12 +1,12 @@
{
"driverFileName":"advvfdipp.py",
"deviceName":"advvfdipp",
"driverId":"0100",
"releaseVersion":"7",
"files": {
"file1":"advvfdipp.py",
"file2":"modbusMap.p",
"file3":"Channel.py" }
"files": {
"file3": "Channel.py",
"file2": "utilities.py",
"file1": "advvfdipp.py",
"file4": "modbusMap.p"
},
"deviceName": "advvfdipp",
"driverId": "0100",
"releaseVersion": "8",
"driverFileName": "advvfdipp.py"
}

12
POCloud/driverConfig.json Normal file
View File

@@ -0,0 +1,12 @@
{
"name": "advvfdipp",
"driverFilename": "advvfdipp.py",
"driverId": "0100",
"additionalDriverFiles": [
"utilities.py",
"Channel.py",
"modbusMap.p"
],
"version": 8,
"s3BucketName": "advvfdipp"
}

File diff suppressed because it is too large Load Diff

54
POCloud/utilities.py Normal file
View File

@@ -0,0 +1,54 @@
"""Utility functions for the driver."""
import socket
import struct
def get_public_ip_address():
"""Find the public IP Address of the host device."""
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
ip = s.getsockname()[0]
s.close()
return ip
def int_to_float16(int_to_convert):
"""Convert integer into float16 representation."""
bin_rep = ('0' * 16 + '{0:b}'.format(int_to_convert))[-16:]
sign = 1.0
if int(bin_rep[0]) == 1:
sign = -1.0
exponent = float(int(bin_rep[1:6], 2))
if exponent == 30:
fraction = float(int("1" + bin_rep[7:17], 2))
else:
fraction = float(int(bin_rep[7:17], 2))
if exponent == float(0b00000):
return sign * 2 ** -14 * fraction / (2.0 ** 10.0)
elif exponent == float(0b11111):
if fraction == 0:
return sign * float("inf")
else:
return float("NaN")
else:
frac_part = 1.0 + fraction / (2.0 ** 10.0)
return sign * (2 ** (exponent - 15)) * frac_part
def ints_to_float(int1, int2):
"""Convert 2 registers into a floating point number."""
mypack = struct.pack('>HH', int1, int2)
f = struct.unpack('>f', mypack)
print("[{}, {}] >> {}".format(int1, int2, f[0]))
return f[0]
def degf_to_degc(temp_f):
"""Convert deg F to deg C."""
return (temp_f - 32.0) * (5.0/9.0)
def degc_to_degf(temp_c):
"""Convert deg C to deg F."""
return temp_c * 1.8 + 32.0