Merge pull request #54 from s-allius/s-allius/issue53

S allius/issue53
This commit is contained in:
Stefan Allius
2024-04-18 19:00:54 +02:00
committed by GitHub
2 changed files with 37 additions and 22 deletions

View File

@@ -14,15 +14,15 @@ class RegisterMap:
__slots__ = ()
map = {
# 0x41020007: {'reg': Register.DEVICE_SNR, 'fmt': '<L'}, # noqa: E501
0x41020018: {'reg': Register.DATA_UP_INTERVAL, 'fmt': '!B', 'ratio': 60}, # noqa: E501
0x41020019: {'reg': Register.COLLECT_INTERVAL, 'fmt': '!B', 'ratio': 1}, # noqa: E501
0x4102001a: {'reg': Register.HEARTBEAT_INTERVAL, 'fmt': '!B', 'ratio': 1}, # noqa: E501
0x4102001c: {'reg': Register.SIGNAL_STRENGTH, 'fmt': '!B', 'ratio': 1}, # noqa: E501
0x41020018: {'reg': Register.DATA_UP_INTERVAL, 'fmt': '<B', 'ratio': 60}, # noqa: E501
0x41020019: {'reg': Register.COLLECT_INTERVAL, 'fmt': '<B', 'ratio': 1}, # noqa: E501
0x4102001a: {'reg': Register.HEARTBEAT_INTERVAL, 'fmt': '<B', 'ratio': 1}, # noqa: E501
0x4102001c: {'reg': Register.SIGNAL_STRENGTH, 'fmt': '<B', 'ratio': 1}, # noqa: E501
0x4102001e: {'reg': Register.COLLECTOR_FW_VERSION, 'fmt': '!40s'}, # noqa: E501
0x4102004c: {'reg': Register.IP_ADRESS, 'fmt': '!16s'}, # noqa: E501
0x41020064: {'reg': Register.VERSION, 'fmt': '!40s'}, # noqa: E501
0x4201001c: {'reg': Register.POWER_ON_TIME, 'fmt': '!H', 'ratio': 1}, # noqa: E501
0x4201001c: {'reg': Register.POWER_ON_TIME, 'fmt': '<H', 'ratio': 1}, # noqa: E501
0x42010020: {'reg': Register.SERIAL_NUMBER, 'fmt': '!16s'}, # noqa: E501
0x420100d2: {'reg': Register.GRID_VOLTAGE, 'fmt': '!H', 'ratio': 0.1}, # noqa: E501
0x420100d4: {'reg': Register.GRID_CURRENT, 'fmt': '!H', 'ratio': 0.01}, # noqa: E501
@@ -56,6 +56,8 @@ class RegisterMap:
0x42010126: {'reg': Register.MAX_DESIGNED_POWER, 'fmt': '!H', 'ratio': 1}, # noqa: E501
0x42010170: {'reg': Register.NO_INPUTS, 'fmt': '!B'}, # noqa: E501
0x4281001c: {'reg': Register.POWER_ON_TIME, 'fmt': '<H', 'ratio': 1}, # noqa: E501
}

View File

@@ -55,6 +55,7 @@ class SolarmanV5(Message):
self.seq = Sequence(server_side)
self.snr = 0
self.db = InfosG3P()
self.time_ofs = 0
self.switch = {
0x4210: self.msg_data_ind, # real time data
@@ -352,9 +353,10 @@ class SolarmanV5(Message):
total = result[1]
tim = result[2]
res = result[3] # always zero
logger.info(f'frame type:{ftype:02x} total:{total}s'
logger.info(f'frame type:{ftype:02x}'
f' timer:{tim:08x}s null:{res}')
dt = datetime.fromtimestamp(total)
if self.time_ofs:
dt = datetime.fromtimestamp(total + self.time_ofs)
logger.info(f'ts: {dt.strftime("%Y-%m-%d %H:%M:%S")}')
self.__process_data(ftype)
@@ -363,27 +365,33 @@ class SolarmanV5(Message):
def msg_data_ind(self):
data = self._recv_buffer
result = struct.unpack_from('<BLLLLL', data, self.header_len)
result = struct.unpack_from('<BHLLLHL', data, self.header_len)
ftype = result[0] # 1 or 0x81
total = result[1]
tim = result[2]
offset = result[3]
unkn = result[4]
cnt = result[5]
logger.info(f'ftype:{ftype:02x} total:{total}s'
f' timer:{tim:08x}s ofs:{offset}'
f' ??: {unkn:08x} cnt:{cnt}')
dt = datetime.fromtimestamp(total)
total = result[2]
tim = result[3]
if 1 == ftype:
self.time_ofs = result[4]
unkn = result[5]
cnt = result[6]
logger.info(f'ftype:{ftype:02x} timer:{tim:08x}s'
f' ??: {unkn:04x} cnt:{cnt}')
if self.time_ofs:
dt = datetime.fromtimestamp(total + self.time_ofs)
logger.info(f'ts: {dt.strftime("%Y-%m-%d %H:%M:%S")}')
self.__process_data(ftype & 0x7f) # mask bit 7 (0x80)
self.__process_data(ftype)
self.__forward_msg()
self.__send_ack_rsp(0x1210, ftype)
def msg_sync_start(self):
data = self._recv_buffer[self.header_len:]
result = struct.unpack_from('<B', data, 0)
result = struct.unpack_from('<BLLL', data, 0)
ftype = result[0]
total = result[1]
self.time_ofs = result[3]
dt = datetime.fromtimestamp(total + self.time_ofs)
logger.info(f'ts: {dt.strftime("%Y-%m-%d %H:%M:%S")}')
self.__forward_msg()
self.__send_ack_rsp(0x1310, ftype)
@@ -407,8 +415,13 @@ class SolarmanV5(Message):
def msg_sync_end(self):
data = self._recv_buffer[self.header_len:]
result = struct.unpack_from('<B', data, 0)
result = struct.unpack_from('<BLLL', data, 0)
ftype = result[0]
total = result[1]
self.time_ofs = result[3]
dt = datetime.fromtimestamp(total + self.time_ofs)
logger.info(f'ts: {dt.strftime("%Y-%m-%d %H:%M:%S")}')
self.__forward_msg()
self.__send_ack_rsp(0x1810, ftype)