提交 514d3f32 编写于 作者: M me-no-dev

Sample Discovery and Monitor scripts

上级 7dc8ca4e
......@@ -190,12 +190,40 @@ recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build
recipe.size.regex=^(?:\.iram0\.text|\.iram0\.vectors|\.dram0\.data|\.flash\.text|\.flash\.rodata|)\s+([0-9]+).*
recipe.size.regex.data=^(?:\.dram0\.data|\.dram0\.bss|\.noinit)\s+([0-9]+).*
## --------------------------------
## Pluggable Discovery and Monitors
## --------------------------------
## Required discoveries and monitors
## ---------------------------------
pluggable_discovery.required.0=builtin:serial-discovery
pluggable_discovery.required.1=builtin:mdns-discovery
pluggable_monitor.required.serial=builtin:serial-monitor
## release.json definition for custom discoveries and monitors
## -----------------------------------------------------------
## "discoveryDependencies": [
## { "packager": "espressif", "name": "espnow-discovery" }
## ],
## "monitorDependencies": [
## { "packager": "espressif", "name": "espnow-monitor" },
## { "packager": "espressif", "name": "espota-monitor" },
## ]
## platform.txt definition for custom discoveries and monitors
## -----------------------------------------------------------
## pluggable_discovery.required.2=espressif:espnow-discovery
## pluggable_monitor.required.espnow=espressif:espnow-monitor
## pluggable_monitor.required.network=espressif:espota-monitor
## Demo Pluggable Discovery
pluggable_discovery.espnow.pattern="{runtime.platform.path}/tools/espnow-discovery.py"
## Demo Pluggable Monitor
pluggable_monitor.pattern.espnow="/Users/ficeto/Documents/Arduino/hardware/espressif/esp32/tools/espnow-monitor.py"
## ------------------
## Upload/Debug tools
## ------------------
......
#!/opt/homebrew/bin/python3
import sys, os, time
import logging
# HELLO <PROTOCOL_VERSION> "<USER_AGENT>"
# {
# "eventType": "hello",
# "protocolVersion": 1,
# "message": "OK"
# }
# START
# {
# "eventType": "start",
# "message": "OK"
# }
# {
# "eventType": "start",
# "error": true,
# "message": "Permission error"
# }
# STOP
# {
# "eventType": "stop",
# "message": "OK"
# }
# {
# "eventType": "stop",
# "error": true,
# "message": "Resource busy"
# }
# QUIT
# {
# "eventType": "quit",
# "message": "OK"
# }
# LIST
# {
# "eventType": "list",
# "ports": [
# {
# "address": <-- THE ADDRESS OF THE PORT
# "label": <-- HOW THE PORT IS DISPLAYED ON THE GUI
# "protocol": <-- THE PROTOCOL USED BY THE BOARD
# "protocolLabel": <-- HOW THE PROTOCOL IS DISPLAYED ON THE GUI
# "properties": {
# <-- A LIST OF PROPERTIES OF THE PORT
# }
# },
# {
# ... <-- OTHER PORTS...
# }
# ]
# }
# {
# "eventType": "list",
# "error": true,
# "message": "Resource busy"
# }
# START_SYNC
# {
# "eventType": "start_sync",
# "message": "OK"
# }
# {
# "eventType": "start_sync",
# "error": true,
# "message": "Resource busy"
# }
# {
# "eventType": "add",
# "port": {
# "address": "/dev/ttyACM0",
# "label": "ttyACM0",
# "properties": {
# "pid": "0x804e",
# "vid": "0x2341",
# "serialNumber": "EBEABFD6514D32364E202020FF10181E",
# "name": "ttyACM0"
# },
# "protocol": "serial",
# "protocolLabel": "Serial Port (USB)"
# }
# }
# {
# "eventType": "remove",
# "port": {
# "address": "/dev/ttyACM0",
# "protocol": "serial"
# }
# }
# Invalid commands
# {
# "eventType": "command_error",
# "error": true,
# "message": "Unknown command XXXX"
# }
logging.basicConfig(filename=os.path.dirname(os.path.realpath(__file__))+'/pluggable.log', filemode='a+', encoding='utf-8', level=logging.DEBUG)
log = logging.getLogger('espnow-discovery')
discovery_hello = False
discovery_started = False
discovery_sync = False
def send_msg(msg):
sys.stdout.write(msg)
sys.stdout.flush()
log.debug("TX: %s" % msg)
if __name__ == "__main__":
try:
while True:
for line in sys.stdin:
line = line.rstrip()
log.debug("RX: %s" % line)
if line.startswith("HELLO 1"):
discovery_hello = True
send_msg('{"eventType": "hello", "protocolVersion": 1, "message": "OK"}')
elif line.startswith("LIST"):
send_msg('{"eventType": "list", "ports": [{"address": "aa:bb:cc:dd:ee:ff", "label": "ESP-NOW aa:bb:cc:dd:ee:ff", "protocol": "espnow", "protocolLabel": "ESP-NOW (WiFi)", "properties": {"channel": "1", "board": "esp32s2"}}]}')
elif line.startswith("START_SYNC"):
discovery_sync = True
send_msg('{"eventType": "start_sync", "message": "OK"}')
# time.sleep(5)
send_msg('{"eventType": "add", "port": {"address": "aa:bb:cc:dd:ee:ff", "label": "ESP-NOW aa:bb:cc:dd:ee:ff", "protocol": "espnow", "protocolLabel": "ESP-NOW (WiFi)", "properties": {"channel": "1", "board": "esp32s2"}}}')
elif line.startswith("START"):
discovery_started = True
send_msg('{"eventType": "start", "message": "OK"}')
elif line.startswith("STOP"):
discovery_started = False
discovery_sync = False
send_msg('{"eventType": "stop", "message": "OK"}')
elif line.startswith("QUIT"):
send_msg('{"eventType": "quit", "message": "OK"}')
sys.exit(0)
else:
send_msg('{"eventType": "command_error", "error": true, "message": "Unknown command XXXX"}')
time.sleep(0.1)
except Exception as e:
sys.exit(1)
sys.exit(0)
#!/opt/homebrew/bin/python3
import sys, os, time
import logging
# HELLO <PROTOCOL_VERSION> "<USER_AGENT>"
# {
# "eventType": "hello",
# "protocolVersion": 1,
# "message": "OK"
# }
# QUIT
# {
# "eventType": "quit",
# "message": "OK"
# }
# Invalid commands
# {
# "eventType": "command_error",
# "error": true,
# "message": "Unknown command XXXX"
# }
# DESCRIBE
# {
# "eventType": "describe",
# "message": "ok",
# "port_description": {
# "protocol": "serial",
# "configuration_parameters": {
# "baudrate": {
# "label": "Baudrate",
# "type": "enum",
# "values": [
# "300", "600", "750", "1200", "2400", "4800", "9600",
# "19200", "38400", "57600", "115200", "230400", "460800",
# "500000", "921600", "1000000", "2000000"
# ],
# "selected": "9600"
# },
# "parity": {
# "label": "Parity",
# "type": "enum",
# "values": [ "N", "E", "O", "M", "S" ],
# "selected": "N"
# },
# "bits": {
# "label": "Data bits",
# "type": "enum",
# "values": [ "5", "6", "7", "8", "9" ],
# "selected": "8"
# },
# "stop_bits": {
# "label": "Stop bits",
# "type": "enum",
# "values": [ "1", "1.5", "2" ],
# "selected": "1"
# }
# }
# }
# }
# CONFIGURE <PARAMETER_NAME> <VALUE>
# {
# "eventType": "configure",
# "message": "ok"
# }
# {
# "eventType": "configure",
# "error": true,
# "message": "invalid value for parameter baudrate: 123456"
# }
# OPEN <CLIENT_TCPIP_ADDRESS> <BOARD_PORT>
# {
# "eventType": "open",
# "message": "ok"
# }
# {
# "eventType": "open",
# "error": true,
# "message": "unknown port /dev/ttyACM23"
# }
# {
# "eventType": "port_closed",
# "message": "serial port disappeared!"
# }
# CLOSE
# {
# "eventType": "close",
# "message": "ok"
# }
# {
# "eventType": "close",
# "error": true,
# "message": "port already closed"
# }
logging.basicConfig(filename=os.path.dirname(os.path.realpath(__file__))+'/pluggable.log', filemode='a+', encoding='utf-8', level=logging.DEBUG)
log = logging.getLogger('espnow-monitor')
monitor_hello = False
monitor_open = False
def send_msg(msg):
sys.stdout.write(msg)
sys.stdout.flush()
log.debug("TX: %s" % msg)
if __name__ == "__main__":
try:
while True:
for line in sys.stdin:
line = line.rstrip()
log.debug("RX: %s" % line)
if line.startswith("HELLO 1"):
monitor_hello = True
send_msg('{"eventType": "hello", "protocolVersion": 1, "message": "OK"}')
elif line.startswith("DESCRIBE"):
send_msg('{"eventType": "describe", "message": "ok", "port_description": {"protocol": "espnow", "configuration_parameters": {"baudrate": {"label": "Baudrate", "type": "enum", "values": ["9600", "19200", "38400", "57600", "115200", "230400", "460800", "921600"], "selected": "921600"}}}}')
elif line.startswith("CONFIGURE "):
send_msg('{"eventType": "configure", "message": "OK"}')
elif line.startswith("OPEN"):
monitor_open = True
send_msg('{"eventType": "open", "message": "OK"}')
elif line.startswith("CLOSE"):
monitor_open = False
send_msg('{"eventType": "close", "message": "OK"}')
elif line.startswith("QUIT"):
send_msg('{"eventType": "quit", "message": "OK"}')
sys.exit(0)
else:
send_msg('{"eventType": "command_error", "error": true, "message": "Unknown command XXXX"}')
time.sleep(0.1)
except Exception as e:
sys.exit(1)
sys.exit(0)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册