mirror of
https://github.com/MoreTore/openpilot.git
synced 2026-07-26 20:32:04 +08:00
Athena: get ipv4 addr
This commit is contained in:
@@ -533,6 +533,17 @@ def getNetworks():
|
||||
return HARDWARE.get_networks()
|
||||
|
||||
|
||||
@dispatcher.add_method
|
||||
def getManagerURL():
|
||||
ip_addr = HARDWARE.get_ipv4_address()
|
||||
if ip_addr:
|
||||
return {
|
||||
'url': f"http://{ip_addr}:8082",
|
||||
}
|
||||
else:
|
||||
raise Exception("Network Error")
|
||||
|
||||
|
||||
@dispatcher.add_method
|
||||
def takeSnapshot() -> str | dict[str, str] | None:
|
||||
from openpilot.system.camerad.snapshot.snapshot import jpeg_write, snapshot
|
||||
|
||||
@@ -144,3 +144,6 @@ class HardwareBase(ABC):
|
||||
|
||||
def get_modem_data_usage(self):
|
||||
return -1, -1
|
||||
|
||||
def get_ipv4_address(self, interface="wlan0"):
|
||||
return None
|
||||
@@ -586,6 +586,29 @@ class Tici(HardwareBase):
|
||||
return False
|
||||
return True
|
||||
|
||||
def get_ipv4_address(self, interface="wlan0"):
|
||||
try:
|
||||
# Run the `ip` command to get interface details
|
||||
result = subprocess.run(
|
||||
["ip", "addr", "show", interface],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
text=True,
|
||||
)
|
||||
|
||||
# Check if the command succeeded
|
||||
if result.returncode != 0:
|
||||
return None
|
||||
|
||||
# Parse the output for the IPv4 address
|
||||
for line in result.stdout.splitlines():
|
||||
line = line.strip()
|
||||
if line.startswith("inet "): # Find the line with 'inet'
|
||||
return line.split()[1].split('/')[0] # Extract the IP address
|
||||
except Exception:
|
||||
pass
|
||||
return None
|
||||
|
||||
if __name__ == "__main__":
|
||||
t = Tici()
|
||||
t.configure_modem()
|
||||
|
||||
Reference in New Issue
Block a user