|
|
|
@ -2,6 +2,7 @@ import sys
|
|
|
|
|
sys.path.append('../../')
|
|
|
|
|
|
|
|
|
|
import struct
|
|
|
|
|
from enum import Enum
|
|
|
|
|
|
|
|
|
|
from utils.DBModels.DeviceParModels import *
|
|
|
|
|
from protocol.ModBus.DPV1Master import DPV1Master
|
|
|
|
@ -14,7 +15,7 @@ class BlockType(Enum):
|
|
|
|
|
levelTB = -3 # 物位转换块
|
|
|
|
|
pressureTB = -4
|
|
|
|
|
PB = 0
|
|
|
|
|
FB = 1
|
|
|
|
|
FB = 2
|
|
|
|
|
|
|
|
|
|
class BlockManage():
|
|
|
|
|
_instance = None
|
|
|
|
@ -25,9 +26,10 @@ class BlockManage():
|
|
|
|
|
cls._instance = super().__new__(cls)
|
|
|
|
|
return cls._instance
|
|
|
|
|
|
|
|
|
|
def __init__(self, address = 66):
|
|
|
|
|
def __init__(self, address = None):
|
|
|
|
|
self.address = address
|
|
|
|
|
self.initBlocks()
|
|
|
|
|
if address:
|
|
|
|
|
self.initBlocks()
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def DPV1Master(self):
|
|
|
|
@ -44,6 +46,7 @@ class BlockManage():
|
|
|
|
|
BlockType.FB : [],
|
|
|
|
|
}
|
|
|
|
|
dirHeadDatas = self.DPV1Master.readParm(address = self.address, slot = 1, index = 0, length = 12)
|
|
|
|
|
dirHeadDatas = struct.unpack('>6h', dirHeadDatas)
|
|
|
|
|
DirID = dirHeadDatas[0] # 目录id
|
|
|
|
|
DirRevNum = dirHeadDatas[1] # 目录版本号
|
|
|
|
|
NumDirObj = dirHeadDatas[2] # 目录对象的个数 (如果整个目录使用多于一个目录对象,
|
|
|
|
@ -58,10 +61,11 @@ class BlockManage():
|
|
|
|
|
|
|
|
|
|
dirLength = 4 * NumDirEntry
|
|
|
|
|
dirDatas = self.DPV1Master.readParm(address = self.address, slot = 1, index = 1, length = dirLength)
|
|
|
|
|
dirDatas = struct.unpack('>{}h'.format(int(dirLength/2)), dirDatas)
|
|
|
|
|
entryTuples = [(dirDatas[i], dirDatas[i+1]) for i in range(0, len(dirDatas), 2)]
|
|
|
|
|
|
|
|
|
|
for typ in [BlockType.PB, BlockType.TB, BlockType.FB]:
|
|
|
|
|
typeIndex = typ.value
|
|
|
|
|
typeIndex = typ.value if type(typ.value) == int else 1
|
|
|
|
|
blkDirMesByte = struct.pack('>h', entryTuples[typeIndex][0])
|
|
|
|
|
blkIndex = int(blkDirMesByte[0]) # 目录对象编号
|
|
|
|
|
blkoffect = int(blkDirMesByte[1]) # 块从第几个Dir_Entry开始
|
|
|
|
@ -69,27 +73,33 @@ class BlockManage():
|
|
|
|
|
# print(blkIndex, blkoffect, numBlk)
|
|
|
|
|
for i in range(numBlk):
|
|
|
|
|
blkEntryListIndex = blkoffect - 1 + i
|
|
|
|
|
# print(blkEntryListIndex, entryTuples)
|
|
|
|
|
blkPointerByte = struct.pack('>h', entryTuples[blkEntryListIndex][0])
|
|
|
|
|
numBlkParms = entryTuples[blkEntryListIndex][1]
|
|
|
|
|
blkSlot = int(blkPointerByte[0])
|
|
|
|
|
blkStartIndex = int(blkPointerByte[1])
|
|
|
|
|
|
|
|
|
|
# print(111, blkStartIndex, )
|
|
|
|
|
block = Block(typ, self.DPV1Master)
|
|
|
|
|
block.slot = blkSlot
|
|
|
|
|
block.startIndex = blkStartIndex
|
|
|
|
|
block.numParms = numBlkParms
|
|
|
|
|
block.blockIndex = i
|
|
|
|
|
block.address = self.address
|
|
|
|
|
block.addParms()
|
|
|
|
|
if not block.getTBType():
|
|
|
|
|
self.blockDict[typ].append(block)
|
|
|
|
|
self.blockDict[typ].append(block)
|
|
|
|
|
# print(blkSlot, blkIndex)
|
|
|
|
|
# print(self.blockDict)
|
|
|
|
|
|
|
|
|
|
def getBlockValues(slef, blockType, blockIndex):
|
|
|
|
|
def getBlockValues(self, blockType, blockIndex):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def getBlockNums(self):
|
|
|
|
|
return [len(self.blockDict[BlockType.PB]), len(self.blockDict[BlockType.TB]), len(self.blockDict[BlockType.FB])]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def searchSlave(self, callback):
|
|
|
|
|
self.DPV1Master.searchSlave(callback)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Block():
|
|
|
|
@ -101,8 +111,8 @@ class Block():
|
|
|
|
|
def __init__(self, blockType, DPV1Master):
|
|
|
|
|
self.parms = []
|
|
|
|
|
self.blockType = blockType
|
|
|
|
|
self.addParms()
|
|
|
|
|
self.DPV1Master = DPV1Master
|
|
|
|
|
# self.addParms()
|
|
|
|
|
|
|
|
|
|
def addParms(self):
|
|
|
|
|
getParmsFunc = {
|
|
|
|
@ -113,12 +123,15 @@ class Block():
|
|
|
|
|
|
|
|
|
|
parmsData = getParmsFunc()
|
|
|
|
|
for parmData in parmsData:
|
|
|
|
|
parm = Parm(parmData, self.slot, self.startIndex, self.DPV1Master)
|
|
|
|
|
# print(parmData)
|
|
|
|
|
# print(self.startIndex, 3214)
|
|
|
|
|
parm = Parm(parmData, self.slot, self.startIndex, self)
|
|
|
|
|
|
|
|
|
|
def getTBType(self):
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
def setTBType(self):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|