Läuft die Voice Acoustic VA-Remotecontrol (AllDSP AllControl) nativ unter Linux auf echtem wxGTK 3.0 — ohne Wine und ohne dekompilierten App-Code. Ausgeführt wird das unveränderte Python-2.7-Bytecode aus dem macOS-.app; C-Extensions (wxGTK/numpy/ scipy/PortAudio) kommen nativ aus Debian stretch. Enthält: va/ (Original-.pyc + pure-Python-Libs + Assets + launch.py mit den drei Linux-Fixes), Dockerfile/run.sh/entrypoint.sh, reference/ (dekompilierter Quellcode zum Debuggen) und README/STATUS. img.cache (378 MB, regenerierbar) ist per .gitignore ausgeschlossen. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
4852 lines
232 KiB
Python
4852 lines
232 KiB
Python
# uncompyle6 version 3.9.3
|
|
# Python bytecode version base 2.6 (62161)
|
|
# Decompiled from: Python 3.9.25 (main, Oct 31 2025, 23:16:49)
|
|
# [GCC 14.2.0]
|
|
# Embedded file name: d_protocol.pyc
|
|
# Compiled at: 2025-05-20 14:45:24
|
|
import sys, socket, collections, mytime, myserial, threading, copy, struct, types, os.path, traceback, wx, codecs, string, main, protocol, math, one_unit, subprocess, d_usb, data_model, server, ConfigParser, os
|
|
from random import randint
|
|
import zipfile, future, cleanImage
|
|
from definitions import *
|
|
|
|
def getString(str):
|
|
return one_unit.getString(str)
|
|
|
|
|
|
mac_names = 'posix'
|
|
if os.name in mac_names:
|
|
newline = '\n'
|
|
else:
|
|
newline = '\r\n'
|
|
FOUND_CODEC_ES9290Q_1 = 1
|
|
FOUND_CODEC_ES9290Q_2 = 2
|
|
FOUND_CODEC_ES9006 = 4
|
|
FOUND_CODEC_ES9017Q = 8
|
|
FOUND_CODEC_PCM1690 = 16
|
|
FOUND_CODEC_TAS5760M = 32
|
|
FOUND_CODEC_AK5702 = 64
|
|
FOUND_CODEC_AK5534 = 128
|
|
FOUND_CODEC_AK5534_NO_I2C = 256
|
|
FOUND_CODEC_TLV320ADC5140 = 512
|
|
FOUND_CODEC_AK5704 = 1024
|
|
FOUND_CODEC_AK4619 = 2048
|
|
FOUND_CODEC_ES9290Q_3 = 4096
|
|
FOUND_CODEC_ES9290Q_4 = 8192
|
|
FOUND_CODEC_ES9026PRO = 16384
|
|
FOUND_PLL_CS2100 = 65536
|
|
FOUND_PLL_SI5351 = 131072
|
|
FOUND_SENSOR_LSM303 = 1048576
|
|
FOUND_SENSOR_DS18B20 = 2097152
|
|
FOUND_HARDWARE_TEXT = {FOUND_CODEC_ES9290Q_1: 'Codec: ES9290Q 1',
|
|
FOUND_CODEC_ES9290Q_2: 'Codec: ES9290Q 2',
|
|
FOUND_CODEC_ES9290Q_3: 'Codec: ES9290Q 3',
|
|
FOUND_CODEC_ES9290Q_4: 'Codec: ES9290Q 4',
|
|
FOUND_CODEC_ES9006: 'Codec: ES9006',
|
|
FOUND_CODEC_ES9017Q: 'Codec: ES9017Q',
|
|
FOUND_CODEC_PCM1690: 'Codec: PCM1690',
|
|
FOUND_CODEC_TAS5760M: 'Codec: TAS5760',
|
|
FOUND_CODEC_AK5702: 'Codec: AK5702',
|
|
FOUND_CODEC_AK5534: 'Codec: AK5534',
|
|
FOUND_CODEC_AK5534_NO_I2C: 'Codec: AK5534 NO I2C',
|
|
FOUND_CODEC_TLV320ADC5140: 'Codec: TLV320ADC5140',
|
|
FOUND_CODEC_AK5704: 'Codec: AK5704',
|
|
FOUND_CODEC_AK4619: 'Codec: AK4619',
|
|
FOUND_CODEC_ES9026PRO: 'Codec: ES9026PRO',
|
|
FOUND_PLL_CS2100: 'PLL: CS2100',
|
|
FOUND_PLL_SI5351: 'PLL: Si5351',
|
|
FOUND_SENSOR_LSM303: 'Sensor: LSM303',
|
|
FOUND_SENSOR_DS18B20: 'Sensor: DS18B20'}
|
|
if True:
|
|
SYNC_DELAY = 0
|
|
MIN_DELAY = 0.03
|
|
MIN_DELAY_USB = 0.1
|
|
MAX_DELAY = 0.05
|
|
MAX_DELAY_USB = 0.1
|
|
CHOOSE_VAR_TO_UPDATE_SKIP_CYCLES = 5000
|
|
CONDITIONAL_VU = True
|
|
Key = collections.namedtuple('Key', 'struct_id, member_id, channel, num')
|
|
CodeTable = (
|
|
233, 45, 98, 215, 123, 42, 99, 23, 178, 132, 200, 150, 100, 50, 77, 43, 54, 90, 31, 43, 123, 234, 211, 177, 65, 133, 3, 64, 23, 83, 251, 1, 54, 34)
|
|
verifiedList = {1: '',
|
|
2: 'AKM ADC installed',
|
|
4: 'Default DAC installed',
|
|
8: 'AUX ADC installed',
|
|
16: 'PLL installed',
|
|
32: 'Inclinometer installed',
|
|
64: '',
|
|
128: '',
|
|
256: '',
|
|
512: '',
|
|
1024: '',
|
|
2048: '',
|
|
4096: 'USB processor installed',
|
|
8192: 'Dante module installed',
|
|
16384: 'PLL is master clock',
|
|
32768: 'Burr Brown ADC installed',
|
|
65536: 'Burr Brown DAC installed',
|
|
131072: '',
|
|
262144: '',
|
|
524288: '',
|
|
1048576: ''}
|
|
notInstalledList = {1: '',
|
|
2: '',
|
|
4: '',
|
|
8: 'AUX ADC not installed',
|
|
16: 'PLL not installed',
|
|
32: 'Inclinometer not installed',
|
|
64: '',
|
|
128: '',
|
|
256: '',
|
|
512: '',
|
|
1024: '',
|
|
2048: '',
|
|
4096: 'USB processor not installed',
|
|
8192: 'Dante module not installed',
|
|
16384: 'DSP is master clock',
|
|
32768: '',
|
|
65536: '',
|
|
131072: '',
|
|
262144: '',
|
|
524288: '',
|
|
1048576: ''}
|
|
errorList = {1: 'DSP bus error',
|
|
2: 'ADC bus error',
|
|
4: 'DAC bus error',
|
|
8: 'AUX ADC bus error',
|
|
16: 'PLL bus error',
|
|
32: 'Motion Sensor not available',
|
|
64: 'Coprocessor bus error',
|
|
128: 'Flash not empty in virgin state',
|
|
256: 'Failed to write Global',
|
|
512: 'Failed to write slot',
|
|
1024: 'Failed to write preset',
|
|
2048: 'Memory full',
|
|
4096: 'Failed to read preset',
|
|
8192: 'Dante module not installed',
|
|
16384: '',
|
|
32768: '',
|
|
65536: ''}
|
|
|
|
def readableHEX(cmd):
|
|
res = ''
|
|
for c in cmd:
|
|
res += hex(ord(c)) + ':'
|
|
|
|
return res[:-1]
|
|
|
|
|
|
def readableDecimal(cmd):
|
|
res = ''
|
|
for c in cmd:
|
|
res += str(ord(c)) + ':'
|
|
|
|
return res[:-1]
|
|
|
|
|
|
def readable(key):
|
|
if key.member_id in (protocol.MEMBER_ID_VU_IN, protocol.MEMBER_ID_VU_OUT, protocol.MEMBER_ID_GR_IN, protocol.MEMBER_ID_GR_OUT):
|
|
res = 'Got ' + protocol.get_member_text(key.member_id) + ' '
|
|
if key.channel < 128:
|
|
res += str(key.channel + 1) + ' '
|
|
else:
|
|
res += str(key.channel - 127) + ' '
|
|
return res
|
|
res = ''
|
|
res += protocol.get_strid_text(key.struct_id) + ' '
|
|
res += protocol.get_member_text(key.member_id) + ' '
|
|
if key.channel < 128:
|
|
res += 'Input ' + str(key.channel + 1) + ' '
|
|
else:
|
|
res += 'Output ' + str(key.channel - 127) + ' '
|
|
res += 'No. ' + str(key.num)
|
|
return res
|
|
|
|
|
|
def safeRemove(array, key):
|
|
try:
|
|
array.remove(key)
|
|
except:
|
|
pass
|
|
|
|
return
|
|
|
|
|
|
class Unit_var():
|
|
"""The state of an interface variable in a hardware unit"""
|
|
|
|
def __init__(self):
|
|
"""Constructor"""
|
|
self.read_val = None
|
|
self.read_ts = None
|
|
self.change_ts = 0
|
|
self.write_val = None
|
|
self.write_ts = 0
|
|
self.SetCount = 0
|
|
self.set_ts = 0
|
|
self.saved_val = None
|
|
self.set_time = 0
|
|
self.target_val = None
|
|
return
|
|
|
|
|
|
class RemoteUnit():
|
|
|
|
def __init__(self):
|
|
self.MAC = 'no MAC'
|
|
self.IP = 'no IP'
|
|
self.type = 'no type'
|
|
self.name = 'no name'
|
|
self.pkt = None
|
|
self.MK2 = False
|
|
self.link_status = None
|
|
self.link_type = None
|
|
self.last_rx = 0
|
|
self.thread = None
|
|
self.preset_names = {}
|
|
self.values = {}
|
|
self.process = None
|
|
self.last_write = {}
|
|
self.BuildNumber = 0
|
|
self.HWVersion = None
|
|
self.FWVersion = 'Unknown'
|
|
self.PICVersion = None
|
|
self.Serial = None
|
|
self.ProductionDate = None
|
|
self.numericalFWVersion = 0
|
|
self.originalSwID = ''
|
|
self.InstanceId = None
|
|
self.Muted = str(False)
|
|
self.DSPState = 0
|
|
self.minPresetLockVersion = 198656
|
|
self.minPINVersion = 198656
|
|
self.minFIRgainVersion = 198677
|
|
self.minBuildNumberVersion = 198679
|
|
self.minModelFirmwareVersion = 198679
|
|
self.foundHardwareString = 'Found Hardware: Unknown'
|
|
return
|
|
|
|
|
|
update_interval = 300
|
|
|
|
class Remote_Link():
|
|
|
|
def __init__(self, parent, MAC):
|
|
self.parent = parent
|
|
self.MAC = MAC
|
|
self.stopping = False
|
|
self.thread = threading.Thread(name=MAC, target=self.process)
|
|
self.thread.daemon = True
|
|
self.lock = threading.Lock()
|
|
self.model_firmware_string = ''
|
|
self.model_firmware = 0
|
|
self.model_number_string = ''
|
|
self.model_number = -1
|
|
self.started_read_image = False
|
|
self.reset_counter = 0
|
|
self.first_sync = True
|
|
self.IP = 'USB'
|
|
self.fastUpdate = False
|
|
self.lastPrintTime = 0
|
|
self.enable_vu = False
|
|
self.initial_sync = False
|
|
self.connectTime = 0
|
|
if self.MAC not in one_unit.app.bootloader_progress:
|
|
one_unit.updateBootloaderDial(self.MAC, None)
|
|
one_unit.app.always_allow_update[self.MAC] = False
|
|
self.main_config = ConfigParser.ConfigParser()
|
|
self.main_config.read(os.path.join(one_unit.app.cwd, 'main.cfg'))
|
|
try:
|
|
emulate = self.main_config.get('ROOT', 'emulate')
|
|
self.main_config = ConfigParser.ConfigParser()
|
|
self.main_config.read(one_unit.app.cwd + '/customers/' + emulate + '/main.cfg')
|
|
except:
|
|
pass
|
|
|
|
try:
|
|
self.global_vu_stereo_out = eval(self.main_config.get('ROOT', 'global_vu_stereo_out'))
|
|
except:
|
|
self.global_vu_stereo_out = False
|
|
|
|
try:
|
|
self.global_vu_channels = eval(self.main_config.get('ROOT', 'global_vu_channels'))
|
|
except:
|
|
self.global_vu_channels = None
|
|
|
|
try:
|
|
self.mute_channels = eval(self.main_config.get('ROOT', 'mute_channels'))
|
|
except:
|
|
self.mute_channels = None
|
|
|
|
self.conn = Protocol_Execute(self)
|
|
self.invalid_packet_counter = 0
|
|
self.delay = 0.01
|
|
self.connection_attempts = 0
|
|
self.ignore_fw_version = ''
|
|
self.ser = None
|
|
self.fw_retry_counter = 0
|
|
self.action = None
|
|
self.start_bootloader_time = mytime.clock()
|
|
self.last_mute_state = {}
|
|
self.last_refresh = mytime.clock()
|
|
self.updateDisplayState = 0
|
|
self.start()
|
|
return
|
|
|
|
def TempMute(self, mute):
|
|
if self.mute_channels == None or self.mute_channels == []:
|
|
self.mute_channels = []
|
|
for key in self.conn.values.keys():
|
|
if key.struct_id == protocol.STRUCT_ID_MUTE and key.channel < 128:
|
|
if key.channel not in self.mute_channels:
|
|
self.mute_channels.append(key.channel)
|
|
self.conn.set_by_key(key, mute)
|
|
self.parent.peers.set_by_key(self.MAC, key, mute)
|
|
self.parent.peers.units[self.MAC].Muted = str(mute)
|
|
|
|
else:
|
|
for channel in self.mute_channels:
|
|
key = data_model.Key(protocol.STRUCT_ID_MUTE, protocol.MEMBER_ID_MUTE, channel, 0)
|
|
self.conn.set_by_key(key, mute)
|
|
self.parent.peers.set_by_key(self.MAC, key, mute)
|
|
self.parent.peers.units[self.MAC].Muted = str(mute)
|
|
|
|
return
|
|
|
|
def restartSocket(self):
|
|
try:
|
|
self.ethSocket.close()
|
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
s.settimeout(0.5)
|
|
s.connect((self.IP, 50675))
|
|
s.settimeout(0.5)
|
|
self.ethSocket = s
|
|
print mytime.displayTime(), 'd_p.Restarted Ethernet socket'
|
|
except:
|
|
print mytime.displayTime(), 'Failed to restart ethernet socket'
|
|
|
|
return
|
|
|
|
def updateDisplay(self, s):
|
|
stateInit = 0
|
|
stateGetNextFile = 1
|
|
stateStartUploadFile = 2
|
|
stateUploadFile = 3
|
|
stateFinishedOK = 4
|
|
stateFinishedFailed = 5
|
|
blockSize = 1024
|
|
if self.updateDisplayState == stateInit:
|
|
self.updateDisplayFileList = []
|
|
try:
|
|
fNames = sorted(os.listdir(one_unit.app.cwd + '/dfi/VT_SET'))
|
|
for fName in fNames:
|
|
if fName in ('CONFIG.txt', '.DS_Store'):
|
|
continue
|
|
self.updateDisplayFileList.append(fName)
|
|
|
|
print self.updateDisplayFileList
|
|
except:
|
|
print mytime.displayTime(), 'd_p.uD. directory not found?'
|
|
traceback.print_exc(file=sys.stdout)
|
|
self.updateDisplayState = stateFinishedFailed
|
|
return
|
|
|
|
if len(self.updateDisplayFileList) == 0:
|
|
print mytime.displayTime(), 'd_p.uD. No file to upload', fNames
|
|
self.updateDisplayState = stateFinishedFailed
|
|
return
|
|
self.updateDisplayState = stateGetNextFile
|
|
self.update_start_time = mytime.clock()
|
|
self.filesToUpload = len(self.updateDisplayFileList)
|
|
s.settimeout(0.5)
|
|
return
|
|
else:
|
|
if self.updateDisplayState == stateGetNextFile:
|
|
if len(self.updateDisplayFileList) == 0:
|
|
self.updateDisplayState = stateFinishedOK
|
|
print mytime.displayTime(), 'File uploaded in', mytime.clock() - self.updateDisplayFileStartTime, 'seconds'
|
|
return
|
|
self.fileStartTime = mytime.clock()
|
|
self.updateDisplayFileName = self.updateDisplayFileList[0]
|
|
f = open(one_unit.app.cwd + '/dfi/VT_SET/' + self.updateDisplayFileName, 'rb')
|
|
fData = f.read()
|
|
f.close()
|
|
self.updateDisplayFileData = fData
|
|
print mytime.displayTime(), 'Upload File:', self.updateDisplayFileName, len(self.updateDisplayFileData), 'bytes'
|
|
self.updateDisplayState = stateStartUploadFile
|
|
self.updateDisplayFileStartTime = mytime.clock()
|
|
if self.updateDisplayState == stateStartUploadFile:
|
|
print mytime.displayTime(), 'd_p.uD.sending file name', self.updateDisplayFileName
|
|
if mytime.clock() - self.fileStartTime > 10:
|
|
print mytime.displayTime(), 'd_p.file timeout'
|
|
self.updateDisplayState = stateFinishedFailed
|
|
return
|
|
cmd = 'DCDISPLAY_FILENAME' + struct.pack('>l', len(self.updateDisplayFileData)) + self.updateDisplayFileName + 'Q'
|
|
print mytime.displayTime(), 'Command:', cmd, readableHEX(cmd)
|
|
if s != None:
|
|
try:
|
|
s.send(cmd)
|
|
except:
|
|
self.restartSocket()
|
|
return
|
|
|
|
try:
|
|
if s != None:
|
|
new_pkt = s.recv(4096)
|
|
else:
|
|
self.restartSocket()
|
|
return
|
|
except:
|
|
new_pkt = None
|
|
self.updateDisplayState = stateFinishedFailed
|
|
return
|
|
|
|
print mytime.displayTime(), 'd:p.uD.got reply', readableHEX(new_pkt[:6]), new_pkt[6:]
|
|
if new_pkt != None and len(new_pkt) >= 7 + len(self.updateDisplayFileName) and ord(new_pkt[0]) == 68 and ord(new_pkt[1]) == 4 and new_pkt[6 + len(self.updateDisplayFileName)] == 'Q':
|
|
returnedFileName = new_pkt[6:6 + len(self.updateDisplayFileName)]
|
|
returnedFileSize = struct.unpack('>l', new_pkt[2:6])[0]
|
|
if returnedFileName == self.updateDisplayFileName and returnedFileSize == len(self.updateDisplayFileData):
|
|
print mytime.displayTime(), 'd_p.uD.file name and size confirmed'
|
|
self.updateDisplayState = stateUploadFile
|
|
self.completion = 0
|
|
mytime.sleep(0.1)
|
|
else:
|
|
print mytime.displayTime(), 'File name:', returnedFileName, len(returnedFileName), self.updateDisplayFileName, len(self.updateDisplayFileName), 'File size:', returnedFileSize, len(self.updateDisplayFileData)
|
|
self.updateDisplayState = stateFinishedFailed
|
|
return
|
|
return
|
|
if self.updateDisplayState == stateUploadFile:
|
|
start = self.completion
|
|
end = self.completion + blockSize
|
|
if end > len(self.updateDisplayFileData):
|
|
end = len(self.updateDisplayFileData)
|
|
print mytime.displayTime(), 'uploading', self.updateDisplayFileName, start, 'to', end, 'of', len(self.updateDisplayFileData), 'bytes'
|
|
if end == len(self.updateDisplayFileData):
|
|
cmd = 'DCDISPLAY_FILELAST' + self.updateDisplayFileData[start:end] + 'Q'
|
|
last = True
|
|
else:
|
|
cmd = 'DCDISPLAY_FILEDATA' + self.updateDisplayFileData[start:end] + 'Q'
|
|
last = False
|
|
if s != None:
|
|
try:
|
|
s.send(cmd)
|
|
except:
|
|
self.restartSocket()
|
|
return
|
|
|
|
try:
|
|
if s != None:
|
|
new_pkt = s.recv(4096)
|
|
else:
|
|
self.restartSocket()
|
|
except:
|
|
new_pkt = None
|
|
self.updateDisplayState = stateFinishedFailed
|
|
return
|
|
else:
|
|
if last and new_pkt != None and len(new_pkt) >= 3 + end - start:
|
|
print mytime.displayTime(), 'last packet:', new_pkt[:18], readableHEX(new_pkt[:18])
|
|
if new_pkt[:17] != 'One file Saved OK':
|
|
print mytime.displayTime(), 'Upload Failed!!! -> retry'
|
|
self.updateDisplayState = stateGetNextFile
|
|
mytime.sleep(1)
|
|
return
|
|
print mytime.displayTime(), 'Upload: File Saved OK'
|
|
new_pkt = new_pkt[18:]
|
|
if new_pkt != None and len(new_pkt) >= 3 + end - start and ord(new_pkt[0]) == 68 and ord(new_pkt[1]) == 5 and new_pkt[2 + end - start] == 'Q':
|
|
if new_pkt[2:2 + end - start] == self.updateDisplayFileData[start:end]:
|
|
self.completion = end
|
|
if last:
|
|
self.updateDisplayState = stateGetNextFile
|
|
self.updateDisplayFileList.remove(self.updateDisplayFileName)
|
|
mytime.sleep(1)
|
|
else:
|
|
print mytime.displayTime(), 'Data not verified', len(new_pkt), new_pkt[:10], new_pkt[-1]
|
|
self.updateDisplayState = stateFinishedFailed
|
|
return
|
|
one_unit.updateBootloaderDial(self.MAC, '(3) Uploading file ' + str(self.filesToUpload - len(self.updateDisplayFileList) + 1) + ' of ' + str(self.filesToUpload) + ' (' + str(self.completion * 100 / len(self.updateDisplayFileData)) + '%)', alwaysUpdate=False)
|
|
else:
|
|
print mytime.displayTime(), 'Invalid packet', len(new_pkt), readableHEX(new_pkt[2:12]), readableHEX(self.updateDisplayFileData[start:start + 10])
|
|
self.updateDisplayState = stateFinishedFailed
|
|
return
|
|
|
|
return
|
|
if self.updateDisplayState == stateFinishedOK:
|
|
one_unit.updateBootloaderDial(self.MAC, '(3) Finished', alwaysUpdate=True)
|
|
print mytime.displayTime(), 'Finished uploading display files in', mytime.clock() - self.update_start_time, 'seconds.'
|
|
s.settimeout(0.5)
|
|
cmd = 'DCDISPLAY_FINISHED'
|
|
if s != None:
|
|
try:
|
|
s.send(cmd)
|
|
except:
|
|
self.restartSocket()
|
|
return
|
|
|
|
self.action = None
|
|
mytime.sleep(0.2)
|
|
one_unit.updateBootloaderDial(self.MAC, '(3) Finished', alwaysUpdate=True)
|
|
return
|
|
if self.updateDisplayState == stateFinishedFailed:
|
|
one_unit.updateBootloaderDial(self.MAC, '(3) Failed', alwaysUpdate=False)
|
|
print mytime.displayTime(), 'Failed to upload display files.'
|
|
s.settimeout(0.5)
|
|
cmd = 'DCDISPLAY_FINISHED'
|
|
if s != None:
|
|
try:
|
|
s.send(cmd)
|
|
except:
|
|
self.restartSocket()
|
|
return
|
|
|
|
self.action = None
|
|
return
|
|
return
|
|
|
|
def startUpdateDisplay(self):
|
|
print mytime.displayTime(), 'd_p.startUpdateDisplay'
|
|
try:
|
|
if self.action == None:
|
|
print mytime.displayTime() + ' d_p.Starting Display Update'
|
|
self.action = 'update_display'
|
|
self.completion = 0
|
|
self.updateDisplayState = 0
|
|
self.updateDisplayFileList = []
|
|
except:
|
|
traceback.print_exc(file=sys.stdout)
|
|
|
|
return
|
|
|
|
def MakeImage(self):
|
|
self.replyTime = mytime.clock()
|
|
self.loopTime = 0
|
|
self.replyDelay = 0
|
|
try:
|
|
if self.action == None:
|
|
print mytime.displayTime() + ' d_p.Starting Make Image'
|
|
self.action = 'make_image'
|
|
self.completion = 0
|
|
self.started_read_image = False
|
|
except:
|
|
traceback.print_exc(file=sys.stdout)
|
|
|
|
return
|
|
|
|
def SetPower(self, state):
|
|
hwstatskey = data_model.Key(protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_HARDWARE_STATUS_FLAGS, 0, 0)
|
|
try:
|
|
hwstatsval = int(self.conn.values[hwstatskey].read_val)
|
|
except:
|
|
hwstatsval = None
|
|
|
|
try:
|
|
if state == True:
|
|
if hwstatsval:
|
|
hwstatsval |= protocol.confStandby
|
|
self.conn.set_by_key(hwstatskey, hwstatsval)
|
|
key = data_model.Key(protocol.STRUCT_ID_COMMAND, protocol.MEMBER_ID_COMMAND, 0, protocol.cmdExitStandby)
|
|
self.conn.set_by_key(key, 1)
|
|
retry = 0
|
|
while self.conn.synced == False and retry < 100:
|
|
mytime.sleep(0.1)
|
|
retry += 1
|
|
|
|
wait = 0
|
|
while wait < 10:
|
|
mytime.sleep(0.05)
|
|
wait += 1
|
|
|
|
self.conn.set_by_key(key, 0)
|
|
wait = 0
|
|
while wait < 10:
|
|
mytime.sleep(0.01)
|
|
wait += 1
|
|
|
|
elif hwstatsval:
|
|
hwstatsval &= 4294967295L ^ protocol.confStandby
|
|
self.conn.set_by_key(hwstatskey, hwstatsval)
|
|
key = data_model.Key(protocol.STRUCT_ID_COMMAND, protocol.MEMBER_ID_COMMAND, 0, protocol.cmdGotoStandby)
|
|
self.conn.set_by_key(key, 1)
|
|
retry = 0
|
|
while self.conn.synced == False and retry < 100:
|
|
mytime.sleep(0.1)
|
|
retry += 1
|
|
|
|
wait = 0
|
|
while wait < 10:
|
|
mytime.sleep(0.05)
|
|
wait += 1
|
|
|
|
self.conn.set_by_key(key, 0)
|
|
wait = 0
|
|
while wait < 10:
|
|
mytime.sleep(0.01)
|
|
wait += 1
|
|
|
|
try:
|
|
del self.conn.values[hwstatskey]
|
|
except:
|
|
pass
|
|
|
|
self.conn.get_list.append(hwstatskey)
|
|
except:
|
|
traceback.print_exc(file=sys.stdout)
|
|
|
|
return
|
|
|
|
def getModelFirmwareString(self):
|
|
try:
|
|
self.model_firmware = 0
|
|
key = data_model.Key(protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_MODEL_NUMBER, 0, 0)
|
|
try:
|
|
mf = self.parent.peers.units[self.MAC].values[key].read_val
|
|
if mf > 0:
|
|
self.model_firmware = mf
|
|
print mytime.displayTime(), 'd_p.mf 1 OK', mf
|
|
except:
|
|
print mytime.displayTime(), 'd_p.mf 1', key, 'not in peers'
|
|
|
|
key = data_model.Key(protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_MODEL_NUMBER, 0, 0)
|
|
try:
|
|
mf = self.conn.values[key].read_val
|
|
if mf > 0:
|
|
self.model_firmware = mf
|
|
print mytime.displayTime(), 'd_p.mf 2 OK', mf
|
|
except:
|
|
print mytime.displayTime(), 'd_p.mf 2', key, 'not in conn'
|
|
|
|
key = data_model.Key(protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_MODEL_FIRMWARE, 0, 0)
|
|
try:
|
|
mf = self.parent.peers.units[self.MAC].values[key].read_val
|
|
if mf > 0:
|
|
self.model_firmware = mf
|
|
print mytime.displayTime(), 'd_p.mf 3 OK', mf
|
|
except:
|
|
print mytime.displayTime(), 'd_p.mf 3', key, 'not in peers'
|
|
|
|
key = data_model.Key(protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_MODEL_FIRMWARE, 0, 0)
|
|
try:
|
|
mf = self.conn.values[key].read_val
|
|
if mf > 0:
|
|
self.model_firmware = mf
|
|
print mytime.displayTime(), 'd_p.mf 4 OK', mf
|
|
except:
|
|
print mytime.displayTime(), 'd_p.mf 4', key, 'not in conn'
|
|
|
|
self.model_firmware_string = '_' + str(self.model_firmware)
|
|
print mytime.displayTime() + ' Loading diversity', self.model_firmware_string[1:]
|
|
except:
|
|
traceback.print_exc(file=sys.stdout)
|
|
self.model_firmware_string = ''
|
|
self.model_firmware = 0
|
|
print mytime.displayTime(), 'd_p.mf not found, default 0'
|
|
|
|
return
|
|
|
|
def StartMainUpdate(self, ignore):
|
|
print mytime.displayTime() + ' d_p.Starting Update....'
|
|
self.get_list = []
|
|
if self.action == None:
|
|
print mytime.displayTime() + ' d_p.smu', self.MAC
|
|
key = data_model.Key(protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_USER_ACCESS_RIGHTS, 0, 2)
|
|
key2 = data_model.Key(protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_ACCESS_RIGHTS, 0, 0)
|
|
self.ignore_fw_version = ignore
|
|
self.action = 'start_bootloader'
|
|
print mytime.displayTime() + ' Starting Bootloader....'
|
|
else:
|
|
print mytime.displayTime() + ' Can not start update of', self.MAC + ', current status:', self.action
|
|
return
|
|
self.getModelFirmwareString()
|
|
return
|
|
|
|
def process(self):
|
|
if self.MAC not in one_unit.app.bootloader_progress:
|
|
one_unit.app.bootloader_progress[self.MAC] = None
|
|
if one_unit.app.bootloader_progress[self.MAC] != None:
|
|
if one_unit.app.bootloader_progress[self.MAC] in ('Starting Main Update',
|
|
'(2) Initializing Update Mode....') or one_unit.app.bootloader_progress[self.MAC].find('Erasing') >= 0 or one_unit.app.bootloader_progress[self.MAC].find('(2) Uploading') >= 0:
|
|
print mytime.displayTime(), 'd_p. Restarting Main Update'
|
|
self.fastUpdate = True
|
|
self.action = 'start_main_update'
|
|
if one_unit.app.bootloader_progress[self.MAC] in ('Preparing Flash Image',
|
|
'iets anders'):
|
|
self.action = 'make_image'
|
|
self.completion = 0
|
|
self.started_read_image = False
|
|
if self.parent.peers.units[self.MAC].link_type == 'USB':
|
|
self.usb_process()
|
|
if self.parent.peers.units[self.MAC].link_type == 'Ethernet':
|
|
print mytime.displayTime() + ' d_p.Starting Ethernet process on ', self.parent.peers.units[self.MAC].IP
|
|
self.ethernet_process()
|
|
print mytime.displayTime() + ' d_p.Ethernet process for', self.MAC, 'finished on', self.parent.peers.units[self.MAC].IP
|
|
if one_unit.app.testpc == True:
|
|
self.parent.peers.units[self.MAC].name = 'No Name'
|
|
self.parent.peers.units[self.MAC].link_status = 'disconnected'
|
|
self.conn.set_aborted = True
|
|
self.parent.peers.units[self.MAC].IP = 'Offline'
|
|
self.parent.peers.set_by_key(self.MAC, data_model.Key(protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_CHECK_PIN, 0, 0), None)
|
|
print mytime.displayTime() + ' d_p.Connection with ' + self.MAC + ' Lost'
|
|
return
|
|
|
|
def get_speed(self):
|
|
if self.delay < 0.01:
|
|
return 100
|
|
return int(1 / self.delay)
|
|
|
|
def read_image(self, s):
|
|
if self.started_read_image == False:
|
|
self.started_read_image = True
|
|
cmd = 'DCCOPY__FIRMWARE'
|
|
if s != None:
|
|
s.send(cmd)
|
|
mytime.sleep(0.5)
|
|
if s != None:
|
|
s.send(cmd)
|
|
mytime.sleep(0.5)
|
|
if self.conn.MK2 == True:
|
|
self.completion = 65536 / 512
|
|
s.settimeout(0.5)
|
|
picversion = self.parent.peers.units[self.MAC].PICVersion.split('.')
|
|
picversion_int = int(picversion[0]) * 65536 + int(picversion[1]) * 256 + int(picversion[2])
|
|
if picversion_int > 198410 or self.conn.MK2 == True:
|
|
buflen = 512
|
|
else:
|
|
buflen = 32
|
|
self.length = one_unit.app.image_filesize[self.MAC]
|
|
self.filename = one_unit.app.image_filename[self.MAC]
|
|
block_high = int(self.completion / 256)
|
|
block_low = self.completion - block_high * 256
|
|
start = (self.completion - 1) * buflen
|
|
end = start + buflen
|
|
if end >= self.length - 1:
|
|
last = True
|
|
cmd = chr(0) + 'Q' + chr(block_high) + chr(block_low)
|
|
else:
|
|
last = False
|
|
cmd = chr(0) + 'R' + chr(block_high) + chr(block_low)
|
|
nul = '0' * 24
|
|
cmd += nul
|
|
if s != None:
|
|
s.send(cmd)
|
|
else:
|
|
self.action = 'Exit'
|
|
return
|
|
if self.completion % 100 == 0:
|
|
print mytime.displayTime() + ' Sent Read Command for block', self.completion
|
|
one_unit.updateBootloaderDial(self.MAC, '(2) Copying (' + str(self.completion * 100 / (self.length / buflen)) + '%)', alwaysUpdate=False)
|
|
start_time = mytime.clock()
|
|
send_time = mytime.clock()
|
|
while one_unit.app.application_stopping == False:
|
|
one_unit.tryYield()
|
|
try:
|
|
if s != None:
|
|
new_pkt = s.recv(4096)
|
|
except:
|
|
new_pkt = None
|
|
|
|
if new_pkt != None and len(new_pkt) >= buflen + 3 and ord(new_pkt[0]) == 0 and ord(new_pkt[1]) == 4 and ord(new_pkt[2]) == block_high and ord(new_pkt[3]) == block_low:
|
|
break
|
|
if mytime.clock() - send_time > 0.05:
|
|
send_time = mytime.clock()
|
|
try:
|
|
if s != None:
|
|
s.send(cmd)
|
|
except:
|
|
print mytime.displayTime() + ' d_p.ri.Send Failed'
|
|
traceback.print_exc(file=sys.stdout)
|
|
|
|
if mytime.clock() - start_time > 1:
|
|
one_unit.tryYield()
|
|
print mytime.displayTime() + ' d_p.ri.Timeout for block', self.completion, '-> Attempt to reconnect'
|
|
try:
|
|
self.ethSocket.close()
|
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
s.settimeout(0.5)
|
|
s.connect((self.IP, 50675))
|
|
s.settimeout(0.5)
|
|
self.ethSocket = s
|
|
cmd2 = 'DCCOPY__FIRMWARE'
|
|
if s != None:
|
|
s.send(cmd2)
|
|
mytime.sleep(0.2)
|
|
if s != None:
|
|
s.send(cmd2)
|
|
mytime.sleep(0.2)
|
|
self.ethSocket.send(cmd)
|
|
continue
|
|
except:
|
|
print mytime.displayTime() + ' d_p.ri.TCP/IP Reconnection of ' + self.MAC + ' to ' + self.IP + ' Failed for block', self.completion
|
|
mytime.sleep(0.5)
|
|
else:
|
|
one_unit.tryYield()
|
|
if mytime.clock() - start_time > 30:
|
|
one_unit.tryYield()
|
|
print mytime.displayTime() + ' d_p.ri.Timeout for block', self.completion, '-> aborting (reconenction attempts failed)'
|
|
mytime.sleep(0.5)
|
|
self.action = 'Exit'
|
|
one_unit.updateBootloaderDial(self.MAC, '(2) Flash Image Failed!')
|
|
return
|
|
|
|
if new_pkt != None and len(new_pkt) >= buflen + 5 and ord(new_pkt[0]) == 0 and ord(new_pkt[1]) == 4 and ord(new_pkt[2]) == block_high and ord(new_pkt[3]) == block_low:
|
|
checksum = 170
|
|
for i in range(4, buflen + 4):
|
|
checksum ^= ord(new_pkt[i])
|
|
|
|
if checksum != ord(new_pkt[buflen + 4]):
|
|
print mytime.displayTime() + ' d_p.checksum failed, Retry packet', self.completion, checksum, ord(new_pkt[buflen + 4]), buflen
|
|
if new_pkt != None:
|
|
sv = 'Packet: '
|
|
for c in new_pkt:
|
|
sv += ':' + hex(ord(c))
|
|
|
|
print sv
|
|
return
|
|
if self.completion == 0 or self.completion == 65536 / 512 and self.conn.MK2 == True:
|
|
try:
|
|
os.remove(self.filename)
|
|
except:
|
|
pass
|
|
else:
|
|
try:
|
|
self.target_file = open(self.filename, 'wb')
|
|
except:
|
|
print mytime.displayTime() + ' Failed to open target file'
|
|
one_unit.updateBootloaderDial(self.MAC, 'File Error')
|
|
self.action = 'Exit'
|
|
return
|
|
else:
|
|
try:
|
|
print mytime.displayTime() + ' Opened target file', self.filename, 'for writing', self.length, 'bytes'
|
|
except:
|
|
pass
|
|
else:
|
|
self.update_start_time = mytime.clock()
|
|
if self.completion > 0 or self.conn.MK2 == True:
|
|
self.target_file.write(new_pkt[4:-1])
|
|
self.completion += 1
|
|
one_unit.tryYield()
|
|
if last == True:
|
|
print mytime.displayTime() + ' Finished copy of', self.MAC, 'in', round(mytime.clock() - self.update_start_time, 1), 'seconds'
|
|
self.action = 'Exit'
|
|
self.target_file.close()
|
|
mytime.sleep(1.1)
|
|
one_unit.updateBootloaderDial(self.MAC, 'Compacting...')
|
|
one_unit.tryYield()
|
|
try:
|
|
if self.conn.MK2 == True:
|
|
sectorSize = one_unit.app.image_sector_size[self.MAC]
|
|
slotSize = one_unit.app.image_slot_size[self.MAC]
|
|
flashDiskStartAddress = one_unit.app.image_start_address[self.MAC] - one_unit.app.update_image_start_address[self.MAC]
|
|
try:
|
|
print mytime.displayTime(), 'd_p.check clean', self.filename, slotSize, flashDiskStartAddress, sectorSize
|
|
except:
|
|
pass
|
|
else:
|
|
if sectorSize != None and slotSize != None:
|
|
cleanImage.cleanImage(self.filename, self.filename, 1, flashDiskStartAddress, sectorSize, 50)
|
|
cmd = 'DCRESARTFIRMWARE'
|
|
if s != None:
|
|
try:
|
|
s.send(cmd)
|
|
except:
|
|
pass
|
|
|
|
self.conn.got_basic_info = False
|
|
zfile = zipfile.ZipFile(self.filename + 'zip', 'w')
|
|
zfile.write(self.filename, os.path.split(self.filename)[1], compress_type=zipfile.ZIP_DEFLATED)
|
|
try:
|
|
type = self.parent.peers.units[self.MAC].type + '_' + str(self.conn.model_number)
|
|
except:
|
|
type = 'Unknown'
|
|
|
|
type = encode(type, 'djkfhnsakdjvdlkf')
|
|
zfile.writestr('/info.lst', type)
|
|
zfile.close()
|
|
os.remove(self.filename)
|
|
os.rename(self.filename + 'zip', self.filename)
|
|
try:
|
|
print mytime.displayTime() + ' Closed target file', self.filename
|
|
except:
|
|
pass
|
|
|
|
mytime.sleep(1.1)
|
|
one_unit.updateBootloaderDial(self.MAC, 'Restarting...')
|
|
one_unit.tryYield()
|
|
except:
|
|
print mytime.displayTime(), 'd_p.ri.problem in file operation'
|
|
traceback.print_exc(file=sys.stdout)
|
|
one_unit.updateBootloaderDial(self.MAC, 'Create Flash Image Failed, file access problem')
|
|
one_unit.tryYield()
|
|
|
|
return
|
|
|
|
def verifyNIC(self):
|
|
numberOfNIC = 0
|
|
retry = 5
|
|
while retry > 0:
|
|
try:
|
|
one_unit.check_interfaces()
|
|
except:
|
|
traceback.print_exc(file=sys.stdout)
|
|
|
|
for adapter in one_unit.app.LAN_adapters:
|
|
if one_unit.app.LAN_adapters[adapter].IPv4 not in ('none', 'None',
|
|
None) or one_unit.app.LAN_adapters[adapter].IPv6 not in ('none',
|
|
'None',
|
|
None):
|
|
numberOfNIC += 1
|
|
|
|
print mytime.displayTime(), 'd_p.vN.Verify NIC: Counted', numberOfNIC, 'network ports'
|
|
if numberOfNIC == 1:
|
|
break
|
|
retry -= 1
|
|
mytime.sleep(0.1)
|
|
|
|
return numberOfNIC
|
|
|
|
def start_bootloader(self, s):
|
|
print mytime.displayTime() + ' d_p.start_bootloader 1'
|
|
if self.action == 'start_bootloader':
|
|
self.parent.peers.units[self.MAC].preset_names = {}
|
|
self.parent.peers.units[self.MAC].values = {}
|
|
key2 = data_model.Key(protocol.STRUCT_ID_COMMAND, protocol.MEMBER_ID_COMMAND, 0, protocol.cmdGotoStandby)
|
|
print mytime.displayTime() + ' d_p.sb.Setting Hardware to standby...'
|
|
self.conn.set_by_key(key2, 1)
|
|
self.start_bootloader_time = mytime.clock()
|
|
one_unit.updateBootloaderDial(self.MAC, getString('sts'), statusInfo=one_unit.app.bootloaderStatus[self.MAC] | infoStatusSettingToStandby)
|
|
print mytime.displayTime() + ' d_p.sb.Setting to Standby'
|
|
self.action = 'start bootloader standby delay'
|
|
mytime.sleep(0.1)
|
|
return
|
|
else:
|
|
if one_unit.app.bootloader_mode == True:
|
|
self.action = 'start_main_update'
|
|
mytime.sleep(0.1)
|
|
return
|
|
if self.parent.peers.units[self.MAC].link_type == 'USB':
|
|
self.action = 'start_main_update'
|
|
mytime.sleep(0.1)
|
|
return
|
|
version = one_unit.app.Version
|
|
try:
|
|
version = one_unit.app.pic_version
|
|
except:
|
|
print mytime.displayTime() + ' Default interface version not found'
|
|
|
|
try:
|
|
version = one_unit.app.pic_versions[self.parent.peers.units[self.MAC].type]
|
|
except:
|
|
pass
|
|
|
|
if self.parent.peers.units[self.MAC].PICVersion == version:
|
|
one_unit.updateBootloaderDial(self.MAC, getString('vfv'), statusInfo=infoStatusVerifyingFirmwareVersion | infoStatusInterfaceUpdate | infoStatusRunning)
|
|
mytime.sleep(1)
|
|
one_unit.tryYield()
|
|
mytime.sleep(1)
|
|
one_unit.tryYield()
|
|
print mytime.displayTime() + ' Interface up-to-date, version', version
|
|
self.action = 'start_main_update'
|
|
return
|
|
if one_unit.app.updating_all == True or one_unit.app.interfaceUpdate[self.MAC] == False:
|
|
one_unit.updateBootloaderDial(self.MAC, 'Ignoring Interface')
|
|
print mytime.displayTime() + ' Ignoring Interface version, found version ', self.parent.peers.units[self.MAC].PICVersion
|
|
self.action = 'start_main_update'
|
|
return
|
|
if one_unit.app.bootloader_ok == False and self.conn.MK2 == False:
|
|
one_unit.app.enable_bootloader = False
|
|
self.action = None
|
|
print mytime.displayTime() + ' Bootloader server not running, aborting'
|
|
one_unit.updateBootloaderDial(self.MAC, None)
|
|
wx.MessageBox('Error: unable to access network port. This may be caused by an internal computer error. Please restart your system.')
|
|
return
|
|
if self.conn.MK2 == True:
|
|
one_unit.app.enable_bootloader = False
|
|
self.action = 'start_main_update'
|
|
one_unit.updateBootloaderDial(self.MAC, None)
|
|
return
|
|
no_of_interfaces = self.verifyNIC()
|
|
if no_of_interfaces > 1:
|
|
print mytime.displayTime(), 'Verify NIC failed:', no_of_interfaces
|
|
res = wx.MessageBox('Error: Multiple active network ports. The network interface update will be skipped.', 'Multiple NIC detected', wx.OK)
|
|
one_unit.app.enable_bootloader = False
|
|
self.action = 'start_main_update'
|
|
one_unit.updateBootloaderDial(self.MAC, None)
|
|
return
|
|
if no_of_interfaces == 0:
|
|
print mytime.displayTime(), 'Verify NIC failed:', no_of_interfaces
|
|
res = wx.MessageBox('Warning: Could not detect active network ports. Please make sure one and only one network port is active for this update.', 'No NIC detected', wx.OK)
|
|
print mytime.displayTime() + ' Updating Interface from', self.parent.peers.units[self.MAC].PICVersion, 'to', version
|
|
one_unit.app.enable_bootloader = True
|
|
if self.action == 'start bootloader standby delay':
|
|
if one_unit.app.interfaceUpdate[self.MAC] == True:
|
|
if one_unit.app.bootloaderStatus['Bootloader'] & infoStatusProgressMask != infoStatusStart:
|
|
print mytime.displayTime(), 'd_p.Bootloader running, exiting', hex(one_unit.app.bootloaderStatus['Bootloader'])
|
|
self.action = 'Exit'
|
|
return
|
|
cmd = 'DDReset_Interface'
|
|
one_unit.updateBootloaderDial(self.MAC, getString('vfv'), statusInfo=infoStatusInterfaceUpdate | infoStatusRunning)
|
|
mytime.sleep(1)
|
|
one_unit.tryYield()
|
|
start_time = mytime.clock()
|
|
interval = 0
|
|
while one_unit.app.application_stopping == False:
|
|
print mytime.displayTime(), 'd_p.reset interface looping'
|
|
mytime.sleep(0.1)
|
|
if interval % 30 == 0:
|
|
tmpLoop = 10
|
|
while tmpLoop > 0:
|
|
tmpLoop -= 1
|
|
try:
|
|
s.send(cmd)
|
|
print mytime.displayTime(), 'd_p.reset interface command sent'
|
|
except:
|
|
self.action = 'wait_for_bootloader'
|
|
try:
|
|
s.close()
|
|
except:
|
|
pass
|
|
|
|
return
|
|
|
|
interval += 1
|
|
try:
|
|
if one_unit.app.bootloaderStatus['Bootloader'] & (infoStatusProcessmask | infoStatusResetOK) == infoStatusInterfaceUpdate | infoStatusResetOK:
|
|
self.action = 'wait_for_bootloader'
|
|
return
|
|
except:
|
|
pass
|
|
|
|
if mytime.clock() - start_time > 25:
|
|
print mytime.displayTime() + ' d_p.sb.Reset Timeout'
|
|
one_unit.updateBootloaderDial(self.MAC, 'Please power cycle the unit.')
|
|
break
|
|
|
|
else:
|
|
self.action = 'start_main_update'
|
|
return
|
|
|
|
def getFirmwareFile(self):
|
|
try:
|
|
self.conn.MK2 = one_unit.app.MK2[self.MAC]
|
|
print mytime.displayTime(), 'd_p.gFF.set MK2 from app for', self.MAC, self.conn.MK2
|
|
except:
|
|
pass
|
|
|
|
try:
|
|
if self.conn.MK2 == True and self.parent.peers.units[self.MAC].link_type == 'Ethernet':
|
|
extension = 'dfu'
|
|
else:
|
|
extension = 'dfi'
|
|
self.broadcasted_skin = self.parent.peers.units[self.MAC].type
|
|
try:
|
|
model_firmware_string = one_unit.app.lastModelFirmwareString[self.MAC]
|
|
print mytime.displayTime(), 'd_p.gFF.mf from app', model_firmware_string
|
|
fName = one_unit.app.cwd + '/dfi/' + self.broadcasted_skin + model_firmware_string + '.' + extension
|
|
datafile = open(os.path.normpath(fName), 'rb')
|
|
self.data = datafile.read()
|
|
datafile.close()
|
|
self.model_firmware_string = model_firmware_string
|
|
print mytime.displayTime() + ' Found', fName
|
|
return
|
|
except:
|
|
pass
|
|
|
|
model_firmware_string = ''
|
|
self.getModelFirmwareString()
|
|
try:
|
|
model_firmware_string = self.model_firmware_string
|
|
fName = one_unit.app.cwd + '/dfi/' + self.broadcasted_skin + model_firmware_string + '.' + extension
|
|
print mytime.displayTime(), 'd_p.gFF.full file name:', self.broadcasted_skin + model_firmware_string + '.' + extension
|
|
datafile = open(os.path.normpath(fName), 'rb')
|
|
self.data = datafile.read()
|
|
datafile.close()
|
|
print mytime.displayTime() + ' d_p.Found', fName
|
|
one_unit.app.lastModelFirmwareString[self.MAC] = model_firmware_string
|
|
except:
|
|
print mytime.displayTime() + ' d_p.Not Found: ', one_unit.app.cwd + '/dfi/' + self.broadcasted_skin + model_firmware_string + '.' + extension
|
|
try:
|
|
if model_firmware_string == '':
|
|
print mytime.displayTime() + ' Trying model 0'
|
|
model_firmware_string = '_0'
|
|
else:
|
|
print mytime.displayTime() + ' Trying without model number'
|
|
model_firmware_string = ''
|
|
fName = one_unit.app.cwd + '/dfi/' + self.broadcasted_skin + model_firmware_string + '.' + extension
|
|
datafile = open(os.path.normpath(fName), 'rb')
|
|
self.data = datafile.read()
|
|
datafile.close()
|
|
self.model_firmware_string = model_firmware_string
|
|
print mytime.displayTime() + ' Found', fName
|
|
one_unit.app.lastModelFirmwareString[self.MAC] = model_firmware_string
|
|
except:
|
|
print mytime.displayTime() + ' Not Found: ', one_unit.app.cwd + '/dfi/' + self.broadcasted_skin + model_firmware_string + '.' + extension
|
|
try:
|
|
print mytime.displayTime() + ' Trying model 0'
|
|
model_firmware_string = '_0'
|
|
datafile = open(os.path.normpath(one_unit.app.cwd + '/dfi/' + self.broadcasted_skin + model_firmware_string + '.' + extension), 'rb')
|
|
self.data = datafile.read()
|
|
datafile.close()
|
|
self.model_firmware_string = model_firmware_string
|
|
print mytime.displayTime() + ' Found', one_unit.app.cwd + '/dfi/' + self.broadcasted_skin + model_firmware_string + '.' + extension
|
|
except:
|
|
found_fw = False
|
|
print mytime.displayTime() + ' Not Found: ', one_unit.app.cwd + '/dfi/' + self.broadcasted_skin + model_firmware_string + '.' + extension
|
|
print mytime.displayTime() + ' Trying to find matching firmware....'
|
|
for testfw in range(100):
|
|
if os.path.exists(os.path.normpath(one_unit.app.cwd + '/dfi/' + self.broadcasted_skin + '_' + str(testfw) + '.' + extension)):
|
|
self.model_firmware_string = '_' + str(testfw)
|
|
print mytime.displayTime() + ' Found ', one_unit.app.cwd + '/dfi/' + self.broadcasted_skin + self.model_firmware_string + '.' + extension
|
|
found_fw = True
|
|
one_unit.app.lastModelFirmwareString[self.MAC] = model_firmware_string
|
|
break
|
|
|
|
if found_fw == False:
|
|
self.data = ''
|
|
print mytime.displayTime() + ' Unsupported hardware type 1:', self.broadcasted_skin
|
|
self.action = None
|
|
one_unit.updateBootloaderDial(self.MAC, '(2) Unsupported Type')
|
|
return
|
|
|
|
except:
|
|
traceback.print_exc(file=sys.stdout)
|
|
|
|
return
|
|
|
|
def upload_main_firmware(self, s, ser=None):
|
|
if one_unit.app.interfaceUpdate[self.MAC] == True or one_unit.app.application_stopping == True:
|
|
self.action = None
|
|
return
|
|
else:
|
|
try:
|
|
if int(self.parent.peers.units[self.MAC].HWVersion[0]) == 3 and int(self.parent.peers.units[self.MAC].HWVersion[2]) == 6 and self.parent.peers.units[self.MAC].link_type == 'Ethernet' and int(self.parent.peers.units[self.MAC].HWVersion[4]) <= 4:
|
|
self.action = None
|
|
one_unit.updateBootloaderDial(self.MAC, 'USB Update Only')
|
|
print mytime.displayTime(), 'd_p. HW too old for Ethernet update, HW version', self.parent.peers.units[self.MAC].HWVersion
|
|
return
|
|
except:
|
|
pass
|
|
|
|
if self.parent.peers.units[self.MAC].link_type == 'Ethernet':
|
|
try:
|
|
s.settimeout(0.03)
|
|
except:
|
|
pass
|
|
|
|
picversion = self.parent.peers.units[self.MAC].PICVersion.split('.')
|
|
picversion_int = int(picversion[0]) * 65536 + int(picversion[1]) * 256 + int(picversion[2])
|
|
if self.conn.MK2 == True and self.parent.peers.units[self.MAC].link_type == 'Ethernet':
|
|
extension = 'dfu'
|
|
else:
|
|
extension = 'dfi'
|
|
if picversion_int > 198410 or self.conn.MK2 == True:
|
|
buflen = 512
|
|
else:
|
|
buflen = 32
|
|
try:
|
|
self.length = len(self.data) / buflen
|
|
except:
|
|
pass
|
|
|
|
if self.action == 'start_main_update':
|
|
if one_unit.app.image_filename[self.MAC] == None:
|
|
self.getFirmwareFile()
|
|
self.length = len(self.data) / buflen
|
|
if one_unit.app.bootloader_mode == True:
|
|
start_time = mytime.clock()
|
|
while True:
|
|
if mytime.clock() - start_time > 10:
|
|
one_unit.updateBootloaderDial(self.MAC, 'FAIL')
|
|
self.action = None
|
|
return
|
|
DSPState = self.parent.peers.units[self.MAC].DSPState
|
|
if DSPState != None:
|
|
if DSPState == 1:
|
|
one_unit.updateBootloaderDial(self.MAC, 'PASS')
|
|
self.action = None
|
|
return
|
|
if DSPState != 67 and self.action == 'start_main_update':
|
|
print mytime.displayTime() + ' Blank Device'
|
|
break
|
|
else:
|
|
mytime.sleep(0.1)
|
|
continue
|
|
|
|
else:
|
|
version = one_unit.app.Version
|
|
try:
|
|
version = one_unit.app.fw_version
|
|
except:
|
|
print mytime.displayTime() + ' Default firmware version not found'
|
|
else:
|
|
try:
|
|
version = one_unit.app.fw_versions[self.parent.peers.units[self.MAC].type]
|
|
except:
|
|
pass
|
|
else:
|
|
if self.parent.peers.units[self.MAC].FWVersion == version and self.ignore_fw_version != 'i':
|
|
one_unit.updateBootloaderDial(self.MAC, 'Firmware OK')
|
|
print mytime.displayTime() + ' Firmware up-to-date, version', version
|
|
self.action = None
|
|
return
|
|
print mytime.displayTime() + ' Updating Main Firmware of', self.MAC, 'from', self.parent.peers.units[self.MAC].FWVersion, 'to', version
|
|
self.parent.peers.clear_preset_names(self.MAC)
|
|
self.parent.peers.units[self.MAC].values = {}
|
|
self.parent.peers.units[self.MAC].link_status = 'Updating Firmware'
|
|
self.update_start_time = mytime.clock()
|
|
cmd = 'DDUPLOADFIRMWARE'
|
|
self.conn.got_basic_info = False
|
|
print mytime.displayTime() + ' d_p.Initiating Firmware Update Mode'
|
|
if one_unit.app.image_filename[self.MAC] == None:
|
|
one_unit.updateBootloaderDial(self.MAC, '(2) Initializing Update Mode....')
|
|
else:
|
|
one_unit.updateBootloaderDial(self.MAC, '(2) Initializing Flash Load....')
|
|
if s != None:
|
|
s.send(cmd)
|
|
else:
|
|
try:
|
|
ser.write(cmd)
|
|
except:
|
|
print mytime.displayTime() + ' Connection Interrupted'
|
|
self.action = None
|
|
one_unit.updateBootloaderDial(self.MAC, '(2) Failed!')
|
|
return
|
|
|
|
mytime.sleep(0.1)
|
|
if s != None:
|
|
s.send(cmd)
|
|
else:
|
|
try:
|
|
ser.write(cmd)
|
|
except:
|
|
print mytime.displayTime() + ' Connection Interrupted'
|
|
self.action = None
|
|
one_unit.updateBootloaderDial(self.MAC, '(2) Failed!')
|
|
return
|
|
|
|
mytime.sleep(0.1)
|
|
if s != None:
|
|
s.send(cmd)
|
|
else:
|
|
try:
|
|
ser.write(cmd)
|
|
except:
|
|
print mytime.displayTime() + ' Connection Interrupted'
|
|
self.action = None
|
|
one_unit.updateBootloaderDial(self.MAC, '(2) Failed!')
|
|
return
|
|
|
|
if one_unit.app.image_filename[self.MAC] != None:
|
|
print mytime.displayTime() + ' d_p.umf.Loading Flash Image File into', self.MAC
|
|
else:
|
|
print mytime.displayTime() + ' d_p.umf.Starting Main Firmware Update of', self.MAC
|
|
self.completion = 'erasing'
|
|
mytime.sleep(0.1)
|
|
start_time = mytime.clock()
|
|
startUpdateLinkCounter = 0
|
|
while one_unit.app.application_stopping == False:
|
|
try:
|
|
if s != None:
|
|
if self.conn.MK2 == True:
|
|
s.send(cmd)
|
|
mytime.sleep(0.1)
|
|
startUpdateLinkCounter += 1
|
|
print mytime.displayTime() + ' d_p.smu.counting', startUpdateLinkCounter, startUpdateLinkCounter % 30
|
|
if startUpdateLinkCounter % 5 == 0:
|
|
print mytime.displayTime(), 'Resetting connection 4.0'
|
|
try:
|
|
self.ethSocket.close()
|
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
s.settimeout(2)
|
|
s.connect((self.IP, 50675))
|
|
s.settimeout(0.5)
|
|
self.ethSocket = s
|
|
self.ethSocket.send(cmd)
|
|
print mytime.displayTime() + ' d_p.ep.Reconnected', self.MAC, 'to', self.IP
|
|
continue
|
|
except:
|
|
print mytime.displayTime() + ' d_p.ep.TCP/IP Reconnection of ' + self.MAC + ' to ' + self.IP + ' Failed'
|
|
mytime.sleep(0.1)
|
|
continue
|
|
|
|
new_pkt = s.recv(4096)
|
|
else:
|
|
l = ser.inWaiting()
|
|
if l > 0:
|
|
new_pkt = ser.read(l)
|
|
else:
|
|
new_pkt = None
|
|
except:
|
|
mytime.sleep(0.1)
|
|
new_pkt = None
|
|
|
|
if new_pkt != None and len(new_pkt) > 7:
|
|
print mytime.displayTime() + ' Update Link -> Got packet:', readableHEX(new_pkt[:20])
|
|
break
|
|
one_unit.tryYield()
|
|
if mytime.clock() - start_time > 30:
|
|
new_pkt = None
|
|
self.action = None
|
|
print mytime.displayTime() + ' Set Hardware to Update mode: Link Timeout'
|
|
one_unit.updateBootloaderDial(self.MAC, '(2) Failed!')
|
|
one_unit.app.image_filename[self.MAC] = None
|
|
return
|
|
|
|
if one_unit.app.application_stopping:
|
|
return
|
|
one_unit.tryYield()
|
|
if ord(new_pkt[0]) == 0 and ord(new_pkt[1]) == 1 and ord(new_pkt[2]) == 66 and ord(new_pkt[3]) == 76:
|
|
skin_high = unicode(ord(new_pkt[4]))
|
|
skin_mid = unicode(ord(new_pkt[5]))
|
|
skin_low = unicode(ord(new_pkt[6]))
|
|
self.broadcasted_skin = skin_high + '_' + skin_mid + '_' + skin_low
|
|
try:
|
|
self.broadcasted_skin = one_unit.app.type_replacements[self.broadcasted_skin]
|
|
except:
|
|
pass
|
|
else:
|
|
if self.broadcasted_skin == self.parent.peers.units[self.MAC].type:
|
|
self.action = 'updating_main_firmware'
|
|
self.completion = 'erasing'
|
|
print mytime.displayTime() + ' d_p.Update Link Established'
|
|
if s != None:
|
|
s.settimeout(0.5)
|
|
loop = 20
|
|
while loop > 0:
|
|
loop -= 1
|
|
try:
|
|
new_pkt = s.recv(4096)
|
|
except:
|
|
pass
|
|
|
|
s.settimeout(0.5)
|
|
print mytime.displayTime() + ' d_p.going to Erase mode'
|
|
return
|
|
else:
|
|
print mytime.displayTime() + ' d_p.Broadcasted skin does not match unit type, got', self.broadcasted_skin, 'but unit type is', self.parent.peers.units[self.MAC].type
|
|
one_unit.app.image_filename[self.MAC] = None
|
|
return
|
|
elif self.action == 'updating_main_firmware':
|
|
if self.completion == 'erasing':
|
|
if s != None:
|
|
try:
|
|
s.settimeout(0.5)
|
|
except:
|
|
try:
|
|
s.close()
|
|
except:
|
|
pass
|
|
else:
|
|
try:
|
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
s.settimeout(0.5)
|
|
s.connect((self.IP, 50675))
|
|
s.settimeout(0.5)
|
|
self.ethSocket = s
|
|
print mytime.displayTime(), 'd_p.umf.12.TCP/IP Connection restored'
|
|
except:
|
|
print mytime.displayTime() + ' d_p.umf.12.TCP/IP Connection of ' + self.MAC + ' to ' + self.IP + ' Failed'
|
|
return
|
|
|
|
else:
|
|
loop = 2
|
|
while loop > 0:
|
|
loop -= 1
|
|
try:
|
|
new_pkt = s.recv(4096)
|
|
except:
|
|
pass
|
|
|
|
print mytime.displayTime(), 'd_p.umf.2'
|
|
counter = 0
|
|
erasecounter = 0
|
|
one_unit.tryYield()
|
|
if False:
|
|
cmd = chr(0) + chr(2) + 'dfdg_dfv' + chr(0) + 'netascii' + chr(0)
|
|
print mytime.displayTime() + ' d_p.partial erase!!!!!!!'
|
|
else:
|
|
cmd = chr(0) + chr(2) + 'dddd.dfi' + chr(0) + 'netascii' + chr(0)
|
|
print mytime.displayTime() + ' d_p.full erase'
|
|
if s != None:
|
|
try:
|
|
s.send(cmd)
|
|
except:
|
|
self.action = 'Exit'
|
|
print mytime.displayTime() + ' d_p.umf.s.send failed'
|
|
traceback.print_exc(file=sys.stdout)
|
|
return
|
|
|
|
else:
|
|
try:
|
|
ser.write(cmd)
|
|
except:
|
|
print mytime.displayTime() + ' Connection Interrupted'
|
|
self.action = None
|
|
one_unit.updateBootloaderDial(self.MAC, '(2) Failed!')
|
|
one_unit.app.image_filename[self.MAC] = None
|
|
return
|
|
|
|
timeout = 60
|
|
if one_unit.app.image_filesize[self.MAC] >= 4194304:
|
|
timeout = 90
|
|
if one_unit.app.image_filesize[self.MAC] >= 8388608:
|
|
timeout = 180
|
|
if self.conn.MK2 == False and self.parent.peers.units[self.MAC].link_type == 'Ethernet':
|
|
timeout = 10
|
|
print mytime.displayTime() + ' Erasing', self.MAC, 'with timeout', timeout
|
|
one_unit.updateBootloaderDial(self.MAC, '(2) Erasing....')
|
|
one_unit.tryYield()
|
|
mytime.sleep(0.1)
|
|
new_pkt = None
|
|
start_time = mytime.clock()
|
|
while one_unit.app.application_stopping == False:
|
|
one_unit.tryYield()
|
|
mytime.sleep(0.01)
|
|
try:
|
|
if s != None:
|
|
new_pkt = s.recv(4096)
|
|
else:
|
|
l = ser.inWaiting()
|
|
if l > 0:
|
|
l = ser.inWaiting()
|
|
new_pkt = ser.read(l)
|
|
else:
|
|
new_pkt = None
|
|
mytime.sleep(1)
|
|
erasecounter += 1
|
|
except:
|
|
mytime.sleep(1)
|
|
erasecounter += 1
|
|
one_unit.tryYield()
|
|
new_pkt = None
|
|
|
|
one_unit.updateBootloaderDial(self.MAC, '(2) Erasing, less than ' + str(timeout - erasecounter) + ' seconds remaining', alwaysUpdate=False)
|
|
if new_pkt != None:
|
|
print mytime.displayTime() + ' Erase -> Got packet (' + str(len(new_pkt)) + ' bytes):', readableHEX(new_pkt)
|
|
if len(new_pkt) > 2 and ord(new_pkt[0]) == 0 and ord(new_pkt[1]) == 4:
|
|
break
|
|
if len(new_pkt) == 8 and ord(new_pkt[0]) == 0 and ord(new_pkt[1]) == 1 and ord(new_pkt[2]) == 66 and ord(new_pkt[3]) == 76:
|
|
if False:
|
|
cmd = chr(0) + chr(2) + 'dfdg_dfv' + chr(0) + 'netascii' + chr(0)
|
|
print mytime.displayTime() + ' d_p. resend partial erase!!!!!!!'
|
|
else:
|
|
cmd = chr(0) + chr(2) + 'dddd.dfi' + chr(0) + 'netascii' + chr(0)
|
|
print mytime.displayTime() + ' d_p. resend full erase'
|
|
if s != None:
|
|
try:
|
|
s.send(cmd)
|
|
except:
|
|
self.action = 'Exit'
|
|
print mytime.displayTime() + ' d_p.umf.s.send failed'
|
|
traceback.print_exc(file=sys.stdout)
|
|
return
|
|
|
|
else:
|
|
try:
|
|
ser.write(cmd)
|
|
except:
|
|
print mytime.displayTime() + ' Connection Interrupted'
|
|
self.action = None
|
|
one_unit.updateBootloaderDial(self.MAC, '(2) Failed!')
|
|
one_unit.app.image_filename[self.MAC] = None
|
|
return
|
|
|
|
if len(new_pkt) == 0:
|
|
print mytime.displayTime(), 'd_p. nul bytes packet, wat gaan we doen? -> reset connection and start_main_update'
|
|
self.action = 'start_main_update'
|
|
s.close()
|
|
try:
|
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
s.settimeout(0.5)
|
|
s.connect((self.IP, 50675))
|
|
s.settimeout(0.5)
|
|
self.ethSocket = s
|
|
print mytime.displayTime(), 'd_p.umf.1.TCP/IP Connection restored'
|
|
except:
|
|
print mytime.displayTime() + ' d_p.umf.1.TCP/IP Connection of ' + self.MAC + ' to ' + self.IP + ' Failed'
|
|
|
|
return
|
|
if mytime.clock() - start_time < 5 and new_pkt != None and len(new_pkt) == 0:
|
|
print mytime.displayTime() + ' Resending Erase command...'
|
|
if s != None:
|
|
s.send(cmd)
|
|
else:
|
|
try:
|
|
ser.write(cmd)
|
|
except:
|
|
print mytime.displayTime() + ' Connection Interrupted'
|
|
self.action = None
|
|
one_unit.updateBootloaderDial(self.MAC, '(2) Failed!')
|
|
one_unit.app.image_filename[self.MAC] = None
|
|
return
|
|
|
|
mytime.sleep(1)
|
|
if mytime.clock() - start_time > timeout:
|
|
print mytime.displayTime() + ' Erase Timeout'
|
|
one_unit.updateBootloaderDial(self.MAC, '(2) Erase Failed (1)!')
|
|
self.action = None
|
|
one_unit.app.image_filename[self.MAC] = None
|
|
break
|
|
|
|
if new_pkt != None and len(new_pkt) > 2 and ord(new_pkt[0]) == 0 and ord(new_pkt[1]) == 4:
|
|
print mytime.displayTime() + ' d_p.Erase OK, erase tijd:', mytime.clock() - start_time
|
|
one_unit.updateBootloaderDial(self.MAC, '(2) Erase OK')
|
|
resend_counter = 0
|
|
if s != None:
|
|
s.settimeout(0.5)
|
|
loop = 20
|
|
while loop > 0:
|
|
one_unit.tryYield()
|
|
loop -= 1
|
|
try:
|
|
new_pkt = s.recv(4096)
|
|
except:
|
|
pass
|
|
|
|
s.settimeout(0.5)
|
|
self.completion = 1
|
|
model_firmware_string = ''
|
|
if one_unit.app.image_filename[self.MAC] != None:
|
|
datafile = open(one_unit.app.image_filename[self.MAC], 'rb')
|
|
self.data = datafile.read()[:one_unit.app.image_filesize[self.MAC]]
|
|
datafile.close()
|
|
try:
|
|
print mytime.displayTime() + ' Starting upload of', one_unit.app.image_filename[self.MAC], 'to', self.MAC
|
|
except:
|
|
pass
|
|
|
|
else:
|
|
try:
|
|
model_firmware_string = self.model_firmware_string
|
|
datafile = open(os.path.normpath(one_unit.app.cwd + '/dfi/' + self.broadcasted_skin + model_firmware_string + '.' + extension), 'rb')
|
|
self.data = datafile.read()
|
|
datafile.close()
|
|
try:
|
|
print mytime.displayTime() + ' Starting upload of', self.broadcasted_skin + model_firmware_string + '.' + extension + ' to', self.MAC
|
|
except:
|
|
pass
|
|
|
|
except:
|
|
try:
|
|
print mytime.displayTime() + ' Not found:', self.broadcasted_skin + model_firmware_string
|
|
if model_firmware_string == '':
|
|
model_firmware_string = '_0'
|
|
else:
|
|
model_firmware_string = ''
|
|
print mytime.displayTime() + ' Trying:', self.broadcasted_skin + model_firmware_string
|
|
datafile = open(os.path.normpath(one_unit.app.cwd + '/dfi/' + self.broadcasted_skin + model_firmware_string + '.' + extension), 'rb')
|
|
self.data = datafile.read()
|
|
datafile.close()
|
|
try:
|
|
print mytime.displayTime() + ' Starting upload of', self.broadcasted_skin + model_firmware_string + '.' + extension + ' to', self.MAC
|
|
except:
|
|
pass
|
|
|
|
except:
|
|
self.data = ''
|
|
print mytime.displayTime() + ' Unsupported hardware type 2:', self.broadcasted_skin + self.model_firmware_string
|
|
self.action = None
|
|
one_unit.updateBootloaderDial(self.MAC, '(2) Unsupported Type')
|
|
one_unit.app.image_filename[self.MAC] = None
|
|
return
|
|
|
|
self.length = len(self.data) / buflen
|
|
elif new_pkt != None:
|
|
print mytime.displayTime() + ' Got invalid packet:',
|
|
print [_[1] for i in new_pkt]
|
|
one_unit.updateBootloaderDial(self.MAC, '(2) Erase Failed!')
|
|
if s != None and self.conn.MK2 == True:
|
|
try:
|
|
cmd = chr(0) + chr(7) + chr(0) + chr(0)
|
|
nul = '0' * buflen
|
|
cmd += nul
|
|
cmd = cmd[:buflen + 4]
|
|
s.send(cmd)
|
|
except:
|
|
print mytime.displayTime(), 'd_p.umf.Sending Abort command failed'
|
|
traceback.print_exc(file=sys.stdout)
|
|
|
|
self.action = None
|
|
one_unit.app.image_filename[self.MAC] = None
|
|
return
|
|
one_unit.tryYield()
|
|
page_empty = False
|
|
while one_unit.app.application_stopping == False:
|
|
if self.conn.MK2 == True:
|
|
block_high = int((self.completion - 1) / 256)
|
|
block_low = self.completion - 1 - block_high * 256
|
|
else:
|
|
block_high = int(self.completion / 256)
|
|
block_low = self.completion - block_high * 256
|
|
start = (self.completion - 1) * buflen
|
|
end = start + buflen
|
|
page_empty = True
|
|
if end >= len(self.data) - 1:
|
|
break
|
|
for i in range(0, buflen):
|
|
if ord(self.data[start + i]) != 255:
|
|
page_empty = False
|
|
break
|
|
|
|
if page_empty and self.completion < self.length:
|
|
self.completion += 1
|
|
else:
|
|
break
|
|
|
|
if end >= len(self.data) - 1:
|
|
print mytime.displayTime() + ' Last Packet', self.completion, 'of', self.length, 'data length:', len(self.data), 'bytes'
|
|
last = True
|
|
cmd = chr(0) + chr(7) + chr(block_high) + chr(block_low) + self.data[start:]
|
|
nul = '0' * buflen
|
|
cmd += nul
|
|
cmd = cmd[:buflen + 4]
|
|
else:
|
|
last = False
|
|
cmd = chr(0) + chr(3) + chr(block_high) + chr(block_low) + self.data[start:end]
|
|
if s != None:
|
|
try:
|
|
s.send(cmd)
|
|
except:
|
|
traceback.print_exc(file=sys.stdout)
|
|
|
|
else:
|
|
try:
|
|
ser.write(cmd)
|
|
except:
|
|
print mytime.displayTime() + ' Connection Interrupted'
|
|
self.action = None
|
|
one_unit.updateBootloaderDial(self.MAC, '(2) Failed!')
|
|
one_unit.app.image_filename[self.MAC] = None
|
|
return
|
|
|
|
percent_completion = self.completion * 100 / self.length
|
|
if percent_completion > 100:
|
|
percent_completion = 100
|
|
one_unit.updateBootloaderDial(self.MAC, '(2) Uploading packet ' + str(self.completion) + ' of ' + str(self.length + 1) + ' (' + str(percent_completion) + '%)', alwaysUpdate=False)
|
|
one_unit.tryYield()
|
|
if mytime.clock() - self.lastPrintTime > 0:
|
|
print mytime.displayTime() + ' (2) Uploading (' + str(percent_completion) + '%)', self.completion - 1, 'of', self.length
|
|
self.lastPrintTime = mytime.clock()
|
|
start_time = mytime.clock()
|
|
send_time = mytime.clock()
|
|
resend_counter = 0
|
|
while one_unit.app.application_stopping == False:
|
|
try:
|
|
if s != None:
|
|
new_pkt = s.recv(4096)
|
|
else:
|
|
l = ser.inWaiting()
|
|
if l > 0:
|
|
new_pkt = ser.read(l)
|
|
else:
|
|
new_pkt = ' '
|
|
except:
|
|
new_pkt = None
|
|
|
|
if new_pkt != None and len(new_pkt) >= buflen + 3 and ord(new_pkt[0]) == 0 and ord(new_pkt[1]) == 4 and ord(new_pkt[2]) == block_high and ord(new_pkt[3]) == block_low:
|
|
break
|
|
elif self.parent.peers.units[self.MAC].link_type == 'Ethernet':
|
|
print mytime.displayTime() + ' Uploading -> Got invalid packet for block', self.completion, ' (' + str(len(new_pkt)) + ' bytes):', readableHEX(new_pkt[:20])
|
|
mytime.sleep(0.1)
|
|
if last == True:
|
|
if self.parent.peers.units[self.MAC].PICVersion == '3.8.2':
|
|
print mytime.displayTime(), 'Exiting, seems to be finished....'
|
|
print mytime.displayTime() + ' Finished update of', self.MAC, 'in', round(mytime.clock() - self.update_start_time, 1), 'seconds (last packet timeout)'
|
|
print mytime.displayTime() + ' Total time:', round(mytime.clock() - self.start_bootloader_time, 1), 'seconds'
|
|
one_unit.updateBootloaderDial(self.MAC, 'Finished')
|
|
if one_unit.app.image_filename[self.MAC].endswith('ffii'):
|
|
os.remove(one_unit.app.image_filename[self.MAC])
|
|
self.action = 'Exit'
|
|
one_unit.tryYield()
|
|
mytime.sleep(0.1)
|
|
one_unit.tryYield()
|
|
return
|
|
if len(new_pkt) > 4 and new_pkt[:2] == 'DD':
|
|
self.action = 'Exit'
|
|
one_unit.updateBootloaderDial(self.MAC, '(2) Failed!')
|
|
print mytime.displayTime(), 'd_p.Got DD packet, exiting'
|
|
return
|
|
if (last == False or self.conn.MK2 == True) and (mytime.clock() - send_time > 0.5 or self.conn.MK2 == True and new_pkt != None and len(new_pkt) == 0):
|
|
one_unit.tryYield()
|
|
send_time = mytime.clock()
|
|
try:
|
|
if self.conn.MK2 == True and (resend_counter > 5 or new_pkt != None and len(new_pkt) == 0):
|
|
print mytime.displayTime() + ' d_p.umf.Resetting Connection 3.0'
|
|
resend_counter = 0
|
|
s.close()
|
|
try:
|
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
s.settimeout(0.5)
|
|
s.connect((self.IP, 50675))
|
|
s.settimeout(0.5)
|
|
self.ethSocket = s
|
|
print mytime.displayTime() + ' d_p.umf.Connection opened'
|
|
except:
|
|
print mytime.displayTime() + ' d_p.umf.1.TCP/IP Connection of ' + self.MAC + ' to ' + self.IP + ' Failed'
|
|
|
|
else:
|
|
print mytime.displayTime() + ' d_p.umf.No response, Resending block', self.completion
|
|
resend_counter += 1
|
|
if s != None:
|
|
s.send(cmd)
|
|
else:
|
|
ser.write(cmd)
|
|
except:
|
|
print mytime.displayTime() + ' d_p.Send Failed (1)'
|
|
traceback.print_exc(file=sys.stdout)
|
|
try:
|
|
s.connect((self.IP, 50675))
|
|
except:
|
|
print mytime.displayTime() + ' d_p.umf.2.TCP/IP Connection of ' + self.MAC + ' to ' + self.IP + ' Failed'
|
|
self.action = 'Exit'
|
|
one_unit.updateBootloaderDial(self.MAC, '(2) Failed!')
|
|
return
|
|
|
|
else:
|
|
mytime.sleep(0.1)
|
|
if mytime.clock() - start_time > 30:
|
|
one_unit.tryYield()
|
|
print mytime.displayTime() + ' Timeout! last:', last, 'MK2:', self.conn.MK2, 'send delay:', mytime.clock() - send_time, 'new packet:', new_pkt
|
|
mytime.sleep(0.5)
|
|
self.action = 'Exit'
|
|
one_unit.updateBootloaderDial(self.MAC, '(2) Failed!')
|
|
if s != None:
|
|
try:
|
|
cmd = chr(0) + chr(7) + chr(0) + chr(0)
|
|
nul = '0' * buflen
|
|
cmd += nul
|
|
cmd = cmd[:buflen + 4]
|
|
s.send(cmd)
|
|
except:
|
|
print mytime.displayTime(), 'd_p.umf.Sending Abort command failed'
|
|
traceback.print_exc(file=sys.stdout)
|
|
|
|
one_unit.app.image_filename[self.MAC] = None
|
|
if s != None:
|
|
s.settimeout(1)
|
|
return
|
|
if last == True and mytime.clock() - start_time > 2:
|
|
one_unit.tryYield()
|
|
print mytime.displayTime() + ' Finished update of', self.MAC, 'in', round(mytime.clock() - self.update_start_time, 1), 'seconds (last packet timeout)'
|
|
print mytime.displayTime() + ' Total time:', round(mytime.clock() - self.start_bootloader_time, 1), 'seconds'
|
|
one_unit.updateBootloaderDial(self.MAC, 'Finished')
|
|
if self.MAC in one_unit.app.image_filename and str(one_unit.app.image_filename[self.MAC]).endswith('ffii'):
|
|
os.remove(one_unit.app.image_filename[self.MAC])
|
|
self.action = 'Exit'
|
|
try:
|
|
ser.close()
|
|
if os.name not in mac_names:
|
|
mytime.sleep(3)
|
|
d_usb.RestartDevice(self.parent.peers.units[self.MAC].InstanceId)
|
|
except:
|
|
pass
|
|
|
|
if s != None and self.conn.MK2 == True:
|
|
loop = 5
|
|
while loop > 0:
|
|
print mytime.displayTime(), 'Restarting Firmware (1)...', loop
|
|
loop -= 1
|
|
cmd = 'DCRESARTFIRMWARE'
|
|
try:
|
|
s.send(cmd)
|
|
except:
|
|
break
|
|
|
|
mytime.sleep(0.1)
|
|
|
|
mytime.sleep(0.1)
|
|
if s != None:
|
|
s.settimeout(1)
|
|
return
|
|
|
|
if new_pkt != None and len(new_pkt) >= buflen + 3 and ord(new_pkt[0]) == 0 and ord(new_pkt[1]) == 4 and ord(new_pkt[2]) == block_high and ord(new_pkt[3]) == block_low:
|
|
one_unit.tryYield()
|
|
verify_ok = True
|
|
for i in range(len(cmd)):
|
|
if i < 4:
|
|
continue
|
|
if cmd[i] != new_pkt[i]:
|
|
print mytime.displayTime(), 'd_p.Packet verification failed, packet', self.completion, 'byte', i, 'memory location', self.completion * buflen, 'should be', hex(ord(cmd[i])), 'but reads', hex(ord(new_pkt[i]))
|
|
verify_ok = False
|
|
break
|
|
|
|
if verify_ok == True:
|
|
self.fw_retry_counter = 0
|
|
if last == True:
|
|
print mytime.displayTime() + ' verify OK for block', self.completion, 'of', self.length + 1, 'return time:', mytime.clock() - send_time
|
|
self.completion += 1
|
|
if last == True:
|
|
print mytime.displayTime() + ' Finished update of', self.MAC, 'in', round(mytime.clock() - self.update_start_time, 1), 'seconds (verify OK)'
|
|
print mytime.displayTime() + ' Total time:', round(mytime.clock() - self.start_bootloader_time, 1), 'seconds'
|
|
one_unit.updateBootloaderDial(self.MAC, 'Finished')
|
|
if self.conn.MK2 == True:
|
|
loop = 5
|
|
while loop > 0:
|
|
print mytime.displayTime(), 'Restarting Firmware (2)...', loop
|
|
loop -= 1
|
|
cmd = 'DCRESARTFIRMWARE'
|
|
try:
|
|
s.send(cmd)
|
|
except:
|
|
break
|
|
|
|
mytime.sleep(0.1)
|
|
|
|
self.action = 'Exit'
|
|
try:
|
|
ser.close()
|
|
if os.name not in mac_names:
|
|
mytime.sleep(3)
|
|
d_usb.RestartDevice(self.parent.peers.units[self.MAC].InstanceId)
|
|
except:
|
|
pass
|
|
else:
|
|
mytime.sleep(0.1)
|
|
else:
|
|
one_unit.tryYield()
|
|
self.fw_retry_counter += 1
|
|
mytime.sleep(0.1)
|
|
if self.fw_retry_counter > 10:
|
|
one_unit.updateBootloaderDial(self.MAC, '(2) Failed!')
|
|
if s != None and self.conn.MK2 == True:
|
|
try:
|
|
cmd = chr(0) + chr(7) + chr(0) + chr(0)
|
|
nul = '0' * buflen
|
|
cmd += nul
|
|
cmd = cmd[:buflen + 4]
|
|
s.send(cmd)
|
|
except:
|
|
print mytime.displayTime(), 'd_p.umf.Sending Abort command failed'
|
|
traceback.print_exc(file=sys.stdout)
|
|
|
|
one_unit.app.image_filename[self.MAC] = None
|
|
print mytime.displayTime() + ' Verify Fail!', self.MAC
|
|
self.action = None
|
|
try:
|
|
ser.close()
|
|
if os.name not in mac_names:
|
|
mytime.sleep(3)
|
|
d_usb.RestartDevice(self.parent.peers.units[self.MAC].InstanceId)
|
|
except:
|
|
pass
|
|
|
|
one_unit.tryYield()
|
|
if s != None:
|
|
s.settimeout(1)
|
|
return
|
|
return
|
|
|
|
def usb_process(self):
|
|
cmd = None
|
|
if os.name in mac_names:
|
|
port = self.parent.peers.units[self.MAC].InstanceId
|
|
else:
|
|
port = int(self.parent.peers.units[self.MAC].IP[9:]) - 1
|
|
self.delay = 0.01
|
|
self.connection_attempts += 1
|
|
if self.connection_attempts > 10:
|
|
self.stopping = True
|
|
return
|
|
else:
|
|
while self.parent.usb_listener.active_port == port:
|
|
print mytime.displayTime() + ' Waiting for detection thread to free up port'
|
|
mytime.sleep(0.1)
|
|
|
|
try:
|
|
self.ser = myserial.Serial(port, 115200, timeout=0, writeTimeout=3)
|
|
except:
|
|
print mytime.displayTime() + ' d_protocol.connect error'
|
|
self.usb_disconnect(port)
|
|
self.reset_counter += 1
|
|
return
|
|
else:
|
|
if self.ser is None:
|
|
print mytime.displayTime() + ' Connection attempt failed!'
|
|
return
|
|
if os.name in mac_names:
|
|
print mytime.displayTime() + ' Connected', self.MAC, 'by port', port, ': ', self.parent.peers.units[self.MAC].type
|
|
else:
|
|
print mytime.displayTime() + ' Connected', self.MAC, 'by port COM', port + 1, ': ', self.parent.peers.units[self.MAC].type
|
|
self.parent.peers.units[self.MAC].link_status = 'available'
|
|
self.conn.Connected = True
|
|
self.conn.ResetValues = False
|
|
self.avg_response_time = 0.001
|
|
packet_counter = 0
|
|
pkt = self.parent.peers.units[self.MAC].pkt
|
|
my_id = 1
|
|
speedtimer = mytime.clock() + 10
|
|
while not self.stopping and one_unit.app.application_stopping == False:
|
|
try:
|
|
while not self.stopping and self.conn.Connected == True and one_unit.app.application_stopping == False:
|
|
if self.action != None:
|
|
if self.action == 'Exit':
|
|
self.usb_disconnect(port)
|
|
return
|
|
if self.action == 'start_bootloader':
|
|
self.start_bootloader(None)
|
|
continue
|
|
if self.action == 'start bootloader standby delay':
|
|
name = self.parent.peers.units[self.MAC].name
|
|
if name is not None and name.strip() in ('No Name',
|
|
'Recovery Mode'):
|
|
print mytime.displayTime() + ' Skipping Standby for', name
|
|
self.start_bootloader(None)
|
|
continue
|
|
if self.conn.synced == True:
|
|
print mytime.displayTime() + ' Standby OK!'
|
|
mytime.sleep(1)
|
|
self.start_bootloader(None)
|
|
continue
|
|
elif mytime.clock() - self.start_bootloader_time > 5:
|
|
print mytime.displayTime() + ' Standby Failed!'
|
|
self.start_bootloader(None)
|
|
continue
|
|
else:
|
|
try:
|
|
self.upload_main_firmware(None, self.ser)
|
|
except:
|
|
traceback.print_exc(file=sys.stdout)
|
|
else:
|
|
continue
|
|
if mytime.clock() > speedtimer:
|
|
speedtimer = mytime.clock() + update_interval
|
|
if self.invalid_packet_counter > 100:
|
|
self.invalid_packet_counter = 0
|
|
self.keepalive_counter = 0
|
|
port_index = 0
|
|
self.last_hw_packet_id = pkt.HW_PacketID
|
|
print mytime.displayTime() + ' d_process_usb.invalid packets exceeded 100'
|
|
self.usb_disconnect(port)
|
|
return
|
|
if mytime.clock() - self.last_refresh > 30 and self.delay == MAX_DELAY_USB:
|
|
self.conn.refresh_get_list()
|
|
self.last_refresh = mytime.clock()
|
|
self.conn.MK2 = pkt.MK2
|
|
cmd = self.conn.build_command(pkt.HW_PacketID, my_id)
|
|
if self.conn.synced == False or len(self.conn.get_list) > 0 or self.conn.got_basic_info == False:
|
|
self.delay = MIN_DELAY_USB
|
|
self.conn.check_vars_delay = 0
|
|
if mytime.clock() - self.conn.full_sync_time > 3:
|
|
self.conn.full_synced = False
|
|
self.last_refresh = mytime.clock()
|
|
elif self.initial_sync == False:
|
|
self.initial_sync = True
|
|
if self.delay == MIN_DELAY_USB:
|
|
if self.first_sync:
|
|
print mytime.displayTime() + ' ' + self.MAC + ' Initial sync finished'
|
|
self.first_sync = False
|
|
self.delay = MAX_DELAY_USB
|
|
self.conn.full_synced = True
|
|
self.conn.full_sync_time = mytime.clock()
|
|
self.setting = 0
|
|
try:
|
|
self.ser.write(cmd)
|
|
except:
|
|
print mytime.displayTime() + ' d_protocol.write error 1'
|
|
self.usb_disconnect(port)
|
|
return
|
|
else:
|
|
send_ts = mytime.clock()
|
|
retry_ts = mytime.clock()
|
|
new_pkt = None
|
|
got_packet = False
|
|
while one_unit.app.application_stopping == False:
|
|
if mytime.clock() - retry_ts > 3:
|
|
print mytime.displayTime() + ' d_protocol.USB: more than 3 seconds no response'
|
|
self.usb_disconnect(port)
|
|
return
|
|
if mytime.clock() - send_ts > 0.1:
|
|
try:
|
|
self.ser.write(cmd)
|
|
except:
|
|
print mytime.displayTime() + ' d_protocol.write error 2'
|
|
self.usb_disconnect(port)
|
|
return
|
|
else:
|
|
send_ts = mytime.clock()
|
|
new_pkt = read_packet(self.ser)
|
|
if new_pkt == None and got_packet == True:
|
|
break
|
|
if not isinstance(new_pkt, Data_packet):
|
|
mytime.sleep(0.01)
|
|
continue
|
|
pkt = new_pkt
|
|
new_pkt = None
|
|
self.parent.peers.units[self.MAC].last_rx = mytime.clock()
|
|
my_id += 1
|
|
if my_id == 255:
|
|
my_id = 1
|
|
self.conn.process_data_pkt(pkt)
|
|
self.invalid_packet_counter += pkt.invalid_packet_counter
|
|
self.connection_attempts = 0
|
|
got_packet = True
|
|
|
|
if self.delay >= 0.01 and self.conn.got_vu == True:
|
|
mytime.sleep(self.delay)
|
|
elif self.conn.got_vu == False:
|
|
mytime.sleep(0.01)
|
|
self.conn.got_vu = False
|
|
|
|
except:
|
|
print mytime.displayTime() + ' d_protocol.loop error'
|
|
traceback.print_exc(file=sys.stdout)
|
|
self.usb_disconnect(port)
|
|
return
|
|
|
|
return
|
|
|
|
def usb_disconnect(self, port):
|
|
try:
|
|
print mytime.displayTime() + ' Exception in USB thread, disconnecting'
|
|
traceback.print_exc(file=sys.stdout)
|
|
except:
|
|
pass
|
|
|
|
try:
|
|
self.ser.close()
|
|
except:
|
|
pass
|
|
|
|
try:
|
|
self.conn.Connected = False
|
|
self.conn.SyncIndicateActive = False
|
|
del self.ser
|
|
except:
|
|
pass
|
|
|
|
try:
|
|
self.conn.DisconnectTime = mytime.clock()
|
|
except:
|
|
pass
|
|
|
|
try:
|
|
mytime.sleep(0.1)
|
|
except:
|
|
pass
|
|
|
|
self.connection_attempts = 0
|
|
if self.action != None and self.action != 'Exit' and one_unit.app.bootloader_progress[self.MAC] != None:
|
|
print mytime.displayTime() + ' USB Disconnect: Aborting Firmware Update'
|
|
one_unit.updateBootloaderDial(self.MAC, '(2) Failed!')
|
|
if os.name not in mac_names:
|
|
d_usb.RestartDevice(self.parent.peers.units[self.MAC].InstanceId)
|
|
return
|
|
|
|
def ethernet_process(self):
|
|
cmd = None
|
|
while not self.stopping and one_unit.app.application_stopping == False:
|
|
my_id = 1
|
|
PORT = 50675
|
|
self.ethSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
self.ethSocket.settimeout(3)
|
|
self.conn.MK2 = self.parent.peers.units[self.MAC].MK2
|
|
try:
|
|
self.conn.MK2 = one_unit.app.MK2[self.MAC]
|
|
print mytime.displayTime(), 'd_p.ep.set MK2 from app for', self.MAC, self.conn.MK2
|
|
except:
|
|
pass
|
|
|
|
self.IP = self.parent.peers.units[self.MAC].IP
|
|
if self.conn.MK2 == True:
|
|
mk2String = '(MK2)'
|
|
else:
|
|
mk2String = ''
|
|
try:
|
|
self.ethSocket.connect((self.IP, PORT))
|
|
except:
|
|
print mytime.displayTime() + ' d_p.ep.TCP/IP Connection of ' + self.MAC + ' to ' + self.IP + ' Failed'
|
|
if one_unit.app.runConnectionTest == True:
|
|
one_unit.app.connectionTestLog.write(mytime.displayTime() + ' d_p.rC10' + newline)
|
|
self.conn.Connected = False
|
|
self.conn.ResetValues = True
|
|
self.conn.SyncIndicateActive = False
|
|
if self.action == 'start_main_update' or self.action == 'wait_for_bootloader':
|
|
self.reset_counter += 1
|
|
else:
|
|
self.reset_counter = 1000
|
|
if one_unit.app.testpc == True:
|
|
self.parent.peers.units[self.MAC].name = 'No Name'
|
|
self.parent.peers.units[self.MAC].link_status = 'disconnected'
|
|
self.ethernet_disconnect(self.ethSocket)
|
|
return
|
|
else:
|
|
if one_unit.app.runConnectionTest == True:
|
|
one_unit.app.connectionTestLog.write(mytime.displayTime() + ' Connected to MAC ' + self.MAC + ' by IP ' + self.IP + newline)
|
|
self.connectTime = mytime.clock()
|
|
self.ethSocket.settimeout(0.1)
|
|
if one_unit.app.EmergencyRecoveryMode == True or self.fastUpdate == True:
|
|
self.fastUpdate = False
|
|
self.action = 'updating_main_firmware'
|
|
one_unit.app.interfaceUpdate[self.MAC] = False
|
|
self.completion = 1
|
|
self.ignore_fw_version = 'i'
|
|
try:
|
|
print mytime.displayTime(), 'd_p.ep.bootloader progress:', one_unit.app.bootloader_progress[self.MAC]
|
|
if True:
|
|
cmd = 'DDUPLOADFIRMWARE'
|
|
print mytime.displayTime() + ' d_p.Auto Initiating Firmware Update Mode'
|
|
retries = 30
|
|
while retries > 0:
|
|
try:
|
|
self.ethSocket.send(cmd)
|
|
mytime.sleep(0.1)
|
|
retries -= 1
|
|
except:
|
|
print mytime.displayTime() + ' d_p.Auto Initiating Firmware Update Mode: Send failed'
|
|
return
|
|
|
|
print mytime.displayTime() + ' d_p.Auto Initiating Firmware Update Mode: Erasing'
|
|
if False:
|
|
cmd = chr(0) + chr(2) + 'dfdg_dfv' + chr(0) + 'netascii' + chr(0)
|
|
print mytime.displayTime() + ' d_p.partial erase!!!!!!!'
|
|
else:
|
|
cmd = chr(0) + chr(2) + 'dddd.dfi' + chr(0) + 'netascii' + chr(0)
|
|
print mytime.displayTime() + ' d_p.full erase'
|
|
retries = 30
|
|
while retries > 0:
|
|
try:
|
|
self.ethSocket.send(cmd)
|
|
mytime.sleep(0.1)
|
|
retries -= 1
|
|
except:
|
|
print mytime.displayTime() + ' d_p.Auto Initiating Firmware Update Mode: Send failed'
|
|
return
|
|
|
|
print mytime.displayTime() + ' d_p.Auto Initiating Firmware Update Mode: Done'
|
|
self.getFirmwareFile()
|
|
self.update_start_time = mytime.clock()
|
|
except:
|
|
pass
|
|
|
|
print mytime.displayTime(), 'Connected', self.MAC, 'by', self.parent.peers.units[self.MAC].IP, ':', self.parent.peers.units[self.MAC].type, 'action:', self.action
|
|
self.parent.peers.units[self.MAC].link_status = 'available'
|
|
self.conn.Connected = True
|
|
one_unit.app.mac_lookup[self.IP] = self.MAC
|
|
self.conn.ResetValues = False
|
|
packet_counter = 0
|
|
pkt = self.parent.peers.units[self.MAC].pkt
|
|
self.delay = 0.01
|
|
self.avg_response_time = 0.001
|
|
speedtimer = mytime.clock() + 10
|
|
last_packet_time = 0
|
|
testcounter = 0
|
|
while not self.stopping and one_unit.app.application_stopping == False:
|
|
try:
|
|
if self.action != None:
|
|
if self.action == 'Exit':
|
|
print mytime.displayTime(), 'd_p.exit command for', self.MAC
|
|
self.ethernet_disconnect(self.ethSocket)
|
|
return
|
|
if self.action == 'update_display':
|
|
self.updateDisplay(self.ethSocket)
|
|
continue
|
|
if self.action == 'make_image':
|
|
self.read_image(self.ethSocket)
|
|
continue
|
|
if self.action == 'start_bootloader':
|
|
self.start_bootloader(self.ethSocket)
|
|
continue
|
|
if self.action == 'start bootloader standby delay':
|
|
name = self.parent.peers.units[self.MAC].name
|
|
if name is not None and name.strip() in ('No Name',
|
|
'Recovery Mode'):
|
|
print mytime.displayTime() + ' Skipping Standby for', name
|
|
self.start_bootloader(None)
|
|
continue
|
|
if self.conn.synced == True:
|
|
print mytime.displayTime() + ' Standby OK!'
|
|
mytime.sleep(1)
|
|
self.start_bootloader(self.ethSocket)
|
|
continue
|
|
elif mytime.clock() - self.start_bootloader_time > 5:
|
|
print mytime.displayTime() + ' Standby Failed!'
|
|
self.start_bootloader(self.ethSocket)
|
|
continue
|
|
else:
|
|
if self.action == 'wait_for_bootloader':
|
|
mytime.sleep(0.1)
|
|
print mytime.displayTime() + ' Exiting communication loop to wait for bootloader'
|
|
self.ethernet_disconnect(self.ethSocket)
|
|
self.reset_counter = 100
|
|
return
|
|
continue
|
|
try:
|
|
self.upload_main_firmware(self.ethSocket)
|
|
except:
|
|
print mytime.displayTime(), 'd_p.error in upload main firmware, exiting', self.MAC
|
|
traceback.print_exc(file=sys.stdout)
|
|
self.action = 'Exit'
|
|
else:
|
|
continue
|
|
if mytime.clock() - self.last_refresh > 30 and self.delay == MAX_DELAY:
|
|
self.conn.refresh_get_list()
|
|
self.last_refresh = mytime.clock()
|
|
if pkt is not None:
|
|
self.conn.MK2 = pkt.MK2
|
|
cmd = self.conn.build_command(pkt.HW_PacketID, my_id)
|
|
else:
|
|
print mytime.displayTime() + ' d_protocol.ethernet.None Packet!'
|
|
print mytime.displayTime() + ' Vroeger: disconnect etc. Nu: Zelfde cmd nog een keer sturen. Beter? Afwachten.'
|
|
if self.conn.synced == False or len(self.conn.get_list) > 0 or self.conn.got_basic_info == False:
|
|
if self.first_sync:
|
|
self.delay = MIN_DELAY
|
|
else:
|
|
self.delay = SYNC_DELAY
|
|
self.conn.check_vars_delay = 0
|
|
if mytime.clock() - self.conn.full_sync_time > 3:
|
|
self.conn.full_synced = False
|
|
self.last_refresh = mytime.clock()
|
|
elif self.initial_sync == False:
|
|
self.initial_sync = True
|
|
if self.delay == MIN_DELAY:
|
|
if self.first_sync:
|
|
print mytime.displayTime() + ' ' + self.MAC + ' Initial sync finished'
|
|
self.first_sync = False
|
|
self.delay = MAX_DELAY
|
|
self.conn.full_synced = True
|
|
self.conn.full_sync_time = mytime.clock()
|
|
self.setting = 0
|
|
vu_delay = len(one_unit.app.server.peers.units) / 50.0
|
|
if vu_delay < 0.1:
|
|
vu_delay = 0.1
|
|
if vu_delay > 1:
|
|
vu_delay = 1
|
|
if self.delay == MAX_DELAY and CONDITIONAL_VU == True and len(cmd) < 10 and self.enable_vu == False and mytime.clock() - last_packet_time < vu_delay:
|
|
mytime.sleep(0.1)
|
|
continue
|
|
last_packet_time = mytime.clock()
|
|
pkt_id = pkt.HW_PacketID
|
|
try:
|
|
self.ethSocket.send(cmd)
|
|
except:
|
|
try:
|
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
s.settimeout(0.5)
|
|
s.connect((self.IP, 50675))
|
|
s.settimeout(0.5)
|
|
self.ethSocket = s
|
|
self.ethSocket.send(cmd)
|
|
except:
|
|
print mytime.displayTime() + ' Sending Ethernet Packet Reconnect Failed, Exiting'
|
|
self.ethernet_disconnect(self.ethSocket)
|
|
return
|
|
|
|
last_id = pkt.HW_PacketID
|
|
send_ts = mytime.clock()
|
|
retry_ts = mytime.clock()
|
|
retry_ts_2 = mytime.clock()
|
|
reconnectCounter = 0
|
|
new_pkt = None
|
|
got_packet = False
|
|
while one_unit.app.application_stopping == False:
|
|
if mytime.clock() - retry_ts_2 > 2:
|
|
reconnectCounter += 1
|
|
try:
|
|
self.ethSocket.close()
|
|
except:
|
|
pass
|
|
else:
|
|
retry_ts = mytime.clock()
|
|
try:
|
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
s.settimeout(0.5)
|
|
s.connect((self.IP, 50675))
|
|
s.settimeout(0.5)
|
|
self.ethSocket = s
|
|
if reconnectCounter > 1:
|
|
print mytime.displayTime() + ' d_p.ep.Reconnected', self.MAC, 'to', self.IP, mytime.clock(), retry_ts_2, reconnectCounter
|
|
break
|
|
except:
|
|
if one_unit.app.runConnectionTest == True:
|
|
one_unit.app.connectionTestLog.write(mytime.displayTime() + ' d_p.rC12' + newline)
|
|
else:
|
|
if reconnectCounter > 13:
|
|
print mytime.displayTime(), self.MAC, 'Ethernet Timeout, uptime', mytime.clock() - self.connectTime, 'seconds'
|
|
print mytime.displayTime(), 'd_p.ts delta:', mytime.clock() - retry_ts, reconnectCounter, self.reset_counter, mytime.clock() - retry_ts_2, 'ts:', retry_ts, retry_ts_2, 'clock:', mytime.clock()
|
|
if one_unit.app.runConnectionTest == True:
|
|
one_unit.app.connectionTestLog.write(mytime.displayTime() + ' d_p.rC13' + newline)
|
|
try:
|
|
cmd = 'DDRESETCONNECTIO'
|
|
self.ethSocket.send(cmd)
|
|
print mytime.displayTime() + ' d_p.Reset connection 3.1'
|
|
except:
|
|
print mytime.displayTime() + ' d_p.Reset connection failed 3.1', reconnectCounter
|
|
|
|
self.ethernet_disconnect(self.ethSocket)
|
|
self.reset_counter += 1
|
|
mytime.sleep(1)
|
|
return
|
|
mytime.sleep(0.1)
|
|
continue
|
|
if mytime.clock() - send_ts > 1:
|
|
print mytime.displayTime(), 'dp.ep.Resending Ethernet packet'
|
|
try:
|
|
self.ethSocket.send(cmd)
|
|
except:
|
|
try:
|
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
s.settimeout(0.5)
|
|
s.connect((self.IP, 50675))
|
|
s.settimeout(0.5)
|
|
self.ethSocket = s
|
|
self.ethSocket.send(cmd)
|
|
except:
|
|
print mytime.displayTime() + ' Ethernet disconnect: repeated send reconnect failed'
|
|
self.ethernet_disconnect(self.ethSocket)
|
|
return
|
|
|
|
else:
|
|
send_ts = mytime.clock()
|
|
try:
|
|
new_pkt = ''
|
|
new_pkt = self.ethSocket.recv(4096)
|
|
except:
|
|
mytime.sleep(0.01)
|
|
if self.conn.synced == False and len(cmd) == 9:
|
|
mytime.sleep(0.1)
|
|
try:
|
|
new_pkt = self.ethSocket.recv(4096)
|
|
except:
|
|
pass
|
|
else:
|
|
break
|
|
continue
|
|
|
|
if len(new_pkt) < 9:
|
|
retry_ts_2 = mytime.clock() - 5
|
|
continue
|
|
new_pkt = parse_packet(new_pkt, length=len(new_pkt) - 10)
|
|
if not isinstance(new_pkt, Data_packet):
|
|
continue
|
|
pkt = new_pkt
|
|
new_pkt = None
|
|
my_id += 1
|
|
if my_id == 255:
|
|
my_id = 1
|
|
packet_counter += 1
|
|
self.conn.process_data_pkt(pkt)
|
|
self.conn.Connected = True
|
|
self.reset_counter = 0
|
|
got_packet = True
|
|
break
|
|
|
|
if self.delay >= 0.01:
|
|
mytime.sleep(self.delay)
|
|
else:
|
|
mytime.sleep(0.01)
|
|
self.conn.got_vu = False
|
|
except:
|
|
print mytime.displayTime() + ' Ethernet exception, closing socket for ' + self.MAC + ' to ' + self.IP
|
|
if one_unit.app.runConnectionTest == True:
|
|
one_unit.app.connectionTestLog.write(mytime.displayTime() + ' d_p.rC14' + newline)
|
|
try:
|
|
traceback.print_exc(file=sys.stdout)
|
|
except:
|
|
pass
|
|
else:
|
|
try:
|
|
self.conn.Connected = False
|
|
self.conn.SyncIndicateActive = False
|
|
except:
|
|
pass
|
|
else:
|
|
break
|
|
|
|
try:
|
|
cmd = 'DDRESETCONNECTIO'
|
|
self.ethSocket.send(cmd)
|
|
except:
|
|
pass
|
|
|
|
print mytime.displayTime() + ' Disconnecting', self.MAC, 'from', self.IP
|
|
if one_unit.app.runConnectionTest == True:
|
|
one_unit.app.connectionTestLog.write(mytime.displayTime() + ' d_p.rC15' + newline)
|
|
|
|
self.ethernet_disconnect(self.ethSocket)
|
|
return
|
|
|
|
try:
|
|
cmd = 'DDRESETCONNECTIO'
|
|
self.ethSocket.send(cmd)
|
|
except:
|
|
pass
|
|
|
|
try:
|
|
print mytime.displayTime() + ' Ethernet disconnect end of loop'
|
|
self.ethernet_disconnect(self.ethSocket)
|
|
except:
|
|
pass
|
|
|
|
return
|
|
|
|
def ethernet_disconnect(self, s):
|
|
print mytime.displayTime(), 'd_p.ethernet disconnect for', self.MAC, self.conn.MK2
|
|
if one_unit.app.runConnectionTest == True:
|
|
one_unit.app.connectionTestLog.write(mytime.displayTime() + ' d_p.rC16' + newline)
|
|
if self.conn.MK2 == True:
|
|
one_unit.app.MK2[self.MAC] = self.conn.MK2
|
|
self.parent.peers.units[self.MAC].MK2 = self.conn.MK2
|
|
print mytime.displayTime(), 'd_p. set one_unit.app.MK2[self.MAC] to', self.conn.MK2, 'for', self.MAC
|
|
try:
|
|
s.settimeout(1)
|
|
pkt = s.recv(1024)
|
|
print mytime.displayTime() + ' d_p.ed.Got disconnect reply from', self.IP
|
|
except:
|
|
print mytime.displayTime() + ' d_p.ed.No reply from', self.IP
|
|
|
|
try:
|
|
s.close()
|
|
except:
|
|
pass
|
|
|
|
mytime.sleep(0.1)
|
|
return
|
|
|
|
def start(self):
|
|
"""Start the updating thread"""
|
|
self.stopping = False
|
|
self.thread.start()
|
|
return
|
|
|
|
def stop(self):
|
|
"""Stop the updating thread"""
|
|
self.stopping = True
|
|
self.thread.join()
|
|
return
|
|
|
|
|
|
class Protocol_Execute():
|
|
|
|
def __init__(self, parent):
|
|
self.parent = parent
|
|
self.lock = threading.Lock()
|
|
self.reset()
|
|
self.stopping = False
|
|
self.broadcasted_skin = ''
|
|
self.keepalive = True
|
|
self.last_hw_packet_id = 0
|
|
self.getIndex = 0
|
|
self.invalid_packet_counter = 0
|
|
self.min = {}
|
|
self.max = {}
|
|
self.firTaps = None
|
|
self.link_type = self.parent.parent.peers.units[self.parent.MAC].link_type
|
|
self.firTapsFromUi = None
|
|
self.adcRef33Main = 3.3
|
|
self.adcRef33Standby = 3.3
|
|
self.DisconnectTime = mytime.clock()
|
|
self.synced = False
|
|
self.last_vu = 0
|
|
self.get_time = {}
|
|
self.maxNumberOfPresets = 100
|
|
self.isTCS = False
|
|
self.isZwembad = False
|
|
self.get_counter = {}
|
|
self.slave_id = 'J'
|
|
self.full_synced = False
|
|
self.FIRmap = {}
|
|
self.firStartBlockByChannel = {}
|
|
self.firBlockSize = 1
|
|
self.full_sync_time = 0
|
|
self.setting = 0
|
|
self.last_impedance = {}
|
|
self.MK2 = False
|
|
try:
|
|
self.MK2 = one_unit.app.MK2[self.parent.MAC]
|
|
except:
|
|
pass
|
|
|
|
self.got_basic_info = False
|
|
self.model_number = None
|
|
self.factory = False
|
|
self.set_aborted = False
|
|
self.got_vu = False
|
|
self.avg_vu_delay = 0
|
|
self.max_vu_delay = 0
|
|
self.min_vu_delay = 1000000000
|
|
self.vu_dropouts = 0
|
|
self.Connected = False
|
|
self.full_config = None
|
|
self.LinkStatus = False
|
|
self.SyncIndicateActive = False
|
|
self.muted = False
|
|
self.last_refresh = mytime.clock()
|
|
self.check_vars_delay = 0
|
|
self.gotVUtime = mytime.clock()
|
|
self.buildNumber = 0
|
|
self.make_get_list()
|
|
decoding_map = codecs.make_identity_dict(range(128))
|
|
self.encoding_map = codecs.make_encoding_map(decoding_map)
|
|
self.testtime = 0
|
|
return
|
|
|
|
def get_relative_group_keys(self):
|
|
for group_id in one_unit.app.groups:
|
|
if group_id == 'all_units':
|
|
continue
|
|
if one_unit.app.group_type[group_id] == 'Relative':
|
|
for grouped_key in one_unit.app.group_links[group_id]:
|
|
self.config_vars.append(Key(grouped_key[0], grouped_key[1], grouped_key[2], grouped_key[3]))
|
|
|
|
return
|
|
|
|
def make_get_list(self):
|
|
if self.got_basic_info == False:
|
|
temp_config_vars = []
|
|
self.config_vars = []
|
|
fwversion = self.parent.parent.peers.units[self.parent.MAC].FWVersion
|
|
key = data_model.Key(protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_SW_VERSION, 0, 0)
|
|
self.config_vars.append(key)
|
|
key = data_model.Key(protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_MODEL_FIRMWARE, 0, 0)
|
|
self.config_vars.append(key)
|
|
key = data_model.Key(protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_MODEL_NUMBER, 0, 0)
|
|
self.config_vars.append(key)
|
|
key = data_model.Key(protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_CURRENT_USER, 0, 0)
|
|
self.config_vars.append(key)
|
|
key = data_model.Key(protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_ACCESS_RIGHTS, 0, 0)
|
|
self.config_vars.append(key)
|
|
try:
|
|
use_preset_lock = eval(self.parent.main_config.get('ROOT', 'use_preset_lock'))
|
|
except:
|
|
if self.parent.parent.peers.units[self.parent.MAC].numericalFWVersion >= self.parent.parent.peers.units[self.parent.MAC].minPresetLockVersion:
|
|
use_preset_lock = True
|
|
else:
|
|
use_preset_lock = False
|
|
|
|
if use_preset_lock:
|
|
for i in range(1, 5):
|
|
pwkey = data_model.Key(protocol.STRUCT_ID_PRESET_GLOBAL, protocol.MEMBER_ID_SET_PASSWORD, i, 0)
|
|
self.config_vars.append(pwkey)
|
|
pwkey = data_model.Key(protocol.STRUCT_ID_PRESET_GLOBAL, protocol.MEMBER_ID_USER_ACCESS_RIGHTS, 0, i + 1)
|
|
self.config_vars.append(pwkey)
|
|
|
|
key = data_model.Key(protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_HARDWARE_STATUS_FLAGS, 0, 0)
|
|
self.config_vars.append(key)
|
|
key = data_model.Key(protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_SHORT_NAME, 0, 0)
|
|
self.config_vars.append(key)
|
|
key = data_model.Key(protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_PIN, 0, 0)
|
|
self.config_vars.append(key)
|
|
key = data_model.Key(protocol.STRUCT_ID_MUTE, protocol.MEMBER_ID_MUTE, 0, 0)
|
|
self.config_vars.append(key)
|
|
self.get_list = self.config_vars[:]
|
|
return
|
|
else:
|
|
key = data_model.Key(protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_MODEL_NUMBER, 0, 0)
|
|
if key not in self.values:
|
|
self.values[key] = Unit_var()
|
|
self.values[key].read_val = -1
|
|
if self.values[key].read_val == -1:
|
|
key = data_model.Key(protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_MODEL_FIRMWARE, 0, 0)
|
|
try:
|
|
self.model_number = self.values[key].read_val
|
|
except KeyError:
|
|
self.values[key] = Unit_var()
|
|
self.values[key].read_val = 0
|
|
except:
|
|
traceback.print_exc(file=sys.stdout)
|
|
self.values[key] = Unit_var()
|
|
self.values[key].read_val = 0
|
|
|
|
self.model_number = self.values[key].read_val
|
|
try:
|
|
key = data_model.Key(protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_SHORT_NAME, 0, 0)
|
|
name = self.values[key].read_val.strip()
|
|
except:
|
|
name = 'Unknown Name'
|
|
|
|
try:
|
|
if len(self.config_vars) > 5:
|
|
temp_config_vars = self.config_vars[:]
|
|
else:
|
|
temp_config_vars = []
|
|
except:
|
|
pass
|
|
|
|
self.config_vars = []
|
|
got_config = False
|
|
number_of_presets = 0
|
|
self.config = None
|
|
myChannels = []
|
|
try:
|
|
model_number_string = '_' + str(self.model_number)
|
|
count = 0
|
|
while count < 3:
|
|
myFullType = self.parent.parent.peers.units[self.parent.MAC].type + model_number_string
|
|
if myFullType in one_unit.app.get_list_by_type:
|
|
self.myFullType = myFullType
|
|
self.config_vars = one_unit.app.get_list_by_type[myFullType]
|
|
self.get_list = self.config_vars[:]
|
|
self.parent.mute_channels = one_unit.app.mute_channels_by_type[myFullType]
|
|
self.min = one_unit.app.min_by_type[myFullType]
|
|
self.max = one_unit.app.max_by_type[myFullType]
|
|
self.config = one_unit.app.config_by_type[myFullType]
|
|
self.full_config = one_unit.app.config_by_type[myFullType]
|
|
self.get_fir_map(self.config)
|
|
self.parent.parent.peers.units[self.parent.MAC].minPresetLockVersion = one_unit.app.minPresetLockVersion[myFullType]
|
|
self.parent.parent.peers.units[self.parent.MAC].minPINVersion = one_unit.app.minPINVersion[myFullType]
|
|
self.parent.parent.peers.units[self.parent.MAC].minFIRgainVersion = one_unit.app.minFIRgainVersion[myFullType]
|
|
self.parent.parent.peers.units[self.parent.MAC].minBuildNumberVersion = one_unit.app.minBuildNumberVersion[myFullType]
|
|
self.parent.parent.peers.units[self.parent.MAC].minModelFirmwareVersion = one_unit.app.minModelFirmwareVersion[myFullType]
|
|
return
|
|
skin_path = os.path.join(one_unit.app.cwd, one_unit.app.skin_path, self.parent.parent.peers.units[self.parent.MAC].type + model_number_string + '_d')
|
|
if os.path.exists(os.path.join(skin_path, 'default.cfg')):
|
|
try:
|
|
config = ConfigParser.ConfigParser()
|
|
config.read(os.path.join(skin_path, 'default.cfg'))
|
|
views = config.get('DEFAULT', 'views')
|
|
self.full_config = config
|
|
try:
|
|
skip = eval(config.get('DEFAULT', 'skip'))
|
|
except:
|
|
if True:
|
|
skip = True
|
|
else:
|
|
skip = False
|
|
|
|
try:
|
|
number_of_presets = config.getint('recall_preset', 'max_value')
|
|
except:
|
|
pass
|
|
|
|
try:
|
|
self.isTCS = eval(config.get('DEFAULT', 'isTCS'))
|
|
except:
|
|
pass
|
|
|
|
self.get_mute_channels(config)
|
|
self.get_min_max(config)
|
|
self.config = config
|
|
myChannels = self.get_all_channels(config, myChannels)
|
|
if skip == False:
|
|
self.get_fir_map(config)
|
|
self.get_config_vars()
|
|
got_config = True
|
|
print mytime.displayTime() + ' d_p.mgl.Loaded config from ' + os.path.split(skin_path)[1]
|
|
else:
|
|
try:
|
|
dummy = config.get('standby_delay_time', 'struct_id')
|
|
key = data_model.Key(protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_STANDBY_DELAY, 0, 0)
|
|
self.config_vars.append(key)
|
|
except:
|
|
pass
|
|
|
|
except:
|
|
traceback.print_exc(file=sys.stdout)
|
|
|
|
skin_path = os.path.join(one_unit.app.cwd, one_unit.app.skin_path, self.parent.parent.peers.units[self.parent.MAC].type + '_d')
|
|
if os.path.exists(os.path.join(skin_path, 'default.cfg')):
|
|
try:
|
|
config = ConfigParser.ConfigParser()
|
|
config.read(os.path.join(skin_path, 'default.cfg'))
|
|
views = config.get('DEFAULT', 'views')
|
|
self.full_config = config
|
|
try:
|
|
skip = eval(config.get('DEFAULT', 'skip'))
|
|
except:
|
|
if True:
|
|
skip = True
|
|
else:
|
|
skip = False
|
|
|
|
try:
|
|
number_of_presets = config.getint('recall_preset', 'max_value')
|
|
except:
|
|
pass
|
|
|
|
try:
|
|
self.isTCS = eval(config.get('DEFAULT', 'isTCS'))
|
|
except:
|
|
pass
|
|
|
|
self.get_mute_channels(config)
|
|
self.get_min_max(config)
|
|
self.config = config
|
|
myChannels = self.get_all_channels(config, myChannels)
|
|
if skip == False:
|
|
self.get_fir_map(config)
|
|
self.get_config_vars()
|
|
got_config = True
|
|
print mytime.displayTime() + ' d_p.mgl.Loaded config from ' + os.path.split(skin_path)[1]
|
|
else:
|
|
try:
|
|
dummy = config.get('standby_delay_time', 'struct_id')
|
|
key = data_model.Key(protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_STANDBY_DELAY, 0, 0)
|
|
self.config_vars.append(key)
|
|
except:
|
|
pass
|
|
|
|
except:
|
|
traceback.print_exc(file=sys.stdout)
|
|
|
|
skin_path = os.path.join(one_unit.app.cwd, one_unit.app.skin_path, self.parent.parent.peers.units[self.parent.MAC].type + model_number_string + '_a')
|
|
if os.path.exists(os.path.join(skin_path, 'default.cfg')):
|
|
try:
|
|
config = ConfigParser.ConfigParser()
|
|
config.read(os.path.join(skin_path, 'default.cfg'))
|
|
views = config.get('DEFAULT', 'views')
|
|
try:
|
|
skip = eval(config.get('DEFAULT', 'skip'))
|
|
except:
|
|
if True:
|
|
skip = True
|
|
else:
|
|
skip = False
|
|
|
|
try:
|
|
number_of_presets = config.getint('recall_preset', 'max_value')
|
|
except:
|
|
pass
|
|
|
|
try:
|
|
self.isTCS = eval(config.get('DEFAULT', 'isTCS'))
|
|
except:
|
|
pass
|
|
|
|
self.get_mute_channels(config)
|
|
self.get_min_max(config)
|
|
myChannels = self.get_all_channels(config, myChannels)
|
|
if skip == False:
|
|
self.get_fir_map(config)
|
|
self.config = config
|
|
self.get_config_vars()
|
|
got_config = True
|
|
print mytime.displayTime() + ' d_p.mgl.Loaded config from ' + os.path.split(skin_path)[1]
|
|
else:
|
|
try:
|
|
dummy = config.get('standby_delay_time', 'struct_id')
|
|
key = data_model.Key(protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_STANDBY_DELAY, 0, 0)
|
|
self.config_vars.append(key)
|
|
except:
|
|
pass
|
|
|
|
except:
|
|
traceback.print_exc(file=sys.stdout)
|
|
|
|
skin_path = os.path.join(one_unit.app.cwd, one_unit.app.skin_path, self.parent.parent.peers.units[self.parent.MAC].type + '_a')
|
|
if os.path.exists(os.path.join(skin_path, 'default.cfg')):
|
|
try:
|
|
config = ConfigParser.ConfigParser()
|
|
config.read(os.path.join(skin_path, 'default.cfg'))
|
|
views = config.get('DEFAULT', 'views')
|
|
try:
|
|
skip = eval(config.get('DEFAULT', 'skip'))
|
|
except:
|
|
if True:
|
|
skip = True
|
|
else:
|
|
skip = False
|
|
|
|
try:
|
|
number_of_presets = config.getint('recall_preset', 'max_value')
|
|
except:
|
|
pass
|
|
|
|
try:
|
|
self.isTCS = eval(config.get('DEFAULT', 'isTCS'))
|
|
except:
|
|
pass
|
|
|
|
self.get_mute_channels(config)
|
|
self.get_min_max(config)
|
|
myChannels = self.get_all_channels(config, myChannels)
|
|
if skip == False:
|
|
self.get_fir_map(config)
|
|
self.config = config
|
|
self.get_config_vars()
|
|
got_config = True
|
|
print mytime.displayTime() + ' d_p.mgl.Loaded config from ' + os.path.split(skin_path)[1]
|
|
else:
|
|
try:
|
|
dummy = config.get('standby_delay_time', 'struct_id')
|
|
key = data_model.Key(protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_STANDBY_DELAY, 0, 0)
|
|
self.config_vars.append(key)
|
|
except:
|
|
pass
|
|
|
|
except:
|
|
traceback.print_exc(file=sys.stdout)
|
|
|
|
skin_path = os.path.join(one_unit.app.cwd, one_unit.app.skin_path, self.parent.parent.peers.units[self.parent.MAC].type + model_number_string + '_u')
|
|
if os.path.exists(os.path.join(skin_path, 'default.cfg')):
|
|
try:
|
|
config = ConfigParser.ConfigParser()
|
|
config.read(os.path.join(skin_path, 'default.cfg'))
|
|
views = config.get('DEFAULT', 'views')
|
|
try:
|
|
skip = eval(config.get('DEFAULT', 'skip'))
|
|
except:
|
|
if True:
|
|
skip = True
|
|
else:
|
|
skip = False
|
|
|
|
try:
|
|
number_of_presets = config.getint('recall_preset', 'max_value')
|
|
except:
|
|
pass
|
|
|
|
try:
|
|
self.isTCS = eval(config.get('DEFAULT', 'isTCS'))
|
|
except:
|
|
pass
|
|
|
|
self.get_mute_channels(config)
|
|
self.get_min_max(config)
|
|
myChannels = self.get_all_channels(config, myChannels)
|
|
if skip == False:
|
|
self.get_fir_map(config)
|
|
self.config = config
|
|
self.get_config_vars()
|
|
got_config = True
|
|
print mytime.displayTime() + ' d_p.mgl.Loaded config from ' + os.path.split(skin_path)[1]
|
|
else:
|
|
try:
|
|
dummy = config.get('standby_delay_time', 'struct_id')
|
|
key = data_model.Key(protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_STANDBY_DELAY, 0, 0)
|
|
self.config_vars.append(key)
|
|
except:
|
|
pass
|
|
|
|
except:
|
|
traceback.print_exc(file=sys.stdout)
|
|
|
|
skin_path = os.path.join(one_unit.app.cwd, one_unit.app.skin_path, self.parent.parent.peers.units[self.parent.MAC].type + '_u')
|
|
if os.path.exists(os.path.join(skin_path, 'default.cfg')):
|
|
try:
|
|
config = ConfigParser.ConfigParser()
|
|
config.read(os.path.join(skin_path, 'default.cfg'))
|
|
views = config.get('DEFAULT', 'views')
|
|
try:
|
|
skip = eval(config.get('DEFAULT', 'skip'))
|
|
except:
|
|
if True:
|
|
skip = True
|
|
else:
|
|
skip = False
|
|
|
|
try:
|
|
number_of_presets = config.getint('recall_preset', 'max_value')
|
|
except:
|
|
pass
|
|
|
|
try:
|
|
self.isTCS = eval(config.get('DEFAULT', 'isTCS'))
|
|
except:
|
|
pass
|
|
|
|
self.get_mute_channels(config)
|
|
self.get_min_max(config)
|
|
myChannels = self.get_all_channels(config, myChannels)
|
|
if skip == False:
|
|
self.get_fir_map(config)
|
|
self.config = config
|
|
self.get_config_vars()
|
|
got_config = True
|
|
print mytime.displayTime() + ' d_p.mgl.Loaded config from ' + os.path.split(skin_path)[1]
|
|
else:
|
|
try:
|
|
dummy = config.get('standby_delay_time', 'struct_id')
|
|
key = data_model.Key(protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_STANDBY_DELAY, 0, 0)
|
|
self.config_vars.append(key)
|
|
except:
|
|
pass
|
|
|
|
except:
|
|
traceback.print_exc(file=sys.stdout)
|
|
|
|
skin_path = os.path.join(one_unit.app.cwd, one_unit.app.skin_path, self.parent.parent.peers.units[self.parent.MAC].type + model_number_string + '_f')
|
|
if os.path.exists(os.path.join(skin_path, 'default.cfg')):
|
|
try:
|
|
config = ConfigParser.ConfigParser()
|
|
config.read(os.path.join(skin_path, 'default.cfg'))
|
|
views = config.get('DEFAULT', 'views')
|
|
try:
|
|
skip = eval(config.get('DEFAULT', 'skip'))
|
|
except:
|
|
if True:
|
|
skip = True
|
|
else:
|
|
skip = False
|
|
|
|
try:
|
|
number_of_presets = config.getint('recall_preset', 'max_value')
|
|
except:
|
|
pass
|
|
|
|
try:
|
|
self.isTCS = eval(config.get('DEFAULT', 'isTCS'))
|
|
except:
|
|
pass
|
|
|
|
self.get_mute_channels(config)
|
|
self.get_min_max(config)
|
|
myChannels = self.get_all_channels(config, myChannels)
|
|
if skip == False:
|
|
self.get_fir_map(config)
|
|
self.config = config
|
|
self.get_config_vars()
|
|
got_config = True
|
|
print mytime.displayTime() + ' Loaded config from ' + os.path.split(skin_path)[1]
|
|
else:
|
|
print mytime.displayTime() + ' Skipping config ' + os.path.split(skin_path)[1] + ', skip:', skip
|
|
try:
|
|
dummy = config.get('standby_delay_time', 'struct_id')
|
|
key = data_model.Key(protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_STANDBY_DELAY, 0, 0)
|
|
self.config_vars.append(key)
|
|
except:
|
|
pass
|
|
|
|
except:
|
|
traceback.print_exc(file=sys.stdout)
|
|
|
|
skin_path = os.path.join(one_unit.app.cwd, one_unit.app.skin_path, self.parent.parent.peers.units[self.parent.MAC].type + model_number_string)
|
|
if os.path.exists(os.path.join(skin_path, 'default.cfg')):
|
|
try:
|
|
config = ConfigParser.ConfigParser()
|
|
config.read(os.path.join(skin_path, 'default.cfg'))
|
|
views = config.get('DEFAULT', 'views')
|
|
if self.full_config == None:
|
|
self.full_config = config
|
|
try:
|
|
skip = eval(config.get('DEFAULT', 'skip'))
|
|
except:
|
|
if True:
|
|
skip = True
|
|
else:
|
|
skip = False
|
|
|
|
try:
|
|
number_of_presets = config.getint('recall_preset', 'max_value')
|
|
except:
|
|
pass
|
|
|
|
try:
|
|
self.isTCS = eval(config.get('DEFAULT', 'isTCS'))
|
|
except:
|
|
pass
|
|
|
|
self.get_mute_channels(config)
|
|
self.get_min_max(config)
|
|
if self.config == None:
|
|
self.config = config
|
|
if skip == False:
|
|
self.get_fir_map(config)
|
|
self.get_config_vars()
|
|
got_config = True
|
|
print mytime.displayTime() + ' d_p.mgl.Loaded config from ' + os.path.split(skin_path)[1]
|
|
else:
|
|
try:
|
|
dummy = config.get('standby_delay_time', 'struct_id')
|
|
key = data_model.Key(protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_STANDBY_DELAY, 0, 0)
|
|
self.config_vars.append(key)
|
|
except:
|
|
pass
|
|
|
|
except:
|
|
traceback.print_exc(file=sys.stdout)
|
|
|
|
skin_path = os.path.join(one_unit.app.cwd, one_unit.app.skin_path, self.parent.parent.peers.units[self.parent.MAC].type)
|
|
if os.path.exists(os.path.join(skin_path, 'default.cfg')):
|
|
try:
|
|
config = ConfigParser.ConfigParser()
|
|
config.read(os.path.join(skin_path, 'default.cfg'))
|
|
views = config.get('DEFAULT', 'views')
|
|
if self.full_config == None:
|
|
self.full_config = config
|
|
try:
|
|
skip = eval(config.get('DEFAULT', 'skip'))
|
|
except:
|
|
if True:
|
|
skip = True
|
|
else:
|
|
skip = False
|
|
|
|
try:
|
|
number_of_presets = config.getint('recall_preset', 'max_value')
|
|
except:
|
|
pass
|
|
|
|
try:
|
|
self.isTCS = eval(config.get('DEFAULT', 'isTCS'))
|
|
except:
|
|
pass
|
|
|
|
self.get_mute_channels(config)
|
|
self.get_min_max(config)
|
|
if self.config == None:
|
|
self.config = config
|
|
if skip == False:
|
|
self.get_fir_map(config)
|
|
self.get_config_vars()
|
|
got_config = True
|
|
print mytime.displayTime() + ' d_p.mgl.Loaded config from ' + os.path.split(skin_path)[1]
|
|
else:
|
|
try:
|
|
dummy = config.get('standby_delay_time', 'struct_id')
|
|
key = data_model.Key(protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_STANDBY_DELAY, 0, 0)
|
|
self.config_vars.append(key)
|
|
except:
|
|
pass
|
|
|
|
except:
|
|
traceback.print_exc(file=sys.stdout)
|
|
|
|
if got_config == True:
|
|
print mytime.clock(), 'Reading Config:', self.parent.parent.peers.units[self.parent.MAC].type + model_number_string
|
|
break
|
|
if count == 0:
|
|
model_number_string = '_0'
|
|
elif count == 1:
|
|
model_number_string = ''
|
|
else:
|
|
break
|
|
count += 1
|
|
|
|
except:
|
|
traceback.print_exc(file=sys.stdout)
|
|
|
|
if got_config == False:
|
|
model_number_string = '_' + str(self.model_number)
|
|
try:
|
|
config = self.config
|
|
except:
|
|
pass
|
|
else:
|
|
if len(temp_config_vars) > 0:
|
|
self.config_vars = temp_config_vars
|
|
try:
|
|
always_load_presets = eval(self.parent.main_config.get('ROOT', 'always_load_presets'))
|
|
except:
|
|
always_load_presets = False
|
|
|
|
if got_config == True or always_load_presets == True:
|
|
self.maxNumberOfPresets = number_of_presets
|
|
for i in range(1, number_of_presets + 1):
|
|
key = data_model.Key(protocol.STRUCT_ID_PRESET_GLOBAL, protocol.MEMBER_ID_SHORT_NAME, i, 0)
|
|
self.config_vars.append(key)
|
|
|
|
try:
|
|
use_preset_lock = eval(self.parent.main_config.get('ROOT', 'use_preset_lock'))
|
|
except:
|
|
if self.parent.parent.peers.units[self.parent.MAC].numericalFWVersion >= self.parent.parent.peers.units[self.parent.MAC].minPresetLockVersion:
|
|
use_preset_lock = True
|
|
else:
|
|
use_preset_lock = False
|
|
|
|
if use_preset_lock:
|
|
for i in range(1, 5):
|
|
pwkey = data_model.Key(protocol.STRUCT_ID_PRESET_GLOBAL, protocol.MEMBER_ID_SET_PASSWORD, i, 0)
|
|
self.config_vars.append(pwkey)
|
|
pwkey = data_model.Key(protocol.STRUCT_ID_PRESET_GLOBAL, protocol.MEMBER_ID_USER_ACCESS_RIGHTS, 0, i + 1)
|
|
self.config_vars.append(pwkey)
|
|
|
|
for map in self.FIRmap.values():
|
|
if map[0] not in myChannels:
|
|
myChannels.append(map[0])
|
|
|
|
if self.parent.IP != 'USB':
|
|
for channel in myChannels:
|
|
key = data_model.Key(protocol.STRUCT_ID_LPF, protocol.MEMBER_ID_GAIN, channel, 0)
|
|
self.config_vars.append(key)
|
|
key = data_model.Key(protocol.STRUCT_ID_HPF, protocol.MEMBER_ID_GAIN, channel, 0)
|
|
self.config_vars.append(key)
|
|
key = data_model.Key(protocol.STRUCT_ID_LPF, protocol.MEMBER_ID_Q, channel, 0)
|
|
self.config_vars.append(key)
|
|
key = data_model.Key(protocol.STRUCT_ID_HPF, protocol.MEMBER_ID_Q, channel, 0)
|
|
self.config_vars.append(key)
|
|
|
|
for i in range(1, 5):
|
|
pwkey = data_model.Key(protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_SET_PASSWORD, i, 0)
|
|
self.config_vars.append(pwkey)
|
|
pwkey = data_model.Key(protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_USER_ACCESS_RIGHTS, 0, i + 1)
|
|
self.config_vars.append(pwkey)
|
|
|
|
key = data_model.Key(protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_CURRENT_USER, 0, 0)
|
|
self.config_vars.append(key)
|
|
key = data_model.Key(protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_ACCESS_RIGHTS, 0, 0)
|
|
self.config_vars.append(key)
|
|
key = data_model.Key(protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_HARDWARE_STATUS_FLAGS, 0, 0)
|
|
self.config_vars.append(key)
|
|
key = data_model.Key(protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_SHORT_NAME, 0, 0)
|
|
self.config_vars.append(key)
|
|
key = data_model.Key(protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_CHECK_PASSWORD, 0, 0)
|
|
self.config_vars.append(key)
|
|
key = data_model.Key(protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_SW_VERSION, 0, 0)
|
|
self.config_vars.append(key)
|
|
key = Key(protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_STARTUP_PRESET, 0, 0)
|
|
self.config_vars.append(key)
|
|
if self.parent.parent.peers.units[self.parent.MAC].link_type == 'Ethernet':
|
|
key = data_model.Key(protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_IP, 0, 0)
|
|
self.config_vars.append(key)
|
|
key = data_model.Key(protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_SUBNET_MASK, 0, 0)
|
|
self.config_vars.append(key)
|
|
if model_number_string != '':
|
|
key = data_model.Key(protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_MODEL_FIRMWARE, 0, 0)
|
|
self.config_vars.append(key)
|
|
self.get_relative_group_keys()
|
|
if self.parent.mute_channels != None:
|
|
for channel in self.parent.mute_channels:
|
|
key = data_model.Key(protocol.STRUCT_ID_MUTE, protocol.MEMBER_ID_MUTE, channel, 0)
|
|
if key not in self.config_vars:
|
|
self.config_vars.append(key)
|
|
|
|
self.get_list = self.config_vars[:]
|
|
self.myFullType = myFullType
|
|
one_unit.app.get_list_by_type[myFullType] = self.config_vars[:]
|
|
one_unit.app.mute_channels_by_type[myFullType] = self.parent.mute_channels
|
|
one_unit.app.min_by_type[myFullType] = self.min
|
|
one_unit.app.max_by_type[myFullType] = self.max
|
|
one_unit.app.minPresetLockVersion[myFullType] = self.parent.parent.peers.units[self.parent.MAC].minPresetLockVersion
|
|
one_unit.app.minPINVersion[myFullType] = self.parent.parent.peers.units[self.parent.MAC].minPINVersion
|
|
one_unit.app.minFIRgainVersion[myFullType] = self.parent.parent.peers.units[self.parent.MAC].minFIRgainVersion
|
|
one_unit.app.minBuildNumberVersion[myFullType] = self.parent.parent.peers.units[self.parent.MAC].minBuildNumberVersion
|
|
one_unit.app.minModelFirmwareVersion[myFullType] = self.parent.parent.peers.units[self.parent.MAC].minModelFirmwareVersion
|
|
one_unit.app.config_by_type[myFullType] = self.config
|
|
return
|
|
|
|
def refresh_get_list(self):
|
|
if self.parent.action != None or self.synced == False or len(self.get_list) > 0:
|
|
return
|
|
else:
|
|
try:
|
|
if self.parent.MAC in one_unit.app.bootloader_progress and one_unit.app.bootloader_progress[self.parent.MAC] != None:
|
|
return
|
|
except:
|
|
traceback.print_exc(file=sys.stdout)
|
|
|
|
if self.got_basic_info == False:
|
|
self.make_get_list()
|
|
return
|
|
vars = []
|
|
key = data_model.Key(protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_HARDWARE_STATUS_FLAGS, 0, 0)
|
|
vars.append(key)
|
|
try:
|
|
for channel in self.parent.mute_channels:
|
|
key = data_model.Key(protocol.STRUCT_ID_MUTE, protocol.MEMBER_ID_MUTE, channel, 0)
|
|
if key not in vars:
|
|
vars.append(key)
|
|
|
|
except:
|
|
pass
|
|
|
|
for key in vars:
|
|
try:
|
|
del self.values[key]
|
|
except:
|
|
pass
|
|
|
|
self.get_list.append(key)
|
|
|
|
return
|
|
|
|
def get_all_channels(self, config, channels):
|
|
for var in config.sections():
|
|
try:
|
|
channel = config.getint(var, 'channel')
|
|
strid = config.getint(var, 'struct_id')
|
|
if strid not in (protocol.STRUCT_ID_GAIN, protocol.STRUCT_ID_VU, protocol.STRUCT_ID_GAIN):
|
|
continue
|
|
if channel not in channels:
|
|
channels.append(channel)
|
|
except:
|
|
pass
|
|
|
|
return channels
|
|
|
|
def get_mute_channels(self, config):
|
|
try:
|
|
self.parent.mute_channels = eval(config.get('DEFAULT', 'mute_channels'))
|
|
except:
|
|
if self.parent.mute_channels == None:
|
|
in_channels = []
|
|
for var in config.sections():
|
|
try:
|
|
channel = config.getint(var, 'channel')
|
|
if channel < 128 and channel not in in_channels and config.getint(var, 'struct_id') not in (-3,
|
|
-2,
|
|
-1,
|
|
13):
|
|
in_channels.append(channel)
|
|
except:
|
|
pass
|
|
|
|
self.parent.mute_channels = in_channels
|
|
|
|
return
|
|
|
|
def get_fir_map(self, config):
|
|
print mytime.displayTime(), 'dp.get FIR map'
|
|
self.makeFirMap(config=config)
|
|
return
|
|
|
|
def makeFirMap(self, firTaps=None, config=None, firBlockSize=None):
|
|
if self.MK2 == False:
|
|
return
|
|
else:
|
|
if config == None:
|
|
if self.full_config != None:
|
|
config = self.full_config
|
|
print mytime.displayTime(), 'dp.Using self.full_config for FIR map'
|
|
else:
|
|
print mytime.displayTime(), 'dp.Failed to make FIR map, full config not set yet!'
|
|
return
|
|
tempFirBlockSize = self.firBlockSize
|
|
self.firBlocksPerChannel = 0
|
|
if firBlockSize == None:
|
|
try:
|
|
self.firBlockSize = config.getint('DEFAULT', 'firBlockSize')
|
|
except:
|
|
try:
|
|
time.sleep(0.1)
|
|
self.firBlockSize = config.getint('DEFAULT', 'firBlockSize')
|
|
except:
|
|
if tempFirBlockSize != None:
|
|
self.firBlockSize = tempFirBlockSize
|
|
else:
|
|
print mytime.displayTime(), 'dp.Failed to make FIR map, FIR block size not set'
|
|
return
|
|
|
|
else:
|
|
self.firBlockSize = firBlockSize
|
|
try:
|
|
self.firBlocksPerChannel = config.getint('DEFAULT', 'firBlocks')
|
|
except:
|
|
pass
|
|
|
|
if firTaps == None:
|
|
try:
|
|
firTaps = eval(config.get('DEFAULT', 'FIR_taps'))
|
|
print 'dp.fir taps from config:', firTaps
|
|
except:
|
|
print mytime.displayTime(), 'dp.Failed to make FIR map, FIR taps not set'
|
|
return
|
|
|
|
if self.firTaps != None and (firTaps == None or len(firTaps) == 0):
|
|
firTaps = self.firTaps
|
|
print mytime.displayTime(), 'dp.Using self.firTaps for FIR map'
|
|
if self.firTapsFromUi != None:
|
|
firTaps = self.firTapsFromUi
|
|
print mytime.displayTime(), 'dp.Using self.firTapsFromUi for FIR map'
|
|
print mytime.displayTime(), 'dp. FIR taps uiteindelijk:', firTaps
|
|
if firTaps == None:
|
|
(
|
|
mytime.displayTime(), 'dp. No FIR taps, aborting')
|
|
self.firStartBlockByChannel = {}
|
|
self.FIRmap = {}
|
|
self.firTaps = firTaps
|
|
block = -1
|
|
for channel in sorted(firTaps.keys()):
|
|
numberOfTaps = firTaps[channel]
|
|
offset = 0
|
|
if numberOfTaps > 0:
|
|
blocks = self.firBlocksPerChannel
|
|
else:
|
|
blocks = 0
|
|
while numberOfTaps > 0 or blocks > 0:
|
|
block = block + 1
|
|
self.FIRmap[block] = (channel, offset)
|
|
offset += self.firBlockSize
|
|
numberOfTaps -= self.firBlockSize
|
|
blocks -= 1
|
|
|
|
for block in self.FIRmap:
|
|
if block == 65535:
|
|
continue
|
|
channel = self.FIRmap[block][0]
|
|
if channel not in self.firStartBlockByChannel:
|
|
self.firStartBlockByChannel[channel] = block
|
|
elif block < self.firStartBlockByChannel[channel]:
|
|
self.firStartBlockByChannel[channel] = block
|
|
|
|
for testkey in self.config_vars[:]:
|
|
if testkey.member_id == protocol.MEMBER_ID_FIR:
|
|
safeRemove(self.config_vars, testkey)
|
|
|
|
for testkey in self.get_list[:]:
|
|
if testkey.member_id & 128 == protocol.MEMBER_ID_FIR:
|
|
safeRemove(self.get_list, testkey)
|
|
|
|
for testkey in self.values.keys():
|
|
if testkey.member_id == protocol.MEMBER_ID_FIR:
|
|
del self.values[testkey]
|
|
|
|
return
|
|
|
|
def get_min_max(self, config):
|
|
try:
|
|
self.parent.parent.peers.units[self.parent.MAC].minPresetLockVersion = config.getint('DEFAULT', 'minPresetLockVersion')
|
|
except:
|
|
pass
|
|
|
|
try:
|
|
self.parent.parent.peers.units[self.parent.MAC].minPINVersion = config.getint('DEFAULT', 'minPINVersion')
|
|
except:
|
|
pass
|
|
|
|
try:
|
|
self.parent.parent.peers.units[self.parent.MAC].minFIRgainVersion = config.getint('DEFAULT', 'minFIRgainVersion')
|
|
except:
|
|
pass
|
|
|
|
try:
|
|
self.parent.parent.peers.units[self.parent.MAC].minBuildNumberVersion = config.getint('DEFAULT', 'minBuildNumberVersion')
|
|
except:
|
|
pass
|
|
|
|
try:
|
|
self.parent.parent.peers.units[self.parent.MAC].minModelFirmwareVersion = config.getint('DEFAULT', 'minModelFirmwareVersion')
|
|
except:
|
|
pass
|
|
|
|
sections = config.sections()
|
|
struct_id = None
|
|
member_id = None
|
|
num = None
|
|
for var in sections:
|
|
channels = []
|
|
if var == 'DEFAULT':
|
|
continue
|
|
try:
|
|
scale = config.get(var, 'svg_file')
|
|
continue
|
|
except:
|
|
pass
|
|
|
|
try:
|
|
struct_id = config.getint(var, 'struct_id')
|
|
member_id = config.getint(var, 'member_id')
|
|
num = config.getint(var, 'num')
|
|
except:
|
|
pass
|
|
|
|
try:
|
|
scale = protocol.get_member_scale(member_id)
|
|
except:
|
|
traceback.print_exc(file=sys.stdout)
|
|
scale = 1.0
|
|
|
|
if struct_id in (
|
|
protocol.STRUCT_ID_INTERNAL,
|
|
protocol.STRUCT_ID_COMMAND,
|
|
protocol.STRUCT_ID_VU,
|
|
protocol.STRUCT_ID_GR,
|
|
protocol.STRUCT_ID_RAW_VU):
|
|
continue
|
|
if member_id in (
|
|
protocol.MEMBER_ID_VU_IN,
|
|
protocol.MEMBER_ID_VU_OUT,
|
|
protocol.MEMBER_ID_GR_IN,
|
|
protocol.MEMBER_ID_GR_OUT,
|
|
protocol.MEMBER_ID_COMMAND,
|
|
protocol.MEMBER_ID_CHECK_PASSWORD,
|
|
protocol.MEMBER_ID_HARDWARE_STATUS_FLAGS,
|
|
protocol.MEMBER_ID_AMP_READINGS,
|
|
protocol.MEMBER_ID_AMP_READINGS_2):
|
|
continue
|
|
try:
|
|
channels = self.channels_for_var(var, config)
|
|
except:
|
|
traceback.print_exc(file=sys.stdout)
|
|
continue
|
|
|
|
for channel in channels:
|
|
key = data_model.Key(struct_id, member_id, channel, num)
|
|
try:
|
|
self.min[key] = config.getfloat(var, 'min_value') * scale
|
|
except:
|
|
self.min[key] = None
|
|
|
|
try:
|
|
self.max[key] = config.getfloat(var, 'max_value') * scale
|
|
except:
|
|
self.max[key] = None
|
|
|
|
break
|
|
|
|
return
|
|
|
|
def get_config_vars(self):
|
|
sections = self.config.sections()
|
|
struct_id = None
|
|
member_id = None
|
|
num = None
|
|
try:
|
|
custom_scales = eval(self.config.get('DEFAULT', 'custom_scales'))
|
|
print 'd_p.jaja custom scales'
|
|
except:
|
|
custom_scales = False
|
|
|
|
for var in sections:
|
|
channels = []
|
|
if var == 'DEFAULT':
|
|
continue
|
|
try:
|
|
scale = self.config.get(var, 'svg_file')
|
|
continue
|
|
except:
|
|
pass
|
|
|
|
try:
|
|
struct_id = self.config.getint(var, 'struct_id')
|
|
member_id = self.config.getint(var, 'member_id')
|
|
num = self.config.getint(var, 'num')
|
|
except:
|
|
pass
|
|
|
|
try:
|
|
min_build_number = self.config.getint(var, 'min_build_number')
|
|
continue
|
|
except:
|
|
pass
|
|
|
|
scale = protocol.get_member_scale(member_id)
|
|
offset = 0.0
|
|
try:
|
|
if custom_scales == True:
|
|
scale = self.config.getfloat(var, 'scale')
|
|
one_unit.app.custom_scale[member_id] = scale
|
|
print 'Scale for', member_id, 'is', scale
|
|
offset = self.config.getfloat(var, 'offset')
|
|
except:
|
|
pass
|
|
|
|
if struct_id in (
|
|
protocol.STRUCT_ID_INTERNAL,
|
|
protocol.STRUCT_ID_COMMAND,
|
|
protocol.STRUCT_ID_VU,
|
|
protocol.STRUCT_ID_GR,
|
|
protocol.STRUCT_ID_RAW_VU):
|
|
continue
|
|
if member_id in (
|
|
protocol.MEMBER_ID_VU_IN,
|
|
protocol.MEMBER_ID_VU_OUT,
|
|
protocol.MEMBER_ID_GR_IN,
|
|
protocol.MEMBER_ID_GR_OUT,
|
|
protocol.MEMBER_ID_COMMAND,
|
|
protocol.MEMBER_ID_CHECK_PASSWORD,
|
|
protocol.MEMBER_ID_HARDWARE_STATUS_FLAGS,
|
|
protocol.MEMBER_ID_AMP_READINGS,
|
|
protocol.MEMBER_ID_AMP_READINGS_2):
|
|
continue
|
|
channels = self.channels_for_var(var)
|
|
for channel in channels:
|
|
key = data_model.Key(struct_id, member_id, channel, num)
|
|
one_unit.app.member_scale[key] = scale
|
|
one_unit.app.member_offset[key] = offset
|
|
if key not in self.config_vars:
|
|
self.config_vars.append(key)
|
|
|
|
return
|
|
|
|
def channels_for_var(self, var, config=None):
|
|
if config == None:
|
|
config = self.config
|
|
channels = []
|
|
try:
|
|
channels = config.get(var, 'channels')
|
|
except ConfigParser.NoOptionError:
|
|
try:
|
|
channel = config.get(var, 'channel')
|
|
except ConfigParser.NoOptionError:
|
|
print mytime.displayTime() + " d_p.variable '%s' has neither 'channels' nor 'channel' attributes defined. This is wrong, variable ignored." % var
|
|
return []
|
|
else:
|
|
channel = int(channel, 0)
|
|
channels = [channel]
|
|
else:
|
|
channels = [_[1] for s in channels.split(',')]
|
|
|
|
return channels
|
|
|
|
def reset(self):
|
|
self.Connected = False
|
|
self.last_refresh = mytime.clock()
|
|
self.LinkStatus = False
|
|
self.ResetValues = True
|
|
self.getIndex = 0
|
|
self.last_get_key = None
|
|
self.SyncIndicateActive = False
|
|
self.last_peq_key = None
|
|
self.last_xover_key = None
|
|
self.values = {}
|
|
self.preset_names = {}
|
|
self.last_requested = -1
|
|
self.correct_vars = 0
|
|
self.check_vars_delay = 0
|
|
return
|
|
|
|
def build_key(self, struct_id, member_id, channel=0, num=0):
|
|
return Key(struct_id, member_id, channel, num)
|
|
|
|
def get(self, struct_id, member_id, channel=0, num=0):
|
|
struct_id = int(struct_id)
|
|
member_id = int(member_id)
|
|
key = self.build_key(struct_id, member_id, channel, num)
|
|
return self.get_by_key(key)
|
|
|
|
def get_by_key(self, key):
|
|
if self.parent.action != None:
|
|
return
|
|
else:
|
|
if key.channel == None or key.channel < 0:
|
|
print mytime.displayTime() + ' d_protocol.get_by_key.invalid key!', key
|
|
try:
|
|
var = self.values[key]
|
|
except KeyError:
|
|
self.values[key] = Unit_var()
|
|
var = self.values[key]
|
|
except:
|
|
raise
|
|
|
|
return copy.deepcopy(var)
|
|
|
|
def set(self, val, struct_id, member_id, channel=0, num=0):
|
|
key = self.build_key(struct_id, member_id, channel, num)
|
|
return self.set_by_key(key, val)
|
|
|
|
def set_last_key(self, key):
|
|
if key.struct_id == protocol.STRUCT_ID_PEQ:
|
|
self.last_peq_key = key
|
|
if key.struct_id == protocol.STRUCT_ID_HPF or key.struct_id == protocol.STRUCT_ID_LPF:
|
|
self.last_xover_key = key
|
|
return
|
|
|
|
def add_by_key(self, key, delta, factory=False):
|
|
try:
|
|
if self.values[key].target_val == None:
|
|
self.values[key].target_val = self.values[key].read_val
|
|
if self.values[key].target_val == None:
|
|
print mytime.displayTime(), 'No base value for', self.parent.MAC
|
|
return
|
|
print mytime.displayTime(), 'Setting', self.parent.MAC, 'from', self.values[key].target_val, 'to', self.values[key].target_val + delta
|
|
self.values[key].target_val = self.values[key].target_val + delta
|
|
val = self.values[key].target_val
|
|
if key in self.min:
|
|
if self.min[key] != None:
|
|
if val < self.min[key]:
|
|
val = self.min[key]
|
|
if key in self.max:
|
|
if self.max[key] != None:
|
|
if val > self.max[key]:
|
|
val = self.max[key]
|
|
self.set_by_key(key, val, factory=factory, update_target_value=False)
|
|
return val
|
|
except KeyError:
|
|
self.get_list.append(key)
|
|
return
|
|
except:
|
|
print mytime.displayTime(), 'Add value failed for', self.parent.MAC
|
|
traceback.print_exc(file=sys.stdout)
|
|
self.get_list.append(key)
|
|
return
|
|
|
|
return
|
|
|
|
def set_by_key(self, key, val, factory=False, update_target_value=True):
|
|
if self.parent.action != None and self.parent.action != 'start_bootloader':
|
|
return
|
|
else:
|
|
if key.struct_id == protocol.STRUCT_ID_GLOBAL and key.member_id == protocol.MEMBER_ID_CURRENT_USER:
|
|
return
|
|
if key.struct_id == protocol.STRUCT_ID_COMMAND and val == 0:
|
|
return
|
|
self.factory = factory
|
|
try:
|
|
var = self.values[key]
|
|
except KeyError:
|
|
self.values[key] = Unit_var()
|
|
var = self.values[key]
|
|
except:
|
|
raise
|
|
|
|
self.check_vars_delay = 0
|
|
if protocol.get_member_format(key.member_id)[-1:] == 's':
|
|
if key.member_id != protocol.MEMBER_ID_UI_CONTROL:
|
|
if isinstance(val, unicode):
|
|
text = val
|
|
else:
|
|
try:
|
|
text = str(val)
|
|
except:
|
|
text = 'Encode Error'
|
|
|
|
try:
|
|
encoded = codecs.charmap_encode(text, 'replace', self.encoding_map)
|
|
except UnicodeEncodeError, err:
|
|
encoded = str(err)
|
|
else:
|
|
val = encoded[0]
|
|
try:
|
|
val = str(val)
|
|
except:
|
|
val = ''
|
|
else:
|
|
validFilenameChars = unicode('#$%&*"+!?/-_.,^@<>=;:{}[]|() ') + string.ascii_letters + string.digits
|
|
val = ('').join(c for c in val if c in validFilenameChars)
|
|
val = val + ' '
|
|
val = val[:int(protocol.get_member_format(key.member_id)[:-1])]
|
|
else:
|
|
try:
|
|
val = int(val)
|
|
except:
|
|
pass
|
|
|
|
if val != var.read_val or key.member_id == protocol.MEMBER_ID_CHECK_PASSWORD or key.struct_id == protocol.STRUCT_ID_COMMAND:
|
|
if var.write_val == None:
|
|
self.setting += 1
|
|
var.write_val = val
|
|
var.set_ts = 0
|
|
self.synced = False
|
|
var.saved_val = var.read_val
|
|
var.set_time = mytime.clock()
|
|
var.read_val = None
|
|
var.read_ts = None
|
|
var.change_ts = None
|
|
var.SetCount = 0
|
|
if update_target_value == True:
|
|
var.target_val = val
|
|
return
|
|
|
|
def choose_var_to_update(self, get=False):
|
|
if self.parent.action != None and self.parent.action != 'start bootloader standby delay':
|
|
return
|
|
else:
|
|
if get == False:
|
|
keys = [_[1] for k in self.values.keys() if k[0] >= 0]
|
|
tmpSynced = True
|
|
for key in keys:
|
|
try:
|
|
var = self.values[key]
|
|
except:
|
|
return
|
|
else:
|
|
if var.write_val is not None:
|
|
self.synced = False
|
|
tmpSynced = False
|
|
if mytime.clock() - var.set_ts > 0.5:
|
|
if var.SetCount < 50:
|
|
var.SetCount = var.SetCount + 1
|
|
var.set_ts = mytime.clock()
|
|
self.synced = False
|
|
if var.SetCount % 10 == 0:
|
|
print mytime.displayTime(), self.parent.MAC, 'd_protocol.Still trying to set', protocol.get_strid_text(key.struct_id), protocol.get_member_text(key.member_id), 'channel', key.channel, 'no. ', key.num, 'tried ', var.write_val, ', current value', var.saved_val
|
|
return key
|
|
print mytime.displayTime(), self.parent.MAC, 'd_protocol.SET Aborted!!!', protocol.get_strid_text(key.struct_id), protocol.get_member_text(key.member_id), 'channel', key.channel, 'no. ', key.num, 'tried ', var.write_val, ', current value', var.saved_val
|
|
var.write_val = None
|
|
var.read_val = var.saved_val
|
|
self.set_aborted = True
|
|
|
|
self.synced = tmpSynced
|
|
if len(self.get_list) > 5:
|
|
self.getIndex += 1
|
|
if self.getIndex >= len(self.get_list):
|
|
self.getIndex = 0
|
|
return self.get_list[self.getIndex]
|
|
if self.MK2 == True:
|
|
if len(self.get_list) < 100:
|
|
timeout = 0.1
|
|
else:
|
|
timeout = 1
|
|
elif len(self.get_list) < 20:
|
|
timeout = 0.1
|
|
else:
|
|
timeout = 3
|
|
if self.link_type == 'USB':
|
|
timeout = 1
|
|
nowtime = mytime.clock()
|
|
for key in self.get_list:
|
|
try:
|
|
lastGetTime = self.get_time[key]
|
|
counter = self.get_counter[key]
|
|
except:
|
|
self.get_time[key] = nowtime
|
|
self.get_counter[key] = 0
|
|
return key
|
|
else:
|
|
if nowtime - lastGetTime < timeout:
|
|
continue
|
|
self.get_counter[key] += 1
|
|
self.get_time[key] = nowtime
|
|
if self.get_counter[key] % 50 == 0:
|
|
print mytime.displayTime(), self.parent.MAC, 'd_protocol.CVTU: Retry getting Key', key, ':', protocol.readable(key), 'Count:', self.get_counter[key]
|
|
if self.get_counter[key] > 148:
|
|
print mytime.displayTime(), self.parent.MAC, 'd_protocol.CVTU: Error getting Key', key, ':', protocol.readable(key), ',giving up now!'
|
|
self.get_counter[key] = 0
|
|
self.get_list.remove(key)
|
|
|
|
if key.struct_id == protocol.STRUCT_ID_PRESET_GLOBAL and key.member_id == protocol.MEMBER_ID_SHORT_NAME and key.channel > self.maxNumberOfPresets:
|
|
print mytime.displayTime(), 'd_p.removing preset', key.channel, self.maxNumberOfPresets
|
|
self.get_list.remove(key)
|
|
return key
|
|
|
|
return
|
|
|
|
def percent_vars_to_update(self):
|
|
if self.parent.action != None:
|
|
return 100
|
|
else:
|
|
keys = [_[1] for k in self.values.keys() if k[0] >= 0]
|
|
nitems = len(keys)
|
|
if nitems == 0:
|
|
return 100
|
|
percent = 0.01
|
|
if nitems == 0:
|
|
return 100
|
|
for key in keys:
|
|
var = self.values[key]
|
|
if var.write_val is None:
|
|
percent += 1
|
|
|
|
return percent / nitems * 99
|
|
|
|
def process_data_pkt(self, pkt):
|
|
if self.got_basic_info == False and len(self.get_list) == 0:
|
|
self.got_basic_info = True
|
|
self.make_get_list()
|
|
in_db_value_max = -100
|
|
out_db_value_max = -100
|
|
db_value_max = None
|
|
gr_value_max = None
|
|
try:
|
|
for (opcode, fragment) in pkt.fragments:
|
|
if opcode == protocol.OPCODE_ID:
|
|
if struct.unpack('B', fragment[0])[0] != self.slave_id:
|
|
return
|
|
else:
|
|
if opcode == protocol.OPCODE_LIST_SLAVES:
|
|
no_of_slaves = struct.unpack('B', fragment[0])[0]
|
|
if no_of_slaves > 0:
|
|
self.slave_id = chr(struct.unpack('B', fragment[1])[0])
|
|
string = str(mytime.clock()) + ' d_p.Found ' + str(no_of_slaves) + ' RS485 Slave IDs: '
|
|
for i in range(0, no_of_slaves):
|
|
string += str(struct.unpack('B', fragment[1 + i])[0]) + ', '
|
|
|
|
string = string[:-2]
|
|
print string
|
|
return
|
|
if opcode in (protocol.OPCODE_VU_DATA_IN, protocol.OPCODE_VU_DATA_OUT, protocol.OPCODE_RAW_VU_IN):
|
|
if opcode == protocol.OPCODE_VU_DATA_IN:
|
|
self.got_vu = True
|
|
channel = 0
|
|
struct_id = protocol.STRUCT_ID_VU
|
|
member_id = protocol.MEMBER_ID_VU_IN
|
|
if opcode == protocol.OPCODE_VU_DATA_OUT:
|
|
member_id = protocol.MEMBER_ID_VU_OUT
|
|
channel = 128
|
|
if opcode == protocol.OPCODE_RAW_VU_IN:
|
|
struct_id = protocol.STRUCT_ID_RAW_VU
|
|
member_id = protocol.MEMBER_ID_RAW_VU_IN
|
|
if self.parent.global_vu_stereo_out == False and self.parent.global_vu_channels == None:
|
|
db_value_max = -100
|
|
for c in fragment:
|
|
db_value = struct.unpack('b', c)[0]
|
|
self.set_read_val(db_value, struct_id, member_id, channel)
|
|
channel += 1
|
|
if db_value > db_value_max:
|
|
db_value_max = db_value
|
|
|
|
if opcode == protocol.OPCODE_VU_DATA_OUT:
|
|
out_db_value_max = db_value_max
|
|
self.set_read_val(db_value_max, protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_VU_OUT, 0, 0)
|
|
if opcode == protocol.OPCODE_VU_DATA_IN:
|
|
in_db_value_max = db_value_max
|
|
self.set_read_val(db_value_max, protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_VU_IN, 0, 0)
|
|
else:
|
|
if self.parent.global_vu_stereo_out == True:
|
|
db_value_max = 0
|
|
for c in fragment:
|
|
db_value = struct.unpack('b', c)[0]
|
|
self.set_read_val(db_value, struct_id, member_id, channel)
|
|
if channel == 128:
|
|
in_db_value_max = db_value
|
|
if channel == 129:
|
|
out_db_value_max = db_value
|
|
channel += 1
|
|
|
|
if self.parent.global_vu_channels != None:
|
|
db_value_max = 0
|
|
for c in fragment:
|
|
db_value = struct.unpack('b', c)[0]
|
|
self.set_read_val(db_value, struct_id, member_id, channel)
|
|
if channel == self.parent.global_vu_channels[0]:
|
|
in_db_value_max = db_value
|
|
if channel == self.parent.global_vu_channels[1]:
|
|
out_db_value_max = db_value
|
|
channel += 1
|
|
|
|
elif opcode in (protocol.OPCODE_GR_DATA_IN, protocol.OPCODE_GR_DATA_OUT):
|
|
channel = 0
|
|
struct_id = protocol.STRUCT_ID_GR
|
|
member_id = protocol.MEMBER_ID_GR_IN
|
|
if opcode == protocol.OPCODE_GR_DATA_OUT:
|
|
member_id = protocol.MEMBER_ID_GR_OUT
|
|
channel = 128
|
|
gr_value_max = 0
|
|
for c in fragment:
|
|
db_value = struct.unpack('b', c)[0]
|
|
self.set_read_val(db_value, struct_id, member_id, channel)
|
|
if db_value > gr_value_max:
|
|
gr_value_max = db_value
|
|
channel += 1
|
|
|
|
if opcode == protocol.OPCODE_GR_DATA_OUT:
|
|
self.set_read_val(gr_value_max, protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_GR_OUT, 0, 0)
|
|
else:
|
|
self.set_read_val(gr_value_max, protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_GR_IN, 0, 0)
|
|
elif opcode == protocol.OPCODE_VU_DATA_READING:
|
|
channel = 128
|
|
struct_id = protocol.STRUCT_ID_VU
|
|
odd = True
|
|
for c in fragment:
|
|
db_value = struct.unpack('B', c)[0]
|
|
if odd:
|
|
self.set_read_val(db_value, struct_id, protocol.MEMBER_ID_VOLTAGE_READING, channel)
|
|
db_value = db_value / 4.0 - 3.75
|
|
voltage = math.pow(10, db_value / 20)
|
|
odd = False
|
|
else:
|
|
self.set_read_val(db_value, struct_id, protocol.MEMBER_ID_CURRENT_READING, channel)
|
|
db_value = db_value / 4.0 - 13.75
|
|
current = math.pow(10, db_value / 20)
|
|
current_db = db_value
|
|
if current < 0.3:
|
|
current = 0
|
|
db_value = -100
|
|
if voltage > 2:
|
|
try:
|
|
impedance = voltage / current
|
|
try:
|
|
last_impedance = self.last_impedance[channel]
|
|
impedance = (last_impedance * 99.0 + impedance) / 100
|
|
except:
|
|
self.last_impedance[channel] = impedance
|
|
|
|
self.last_impedance[channel] = impedance
|
|
impedance = round(impedance, 1)
|
|
except:
|
|
try:
|
|
impedance = self.last_impedance[channel] * 1.01
|
|
self.last_impedance[channel] = impedance
|
|
impedance = round(impedance, 1)
|
|
except:
|
|
impedance = '--'
|
|
|
|
else:
|
|
try:
|
|
impedance = self.last_impedance[channel]
|
|
impedance = round(impedance, 1)
|
|
except:
|
|
impedance = '--'
|
|
|
|
try:
|
|
if impedance > 100 and impedance != '--':
|
|
self.last_impedance[channel] = '--'
|
|
impedance = '--'
|
|
except:
|
|
pass
|
|
|
|
self.set_read_val(str(impedance) + ' Ohm', struct_id, protocol.MEMBER_ID_IMPEDANCE_READING, channel)
|
|
try:
|
|
watt = voltage * current
|
|
watt = 20 * math.log10(watt)
|
|
except:
|
|
try:
|
|
watt = self.values[data_model.Key(struct_id, protocol.MEMBER_ID_POWER_READING, channel, 0)].read_val
|
|
except:
|
|
watt = 0
|
|
else:
|
|
if watt == None:
|
|
watt = 0
|
|
elif watt > -1:
|
|
watt = watt - 5
|
|
|
|
self.set_read_val(watt, struct_id, protocol.MEMBER_ID_POWER_READING, channel)
|
|
odd = True
|
|
channel += 1
|
|
|
|
elif opcode == protocol.OPCODE_INCLINATION:
|
|
x = struct.unpack('>h', fragment[0:2])[0] / 100.0
|
|
y = struct.unpack('>h', fragment[2:4])[0] / 100.0
|
|
z = struct.unpack('>h', fragment[4:6])[0] / 100.0
|
|
elif opcode == protocol.OPCODE_ORIENTATION:
|
|
x = struct.unpack('>h', fragment[0:2])[0]
|
|
y = struct.unpack('>h', fragment[2:4])[0]
|
|
z = struct.unpack('>h', fragment[4:6])[0]
|
|
elif opcode == protocol.OPCODE_TEST_RESULT:
|
|
one_unit.app.testResult = fragment
|
|
elif opcode == protocol.OPCODE_GPI:
|
|
bits = struct.unpack('>L', fragment[0:4])[0]
|
|
elif opcode == protocol.OPCODE_FOUND_HARDWARE:
|
|
bits = struct.unpack('>L', fragment[0:4])[0]
|
|
txt = 'Found Hardware:\n'
|
|
for bitPos in range(32):
|
|
bit = 1 << bitPos
|
|
if bits & bit:
|
|
if bit in FOUND_HARDWARE_TEXT:
|
|
txt += '\t' + FOUND_HARDWARE_TEXT[bit] + '\n'
|
|
else:
|
|
txt += '\t Unknown Hardware' + hex(bit) + '\n'
|
|
|
|
self.parent.parent.peers.units[self.parent.MAC].foundHardwareString = txt
|
|
if one_unit.app.mijnpc == True:
|
|
print mytime.displayTime(), self.parent.MAC, txt
|
|
elif opcode == protocol.OPCODE_ADC:
|
|
adcNum = struct.unpack('>B', fragment[0])[0]
|
|
if adcNum <= 23:
|
|
val = 1.02 * float(struct.unpack('>H', fragment[1:3])[0]) / 10000
|
|
adcName = 'rADC ' + str(adcNum)
|
|
if adcNum == 19:
|
|
self.adcRef33Main = val
|
|
elif adcNum == 22:
|
|
self.adcRef33Standby = val
|
|
elif adcNum == 16:
|
|
val = self.adcRef33Standby - (self.adcRef33Standby - val) * 11
|
|
self.set_read_val(val, protocol.STRUCT_ID_ADC_READING, protocol.MEMBER_ID_VSS_READING, 0, 0)
|
|
elif adcNum == 0:
|
|
val = val * 5.7
|
|
self.set_read_val(val, protocol.STRUCT_ID_ADC_READING, protocol.MEMBER_ID_VCC_READING, 0, 0)
|
|
elif adcNum == 5:
|
|
val = val * 5.7
|
|
self.set_read_val(val, protocol.STRUCT_ID_ADC_READING, protocol.MEMBER_ID_VD_READING, 0, 0)
|
|
elif adcNum > 5:
|
|
self.set_read_val(val, protocol.STRUCT_ID_ADC_READING, protocol.MEMBER_ID_ADC_READING, adcNum - 2, 0)
|
|
else:
|
|
self.set_read_val(val, protocol.STRUCT_ID_ADC_READING, protocol.MEMBER_ID_ADC_READING, adcNum - 1, 0)
|
|
else:
|
|
adcNum -= 24
|
|
if adcNum < 16:
|
|
val = struct.unpack('>B', fragment[1])[0]
|
|
self.set_read_val(val, protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_TEMPERATURE, adcNum, 0)
|
|
val = struct.unpack('>B', fragment[2])[0]
|
|
self.set_read_val(val, protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_TEMPERATURE, adcNum + 1, 0)
|
|
else:
|
|
val = struct.unpack('>B', fragment[1])[0]
|
|
self.set_read_val(val, protocol.STRUCT_ID_CHANNEL, protocol.MEMBER_ID_TEMPERATURE, adcNum - 16 + 128, 0)
|
|
val = struct.unpack('>B', fragment[2])[0]
|
|
self.set_read_val(val, protocol.STRUCT_ID_CHANNEL, protocol.MEMBER_ID_TEMPERATURE, adcNum - 16 + 128 + 1, 0)
|
|
elif opcode == protocol.OPCODE_RSP:
|
|
if len(fragment) < 5:
|
|
print mytime.displayTime() + ' Too small fragment! len=', len(fragment), ', packet discarded'
|
|
self.parent.invalid_packet_counter = self.parent.invalid_packet_counter + 1
|
|
return
|
|
struct_id = struct.unpack('B', fragment[0])[0]
|
|
member_id = struct.unpack('B', fragment[1])[0]
|
|
channel = struct.unpack('B', fragment[2])[0]
|
|
index = struct.unpack('B', fragment[3])[0]
|
|
if struct_id == protocol.STRUCT_ID_FIR and member_id & 128 == 128:
|
|
index = index + 256 * (member_id & 127)
|
|
member_id = protocol.MEMBER_ID_FIR
|
|
data_len = len(fragment) - 4
|
|
if struct_id == protocol.STRUCT_ID_FIR_BLOCK:
|
|
if channel not in self.FIRmap:
|
|
continue
|
|
FIRmap = self.FIRmap[channel]
|
|
if index > 0:
|
|
part = 2
|
|
else:
|
|
part = 1
|
|
if part == 1 and data_len / 2 != self.firBlockSize:
|
|
print mytime.displayTime(), 'FIR block size incorrect!! recalculating FIR map from', self.firBlockSize, 'to', data_len / 2
|
|
self.makeFirMap(firBlockSize=data_len / 2)
|
|
channel = FIRmap[0]
|
|
index += FIRmap[1]
|
|
offset = 0
|
|
while offset < data_len:
|
|
val = struct.unpack('>l', fragment[4 + offset:8 + offset])[0]
|
|
self.set_read_val(val, protocol.STRUCT_ID_FIR, protocol.MEMBER_ID_FIR, channel, index)
|
|
offset += 4
|
|
index += 1
|
|
|
|
continue
|
|
try:
|
|
val = struct.unpack(protocol.get_member_format(member_id), fragment[4:])[0]
|
|
except:
|
|
print mytime.displayTime() + ' ERROR: Member ID ', member_id, ' unknown'
|
|
continue
|
|
else:
|
|
self.set_read_val(val, struct_id, member_id, channel, index)
|
|
elif opcode == protocol.OPCODE_ACTIVITY_LOG:
|
|
page = ord(fragment[0])
|
|
val = fragment[1:]
|
|
tenDayLogEntries = {}
|
|
sixteenHourLogEntries = {}
|
|
oneHourLogEntries = {}
|
|
sixMinuteLogEntries = {}
|
|
latest = 0
|
|
valid = False
|
|
try:
|
|
for i in range(64):
|
|
if i == 0:
|
|
if ord(val[0]) in (224, 225):
|
|
valid = True
|
|
else:
|
|
break
|
|
else:
|
|
timeCode = ord(val[0]) & 31
|
|
if timeCode != 0:
|
|
if self.isTCS:
|
|
if self.parent.parent.peers.units[self.parent.MAC].name.lower().find('zwembad') >= 0:
|
|
averageTemperature = ord(val[1]) / 2.0
|
|
peakTemperature = ord(val[1]) / 2.0
|
|
averageSignalLevel = ord(val[2]) / 2.0
|
|
peakSignalLevel = ord(val[2]) / 2.0
|
|
averageGainReduction = ord(val[3]) / 2.0
|
|
peakGainReduction = ord(val[3]) / 2.0
|
|
print mytime.displayTime(), 'Zwembad activity log', averageSignalLevel, averageGainReduction, averageTemperature
|
|
else:
|
|
averageTemperature = ord(val[1])
|
|
peakTemperature = ord(val[1])
|
|
averageSignalLevel = ord(val[2]) * 10
|
|
peakSignalLevel = ord(val[2]) * 10
|
|
averageGainReduction = ord(val[3]) * 10
|
|
peakGainReduction = ord(val[3]) * 10
|
|
else:
|
|
averageTemperature = (ord(val[1]) & 240) / 16 * 5 + 25
|
|
peakTemperature = (ord(val[1]) & 15) * 5 + 25
|
|
averageSignalLevel = (ord(val[2]) & 240) / 16 * 6 - 64
|
|
peakSignalLevel = (ord(val[2]) & 15) * 6 - 64
|
|
averageGainReduction = (ord(val[3]) & 240) / 16
|
|
peakGainReduction = ord(val[3]) & 15
|
|
statusBits = struct.unpack('<L', val[4:8])[0]
|
|
logEntry = (ord(val[0]), averageTemperature, peakTemperature, averageSignalLevel, peakSignalLevel, averageGainReduction, peakGainReduction, statusBits)
|
|
if i < 5:
|
|
tenDayLogEntries[i] = logEntry
|
|
elif i < 20:
|
|
sixteenHourLogEntries[i] = logEntry
|
|
elif i < 36:
|
|
oneHourLogEntries[i] = logEntry
|
|
else:
|
|
sixMinuteLogEntries[i] = logEntry
|
|
val = val[8:]
|
|
|
|
printLog = False
|
|
if valid:
|
|
one_unit.app.unitLogs[self.parent.MAC] = {}
|
|
tmpList = (tenDayLogEntries, sixteenHourLogEntries, oneHourLogEntries, sixMinuteLogEntries)
|
|
tmpTitles = ('10 day', '16 hour', '1 hour', '6 minute')
|
|
latest = 0
|
|
for entryType in range(4):
|
|
one_unit.app.unitLogs[self.parent.MAC][tmpTitles[entryType]] = []
|
|
logEntries = tmpList[entryType]
|
|
if len(logEntries) == 0:
|
|
continue
|
|
lastTimeCode = logEntries[sorted(logEntries.keys())[-1]][0] & 31
|
|
for logEntry in sorted(logEntries.keys()):
|
|
timeCode = logEntries[logEntry][0] & 31
|
|
if timeCode != lastTimeCode % 31 + 1 and timeCode != 0:
|
|
latest = logEntry - 1
|
|
if latest < 0:
|
|
latest = sorted(logEntries.keys())[-1]
|
|
lastTimeCode = timeCode
|
|
|
|
sortedLogEntries = {}
|
|
for i in logEntries:
|
|
j = i - latest
|
|
if j > 0:
|
|
j -= len(logEntries)
|
|
sortedLogEntries[j] = i
|
|
|
|
tmpLogEntries = {}
|
|
for j in sorted(sortedLogEntries.keys()):
|
|
tmpLogEntries[j] = logEntries[sortedLogEntries[j]]
|
|
|
|
logEntries = tmpLogEntries
|
|
for logEntryNumber in sorted(logEntries.keys(), reverse=True):
|
|
res = logEntries[logEntryNumber]
|
|
if printLog:
|
|
if res[0] & 32 == 0:
|
|
print mytime.displayTime(), 'Activity log', tmpTitles[entryType], 'entry (newest first), entry number:', res[0] & 31, 'avgT:', res[1], 'pkT:', res[2], 'avgSL:', res[3], 'pkSL:', res[4], 'avgGR:', res[5], 'pkGR:', res[6], 'status:',
|
|
print [_[1] for i in range(32) if res[7] & 1 << i > 0]
|
|
else:
|
|
print mytime.displayTime(), 'Activity log', tmpTitles[entryType], 'entry (newest first), entry number:', res[0] & 31, 'avgT:', res[1], 'pkT:', res[2], 'avgSL:', res[3], 'pkSL:', res[4], 'avgGR:', res[5], 'pkGR:', res[6], 'ERROR:',
|
|
print [_[2] for i in range(32) if res[7] & 1 << i > 0]
|
|
one_unit.app.unitLogs[self.parent.MAC][tmpTitles[entryType]].append(res)
|
|
|
|
except:
|
|
print mytime.displayTime(), 'd_p.aLE.Error:',
|
|
print [_[3] for c in val[:20]]
|
|
traceback.print_exc(file=sys.stdout)
|
|
else:
|
|
alkey = data_model.Key(protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_ACTIVITY_LOG, 0, 0)
|
|
if alkey in self.get_list:
|
|
self.get_list.remove(alkey)
|
|
alkey = data_model.Key(protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_ACTIVITY_LOG, 0, page)
|
|
if alkey in self.get_list:
|
|
self.get_list.remove(alkey)
|
|
self.set_read_val(val, protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_ACTIVITY_LOG, 0, page)
|
|
else:
|
|
print mytime.displayTime(), 'Unknown opcode', opcode
|
|
|
|
self.parent.invalid_packet_counter = 0
|
|
except:
|
|
traceback.print_exc(file=sys.stdout)
|
|
|
|
if db_value_max != None:
|
|
if in_db_value_max > 24:
|
|
in_db_value_max = 24
|
|
if out_db_value_max > 24:
|
|
out_db_value_max = 24
|
|
server.unit_data.vu[self.parent.MAC] = (
|
|
in_db_value_max, out_db_value_max)
|
|
if gr_value_max != None:
|
|
server.unit_data.gr[self.parent.MAC] = gr_value_max
|
|
return
|
|
|
|
def set_read_val(self, val, struct_id, member_id, channel=0, num=0):
|
|
if self.parent.action != None and self.parent.action != 'start bootloader standby delay':
|
|
return
|
|
else:
|
|
if member_id == protocol.MEMBER_ID_BUILD_NUMBER:
|
|
self.parent.parent.peers.units[self.parent.MAC].BuildNumber = str(val)
|
|
try:
|
|
self.buildNumber = int(val)
|
|
except:
|
|
pass
|
|
else:
|
|
if val < 40190:
|
|
bnkey = data_model.Key(protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_MODEL_NUMBER, 0, 0)
|
|
while bnkey in self.get_list:
|
|
self.get_list.remove(bnkey)
|
|
|
|
if bnkey not in self.values:
|
|
self.values[bnkey] = Unit_var()
|
|
self.values[bnkey].read_val = -1
|
|
if val >= 41995 and self.MK2 == True and self.parent.parent.peers.units[self.parent.MAC].link_type == 'Ethernet':
|
|
alkey = data_model.Key(protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_ACTIVITY_LOG, 0, 0)
|
|
if alkey not in self.values:
|
|
self.get_list.append(alkey)
|
|
print mytime.displayTime(), 'd_p.appended key for activity log and getting 512 UI key in basic info data!!'
|
|
ui = 511
|
|
while ui >= 0:
|
|
key = data_model.Key(protocol.STRUCT_ID_UI_CONTROL, protocol.MEMBER_ID_UI_CONTROL, int(ui) / 256, int(ui) % 256)
|
|
self.get_list.append(key)
|
|
ui -= 1
|
|
|
|
if member_id == protocol.MEMBER_ID_SW_VERSION:
|
|
if val != None:
|
|
high = int(val / 65536)
|
|
mid = int((val - high * 65536) / 256)
|
|
low = int(val - high * 65536 - mid * 256)
|
|
FWVersion = str(high) + '.' + str(mid) + '.' + str(low)
|
|
self.parent.parent.peers.units[self.parent.MAC].FWVersion = FWVersion
|
|
self.parent.parent.peers.units[self.parent.MAC].numericalFWVersion = val
|
|
if int(val) < self.parent.parent.peers.units[self.parent.MAC].minBuildNumberVersion:
|
|
bnkey = data_model.Key(protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_BUILD_NUMBER, 0, 0)
|
|
while bnkey in self.get_list:
|
|
self.get_list.remove(bnkey)
|
|
|
|
if bnkey not in self.values:
|
|
self.values[bnkey] = Unit_var()
|
|
self.values[bnkey].read_val = 0
|
|
self.parent.parent.peers.units[self.parent.MAC].BuildNumber = '0'
|
|
if int(val) < self.parent.parent.peers.units[self.parent.MAC].minPINVersion:
|
|
bnkey = data_model.Key(protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_PIN, 0, 0)
|
|
while bnkey in self.get_list:
|
|
self.get_list.remove(bnkey)
|
|
|
|
if bnkey not in self.values:
|
|
self.values[bnkey] = Unit_var()
|
|
self.values[bnkey].read_val = 0
|
|
if int(val) < self.parent.parent.peers.units[self.parent.MAC].minModelFirmwareVersion:
|
|
bnkey = data_model.Key(protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_MODEL_NUMBER, 0, 0)
|
|
while bnkey in self.get_list:
|
|
self.get_list.remove(bnkey)
|
|
|
|
if bnkey not in self.values:
|
|
self.values[bnkey] = Unit_var()
|
|
self.values[bnkey].read_val = -1
|
|
if int(val) < self.parent.parent.peers.units[self.parent.MAC].minModelFirmwareVersion:
|
|
bnkey = data_model.Key(protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_MODEL_FIRMWARE, 0, 0)
|
|
while bnkey in self.get_list:
|
|
self.get_list.remove(bnkey)
|
|
|
|
if bnkey not in self.values:
|
|
self.values[bnkey] = Unit_var()
|
|
self.values[bnkey].read_val = 0
|
|
else:
|
|
key = data_model.Key(protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_BUILD_NUMBER, 0, 0)
|
|
if key not in self.values:
|
|
self.config_vars.append(key)
|
|
if struct_id == protocol.STRUCT_ID_PRESET_GLOBAL and member_id == protocol.MEMBER_ID_SHORT_NAME and num > 0:
|
|
self.maxNumberOfPresets = num
|
|
num = 0
|
|
key = Key(struct_id, member_id, channel, num)
|
|
if struct_id == protocol.STRUCT_ID_GLOBAL and member_id == protocol.MEMBER_ID_SHORT_NAME:
|
|
self.parent.parent.peers.set_unit_name(self.parent.MAC, val)
|
|
now = mytime.clock()
|
|
try:
|
|
var = self.values[key]
|
|
except KeyError:
|
|
self.values[key] = Unit_var()
|
|
var = self.values[key]
|
|
var.read_val = val
|
|
var.read_ts = now
|
|
except:
|
|
raise
|
|
|
|
try:
|
|
if struct_id == protocol.STRUCT_ID_PRESET_GLOBAL and member_id == protocol.MEMBER_ID_SHORT_NAME and channel > 0:
|
|
if ord(val[0]) == 0:
|
|
for v in val:
|
|
presetNumber = ord(v)
|
|
if presetNumber != 0:
|
|
self.set_read_val('Empty ', struct_id, member_id, channel=presetNumber)
|
|
|
|
val = 'Empty '
|
|
except:
|
|
traceback.print_exc(file=sys.stdout)
|
|
|
|
if self.Connected == True and self.LinkStatus == False:
|
|
self.LinkStatus = True
|
|
self.SyncIndicateActive = True
|
|
if var.write_val is not None:
|
|
alternative_val = None
|
|
write_val = 1
|
|
if struct_id == protocol.STRUCT_ID_GLOBAL and member_id == protocol.MEMBER_ID_HARDWARE_STATUS_FLAGS:
|
|
alternative_val = val & (4294967295L ^ protocol.HARDWARE_STATUS_FLAGS_READ_ONLY_MASK)
|
|
write_val = var.write_val & (4294967295L ^ protocol.HARDWARE_STATUS_FLAGS_READ_ONLY_MASK)
|
|
if var.write_val == val or write_val == alternative_val:
|
|
if one_unit.app.mijnpc:
|
|
if struct_id == protocol.STRUCT_ID_UI_CONTROL:
|
|
print mytime.displayTime() + ' ' + self.parent.MAC + ' Unit SET Ok: ' + protocol.get_strid_text(struct_id) + ' ' + protocol.get_member_text(member_id) + ' channel ' + str(channel) + ' no. ' + str(num) + ' set to ' + str([_[1] for c in val]) + ' (' + str(int(round(mytime.clock() - var.set_time, 3) * 1000)) + 'ms, ' + str(var.SetCount - 1) + ' retries)'
|
|
elif member_id == protocol.MEMBER_ID_USER_ACCESS_RIGHTS:
|
|
print mytime.displayTime() + ' ' + self.parent.MAC + ' Unit SET Ok: ' + protocol.get_strid_text(struct_id) + ' ' + protocol.get_member_text(member_id) + ' channel ' + str(channel) + ' no. ' + str(num) + ' set to ' + hex(int(val)) + ' (' + str(int(round(mytime.clock() - var.set_time, 3) * 1000)) + 'ms, ' + str(var.SetCount - 1) + ' retries)'
|
|
elif member_id & 128 == protocol.MEMBER_ID_FIR:
|
|
firBlock = self.firStartBlockByChannel[channel] + num / self.firBlockSize
|
|
if num == 0 or num == self.firBlockSize / 2:
|
|
print mytime.displayTime() + ' ' + self.parent.MAC + ' Unit SET Ok: FIR Half Block ' + str(firBlock) + '.' + str(num / (self.firBlockSize / 2)) + ' channel ' + str(channel) + ' (' + str(int(round(mytime.clock() - var.set_time, 3) * 1000)) + 'ms, ' + str(var.SetCount - 1) + ' retries)'
|
|
else:
|
|
print mytime.displayTime() + ' ' + self.parent.MAC + ' Unit SET Ok: ' + protocol.get_strid_text(struct_id) + ' ' + protocol.get_member_text(member_id) + ' channel ' + str(channel) + ' no. ' + str(num) + ' set to ' + str(val) + ' (' + str(int(round(mytime.clock() - var.set_time, 3) * 1000)) + 'ms, ' + str(var.SetCount - 1) + ' retries)'
|
|
var.write_val = None
|
|
var.read_val = val
|
|
var.SetCount = 0
|
|
self.setting -= 1
|
|
else:
|
|
timeout = 10
|
|
if self.MK2 == True or mytime.clock() - var.set_ts > timeout or now < 10:
|
|
var.write_val = None
|
|
if key.member_id == protocol.MEMBER_ID_AMP_READINGS:
|
|
tempkey = data_model.Key(key.struct_id, key.member_id, 130, 0)
|
|
tempval = int(val) >> 8 & 255
|
|
self.parent.parent.peers.set_by_key(self.parent.MAC, tempkey, tempval)
|
|
try:
|
|
temp = self.values[tempkey].read_val
|
|
except KeyError:
|
|
self.values[tempkey] = Unit_var()
|
|
else:
|
|
self.values[tempkey].read_val = tempval
|
|
tempkey = data_model.Key(key.struct_id, key.member_id, 129, 0)
|
|
tempval = int(val) >> 16 & 255
|
|
self.parent.parent.peers.set_by_key(self.parent.MAC, tempkey, tempval)
|
|
try:
|
|
temp = self.values[tempkey].read_val
|
|
except KeyError:
|
|
self.values[tempkey] = Unit_var()
|
|
else:
|
|
self.values[tempkey].read_val = tempval
|
|
self.values[tempkey].read_val = tempval
|
|
tempkey = data_model.Key(key.struct_id, key.member_id, 128, 0)
|
|
tempval = int(val) >> 24 & 255
|
|
self.parent.parent.peers.set_by_key(self.parent.MAC, tempkey, tempval)
|
|
try:
|
|
temp = self.values[tempkey].read_val
|
|
except KeyError:
|
|
self.values[tempkey] = Unit_var()
|
|
else:
|
|
self.values[tempkey].read_val = tempval
|
|
self.values[tempkey].read_val = tempval
|
|
val = int(val) & 255
|
|
if key.member_id == protocol.MEMBER_ID_AMP_READINGS_2:
|
|
tempkey = data_model.Key(key.struct_id, key.member_id, 0, 0)
|
|
tempval = int(val) >> 8 & 255
|
|
self.parent.parent.peers.set_by_key(self.parent.MAC, tempkey, tempval)
|
|
try:
|
|
temp = self.values[tempkey].read_val
|
|
except KeyError:
|
|
self.values[tempkey] = Unit_var()
|
|
else:
|
|
self.values[tempkey].read_val = tempval
|
|
self.values[tempkey].read_val = tempval
|
|
tempkey = data_model.Key(key.struct_id, key.member_id, 0, 1)
|
|
tempval = int(val) >> 16 & 255
|
|
self.parent.parent.peers.set_by_key(self.parent.MAC, tempkey, tempval)
|
|
try:
|
|
temp = self.values[tempkey].read_val
|
|
except KeyError:
|
|
self.values[tempkey] = Unit_var()
|
|
else:
|
|
self.values[tempkey].read_val = tempval
|
|
self.values[tempkey].read_val = tempval
|
|
tempkey = data_model.Key(key.struct_id, key.member_id, 0, 2)
|
|
tempval = int(val) >> 24 & 255
|
|
self.parent.parent.peers.set_by_key(self.parent.MAC, tempkey, tempval)
|
|
try:
|
|
temp = self.values[tempkey].read_val
|
|
except KeyError:
|
|
self.values[tempkey] = Unit_var()
|
|
else:
|
|
self.values[tempkey].read_val = tempval
|
|
self.values[tempkey].read_val = tempval
|
|
val = int(val) & 255
|
|
var.read_val = val
|
|
var.read_ts = now
|
|
self.parent.parent.peers.set_by_key(self.parent.MAC, key, val)
|
|
while key in self.get_list:
|
|
self.get_list.remove(key)
|
|
|
|
try:
|
|
self.get_time[key] = 0
|
|
self.get_counter[key] = 0
|
|
except:
|
|
pass
|
|
|
|
if struct_id == protocol.STRUCT_ID_MUTE:
|
|
muted = True
|
|
listed = False
|
|
if self.parent.mute_channels == None:
|
|
if key.channel == 0:
|
|
listed = True
|
|
if self.values[key].read_val == 0:
|
|
muted = False
|
|
if self.values[key].read_val == None:
|
|
listed = False
|
|
elif key.channel in self.parent.mute_channels:
|
|
listed = True
|
|
for channel in self.parent.mute_channels:
|
|
testKey = data_model.Key(protocol.STRUCT_ID_MUTE, protocol.MEMBER_ID_MUTE, channel, 0)
|
|
if testKey not in self.values or self.values[testKey].read_val == None:
|
|
listed = False
|
|
continue
|
|
if self.values[testKey].read_val == 0:
|
|
muted = False
|
|
break
|
|
|
|
if listed == True:
|
|
self.muted = muted
|
|
self.parent.parent.peers.units[self.parent.MAC].Muted = str(self.muted)
|
|
return
|
|
|
|
def getVarsForCommand(self, packetLen):
|
|
if packetLen > 50 and len(self.get_list) > 5:
|
|
key = self.choose_var_to_update(get=True)
|
|
if key == None:
|
|
return (None, None)
|
|
if key in data_model.GET_replace_list:
|
|
key = data_model.GET_replace_list[key]
|
|
if key.member_id in (protocol.MEMBER_ID_AMP_READINGS, protocol.MEMBER_ID_AMP_READINGS_2):
|
|
key = data_model.Key(protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_CURRENT_USER, 0, 0)
|
|
if key in self.commandKeys:
|
|
return (None, None)
|
|
return (key, None)
|
|
else:
|
|
key = self.choose_var_to_update()
|
|
if key == None:
|
|
return (None, None)
|
|
if key in self.values:
|
|
val = self.values[key].write_val
|
|
else:
|
|
val = None
|
|
if val == None:
|
|
if key in data_model.GET_replace_list:
|
|
key = data_model.GET_replace_list[key]
|
|
if key.member_id in (protocol.MEMBER_ID_AMP_READINGS, protocol.MEMBER_ID_AMP_READINGS_2):
|
|
key = data_model.Key(protocol.STRUCT_ID_GLOBAL, protocol.MEMBER_ID_CURRENT_USER, 0, 0)
|
|
return (
|
|
key, val)
|
|
|
|
def build_command(self, HW_id, my_id):
|
|
"""Build a command for reading and optionally writing to interface
|
|
variables. Computes checksum, prepents length."""
|
|
cmd = chr(5) + 'DDJ'
|
|
packetLen = 4
|
|
self.commandKeys = []
|
|
if self.MK2 == True:
|
|
maxLen = 768
|
|
else:
|
|
maxLen = 16
|
|
if self.check_vars_delay <= 0:
|
|
self.check_vars_delay = CHOOSE_VAR_TO_UPDATE_SKIP_CYCLES
|
|
while packetLen < maxLen:
|
|
try:
|
|
(k, v) = self.getVarsForCommand(packetLen)
|
|
except:
|
|
traceback.print_exc(file=sys.stdout)
|
|
|
|
if k == None:
|
|
break
|
|
self.commandKeys.append(k)
|
|
(struct_id, member_id, channel, index) = k
|
|
if channel is None or channel < 0:
|
|
print mytime.displayTime() + ' d_p.bc.polluted cache: channel =', channel
|
|
channel = 0
|
|
v = None
|
|
if v is None:
|
|
opcode = protocol.OPCODE_GET
|
|
if struct_id == protocol.STRUCT_ID_FIR and member_id & 128 == 128:
|
|
if self.buildNumber > 44356:
|
|
if channel not in self.firStartBlockByChannel or self.firBlockSize < 2:
|
|
if self.full_config != None:
|
|
print mytime.displayTime(), 'd_p.bc.FIR map Get error for channel', channel, '-> probeer FIR map te maken', self.firStartBlockByChannel
|
|
try:
|
|
self.makeFirMap()
|
|
mytime.sleep(0.1)
|
|
if one_unit.app.application_stopping:
|
|
return cmd
|
|
except:
|
|
print mytime.displayTime(), 'd_p.failed to make FIR map'
|
|
traceback.print_exc(file=sys.stdout)
|
|
|
|
continue
|
|
try:
|
|
startBlock = self.firStartBlockByChannel[channel]
|
|
inIndex = index
|
|
channel = startBlock + index / self.firBlockSize
|
|
blockIndex = index / (self.firBlockSize / 2) * (self.firBlockSize / 2)
|
|
if index != blockIndex:
|
|
safeRemove(self.get_list, k)
|
|
continue
|
|
index = blockIndex
|
|
struct_id = protocol.STRUCT_ID_FIR_BLOCK
|
|
index = index % self.firBlockSize
|
|
except:
|
|
print mytime.displayTime(), 'd_p. FIR map command error'
|
|
traceback.print_exc(file=sys.stdout)
|
|
continue
|
|
|
|
else:
|
|
findex = index
|
|
index = findex % 256
|
|
member_id += findex / 256
|
|
if member_id >= 1000:
|
|
try:
|
|
self.get_list.remove(k)
|
|
except:
|
|
pass
|
|
else:
|
|
continue
|
|
try:
|
|
cmd += ('').join([_[1] for i in (opcode, 7, struct_id, member_id, channel, index)]) + 'j'
|
|
except:
|
|
print mytime.displayTime(), 'd_p. error building command', opcode, struct_id, member_id, channel, index
|
|
traceback.print_exc(file=sys.stdout)
|
|
else:
|
|
packetLen += 7
|
|
else:
|
|
opcode = protocol.OPCODE_SET
|
|
if self.factory == True:
|
|
opcode = protocol.OPCODE_FACTORY
|
|
if struct_id == protocol.STRUCT_ID_FIR and member_id & 128 == 128:
|
|
if self.buildNumber > 44356:
|
|
if channel not in self.firStartBlockByChannel:
|
|
print mytime.displayTime(), 'd_p.bc.FIR map Set error for channel', channel, '-> aborting', self.firStartBlockByChannel
|
|
continue
|
|
try:
|
|
startBlock = self.firStartBlockByChannel[channel]
|
|
if packetLen + 6 + self.firBlockSize / 2 * 4 > maxLen:
|
|
break
|
|
process = startBlock + index / self.firBlockSize
|
|
index = index / (self.firBlockSize / 2) * (self.firBlockSize / 2)
|
|
struct_id = protocol.STRUCT_ID_FIR_BLOCK
|
|
new_val = ''
|
|
for i in range(self.firBlockSize / 2):
|
|
key = data_model.Key(protocol.STRUCT_ID_FIR, protocol.MEMBER_ID_FIR, channel, index + i)
|
|
try:
|
|
var = self.values[key]
|
|
v = var.write_val
|
|
if v == None:
|
|
v = var.read_val
|
|
else:
|
|
var.SetCount = var.SetCount + 1
|
|
var.set_ts = mytime.clock()
|
|
if v == None:
|
|
print mytime.displayTime(), 'd_p.bc. FIR block: No write val, no read val for key', key, ', defaulting to 0'
|
|
v = 0
|
|
except:
|
|
v = 0
|
|
|
|
new_val += struct.pack('>l', v)
|
|
|
|
sentIndex = index % self.firBlockSize
|
|
cmd += ('').join([_[2] for i in (opcode, 6 + len(new_val) / 4, struct_id, member_id, process, sentIndex)]) + new_val
|
|
packetLen += 6 + len(new_val)
|
|
continue
|
|
except:
|
|
print mytime.displayTime(), 'd_p. FIR map command error'
|
|
traceback.print_exc(file=sys.stdout)
|
|
continue
|
|
|
|
else:
|
|
findex = index
|
|
index = findex % 256
|
|
member_id += findex / 256
|
|
new_val = struct.pack(protocol.get_member_format(member_id), v)
|
|
else:
|
|
new_val = struct.pack(protocol.get_member_format(member_id), v)
|
|
cmd += ('').join([_[3] for i in (opcode, 6 + len(new_val), struct_id, member_id, channel, index)]) + new_val
|
|
packetLen += 6 + len(new_val)
|
|
|
|
else:
|
|
self.check_vars_delay -= 1
|
|
if packetLen > 4:
|
|
decoded_buf = ''
|
|
i = 0
|
|
for encoded_byte in cmd[4:]:
|
|
decoded_byte = ord(encoded_byte) ^ CodeTable[i % 32]
|
|
i += 1
|
|
decoded_buf += chr(decoded_byte)
|
|
|
|
cmd = cmd[:4] + decoded_buf
|
|
cmd += chr(253) + chr(HW_id) + chr(255) + chr(my_id)
|
|
if self.MK2 == True:
|
|
cmd = chr(packetLen / 256) + chr(packetLen % 256) + cmd[2:]
|
|
cs = Checksum()
|
|
cs.add(cmd)
|
|
cmd += cs.get()
|
|
return cmd
|
|
|
|
|
|
def print_hex(cmd):
|
|
s = ''
|
|
for c in cmd:
|
|
s += hex(ord(c)) + ':'
|
|
|
|
s = s[:-1]
|
|
return s
|
|
|
|
|
|
class Announcement():
|
|
"""The announcement broadcast by hardware units over USB"""
|
|
|
|
def __init__(self):
|
|
"""Constructor"""
|
|
self.UnitType2 = None
|
|
self.UnitType1 = None
|
|
self.MAC = None
|
|
self.PC_PacketId = None
|
|
self.HW_PacketId = None
|
|
self.skin_high = None
|
|
self.skin_mid = None
|
|
self.skin_low = None
|
|
self.broadcasted_skin = None
|
|
self.MK2 = False
|
|
return
|
|
|
|
def __str__(self):
|
|
return 'Announcement(%s, Type1=%s, Type2=%s)' % (self.MAC,
|
|
self.UnitType1, self.UnitType2)
|
|
|
|
|
|
class Data_packet():
|
|
"""The announcement broadcast by hardware units over USB"""
|
|
|
|
def __init__(self):
|
|
"""Constructor"""
|
|
self.fragments = []
|
|
self.PC_PacketId = None
|
|
self.HW_PacketId = None
|
|
self.invalid_packet_counter = 0
|
|
self.MK2 = False
|
|
return
|
|
|
|
def __str__(self):
|
|
return 'Data_packet '
|
|
|
|
|
|
class NACK_packet():
|
|
"""The packet is sent by the HW unit to indicate that it was not
|
|
able to process the latest command from me for whatever internal
|
|
reason. The command can be repeated, the sequence numbers in the
|
|
session should not change."""
|
|
|
|
def __init__(self):
|
|
"""Constructor"""
|
|
self.PC_PacketId = None
|
|
self.HW_PacketId = None
|
|
self.MK2 = False
|
|
return
|
|
|
|
def __str__(self):
|
|
return 'NACK packet '
|
|
|
|
|
|
class Checksum():
|
|
"""This one-byte checksum helps ensuring the data integrity
|
|
in communication between hardware units and our software.
|
|
"""
|
|
|
|
def __init__(self):
|
|
self.cs = 170
|
|
return
|
|
|
|
def add(self, s):
|
|
"""Update the checksum with the string 's'."""
|
|
for c in s:
|
|
self.cs ^= ord(c)
|
|
|
|
return
|
|
|
|
def get(self):
|
|
"""Get the accumulated checksum as a character."""
|
|
return chr(self.cs)
|
|
|
|
|
|
def parse_announce(data):
|
|
"""Parse the data sent by MakeConfigData(void) in DDEthernet.c,
|
|
line 537. This data can be found in UDP broadcasts and in TCP
|
|
responces to the 'J' command from the user.
|
|
"""
|
|
if len(data) < 42 or data[41] != 'Q' or data[:3] != 'DDB':
|
|
return None
|
|
else:
|
|
res = Announcement()
|
|
res.UnitType2 = ord(data[4])
|
|
res.UnitType1 = ord(data[5])
|
|
res.MAC = data[6:22]
|
|
res.PC_PacketID = ord(data[39])
|
|
res.HW_PacketID = ord(data[40])
|
|
res.skin_high = ord(data[33])
|
|
res.skin_mid = ord(data[34])
|
|
res.skin_low = ord(data[35])
|
|
res.broadcasted_skin = ''
|
|
res.broadcasted_skin += chr(ord('0') + res.skin_high) + '_' + chr(ord('0') + res.skin_mid) + '_' + chr(ord('0') + res.skin_low)
|
|
return res
|
|
|
|
|
|
def parse_NACK(data):
|
|
if len(data) < 42 or data[41] != 'Q' or data[:3] != 'DDN' and data[:3] != 'DDM':
|
|
return None
|
|
else:
|
|
res = NACK_packet()
|
|
res.PC_PacketID = ord(data[39])
|
|
res.HW_PacketID = ord(data[40])
|
|
return res
|
|
|
|
|
|
def parse_data_packet(data, length=32):
|
|
res = Data_packet()
|
|
if data[:3] == 'DDA':
|
|
res.PC_PacketID = ord(data[39])
|
|
res.HW_PacketID = ord(data[40])
|
|
if len(data) < length + 10 or data[length + 9] != 'Q' or data[:3] != 'DDA':
|
|
res.invalid_packet_counter = 1
|
|
return res
|
|
try:
|
|
if length == 32:
|
|
if ord(data[3]) == 233:
|
|
if ord(data[4]) == 213:
|
|
opcode = 9
|
|
else:
|
|
opcode = 5
|
|
try:
|
|
next_opcode = ord(data[ord(data[4]) + 3])
|
|
if next_opcode == 2:
|
|
opcode = 1
|
|
if next_opcode == 8:
|
|
opcode = 7
|
|
except:
|
|
pass
|
|
|
|
new_data = data[:3] + chr(opcode) + data[4:]
|
|
data = new_data
|
|
except:
|
|
pass
|
|
else:
|
|
pos = 3
|
|
elif data[:3] == 'DDW':
|
|
res.PC_PacketID = ord(data[7])
|
|
res.HW_PacketID = ord(data[8])
|
|
res.MK2 = True
|
|
pos = 10
|
|
else:
|
|
print mytime.displayTime() + ' Got strange packet:'
|
|
print mytime.displayTime() + (' ').join([_[1] for c in data[:len(data)]])
|
|
return
|
|
checksum_ok = False
|
|
while pos + 2 < len(data):
|
|
opcode = ord(data[pos])
|
|
pos += 1
|
|
if opcode == protocol.OPCODE_DATA_END:
|
|
break
|
|
elif opcode == protocol.OPCODE_CHECKSUM:
|
|
checksum = 213
|
|
if data[:3] == 'DDA':
|
|
for i in range(3, pos - 1):
|
|
checksum = checksum ^ ord(data[i])
|
|
|
|
else:
|
|
for i in range(10, pos - 1):
|
|
checksum = checksum ^ ord(data[i])
|
|
|
|
result = checksum - ord(data[pos])
|
|
pos += 1
|
|
if result != 0:
|
|
res.fragments = []
|
|
res.invalid_packet_counter = res.invalid_packet_counter + 1
|
|
print mytime.displayTime() + ' Checksum error, packet discarded'
|
|
return res
|
|
checksum_ok = True
|
|
continue
|
|
elif opcode == protocol.OPCODE_ACTIVITY_LOG:
|
|
size = 513
|
|
res.fragments.append((opcode, data[pos:pos + size]))
|
|
pos += 513
|
|
continue
|
|
elif opcode in (protocol.OPCODE_ADC, protocol.OPCODE_TEST_RESULT):
|
|
size = ord(data[pos])
|
|
pos += 1
|
|
size -= 2
|
|
if size < 1:
|
|
print mytime.displayTime() + ' Too small fragment 2, opcode: ', opcode, ' size:', size + 2, ',data:',
|
|
print (' ').join([_[2] for c in data[:len(data)]])
|
|
res.fragments = []
|
|
res.invalid_packet_counter = res.invalid_packet_counter + 1
|
|
return res
|
|
if pos + size >= len(data):
|
|
res.invalid_packet_counter = res.invalid_packet_counter + 1
|
|
res.fragments = []
|
|
return res
|
|
res.fragments.append((opcode, data[pos:pos + size]))
|
|
pos += size
|
|
else:
|
|
size = ord(data[pos])
|
|
pos += 1
|
|
if opcode == protocol.OPCODE_RSP:
|
|
strid = ord(data[pos])
|
|
if strid == protocol.STRUCT_ID_FIR_BLOCK:
|
|
size = (size - 6) * 4 + 6
|
|
size -= 2
|
|
if size < 1:
|
|
print mytime.displayTime() + ' Too small fragment 3, opcode: ', opcode, ' size:', size + 2, ',data:',
|
|
print (' ').join([_[3] for c in data[:len(data)]])
|
|
res.fragments = []
|
|
res.invalid_packet_counter = res.invalid_packet_counter + 1
|
|
return res
|
|
if pos + size >= len(data):
|
|
res.invalid_packet_counter = res.invalid_packet_counter + 1
|
|
res.fragments = []
|
|
return res
|
|
res.fragments.append((opcode, data[pos:pos + size]))
|
|
pos += size
|
|
|
|
if checksum_ok != True:
|
|
res.fragments = []
|
|
res.invalid_packet_counter = res.invalid_packet_counter + 1
|
|
return res
|
|
|
|
|
|
def setkeepalives(sck):
|
|
sck.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
|
|
return
|
|
|
|
|
|
def read_packet(ser):
|
|
buf = ''
|
|
try:
|
|
waiting = ser.inWaiting()
|
|
if waiting < 42:
|
|
return
|
|
buf = ser.read(42)
|
|
return parse_packet(buf)
|
|
except:
|
|
return
|
|
|
|
return
|
|
|
|
|
|
def readableErrorcode(code):
|
|
if code == 1:
|
|
return '1: response_len < 9'
|
|
if code == 2:
|
|
return '2: validLen != response_len-5'
|
|
if code == 3:
|
|
return "3: nw_rx_buffer[3]!='J'"
|
|
if code == 4:
|
|
return '4: Checksum failed'
|
|
if code == 5:
|
|
return '5: response_len>1200'
|
|
if code == 7:
|
|
return '7: send while send_flag True'
|
|
return str(code) + ': unregistered error'
|
|
|
|
|
|
def parse_packet(buf, length=32):
|
|
if buf.find('DD') < 0:
|
|
buf = ''
|
|
return
|
|
else:
|
|
if buf[:3] == 'DDW':
|
|
length += 10
|
|
if length < 12:
|
|
return
|
|
if length - 10 != 256 * ord(buf[8]) + ord(buf[9]) or length != len(buf):
|
|
return
|
|
try:
|
|
decoded_buf = buf[:10]
|
|
for i in range(10, length):
|
|
decoded_byte = ord(buf[i]) ^ CodeTable[(i - 10) % 34]
|
|
decoded_buf += chr(decoded_byte)
|
|
|
|
except:
|
|
traceback.print_exc(file=sys.stdout)
|
|
return
|
|
else:
|
|
try:
|
|
pkt = parse_data_packet(decoded_buf + 'Q', length)
|
|
except:
|
|
traceback.print_exc(file=sys.stdout)
|
|
return
|
|
|
|
if pkt == None:
|
|
return
|
|
return pkt
|
|
if buf[length + 9] != 'Q':
|
|
if len(buf) == 10 and buf[:3] == 'DDN':
|
|
errorcode = ord(buf[5])
|
|
errornumber1 = ord(buf[6]) * 256 + ord(buf[7])
|
|
errornumber2 = ord(buf[8]) * 256 + ord(buf[9])
|
|
return
|
|
return
|
|
pkt = None
|
|
if buf[:3] == 'DDB':
|
|
pkt = parse_announce(buf)
|
|
elif buf[:3] == 'DDA' or buf[:3] == 'DDN':
|
|
try:
|
|
if ord(buf[3]) == 0 and ord(buf[4]) == 0:
|
|
packet_empty = True
|
|
else:
|
|
packet_empty = False
|
|
decoded_buf = ''
|
|
i = 0
|
|
for encoded_byte in buf[3:length + 7]:
|
|
if packet_empty:
|
|
decoded_byte = 0
|
|
else:
|
|
decoded_byte = ord(encoded_byte) ^ CodeTable[i]
|
|
i += 1
|
|
if i > 31:
|
|
i = 0
|
|
decoded_buf += chr(decoded_byte)
|
|
|
|
buf = 'DDA' + decoded_buf + buf[length + 7:]
|
|
except:
|
|
traceback.print_exc(file=sys.stdout)
|
|
else:
|
|
try:
|
|
pkt = parse_data_packet(buf, length)
|
|
except:
|
|
traceback.print_exc(file=sys.stdout)
|
|
else:
|
|
if pkt == None:
|
|
return
|
|
elif buf[:3] == 'DDN':
|
|
return
|
|
if buf[:3] == 'DDC':
|
|
pkt = parse_NACK(buf)
|
|
elif buf[:3] == 'DDM':
|
|
pkt = parse_NACK(buf)
|
|
else:
|
|
return
|
|
return pkt
|
|
|
|
|
|
|
|
# okay decompiling pycode/d_protocol.pyc
|