{
    "firmware": "examples",
    "on_error": "continue",
    "loop": 1,
    "loop_infinite": true,
    "same_line": false,
    "channel_a": {
        "enabled": true,
        "transport": "tcp",
        "ip": "127.0.0.1",
        "port": 502,
        "role": "master",
        "slave_id": 1,
        "timeout_ms": 1000,
        "retry": 0
    },
    "channel_b": {
        "enabled": false
    },
    "cases": [
        {
            "test": "Power cycle",
            "steps": [
                {
                    "log": "Waiting for the device to power up"
                },
                {
                    "wait_until": {
                        "channel": "A",
                        "function": 3,
                        "address": "0x0000",
                        "compare": false,
                        "timeout_ms": 0,
                        "interval_ms": 500
                    }
                },
                {
                    "wait": {
                        "ms": 3000
                    }
                },
                {
                    "call": {
                        "sub": "check_values",
                        "store": "result"
                    }
                },
                {
                    "if": {
                        "cond": {
                            "expr": "${result} != 1"
                        }
                    }
                },
                {
                    "verdict": "fail"
                },
                {
                    "endif": true
                },
                {
                    "log": "Waiting for the power to go off"
                },
                {
                    "wait_until": {
                        "channel": "A",
                        "function": 3,
                        "address": "0x0000",
                        "no_response": true,
                        "timeout_ms": 0,
                        "interval_ms": 500
                    }
                }
            ]
        }
    ],
    "subroutines": [
        {
            "name": "check_values",
            "steps": [
                {
                    "set": {
                        "var": "ok",
                        "value": 0
                    }
                },
                {
                    "set": {
                        "var": "last",
                        "value": -1
                    }
                },
                {
                    "while": {
                        "cond": {
                            "expr": "${ok} == 0"
                        },
                        "max_loops": 0
                    }
                },
                {
                    "set": {
                        "var": "a",
                        "value": -1
                    }
                },
                {
                    "set": {
                        "var": "v",
                        "value": -1
                    }
                },
                {
                    "read": {
                        "channel": "A",
                        "function": 3,
                        "address": "0x0000",
                        "compare": false,
                        "store": "a"
                    }
                },
                {
                    "if": {
                        "cond": {
                            "expr": "${a} == -1"
                        }
                    }
                },
                {
                    "set": {
                        "var": "ok",
                        "value": 2
                    }
                },
                {
                    "else": true
                },
                {
                    "set": {
                        "var": "last",
                        "value": "${a}"
                    }
                },
                {
                    "read": {
                        "channel": "A",
                        "function": 3,
                        "address": "0x0010",
                        "end_address": "0x0011",
                        "format": "float_abcd",
                        "compare": false,
                        "store": "v"
                    }
                },
                {
                    "if": {
                        "cond": {
                            "expr": "${a} == 1 && ${v} >= 219.5 && ${v} <= 240.5"
                        }
                    }
                },
                {
                    "set": {
                        "var": "ok",
                        "value": 1
                    }
                },
                {
                    "else": true
                },
                {
                    "wait": {
                        "ms": 500
                    }
                },
                {
                    "endif": true
                },
                {
                    "endif": true
                },
                {
                    "endwhile": true
                },
                {
                    "if": {
                        "cond": {
                            "expr": "${ok} == 2"
                        }
                    }
                },
                {
                    "log": "Power went off before the values were right (last status ${last})"
                },
                {
                    "endif": true
                },
                {
                    "return": {
                        "value": "${ok}"
                    }
                }
            ]
        }
    ]
}
