move forward_at_cmd_resp into InfosG3P class
- the variable is shared between the two connections of an inverter. One is for the TSUN cloud and the other for the device.
This commit is contained in:
@@ -193,11 +193,19 @@ class RegisterSel:
|
|||||||
|
|
||||||
|
|
||||||
class InfosG3P(Infos):
|
class InfosG3P(Infos):
|
||||||
__slots__ = ('client_mode', )
|
__slots__ = ('client_mode', 'forward_at_cmd_resp')
|
||||||
|
|
||||||
def __init__(self, client_mode: bool):
|
def __init__(self, client_mode: bool):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.client_mode = client_mode
|
self.client_mode = client_mode
|
||||||
|
# shared value between both inverter connections
|
||||||
|
self.forward_at_cmd_resp = False
|
||||||
|
'''Flag if response for the last at command must be send to the cloud.
|
||||||
|
|
||||||
|
False: send result only to the MQTT broker, cause the AT+ command
|
||||||
|
came from there
|
||||||
|
True: send response packet to the cloud, cause the AT+ command
|
||||||
|
came from the cloud'''
|
||||||
self.set_db_def_value(Register.MANUFACTURER, 'TSUN')
|
self.set_db_def_value(Register.MANUFACTURER, 'TSUN')
|
||||||
self.set_db_def_value(Register.EQUIPMENT_MODEL, 'TSOL-MSxx00')
|
self.set_db_def_value(Register.EQUIPMENT_MODEL, 'TSOL-MSxx00')
|
||||||
self.set_db_def_value(Register.CHIP_TYPE, 'IGEN TECH')
|
self.set_db_def_value(Register.CHIP_TYPE, 'IGEN TECH')
|
||||||
|
|||||||
@@ -259,7 +259,6 @@ class SolarmanV5(SolarmanBase):
|
|||||||
mb_timeout=8)
|
mb_timeout=8)
|
||||||
|
|
||||||
self.db = InfosG3P(client_mode)
|
self.db = InfosG3P(client_mode)
|
||||||
self.forward_at_cmd_resp = False
|
|
||||||
self.no_forwarding = False
|
self.no_forwarding = False
|
||||||
'''not allowed to connect to TSUN cloud by connection type'''
|
'''not allowed to connect to TSUN cloud by connection type'''
|
||||||
self.establish_inv_emu = False
|
self.establish_inv_emu = False
|
||||||
@@ -519,7 +518,7 @@ class SolarmanV5(SolarmanBase):
|
|||||||
await Proxy.mqtt.publish(f'{Proxy.entity_prfx}{node_id}{key}', data_json) # noqa: E501
|
await Proxy.mqtt.publish(f'{Proxy.entity_prfx}{node_id}{key}', data_json) # noqa: E501
|
||||||
return
|
return
|
||||||
|
|
||||||
self.forward_at_cmd_resp = False
|
self.db.forward_at_cmd_resp = False
|
||||||
self._build_header(0x4510)
|
self._build_header(0x4510)
|
||||||
self.ifc.tx_add(struct.pack(f'<BHLLL{len(at_cmd)}sc', self.AT_CMD,
|
self.ifc.tx_add(struct.pack(f'<BHLLL{len(at_cmd)}sc', self.AT_CMD,
|
||||||
0x0002, 0, 0, 0,
|
0x0002, 0, 0, 0,
|
||||||
@@ -644,7 +643,7 @@ class SolarmanV5(SolarmanBase):
|
|||||||
self.inc_counter('AT_Command_Blocked')
|
self.inc_counter('AT_Command_Blocked')
|
||||||
return
|
return
|
||||||
self.inc_counter('AT_Command')
|
self.inc_counter('AT_Command')
|
||||||
self.forward_at_cmd_resp = True
|
self.db.forward_at_cmd_resp = True
|
||||||
|
|
||||||
elif ftype == self.MB_RTU_CMD:
|
elif ftype == self.MB_RTU_CMD:
|
||||||
rstream = self.ifc.remote.stream
|
rstream = self.ifc.remote.stream
|
||||||
@@ -664,8 +663,9 @@ class SolarmanV5(SolarmanBase):
|
|||||||
|
|
||||||
def get_cmd_rsp_log_lvl(self) -> int:
|
def get_cmd_rsp_log_lvl(self) -> int:
|
||||||
ftype = self.ifc.rx_peek()[self.header_len]
|
ftype = self.ifc.rx_peek()[self.header_len]
|
||||||
if ftype == self.AT_CMD:
|
if ftype == self.AT_CMD or \
|
||||||
if self.forward_at_cmd_resp:
|
ftype == self.AT_CMD_RSP:
|
||||||
|
if self.db.forward_at_cmd_resp:
|
||||||
return logging.INFO
|
return logging.INFO
|
||||||
return logging.DEBUG
|
return logging.DEBUG
|
||||||
elif ftype == self.MB_RTU_CMD \
|
elif ftype == self.MB_RTU_CMD \
|
||||||
@@ -680,7 +680,7 @@ class SolarmanV5(SolarmanBase):
|
|||||||
ftype = data[0]
|
ftype = data[0]
|
||||||
if ftype == self.AT_CMD or \
|
if ftype == self.AT_CMD or \
|
||||||
ftype == self.AT_CMD_RSP:
|
ftype == self.AT_CMD_RSP:
|
||||||
if not self.forward_at_cmd_resp:
|
if not self.db.forward_at_cmd_resp:
|
||||||
data_json = data[14:].decode("utf-8")
|
data_json = data[14:].decode("utf-8")
|
||||||
node_id = self.node_id
|
node_id = self.node_id
|
||||||
key = 'at_resp'
|
key = 'at_resp'
|
||||||
|
|||||||
Reference in New Issue
Block a user