.MESH_INIT_COND: &MESH_INIT_COND
  test script: InitCondMesh
  restore post cmd set:
  - ''
  - - 'MSSC SSC[1-<node_num>] mesh -F -o 4 -a 1'
    - ['P SSC[1-<node_num>] C +MESHFLAG:OK']
  - - 'MSSC SSC[1-<node_num>] mesh -F -o 5 -a 1'
    - ['P SSC[1-<node_num>] C +MESHFLAG:OK']
  - - 'MSSC SSC[1-<node_num>] mesh -Q -o 1'
    - ['P SSC[1-<node_num>] C MESH_NETWORK']
  - - 'MSSC SSC[1-<node_num>] mesh -Q -o 3'
    - ['P SSC[1-<node_num>] C +MESH_CONFIG:ALL']
  - - 'MSSC SSC[1-<node_num>] ram'
    - ['P SSC[1-<node_num>] C +FREEHEAP:']

.mesh_get_device_mac: &mesh_get_device_mac
  LIST_MERGE:
    - - 'MSSC SSC[1-<node_num>] mac'
      - ['R SSC[1-<node_num>] A <device_mac>:\+STAMAC:(.+)\r\n']

.mesh_check_get_tree: &mesh_check_get_tree
  LIST_MERGE:
    - - 'MSSC SSC[1-<node_num>] mac'
      - ['P SSC[1-<node_num>] A <device_mac>:\+STAMAC:(.+)\r\n']
    - - 'MSSC SSC[1-<node_num>] mesh -Q -o 2'
      - ['P SSC[1-<node_num>] T <node_num>']
    - - 'MESHTREE'
      - ['P PC_COM RE "MESHTREE:%%s%20nodes"%%(<node_num>)']

.mesh_check_tree_stable: &mesh_check_tree_stable
  LIST_MERGE:
    - - 'DELAY 10'
      - ['']
    - - 'SSC MNODE(0) mesh -Q -o 1 -t 10'
      - ['R MNODE(0) C MESH_STABLE_CHECK:PASS']

.reboot_all: &reboot_all
  LIST_MERGE:
    - - 'MSSC SSC[1-<node_num>] reboot'
      - ['P SSC[1-<node_num>] C !!!ready!!!']

.force_reboot: &force_reboot
  LIST_MERGE:
    - - 'FPOWERON SSC[1-<node_num>]'
      - ['']
    - - 'DELAY 1'
      - ['']
    - - 'MSSC SSC[1-<node_num>] restore'
      - ['P SSC[1-<node_num>] C !!!ready!!!']

.all_nodes_mesh_config: &all_nodes_mesh_config
  LIST_MERGE:
    - - 'MSSC SSC[1-<node_num>] mesh -I'
      - ['P SSC[1-<node_num>] C +MESH:INITED']
    - - 'MSSC SSC[1-<node_num>] mesh -A -o 12 -t <duration_ms> -c <cnx_rssi> -l <select_rssi> -f <switch_rssi> -b <backoff_rssi>'
      - ['P SSC[1-<node_num>] C +MESH_SET_PARENT_SWITCH:OK']
    - - 'MSSC SSC[1-<node_num>] mesh -A -o 14 -t <threshold_high> -c <threshold_medium> -l <threshold_low>'
      - ['P SSC[1-<node_num>] C +MESH_RSSI_THRESHOLD:OK']
    - - 'MSSC SSC[1-<node_num>] mesh -A -o 9 -t <auth_mode> -s <map_password>'
      - ['P SSC[1-<node_num>] C +MESH_SET_AP_AUTH_MODE:OK']
    - - 'MSSC SSC[1-<node_num>] mesh -P -g <mesh_id> -s <ap_ssid> -p <ap_password> -n <ap_channel> -m <max_connect> -y <max_layer>'
      - ['P SSC[1-<node_num>] C +MESH:CONFIG,OK']

.root_do_connect: &root_do_connect
  LIST_MERGE:
    - - 'SOC SOC1 LISTEN <test_tcp_port1> <pc_ip>'
      - ['R SOC_COM L OK']
    - - 'SSC MNODE(0) mesh -S -o 0 -i <pc_ip> -t <test_tcp_port1>'
      - ['P MNODE(0) C +CONNECT,OK']
      - ['P SOC1 C +ACCEPT']
    - - 'SOC SOC1 MACCEPT GSOC1'
      - ['R SOC_COM L OK']

initial condition:
- tag: ENABLED_1
  <<: *MESH_INIT_COND
  initial condition detail: if mesh tree not exist, start one node first, then start others, after mesh network
    established, root connect server
  check cmd set:
  - ''
  - *mesh_check_get_tree
  - *mesh_check_tree_stable
  - *root_do_connect
  restore cmd set:
  - ''
  - *reboot_all
  - *all_nodes_mesh_config
  - - SSC SSC1 mesh -T
    - - P SSC1 C +MESH:START,OK
  - - DELAY 10
    - - P SSC1 C MESH_EVENT_CONNECTED
  - - SSC SSC[2-<node_num>] mesh -T
    - - P SSC[2-<node_num>] C +MESH:START,OK
  - - DELAY <delay_time>
    - - ''
  - *mesh_check_get_tree
  - *mesh_check_tree_stable
  - *root_do_connect
  force restore cmd set:
  - ''
  - *force_reboot
  - *all_nodes_mesh_config
  - - SSC SSC1 mesh -T
    - - P SSC1 C +MESH:START,OK
  - - DELAY 10
    - - P SSC1 C MESH_EVENT_CONNECTED
  - - SSC SSC[2-<node_num>] mesh -T
    - - P SSC[2-<node_num>] C +MESH:START,OK
  - - DELAY <delay_time>
    - - ''
  - *mesh_check_get_tree
  - *mesh_check_tree_stable
  - *root_do_connect
- tag: ENABLED_2
  <<: *MESH_INIT_COND
  initial condition detail: if mesh tree not exist, start all nodes together
  check cmd set:
  - ''
  - *mesh_check_get_tree
  - *mesh_check_tree_stable
  restore cmd set:
  - ''
  - *reboot_all
  - *all_nodes_mesh_config
  - - MSSC SSC[1-<node_num>] mesh -T
    - - P SSC[1-<node_num>] C +MESH:START,OK
  - - DELAY <delay_time>
    - - ''
  - *mesh_check_get_tree
  - *mesh_check_tree_stable
  force restore cmd set:
  - ''
  - *force_reboot
  - *all_nodes_mesh_config
  - - MSSC SSC[1-<node_num>] mesh -T
    - - P SSC[1-<node_num>] C +MESH:START,OK
  - - DELAY <delay_time>
    - - ''
  - *mesh_check_get_tree
  - *mesh_check_tree_stable
- tag: ENABLED_3
  <<: *MESH_INIT_COND
  initial condition detail: all mesh nodes configed but not started
  check cmd set:
  - ''
  - - ASSERT
    - - ''
  restore cmd set:
  - ''
  - *reboot_all
  - *all_nodes_mesh_config
  - *mesh_get_device_mac
  force restore cmd set:
  - ''
  - *force_reboot
  - *all_nodes_mesh_config
  - *mesh_get_device_mac
- tag: DISABLED_1
  <<: *MESH_INIT_COND
  initial condition detail: all mesh node in softap+sta mode, disable all mesh node
  restore post cmd set:
  - ''
  check cmd set:
  - ''
  - - ASSERT
    - - ''
  restore cmd set:
  - ''
  - *reboot_all
  - - MSSC SSC[1-<node_num>] op -S -o 3
    - - P SSC[1-<node_num>] C +MODE:OK
  - - MSSC SSC[1-<node_num>] sta -D
    - - P SSC[1-<node_num>] C +QAP:OK
  - *mesh_get_device_mac
  force restore cmd set:
  - ''
  - *force_reboot
  - - MSSC SSC[1-<node_num>] op -S -o 3
    - - P SSC[1-<node_num>] C +MODE:OK
  - - MSSC SSC[1-<node_num>] sta -D
    - - P SSC[1-<node_num>] C +QAP:OK
  - *mesh_get_device_mac
