Adds device IP address to channels
This commit is contained in:
53
python-driver/abbflow.py
Normal file
53
python-driver/abbflow.py
Normal file
@@ -0,0 +1,53 @@
|
||||
"""Driver for connecting ABB Flowmeter to Meshify."""
|
||||
import threading
|
||||
import time
|
||||
from device_base import deviceBase
|
||||
from utilities import get_public_ip_address
|
||||
|
||||
WAIT_FOR_CONNECTION_SECONDS = 60
|
||||
IP_CHECK_PERIOD = 60
|
||||
|
||||
class start(threading.Thread, deviceBase):
|
||||
"""Start class required for driver."""
|
||||
|
||||
def __init__(self, name=None, number=None, mac=None, Q=None, mcu=None,
|
||||
companyId=None, offset=None, mqtt=None, Nodes=None):
|
||||
"""Initalize the driver."""
|
||||
threading.Thread.__init__(self)
|
||||
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 = "8"
|
||||
self.finished = threading.Event()
|
||||
self.public_ip_address = ""
|
||||
self.public_ip_address_last_checked = 0
|
||||
threading.Thread.start(self)
|
||||
|
||||
# this is a required function for all drivers
|
||||
# its goal is to upload some piece of data
|
||||
# about your device so it can be seen on the web
|
||||
def register(self):
|
||||
"""Register the driver."""
|
||||
self.channels["status"]["last_value"] = ""
|
||||
|
||||
def run(self):
|
||||
"""Run the driver."""
|
||||
for i in range(0, WAIT_FOR_CONNECTION_SECONDS):
|
||||
print("abbflow driver will start in {} seconds".format(WAIT_FOR_CONNECTION_SECONDS - i))
|
||||
time.sleep(1)
|
||||
|
||||
while True:
|
||||
if (time.time() - self.public_ip_address_last_checked) > IP_CHECK_PERIOD:
|
||||
self._check_ip_address()
|
||||
|
||||
def _check_ip_address(self):
|
||||
"""Check the public IP address and send to Meshify if changed."""
|
||||
print("Checking IP Address...")
|
||||
self.public_ip_address_last_checked = time.time()
|
||||
test_public_ip = get_public_ip_address()
|
||||
print("Got {} for IP Address".format(test_public_ip))
|
||||
if not test_public_ip == self.public_ip_address:
|
||||
self.sendtodbDev(1, 'public_ip_address', test_public_ip, 0, 'abbflow')
|
||||
self.public_ip_address = test_public_ip
|
||||
11
python-driver/config.txt
Normal file
11
python-driver/config.txt
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
|
||||
"driverFileName":"abbflow.py",
|
||||
"deviceName":"abbflow",
|
||||
"driverId":"0110",
|
||||
"releaseVersion":"8",
|
||||
"files": {
|
||||
"file1":"abbflow.py",
|
||||
"file2":"modbusMap.p" }
|
||||
|
||||
}
|
||||
11
python-driver/driverConfig.json
Normal file
11
python-driver/driverConfig.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "abbflow",
|
||||
"driverFilename": "abbflow.py",
|
||||
"driverId": "0110",
|
||||
"additionalDriverFiles": [
|
||||
"utilities.py",
|
||||
"modbusMap.p"
|
||||
],
|
||||
"version": 8,
|
||||
"s3BucketName": "abbflow"
|
||||
}
|
||||
893
python-driver/modbusMap.p
Normal file
893
python-driver/modbusMap.p
Normal file
@@ -0,0 +1,893 @@
|
||||
(dp0
|
||||
S'1'
|
||||
p1
|
||||
(dp2
|
||||
S'c'
|
||||
p3
|
||||
VM1-232
|
||||
p4
|
||||
sS'b'
|
||||
p5
|
||||
V9600
|
||||
p6
|
||||
sS'addresses'
|
||||
p7
|
||||
(dp8
|
||||
V1
|
||||
p9
|
||||
(dp10
|
||||
V2-2
|
||||
p11
|
||||
(dp12
|
||||
Vah
|
||||
p13
|
||||
V
|
||||
p14
|
||||
sVbytary
|
||||
p15
|
||||
NsVal
|
||||
p16
|
||||
g14
|
||||
sVvn
|
||||
p17
|
||||
VVolume Flow
|
||||
p18
|
||||
sVct
|
||||
p19
|
||||
Vnumber
|
||||
p20
|
||||
sVle
|
||||
p21
|
||||
V32
|
||||
p22
|
||||
sVgrp
|
||||
p23
|
||||
V3600
|
||||
p24
|
||||
sVla
|
||||
p25
|
||||
F1301.77
|
||||
sVchn
|
||||
p26
|
||||
Vvolume_flow
|
||||
p27
|
||||
sVun
|
||||
p28
|
||||
V1
|
||||
p29
|
||||
sVdn
|
||||
p30
|
||||
Vabbflow
|
||||
p31
|
||||
sVda
|
||||
p32
|
||||
g29
|
||||
sVlrt
|
||||
p33
|
||||
F1502726350.0681692
|
||||
sVa
|
||||
p34
|
||||
V4003
|
||||
p35
|
||||
sVc
|
||||
p36
|
||||
V20.0
|
||||
p37
|
||||
sVmisc_u
|
||||
p38
|
||||
VMCF/Day
|
||||
p39
|
||||
sVf
|
||||
p40
|
||||
V4
|
||||
p41
|
||||
sVmrt
|
||||
p42
|
||||
V60
|
||||
p43
|
||||
sVm
|
||||
p44
|
||||
Vnone
|
||||
p45
|
||||
sVm1ch
|
||||
p46
|
||||
g11
|
||||
sVmv
|
||||
p47
|
||||
V0
|
||||
p48
|
||||
sVs
|
||||
p49
|
||||
VOn
|
||||
p50
|
||||
sVr
|
||||
p51
|
||||
V0-5000
|
||||
p52
|
||||
sVt
|
||||
p53
|
||||
Vfloat
|
||||
p54
|
||||
sVvm
|
||||
p55
|
||||
NssV2-3
|
||||
p56
|
||||
(dp57
|
||||
Vah
|
||||
p58
|
||||
g14
|
||||
sVbytary
|
||||
p59
|
||||
NsVal
|
||||
p60
|
||||
g48
|
||||
sVvn
|
||||
p61
|
||||
VToday Volume
|
||||
p62
|
||||
sVct
|
||||
p63
|
||||
Vnumber
|
||||
p64
|
||||
sVle
|
||||
p65
|
||||
V32
|
||||
p66
|
||||
sVgrp
|
||||
p67
|
||||
V3600
|
||||
p68
|
||||
sVla
|
||||
p69
|
||||
F214.742
|
||||
sVchn
|
||||
p70
|
||||
Vtoday_volume
|
||||
p71
|
||||
sVun
|
||||
p72
|
||||
g29
|
||||
sVdn
|
||||
p73
|
||||
Vabbflow
|
||||
p74
|
||||
sVda
|
||||
p75
|
||||
g29
|
||||
sVlrt
|
||||
p76
|
||||
F1502726379.1855019
|
||||
sg51
|
||||
V0-1000
|
||||
p77
|
||||
sg34
|
||||
V4005
|
||||
p78
|
||||
sg36
|
||||
V10.0
|
||||
p79
|
||||
sVmisc_u
|
||||
p80
|
||||
VMCF
|
||||
p81
|
||||
sg40
|
||||
g41
|
||||
sVmrt
|
||||
p82
|
||||
V60
|
||||
p83
|
||||
sg44
|
||||
Vnone
|
||||
p84
|
||||
sVm1ch
|
||||
p85
|
||||
g56
|
||||
sg49
|
||||
VOn
|
||||
p86
|
||||
sVmv
|
||||
p87
|
||||
g48
|
||||
sg53
|
||||
Vfloat
|
||||
p88
|
||||
sVvm
|
||||
p89
|
||||
NssV2-1
|
||||
p90
|
||||
(dp91
|
||||
Vah
|
||||
p92
|
||||
g14
|
||||
sVbytary
|
||||
p93
|
||||
NsVal
|
||||
p94
|
||||
g14
|
||||
sVvn
|
||||
p95
|
||||
VBattery Voltage
|
||||
p96
|
||||
sVct
|
||||
p97
|
||||
Vnumber
|
||||
p98
|
||||
sVle
|
||||
p99
|
||||
V32
|
||||
p100
|
||||
sVgrp
|
||||
p101
|
||||
V3600
|
||||
p102
|
||||
sVla
|
||||
p103
|
||||
F12.477
|
||||
sVchn
|
||||
p104
|
||||
Vbattery_voltage
|
||||
p105
|
||||
sg51
|
||||
V0-50
|
||||
p106
|
||||
sVdn
|
||||
p107
|
||||
Vabbflow
|
||||
p108
|
||||
sVda
|
||||
p109
|
||||
g29
|
||||
sVlrt
|
||||
p110
|
||||
F1502725891.0710198
|
||||
sg34
|
||||
V4001
|
||||
p111
|
||||
sg36
|
||||
V5
|
||||
p112
|
||||
sVmisc_u
|
||||
p113
|
||||
VV
|
||||
p114
|
||||
sg40
|
||||
g41
|
||||
sVmrt
|
||||
p115
|
||||
V60
|
||||
p116
|
||||
sg44
|
||||
Vnone
|
||||
p117
|
||||
sVm1ch
|
||||
p118
|
||||
g90
|
||||
sVmv
|
||||
p119
|
||||
g48
|
||||
sg49
|
||||
VOn
|
||||
p120
|
||||
sVun
|
||||
p121
|
||||
g29
|
||||
sg53
|
||||
Vfloat
|
||||
p122
|
||||
sVvm
|
||||
p123
|
||||
NssV2-6
|
||||
p124
|
||||
(dp125
|
||||
Vah
|
||||
p126
|
||||
g14
|
||||
sVbytary
|
||||
p127
|
||||
NsVal
|
||||
p128
|
||||
g48
|
||||
sVvn
|
||||
p129
|
||||
VLast Calc. Period Volume
|
||||
p130
|
||||
sVct
|
||||
p131
|
||||
Vnumber
|
||||
p132
|
||||
sVle
|
||||
p133
|
||||
V32
|
||||
p134
|
||||
sVgrp
|
||||
p135
|
||||
V86400
|
||||
p136
|
||||
sVla
|
||||
p137
|
||||
F14.691
|
||||
sVchn
|
||||
p138
|
||||
Vlast_calculation_period_volume
|
||||
p139
|
||||
sVun
|
||||
p140
|
||||
g29
|
||||
sVdn
|
||||
p141
|
||||
Vabbflow
|
||||
p142
|
||||
sVda
|
||||
p143
|
||||
g29
|
||||
sVlrt
|
||||
p144
|
||||
F1502682560.7307109
|
||||
sg34
|
||||
V4011
|
||||
p145
|
||||
sg36
|
||||
V10
|
||||
p146
|
||||
sVmisc_u
|
||||
p147
|
||||
VSCF
|
||||
p148
|
||||
sg40
|
||||
g41
|
||||
sVmrt
|
||||
p149
|
||||
V60
|
||||
p150
|
||||
sg44
|
||||
Vnone
|
||||
p151
|
||||
sVm1ch
|
||||
p152
|
||||
g124
|
||||
sVmv
|
||||
p153
|
||||
g48
|
||||
sg49
|
||||
VOn
|
||||
p154
|
||||
sg51
|
||||
V0-1000000
|
||||
p155
|
||||
sg53
|
||||
Vfloat
|
||||
p156
|
||||
sVvm
|
||||
p157
|
||||
NssV2-7
|
||||
p158
|
||||
(dp159
|
||||
Vah
|
||||
p160
|
||||
g14
|
||||
sVbytary
|
||||
p161
|
||||
NsVal
|
||||
p162
|
||||
g48
|
||||
sVvn
|
||||
p163
|
||||
VDifferential Pressure
|
||||
p164
|
||||
sVct
|
||||
p165
|
||||
Vnumber
|
||||
p166
|
||||
sVle
|
||||
p167
|
||||
V32
|
||||
p168
|
||||
sVgrp
|
||||
p169
|
||||
V3600
|
||||
p170
|
||||
sVla
|
||||
p171
|
||||
F3.095
|
||||
sVchn
|
||||
p172
|
||||
Vdifferential_pressure
|
||||
p173
|
||||
sVun
|
||||
p174
|
||||
g29
|
||||
sVdn
|
||||
p175
|
||||
Vabbflow
|
||||
p176
|
||||
sVda
|
||||
p177
|
||||
g29
|
||||
sVlrt
|
||||
p178
|
||||
F1502725891.811299
|
||||
sg51
|
||||
V0-500
|
||||
p179
|
||||
sg34
|
||||
V4013
|
||||
p180
|
||||
sg36
|
||||
g112
|
||||
sVmisc_u
|
||||
p181
|
||||
VInH20
|
||||
p182
|
||||
sg40
|
||||
g41
|
||||
sVmrt
|
||||
p183
|
||||
V60
|
||||
p184
|
||||
sg44
|
||||
Vnone
|
||||
p185
|
||||
sVm1ch
|
||||
p186
|
||||
g158
|
||||
sg49
|
||||
VOn
|
||||
p187
|
||||
sVmv
|
||||
p188
|
||||
g48
|
||||
sg53
|
||||
Vfloat
|
||||
p189
|
||||
sVvm
|
||||
p190
|
||||
NssV2-4
|
||||
p191
|
||||
(dp192
|
||||
Vah
|
||||
p193
|
||||
g14
|
||||
sVbytary
|
||||
p194
|
||||
NsVal
|
||||
p195
|
||||
V0
|
||||
p196
|
||||
sVvn
|
||||
p197
|
||||
VYesterday Volume
|
||||
p198
|
||||
sVct
|
||||
p199
|
||||
Vnumber
|
||||
p200
|
||||
sVle
|
||||
p201
|
||||
V32
|
||||
p202
|
||||
sVgrp
|
||||
p203
|
||||
V21600
|
||||
p204
|
||||
sVla
|
||||
p205
|
||||
F640.448
|
||||
sVchn
|
||||
p206
|
||||
Vyesterday_volume
|
||||
p207
|
||||
sVun
|
||||
p208
|
||||
V1
|
||||
p209
|
||||
sVdn
|
||||
p210
|
||||
Vabbflow
|
||||
p211
|
||||
sVda
|
||||
p212
|
||||
g209
|
||||
sVlrt
|
||||
p213
|
||||
F1502517692.3270172
|
||||
sVa
|
||||
p214
|
||||
V4007
|
||||
p215
|
||||
sVc
|
||||
p216
|
||||
V10.0
|
||||
p217
|
||||
sVmisc_u
|
||||
p218
|
||||
VMCF
|
||||
p219
|
||||
sVf
|
||||
p220
|
||||
V4
|
||||
p221
|
||||
sVmrt
|
||||
p222
|
||||
V60
|
||||
p223
|
||||
sVm
|
||||
p224
|
||||
Vnone
|
||||
p225
|
||||
sVm1ch
|
||||
p226
|
||||
g191
|
||||
sVmv
|
||||
p227
|
||||
g196
|
||||
sVs
|
||||
p228
|
||||
VOn
|
||||
p229
|
||||
sVr
|
||||
p230
|
||||
V0-5000
|
||||
p231
|
||||
sVt
|
||||
p232
|
||||
Vfloat
|
||||
p233
|
||||
sVvm
|
||||
p234
|
||||
NssV2-5
|
||||
p235
|
||||
(dp236
|
||||
Vah
|
||||
p237
|
||||
g14
|
||||
sVbytary
|
||||
p238
|
||||
NsVal
|
||||
p239
|
||||
g48
|
||||
sVvn
|
||||
p240
|
||||
VAccumulated Volume
|
||||
p241
|
||||
sVct
|
||||
p242
|
||||
Vnumber
|
||||
p243
|
||||
sVle
|
||||
p244
|
||||
V32
|
||||
p245
|
||||
sVgrp
|
||||
p246
|
||||
V3600
|
||||
p247
|
||||
sVla
|
||||
p248
|
||||
F23666.424
|
||||
sVchn
|
||||
p249
|
||||
Vaccumulated_volume
|
||||
p250
|
||||
sVun
|
||||
p251
|
||||
g29
|
||||
sVdn
|
||||
p252
|
||||
Vabbflow
|
||||
p253
|
||||
sVda
|
||||
p254
|
||||
g29
|
||||
sVlrt
|
||||
p255
|
||||
F1502726134.0120882
|
||||
sg34
|
||||
V4009
|
||||
p256
|
||||
sg36
|
||||
V10
|
||||
p257
|
||||
sVmisc_u
|
||||
p258
|
||||
VMCF
|
||||
p259
|
||||
sg40
|
||||
g41
|
||||
sVmrt
|
||||
p260
|
||||
V60
|
||||
p261
|
||||
sg44
|
||||
Vnone
|
||||
p262
|
||||
sVm1ch
|
||||
p263
|
||||
g235
|
||||
sVmv
|
||||
p264
|
||||
g48
|
||||
sg49
|
||||
VOn
|
||||
p265
|
||||
sg51
|
||||
V0-1000000
|
||||
p266
|
||||
sg53
|
||||
Vfloat
|
||||
p267
|
||||
sVvm
|
||||
p268
|
||||
NssV2-8
|
||||
p269
|
||||
(dp270
|
||||
Vah
|
||||
p271
|
||||
g14
|
||||
sVbytary
|
||||
p272
|
||||
NsVal
|
||||
p273
|
||||
g48
|
||||
sVvn
|
||||
p274
|
||||
VStatic Pressure
|
||||
p275
|
||||
sVct
|
||||
p276
|
||||
Vnumber
|
||||
p277
|
||||
sVle
|
||||
p278
|
||||
V32
|
||||
p279
|
||||
sVgrp
|
||||
p280
|
||||
V3600
|
||||
p281
|
||||
sVla
|
||||
p282
|
||||
F27.048
|
||||
sVchn
|
||||
p283
|
||||
Vstatic_pressure
|
||||
p284
|
||||
sg51
|
||||
V0-250
|
||||
p285
|
||||
sVun
|
||||
p286
|
||||
g29
|
||||
sVdn
|
||||
p287
|
||||
Vabbflow
|
||||
p288
|
||||
sVda
|
||||
p289
|
||||
g29
|
||||
sVlrt
|
||||
p290
|
||||
F1502725884.2453662
|
||||
sg34
|
||||
V4015
|
||||
p291
|
||||
sg36
|
||||
g112
|
||||
sVmisc_u
|
||||
p292
|
||||
VPSIA
|
||||
p293
|
||||
sg40
|
||||
g41
|
||||
sVmrt
|
||||
p294
|
||||
V60
|
||||
p295
|
||||
sg44
|
||||
Vnone
|
||||
p296
|
||||
sVm1ch
|
||||
p297
|
||||
g269
|
||||
sg49
|
||||
VOn
|
||||
p298
|
||||
sVmv
|
||||
p299
|
||||
g48
|
||||
sg53
|
||||
Vfloat
|
||||
p300
|
||||
sVvm
|
||||
p301
|
||||
NssV2-9
|
||||
p302
|
||||
(dp303
|
||||
Vah
|
||||
p304
|
||||
g14
|
||||
sVbytary
|
||||
p305
|
||||
NsVal
|
||||
p306
|
||||
g48
|
||||
sVvn
|
||||
p307
|
||||
VTemperature
|
||||
p308
|
||||
sVct
|
||||
p309
|
||||
Vnumber
|
||||
p310
|
||||
sVle
|
||||
p311
|
||||
V32
|
||||
p312
|
||||
sVgrp
|
||||
p313
|
||||
V3600
|
||||
p314
|
||||
sVla
|
||||
p315
|
||||
F85.208
|
||||
sVchn
|
||||
p316
|
||||
Vtemperature
|
||||
p317
|
||||
sg51
|
||||
V0-300
|
||||
p318
|
||||
sVun
|
||||
p319
|
||||
g29
|
||||
sVdn
|
||||
p320
|
||||
Vabbflow
|
||||
p321
|
||||
sVda
|
||||
p322
|
||||
g29
|
||||
sVlrt
|
||||
p323
|
||||
F1502724763.458232
|
||||
sg34
|
||||
V4017
|
||||
p324
|
||||
sg36
|
||||
g112
|
||||
sVmisc_u
|
||||
p325
|
||||
Vdeg F
|
||||
p326
|
||||
sg40
|
||||
g41
|
||||
sVmrt
|
||||
p327
|
||||
V60
|
||||
p328
|
||||
sg44
|
||||
Vnone
|
||||
p329
|
||||
sVm1ch
|
||||
p330
|
||||
g302
|
||||
sg49
|
||||
VOn
|
||||
p331
|
||||
sVmv
|
||||
p332
|
||||
g48
|
||||
sg53
|
||||
Vfloat
|
||||
p333
|
||||
sVvm
|
||||
p334
|
||||
NssV2-10
|
||||
p335
|
||||
(dp336
|
||||
Vah
|
||||
p337
|
||||
g14
|
||||
sVbytary
|
||||
p338
|
||||
NsVal
|
||||
p339
|
||||
g14
|
||||
sVvn
|
||||
p340
|
||||
VCharger Voltage
|
||||
p341
|
||||
sVct
|
||||
p342
|
||||
Vnumber
|
||||
p343
|
||||
sVle
|
||||
p344
|
||||
V32
|
||||
p345
|
||||
sVgrp
|
||||
p346
|
||||
V3600
|
||||
p347
|
||||
sVla
|
||||
p348
|
||||
F13.356
|
||||
sVchn
|
||||
p349
|
||||
Vcharger_voltage
|
||||
p350
|
||||
sg51
|
||||
V0-50
|
||||
p351
|
||||
sVdn
|
||||
p352
|
||||
Vabbflow
|
||||
p353
|
||||
sVda
|
||||
p354
|
||||
g29
|
||||
sVlrt
|
||||
p355
|
||||
F1502725893.760519
|
||||
sg34
|
||||
V4019
|
||||
p356
|
||||
sg36
|
||||
g112
|
||||
sVmisc_u
|
||||
p357
|
||||
g114
|
||||
sg40
|
||||
g41
|
||||
sVmrt
|
||||
p358
|
||||
V60
|
||||
p359
|
||||
sg44
|
||||
Vnone
|
||||
p360
|
||||
sVm1ch
|
||||
p361
|
||||
g335
|
||||
sVmv
|
||||
p362
|
||||
g48
|
||||
sg49
|
||||
VOn
|
||||
p363
|
||||
sVun
|
||||
p364
|
||||
g29
|
||||
sg53
|
||||
Vfloat
|
||||
p365
|
||||
sVvm
|
||||
p366
|
||||
NssssS'f'
|
||||
p367
|
||||
VOff
|
||||
p368
|
||||
sS'p'
|
||||
p369
|
||||
g14
|
||||
sS's'
|
||||
p370
|
||||
g209
|
||||
ssS'2'
|
||||
p371
|
||||
(dp372
|
||||
g3
|
||||
VM1-232
|
||||
p373
|
||||
sg5
|
||||
V9600
|
||||
p374
|
||||
sg7
|
||||
(dp375
|
||||
sg367
|
||||
VOff
|
||||
p376
|
||||
sg369
|
||||
g14
|
||||
sg370
|
||||
g209
|
||||
ss.
|
||||
49
python-driver/utilities.py
Normal file
49
python-driver/utilities.py
Normal file
@@ -0,0 +1,49 @@
|
||||
"""Utility functions for the driver."""
|
||||
import socket
|
||||
import struct
|
||||
|
||||
|
||||
def get_public_ip_address():
|
||||
"""Find the public IP Address of the host device."""
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
sock.connect(("8.8.8.8", 80))
|
||||
ip_address = sock.getsockname()[0]
|
||||
sock.close()
|
||||
return ip_address
|
||||
|
||||
|
||||
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))
|
||||
fraction = float(int(bin_rep[6: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")
|
||||
return float("NaN")
|
||||
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_unpacked = struct.unpack('>f', mypack)
|
||||
print("[{}, {}] >> {}".format(int1, int2, f_unpacked[0]))
|
||||
return f_unpacked[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
|
||||
Reference in New Issue
Block a user