Skip to content

Commit 036a37f

Browse files
Add Anjoy and OpenIPC cameras to vendor list (#376)
### Motivation We want to use two new camera firmwares with rosys. ### Implementation This adds anjoy cameras with their (observed) mac range and OpenIPC cameras with the mac range that we set for them. The functions for determining vendor and mac were also refactored to use dicts. Otherwise, we would run into a "too many return statements" Pylint error now.
1 parent 39ad0c3 commit 036a37f

File tree

1 file changed

+31
-18
lines changed

1 file changed

+31
-18
lines changed

rosys/vision/rtsp_camera/vendors.py

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,42 @@ class VendorType(Enum):
77
AXIS = 3
88
REOLINK = 4
99
UNIARCH = 5
10+
ANJOY = 6
11+
OPENIPC = 7
1012
OTHER = -1
1113

1214

15+
mac_prefix_to_vendor: dict[str, VendorType] = {
16+
'e0:62:90': VendorType.JOVISION,
17+
'e4:24:6c': VendorType.DAHUA,
18+
'3c:e3:6b': VendorType.DAHUA,
19+
'd4:43:0e': VendorType.DAHUA,
20+
'fc:5f:49': VendorType.DAHUA,
21+
'30:dd:aa': VendorType.DAHUA,
22+
'ec:71:db': VendorType.REOLINK,
23+
'6c:f1:7e': VendorType.UNIARCH,
24+
'f0:00:06': VendorType.ANJOY,
25+
'7a:7a:21': VendorType.OPENIPC,
26+
}
27+
28+
29+
vendor_to_url: dict[VendorType, str] = {
30+
VendorType.JOVISION: 'rtsp://admin:admin@{ip}/profile{substream}',
31+
VendorType.DAHUA: 'rtsp://admin:Adminadmin@{ip}/cam/realmonitor?channel=1&subtype={substream}',
32+
VendorType.REOLINK: 'rtsp://admin:Adminadmin@{ip}/Preview_01_{"sub" if substream else "main"}',
33+
VendorType.UNIARCH: 'rtsp://admin:Admin_adm1n@{ip}/media/video{2 if substream else 1}',
34+
VendorType.ANJOY: 'rtsp://admin:123456@{ip}/h264/ch{2 if substream else 1}',
35+
VendorType.OPENIPC: 'rtsp://root:Adminadmin@{ip}/stream={substream}',
36+
}
37+
38+
1339
def mac_to_vendor(mac: str) -> VendorType:
14-
if mac.startswith('e0:62:90'):
15-
return VendorType.JOVISION
16-
if mac.startswith(('e4:24:6c', '3c:e3:6b', 'd4:43:0e', 'fc:5f:49', '30:dd:aa')):
17-
return VendorType.DAHUA
18-
if mac.startswith('ec:71:db'):
19-
return VendorType.REOLINK
20-
if mac.startswith('6c:f1:7e'):
21-
return VendorType.UNIARCH
22-
return VendorType.OTHER
40+
prefix = mac[:8]
41+
return mac_prefix_to_vendor.get(prefix, VendorType.OTHER)
2342

2443

2544
def mac_to_url(mac: str, ip: str, substream: int = 0) -> str | None:
2645
vendor = mac_to_vendor(mac)
27-
if vendor == VendorType.JOVISION:
28-
return f'rtsp://admin:admin@{ip}/profile{substream}'
29-
if vendor == VendorType.DAHUA:
30-
return f'rtsp://admin:Adminadmin@{ip}/cam/realmonitor?channel=1&subtype={substream}'
31-
if vendor == VendorType.REOLINK:
32-
return f'rtsp://admin:Adminadmin@{ip}/Preview_01_{"sub" if substream else "main"}'
33-
if vendor == VendorType.UNIARCH:
34-
return f'rtsp://admin:Admin_adm1n@{ip}/media/video{2 if substream else 1}'
35-
return None
46+
if vendor == VendorType.OTHER:
47+
return None
48+
return vendor_to_url[vendor].format(ip=ip, substream=substream)

0 commit comments

Comments
 (0)