BEGIN {
    FS="[ ,]"
}

/^INIT: [01]/ {
    system( "uci -P/var/state revert plc.plc.simpleconnect" );
    system( "uci -P/var/state set plc.plc.simpleconnect=0" );
    if ( $2 == 1 ) {
        system("logger \"plcgpio: Simple Connect sanity check triggered.\"");
    }
}

/^EVENT: 1[34],/ {
    system( "uci -P/var/state revert plc.plc.simpleconnect" );
    system( "uci -P/var/state set plc.plc.simpleconnect=" ($2 - 13) * 256 + $3 );

    if( $3 != 0 ) {
        system( "uci -P/var/state revert plc.plc.joiner" );
    }
}

/^JOINER:/ {
    system( "uci -P/var/state revert plc.plc.joiner" );
    system( "uci -P/var/state set plc.plc.joiner=" $2 );
}
