Created
November 19, 2020 15:55
-
-
Save wcauchois/de24d29ddc016a3a9ad1eb9f9296d487 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const machine = Machine({ | |
id: 'module-net-machine', | |
on: { | |
"BLE_CONNECT": [{ actions: [], target: "#ble-connection", }, | |
], | |
}, | |
initial: 'no-connection', | |
states: { | |
"no-connection": { | |
id: "no-connection", | |
entry: ["start_timer", ], | |
exit: ["stop_timer", ], | |
on: { | |
"TIMER": [{ actions: [], target: "#run-wifi", cond: "should_try_wifi_connect", }, | |
{ actions: [], target: "#send-gps-lte-report", cond: "should_send_lte_report", }, | |
{ actions: [], target: '#no-connection', internal: true, }, | |
], | |
}, | |
}, | |
"ble-connection": { | |
id: "ble-connection", | |
entry: [], | |
exit: [], | |
on: { | |
"BLE_DISCONNECT": [{ actions: ["set_report_update_interval", "clear_lte_backoff", "set_next_try_wifi_connect_time", ], target: "#no-connection", }, | |
], | |
}, | |
initial: 'ble:idle', | |
states: { | |
"ble:idle": { | |
id: "ble:idle", | |
entry: ["start_timer", ], | |
exit: ["stop_timer", ], | |
on: { | |
"TIMER": [{ actions: ["ble_notify_dispatch", ], target: '#ble:idle', internal: true, }, | |
], | |
"WIFI_SETUP_GET_SCAN_LIST": [{ actions: [], target: "#ble:setup-scan", }, | |
], | |
"WIFI_SETUP_CONNECT_TO_NETWORK": [{ actions: [], target: "#ble:setup-try-connect", }, | |
], | |
}, | |
}, | |
"ble:setup-scan": { | |
id: "ble:setup-scan", | |
entry: ["wifi_start", "send_wifisetup_scan_results", ], | |
exit: ["wifi_stop", ], | |
on: { | |
"WIFI_SETUP_FINISHED_SENDING_SCAN_RESULTS": [{ actions: [], target: "#ble:idle", }, | |
], | |
"WIFI_SETUP_GET_SCAN_LIST": [{ actions: [], target: '#ble:setup-scan', internal: true, }, | |
], | |
}, | |
}, | |
"ble:setup-try-connect": { | |
id: "ble:setup-try-connect", | |
entry: ["wifi_start", "wifisetup_connect_to_network", "start_timer", ], | |
exit: ["wifi_stop", "stop_timer", ], | |
on: { | |
"TIMER": [{ actions: ["send_wifisetup_connect_result", ], target: "#ble:idle", }, | |
], | |
"WIFI_STA_DISCONNECTED": [{ actions: ["send_wifisetup_connect_result", ], target: "#ble:idle", }, | |
], | |
"WIFI_STA_CONNECTED": [{ actions: ["send_wifisetup_connect_result", ], target: "#ble:idle", }, | |
], | |
"WIFI_SETUP_CONNECT_TO_NETWORK": [{ actions: [], target: '#ble:setup-try-connect', internal: true, }, | |
], | |
}, | |
}, | |
}, | |
}, | |
"run-wifi": { | |
id: "run-wifi", | |
entry: ["wifi_start", ], | |
exit: ["wifi_stop", "set_next_try_wifi_connect_time", ], | |
on: { | |
"WIFI_SERVER_DISCONNECTED": [{ actions: ["report_wifi_connect_result", ], target: "#wifi:scan", }, | |
], | |
"TIMER": [{ actions: ["wifi_restart", "report_wifi_connect_result", ], target: "#wifi:scan", }, | |
], | |
"WIFI_STA_DISCONNECTED": [{ actions: ["report_wifi_connect_result", ], target: "#wifi:scan", }, | |
], | |
}, | |
initial: 'wifi:scan', | |
states: { | |
"wifi:scan": { | |
id: "wifi:scan", | |
entry: ["wifi_evaluate_scan_list", ], | |
exit: [], | |
on: { | |
"WIFI_SCAN_RESULT_CANDIDATE": [{ actions: [], target: "#wifi:attempt-connect", }, | |
], | |
"WIFI_SCAN_RESULT_NO_CANDIDATES": [{ actions: [], target: "#no-connection", }, | |
], | |
}, | |
}, | |
"wifi:attempt-connect": { | |
id: "wifi:attempt-connect", | |
entry: ["wifi_start_raw_connect_logging", "wifi_attempt_connect", "start_timer", ], | |
exit: ["wifi_stop_raw_connect_logging", "stop_timer", ], | |
on: { | |
"WIFI_STA_CONNECTED": [{ actions: [], target: "#wifi:run-ota", cond: "wifi_should_start_ota", }, | |
], | |
"WIFI_STA_CONNECTED": [{ actions: [], target: "#wifi:server-connect", }, | |
], | |
}, | |
}, | |
"wifi:run-ota": { | |
id: "wifi:run-ota", | |
entry: ["start_timer", "start_timer2", "wifi_start_ota", ], | |
exit: ["stop_timer2", "stop_timer", ], | |
on: { | |
"WIFI_OTA_SUCCESS": [{ actions: ["reboot", ], target: '#wifi:run-ota', internal: true, }, | |
], | |
"TIMER2": [{ actions: ["wifi_ota_get_status", ], target: '#wifi:run-ota', internal: true, }, | |
], | |
"WIFI_OTA_FAILED": [{ actions: [], target: "#wifi:server-connect", }, | |
], | |
"TIMER": [{ actions: [], target: "#wifi:server-connect", }, | |
], | |
}, | |
}, | |
"wifi:server-connect": { | |
id: "wifi:server-connect", | |
entry: ["start_timer", "wifi_server_connect", ], | |
exit: ["stop_timer", ], | |
on: { | |
"WIFI_SERVER_CONNECTED": [{ actions: [], target: "#wifi:start-ws", }, | |
], | |
}, | |
}, | |
"wifi:start-ws": { | |
id: "wifi:start-ws", | |
entry: ["start_timer", "wifi_start_ws", ], | |
exit: ["stop_timer", ], | |
on: { | |
"WIFI_WS_UPGRADED": [{ actions: ["report_wifi_connect_result", ], target: "#wifi:connected", }, | |
], | |
}, | |
}, | |
"wifi:connected": { | |
id: "wifi:connected", | |
entry: [], | |
exit: [], | |
on: { | |
"WIFI_SERVER_DISCONNECTED": [{ actions: ["report_wifi_connect_result", ], target: "#wifi:scan", }, | |
], | |
"WIFI_STA_DISCONNECTED": [{ actions: ["report_wifi_connect_result", "wifi_restart", ], target: "#wifi:scan", }, | |
], | |
}, | |
initial: 'wifi-connected:submit-report', | |
states: { | |
"wifi-connected:idle": { | |
id: "wifi-connected:idle", | |
entry: ["start_timer2", ], | |
exit: ["stop_timer2", ], | |
on: { | |
"TIMER2": [{ actions: [], target: "#wifi-connected:submit-report", }, | |
], | |
}, | |
}, | |
"wifi-connected:submit-report": { | |
id: "wifi-connected:submit-report", | |
entry: ["start_timer", "wifi_submit_report", ], | |
exit: ["stop_timer", ], | |
on: { | |
"WIFI_REPORT_SUCCESS": [{ actions: [], target: "#wifi-connected:idle", }, | |
], | |
}, | |
}, | |
}, | |
}, | |
}, | |
}, | |
"send-gps-lte-report": { | |
id: "send-gps-lte-report", | |
entry: ["enable_signal", "enable_signal", ], | |
exit: ["disable_signal", "disable_signal", ], | |
on: { | |
}, | |
initial: 'lte:run-gps', | |
states: { | |
"lte:run-gps": { | |
id: "lte:run-gps", | |
entry: ["start_gps", ], | |
exit: ["stop_gps", ], | |
on: { | |
"GPS_FIX_SUCCESS": [{ actions: [], target: "#lte:boot-modem", }, | |
], | |
"GPS_FIX_FAILED": [{ actions: [], target: "#lte:boot-modem", }, | |
], | |
}, | |
initial: 'gps:run', | |
states: { | |
"gps:run": { | |
id: "gps:run", | |
entry: [], | |
exit: [], | |
on: { | |
"GPS_NEEDS_AGNSS": [{ actions: [], target: '#gps:run', internal: true, cond: "should_skip_agnss", }, | |
{ actions: [], target: "#gps:boot-modem", }, | |
], | |
}, | |
}, | |
"gps:boot-modem": { | |
id: "gps:boot-modem", | |
entry: ["start_modem", "start_timer", ], | |
exit: ["stop_timer", ], | |
on: { | |
"GPS_NEEDS_AGNSS": [{ actions: [], target: '#gps:boot-modem', internal: true, }, | |
], | |
"TIMER": [{ actions: ["stop_modem", ], target: "#gps:run", }, | |
], | |
"LTE_REGISTRATION_SUCCEEDED": [{ actions: [], target: "#gps:fetch-agnss", }, | |
], | |
"LTE_POWER_DOWN": [{ actions: [], target: "#gps:run", }, | |
], | |
}, | |
}, | |
"gps:fetch-agnss": { | |
id: "gps:fetch-agnss", | |
entry: ["fetch_agnss", "start_timer", ], | |
exit: ["stop_modem", "stop_timer", ], | |
on: { | |
"LTE_REGISTRATION_SUCCEEDED": [{ actions: [], target: '#gps:fetch-agnss', internal: true, }, | |
], | |
"GPS_NEEDS_AGNSS": [{ actions: [], target: '#gps:fetch-agnss', internal: true, }, | |
], | |
"LTE_POWER_DOWN": [{ actions: [], target: "#gps:run", }, | |
], | |
"TIMER": [{ actions: [], target: "#gps:run", }, | |
], | |
}, | |
}, | |
}, | |
}, | |
"lte:boot-modem": { | |
id: "lte:boot-modem", | |
entry: ["start_timer", "start_modem", ], | |
exit: ["stop_timer", ], | |
on: { | |
"TIMER": [{ actions: ["stop_modem", ], target: "#no-connection", }, | |
], | |
"LTE_REGISTRATION_SUCCEEDED": [{ actions: [], target: "#lte:send-report", }, | |
], | |
"LTE_POWER_DOWN": [{ actions: [], target: "#no-connection", }, | |
], | |
}, | |
}, | |
"lte:send-report": { | |
id: "lte:send-report", | |
entry: ["start_timer", "dispatch_lte_report", ], | |
exit: ["stop_timer", ], | |
on: { | |
"TIMER": [{ actions: ["stop_modem", ], target: "#no-connection", }, | |
], | |
"LTE_REGISTRATION_SUCCEEDED": [{ actions: [], target: '#lte:send-report', internal: true, }, | |
], | |
"LTE_POWER_DOWN": [{ actions: [], target: "#no-connection", }, | |
], | |
"LTE_REPORT_SUCCESS": [{ actions: [], target: '#lte:send-report', internal: true, }, | |
], | |
}, | |
}, | |
}, | |
}, | |
}, | |
}, | |
{ guards: { | |
should_try_wifi_connect: () => false,should_send_lte_report: () => false,wifi_should_start_ota: () => false,should_skip_agnss: () => false,}} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment