src/eric7/MicroPython/Devices/CircuitPythonDevices.py

branch
eric7
changeset 11263
28f0ead11a82
parent 11236
75c26fe1d1c7
child 11267
9fc085d7e4fd
equal deleted inserted replaced
11262:07d9cc8d773c 11263:28f0ead11a82
798 r = wifi.radio 798 r = wifi.radio
799 799
800 station = { 800 station = {
801 'active': r.enabled and r.ipv4_address is not None, 801 'active': r.enabled and r.ipv4_address is not None,
802 'connected': r.ipv4_address is not None, 802 'connected': r.ipv4_address is not None,
803 'mac': binascii.hexlify(r.mac_address, ':').decode(),
803 'ifconfig': ( 804 'ifconfig': (
804 str(r.ipv4_address) if r.ipv4_address else'0.0.0.0', 805 str(r.ipv4_address) if r.ipv4_address else'0.0.0.0',
805 str(r.ipv4_subnet) if r.ipv4_subnet else'0.0.0.0', 806 str(r.ipv4_subnet) if r.ipv4_subnet else'0.0.0.0',
806 str(r.ipv4_gateway) if r.ipv4_gateway else'0.0.0.0', 807 str(r.ipv4_gateway) if r.ipv4_gateway else'0.0.0.0',
807 str(r.ipv4_dns) if r.ipv4_dns else'0.0.0.0', 808 str(r.ipv4_dns) if r.ipv4_dns else'0.0.0.0',
808 ), 809 ),
809 'mac': binascii.hexlify(r.mac_address, ':').decode(), 810 'ipv6_addr': [],
810 } 811 }
811 try: 812 try:
812 station['txpower'] = r.tx_power 813 station['txpower'] = r.tx_power
813 except AttributeError: 814 except AttributeError:
814 pass 815 pass
832 print(json.dumps(station)) 833 print(json.dumps(station))
833 834
834 ap = { 835 ap = {
835 'active': r.enabled and r.ipv4_address_ap is not None, 836 'active': r.enabled and r.ipv4_address_ap is not None,
836 'connected': r.ipv4_address_ap is not None, 837 'connected': r.ipv4_address_ap is not None,
838 'mac': binascii.hexlify(r.mac_address_ap, ':').decode(),
837 'ifconfig': ( 839 'ifconfig': (
838 str(r.ipv4_address_ap) if r.ipv4_address_ap else'0.0.0.0', 840 str(r.ipv4_address_ap) if r.ipv4_address_ap else'0.0.0.0',
839 str(r.ipv4_subnet_ap) if r.ipv4_subnet_ap else'0.0.0.0', 841 str(r.ipv4_subnet_ap) if r.ipv4_subnet_ap else'0.0.0.0',
840 str(r.ipv4_gateway_ap) if r.ipv4_gateway_ap else'0.0.0.0', 842 str(r.ipv4_gateway_ap) if r.ipv4_gateway_ap else'0.0.0.0',
841 str(r.ipv4_dns) if r.ipv4_dns else'0.0.0.0', 843 str(r.ipv4_dns) if r.ipv4_dns else'0.0.0.0',
842 ), 844 ),
843 'mac': binascii.hexlify(r.mac_address_ap, ':').decode(), 845 'ipv6_addr': [],
844 } 846 }
845 try: 847 try:
846 ap['txpower'] = r.tx_power 848 ap['txpower'] = r.tx_power
847 except AttributeError: 849 except AttributeError:
848 pass 850 pass
850 852
851 overall = { 853 overall = {
852 'active': r.enabled, 854 'active': r.enabled,
853 'hostname': r.hostname, 855 'hostname': r.hostname,
854 } 856 }
857 overall['prefer'] = 4
855 print(json.dumps(overall)) 858 print(json.dumps(overall))
856 859
857 wifi_status() 860 wifi_status()
858 del wifi_status 861 del wifi_status
859 """ 862 """
1386 def getEthernetStatus(self): 1389 def getEthernetStatus(self):
1387 """ 1390 """
1388 Public method to get Ethernet status data of the connected board. 1391 Public method to get Ethernet status data of the connected board.
1389 1392
1390 @return list of tuples containing the translated status data label and 1393 @return list of tuples containing the translated status data label and
1391 the associated value 1394 the associated value and a dictionary with keys 'ipv4' and 'ipv6'
1392 @rtype list of tuples of (str, str) 1395 containing the respective address information
1396 @rtype tuple of list of tuples of (str, str) and dict
1393 @exception OSError raised to indicate an issue with the device 1397 @exception OSError raised to indicate an issue with the device
1394 """ 1398 """
1395 command = """{0} 1399 command = """{0}
1396 def ethernet_status(): 1400 def ethernet_status():
1397 import binascii 1401 import binascii
1400 w5x00_init() 1404 w5x00_init()
1401 1405
1402 res = {{ 1406 res = {{
1403 'active': nic.link_status != 0, 1407 'active': nic.link_status != 0,
1404 'connected': nic.link_status == 1 and nic.ifconfig[0] != b'\x00\x00\x00\x00', 1408 'connected': nic.link_status == 1 and nic.ifconfig[0] != b'\x00\x00\x00\x00',
1405 'ifconfig': ( 1409 'ipv4_addr': (
1406 nic.pretty_ip(nic.ifconfig[0]), 1410 nic.pretty_ip(nic.ifconfig[0]),
1407 nic.pretty_ip(nic.ifconfig[1]), 1411 nic.pretty_ip(nic.ifconfig[1]),
1408 nic.pretty_ip(nic.ifconfig[2]), 1412 nic.pretty_ip(nic.ifconfig[2]),
1409 nic.pretty_ip(nic.ifconfig[3]), 1413 nic.pretty_ip(nic.ifconfig[3]),
1410 ), 1414 ),
1422 1426
1423 out, err = self.executeCommands(command, mode=self._submitMode, timeout=10000) 1427 out, err = self.executeCommands(command, mode=self._submitMode, timeout=10000)
1424 if err: 1428 if err:
1425 raise OSError(self._shortError(err)) 1429 raise OSError(self._shortError(err))
1426 1430
1427 status = []
1428 ethStatus = json.loads(out.decode("utf-8")) 1431 ethStatus = json.loads(out.decode("utf-8"))
1429 status.append((self.tr("Active"), self.bool2str(ethStatus["active"]))) 1432 status = [
1430 status.append((self.tr("Connected"), self.bool2str(ethStatus["connected"]))) 1433 (self.tr("Active"), self.bool2str(ethStatus["active"])),
1431 status.append((self.tr("IPv4 Address"), ethStatus["ifconfig"][0])) 1434 (self.tr("Connected"), self.bool2str(ethStatus["connected"])),
1432 status.append((self.tr("Netmask"), ethStatus["ifconfig"][1])) 1435 (self.tr("MAC-Address"), ethStatus["mac"]),
1433 status.append((self.tr("Gateway"), ethStatus["ifconfig"][2])) 1436 (self.tr("Chip Type"), ethStatus["chip"]),
1434 status.append((self.tr("DNS"), ethStatus["ifconfig"][3])) 1437 (self.tr("max. Sockets"), ethStatus["max_sockets"]),
1435 status.append((self.tr("MAC-Address"), ethStatus["mac"])) 1438 ]
1436 status.append((self.tr("Chip Type"), ethStatus["chip"])) 1439 addressInfo = {
1437 status.append((self.tr("max. Sockets"), ethStatus["max_sockets"])) 1440 "ipv4": ethStatus["ipv4_addr"],
1438 1441 "ipv6": [],
1439 return status 1442 }
1443
1444 return status, addressInfo
1440 1445
1441 def connectToLan(self, config, hostname): 1446 def connectToLan(self, config, hostname):
1442 """ 1447 """
1443 Public method to connect the connected device to the LAN. 1448 Public method to connect the connected device to the LAN.
1444 1449

eric ide

mercurial