### ----------------------------------------------------
### -- Iec104Parser
### -- Licenses: Artistic License 2.0
### -- Authors: ohmycloudy@gmail.com
### -- File: lib/Iec104/Asdu/InfoObj/PointDesc.rakumod
### ----------------------------------------------------
unit module Iec104::Asdu::InfoObj::PointDesc;

sub point(Int $i, Int $ti --> Str) is export {
    my Str $s = "";
    if $ti == 1 || $ti == 30 {
        $s ~= "无效/" if $i +& 0x80 == 128;
        $s ~= "有效/" if $i +& 0x80 == 0;
        $s ~= "非当前值/" if $i +& 0x40 == 64;
        $s ~= "当前值/" if $i +& 0x40 == 0;
        $s ~= "被取代/" if $i +& 0x20 == 32;
        $s ~= "未被取代/" if $i +& 0x20 == 0;
        $s ~= "被闭锁/" if $i +& 0x10 == 16;
        $s ~= "未被闭锁/" if $i +& 0x10 == 0;
        $s ~= "开关合\t" if $i +& 0x01 == 1;
        $s ~= "开关分\t" if $i +& 0x01 == 0;
    }

    if $ti == 3 || $ti == 31 {
        $s ~= "无效/" if $i +& 0x80 == 128;
        $s ~= "有效/" if $i +& 0x80 == 0;
        $s ~= "非当前值/" if $i +& 0x40 == 64;
        $s ~= "当前值/" if $i +& 0x40 == 0;
        $s ~= "被取代/" if $i +& 0x20 == 32;
        $s ~= "未被取代/" if $i +& 0x20 == 0;
        $s ~= "被闭锁/" if $i +& 0x10 == 16;
        $s ~= "未被闭锁/" if $i +& 0x10 == 0;
        $s ~= "不确定或中间状态\t" if $i +& 0x03 == 0;
        $s ~= "确定开关分\t" if $i +& 0x03 == 1;
        $s ~= "确定开关合\t" if $i +& 0x03 == 2;
        $s ~= "不确定\t" if $i +& 0x03 == 3;
    }
    $s
}


