|
@@ -187,13 +187,10 @@ class TestPanelRegistration:
|
|
|
|
|
|
|
|
# 下发 0x10 与业务读卡都发生
|
|
# 下发 0x10 与业务读卡都发生
|
|
|
assert self.mock_modbus.set_card_mapping.called
|
|
assert self.mock_modbus.set_card_mapping.called
|
|
|
- # 顺序:最后一次 set_card_mapping(0x10) 在最后一次业务 read(0x03) 之前
|
|
|
|
|
- # (_hardware_card_base 取硬件基底的那次 read 不计,它在 set_card_mapping 之前)
|
|
|
|
|
|
|
+ # 顺序:先 set_card_mapping(0x10) 再业务 read(0x03)(不再有基底 read)
|
|
|
names = [c[0] for c in self.mock_modbus.method_calls]
|
|
names = [c[0] for c in self.mock_modbus.method_calls]
|
|
|
last_set = len(names) - 1 - names[::-1].index('set_card_mapping')
|
|
last_set = len(names) - 1 - names[::-1].index('set_card_mapping')
|
|
|
- last_read = len(names) - 1 - names[::-1].index('read_all_antenna_cards')
|
|
|
|
|
- assert last_set > names.index('read_all_antenna_cards')
|
|
|
|
|
- assert last_set < last_read
|
|
|
|
|
|
|
+ assert last_set < names.index('read_all_antenna_cards')
|
|
|
|
|
|
|
|
def test_one_miss_still_reads_two_miss_offline_stops_read(self):
|
|
def test_one_miss_still_reads_two_miss_offline_stops_read(self):
|
|
|
"""严格模式:第1次无81仍读卡并计1;连续第2次无81(读卡也失败)判离线、停止读卡。"""
|
|
"""严格模式:第1次无81仍读卡并计1;连续第2次无81(读卡也失败)判离线、停止读卡。"""
|
|
@@ -304,12 +301,10 @@ class TestPanelRegistration:
|
|
|
assert pid not in app_module.panel_keepalive_miss
|
|
assert pid not in app_module.panel_keepalive_miss
|
|
|
assert self.mock_modbus.query_address.call_count == 1
|
|
assert self.mock_modbus.query_address.call_count == 1
|
|
|
assert self.mock_modbus.query_address.call_args.kwargs.get('uid') == uid
|
|
assert self.mock_modbus.query_address.call_args.kwargs.get('uid') == uid
|
|
|
- # 重新上线先 0x10 再业务读卡(基底 read 不计)
|
|
|
|
|
|
|
+ # 重新上线先 0x10 再业务读卡(不再有基底 read)
|
|
|
names = [c[0] for c in self.mock_modbus.method_calls]
|
|
names = [c[0] for c in self.mock_modbus.method_calls]
|
|
|
last_set = len(names) - 1 - names[::-1].index('set_card_mapping')
|
|
last_set = len(names) - 1 - names[::-1].index('set_card_mapping')
|
|
|
- last_read = len(names) - 1 - names[::-1].index('read_all_antenna_cards')
|
|
|
|
|
- assert last_set > names.index('read_all_antenna_cards')
|
|
|
|
|
- assert last_set < last_read
|
|
|
|
|
|
|
+ assert last_set < names.index('read_all_antenna_cards')
|
|
|
|
|
|
|
|
def test_unbound_probe_registers_new_panel_without_confirm(self):
|
|
def test_unbound_probe_registers_new_panel_without_confirm(self):
|
|
|
"""未绑定地址全 0 探测收到 81 -> 本地建立绑定①并上线;不发 82,先 0x10 再读卡。"""
|
|
"""未绑定地址全 0 探测收到 81 -> 本地建立绑定①并上线;不发 82,先 0x10 再读卡。"""
|
|
@@ -513,21 +508,18 @@ class TestPanelRegistration:
|
|
|
assert app_module._address_range() == (1, 50)
|
|
assert app_module._address_range() == (1, 50)
|
|
|
|
|
|
|
|
def test_single_port_write_persists_only_target_port(self):
|
|
def test_single_port_write_persists_only_target_port(self):
|
|
|
- """单端口写卡:硬件帧带全 24 口,但配置只落目标这一条(修复映射污染)。"""
|
|
|
|
|
|
|
+ """单端口写卡:配置只落目标这一条;未配置端口一律 0xFF,不采用硬件读回值。"""
|
|
|
client = app.test_client()
|
|
client = app.test_client()
|
|
|
pid = 'PANEL_dtu_001_8'
|
|
pid = 'PANEL_dtu_001_8'
|
|
|
app_module.panel_config[pid] = {'address': 8, 'position': 8,
|
|
app_module.panel_config[pid] = {'address': 8, 'position': 8,
|
|
|
'panel_uid': 'cc' * 12, 'status': 'online'}
|
|
'panel_uid': 'cc' * 12, 'status': 'online'}
|
|
|
app_module.dtu_config['port_mappings'] = {}
|
|
app_module.dtu_config['port_mappings'] = {}
|
|
|
- # 硬件基底:4/22/23 口插着卡(这些只应出现在下发帧,不应落盘)
|
|
|
|
|
|
|
+ # 硬件读回:4/22/23 口“有卡”——这些位置不可信,不得进入下发帧
|
|
|
self.mock_modbus.read_all_antenna_cards.return_value = read_result(
|
|
self.mock_modbus.read_all_antenna_cards.return_value = read_result(
|
|
|
make_cards({4: '04' * 6, 22: '16' * 6, 23: '17' * 6}), addr=8)
|
|
make_cards({4: '04' * 6, 22: '16' * 6, 23: '17' * 6}), addr=8)
|
|
|
# set_card_mapping 回 24 路 cards_written(模拟真实实现)
|
|
# set_card_mapping 回 24 路 cards_written(模拟真实实现)
|
|
|
written = {p: None for p in range(1, 25)}
|
|
written = {p: None for p in range(1, 25)}
|
|
|
written[1] = 'aabbccddeeff'
|
|
written[1] = 'aabbccddeeff'
|
|
|
- written[4] = '040404040404'
|
|
|
|
|
- written[22] = '161616161616'
|
|
|
|
|
- written[23] = '171717171717'
|
|
|
|
|
self.mock_modbus.set_card_mapping.return_value = {
|
|
self.mock_modbus.set_card_mapping.return_value = {
|
|
|
'success': True, 'device_address': 8, 'cards_written': written, 'raw_data': 'T'}
|
|
'success': True, 'device_address': 8, 'cards_written': written, 'raw_data': 'T'}
|
|
|
with patch.object(app_module.serial_client, 'get_status', return_value={'connected': True}):
|
|
with patch.object(app_module.serial_client, 'get_status', return_value={'connected': True}):
|
|
@@ -536,12 +528,16 @@ class TestPanelRegistration:
|
|
|
'card_uid': 'AABBCCDDEEFF'})
|
|
'card_uid': 'AABBCCDDEEFF'})
|
|
|
assert resp.status_code == 200 and resp.get_json()['success']
|
|
assert resp.status_code == 200 and resp.get_json()['success']
|
|
|
saved = app_module.dtu_config['port_mappings'][pid]
|
|
saved = app_module.dtu_config['port_mappings'][pid]
|
|
|
- # 只落目标 1 口;硬件基底里的 4/22/23 不得被灌进配置,也不得出现 null
|
|
|
|
|
|
|
+ # 只落目标 1 口;硬件读回的 4/22/23 不得落盘,也不得出现 null
|
|
|
assert saved == {'1': 'AABBCCDDEEFF'}
|
|
assert saved == {'1': 'AABBCCDDEEFF'}
|
|
|
- # 下发帧仍带全部端口(目标口是新卡号,其它保留硬件读回值)
|
|
|
|
|
|
|
+ # 下发帧:目标口是新卡号,其它端口一律 None(0xFF)
|
|
|
args, _ = self.mock_modbus.set_card_mapping.call_args
|
|
args, _ = self.mock_modbus.set_card_mapping.call_args
|
|
|
assert args[1][1] == 'AABBCCDDEEFF'
|
|
assert args[1][1] == 'AABBCCDDEEFF'
|
|
|
- assert args[1][4] == '040404040404'
|
|
|
|
|
|
|
+ assert args[1][4] is None
|
|
|
|
|
+ assert args[1][22] is None
|
|
|
|
|
+ assert args[1][23] is None
|
|
|
|
|
+ # 不再为了取“硬件基底”而读卡
|
|
|
|
|
+ self.mock_modbus.read_all_antenna_cards.assert_not_called()
|
|
|
assert self.mock_save_dtu.called
|
|
assert self.mock_save_dtu.called
|
|
|
|
|
|
|
|
def test_single_port_clear_deletes_mapping_key(self):
|
|
def test_single_port_clear_deletes_mapping_key(self):
|
|
@@ -564,6 +560,36 @@ class TestPanelRegistration:
|
|
|
args, _ = self.mock_modbus.set_card_mapping.call_args
|
|
args, _ = self.mock_modbus.set_card_mapping.call_args
|
|
|
assert args[1][1] is None # 硬件目标口清成 0xFF
|
|
assert args[1][1] is None # 硬件目标口清成 0xFF
|
|
|
|
|
|
|
|
|
|
+ def test_single_port_write_ignores_misreported_hardware_port(self):
|
|
|
|
|
+ """回归(现场 2026-11-09):固件把卡回报在端口1,写端口2 时不得把端口1 带进帧。
|
|
|
|
|
+
|
|
|
|
|
+ 现象:只设端口2=CFB88E295301,下发帧却是
|
|
|
|
|
+ `...CFB8... [端口1] CFB8... [端口2]`,看起来“端口1 也被映射”。
|
|
|
|
|
+ 根因:下发前用 0x03 读回硬件当基底,而该固件回报的天线号与物理端口对不上。
|
|
|
|
|
+ 修复:平台为唯一权威,未配置端口一律 0xFF。
|
|
|
|
|
+ """
|
|
|
|
|
+ client = app.test_client()
|
|
|
|
|
+ pid = 'PANEL_dtu_001_1'
|
|
|
|
|
+ app_module.panel_config[pid] = {'address': 1, 'position': 1,
|
|
|
|
|
+ 'panel_uid': 'ce' * 12, 'status': 'online'}
|
|
|
|
|
+ app_module.address_config.stored_devices['ce' * 12] = 1
|
|
|
|
|
+ app_module.dtu_config['port_mappings'] = {}
|
|
|
|
|
+ # 固件把同一张卡错误回报在端口1(实际设的是端口2)
|
|
|
|
|
+ self.mock_modbus.read_all_antenna_cards.return_value = read_result(
|
|
|
|
|
+ make_cards({1: 'cfb88e295301'}), addr=1)
|
|
|
|
|
+ self.mock_modbus.set_card_mapping.return_value = {'success': True}
|
|
|
|
|
+ with patch.object(app_module.serial_client, 'get_status', return_value={'connected': True}):
|
|
|
|
|
+ resp = client.post('/api/panel/mapping',
|
|
|
|
|
+ json={'panel_id': pid, 'port': 2,
|
|
|
|
|
+ 'card_uid': 'CFB88E295301'})
|
|
|
|
|
+ assert resp.status_code == 200 and resp.get_json()['success']
|
|
|
|
|
+ args, _ = self.mock_modbus.set_card_mapping.call_args
|
|
|
|
|
+ frame_map = args[1]
|
|
|
|
|
+ assert frame_map[2] == 'CFB88E295301' # 目标端口正确
|
|
|
|
|
+ assert frame_map[1] is None # 端口1 必须是 0xFF,不被读回值污染
|
|
|
|
|
+ # 配置里也只有端口2
|
|
|
|
|
+ assert app_module.dtu_config['port_mappings'][pid] == {'2': 'CFB88E295301'}
|
|
|
|
|
+
|
|
|
def test_prune_null_port_mappings(self):
|
|
def test_prune_null_port_mappings(self):
|
|
|
"""启动清理:删除 null/空端口,保留有效卡号;面板清空后整组移除。"""
|
|
"""启动清理:删除 null/空端口,保留有效卡号;面板清空后整组移除。"""
|
|
|
app_module.dtu_config['port_mappings'] = {
|
|
app_module.dtu_config['port_mappings'] = {
|