Ejemplo n.º 1
0
 public static function getValue($dif, $vif, $data)
 {
     if ($vif != 0x0) {
         $vifNoExt = $vif & 0x7f;
         switch ($vifNoExt) {
             // E110 110n Time Point
             // n = 0        date
             // n = 1 time & date
             // data type G
             // data type F
             case $vifNoExt >= 0x6c && $vifNoExt <= 0x6d:
                 if ($vif & 0x1) {
                     // Data length should be 4 bytes.
                     if (count($data) < 4) {
                         return "Invalid number of bytes to determine date and time!";
                     }
                     return mbus_utils::data_date_time_decode($data);
                 } else {
                     return "NYI - Time Point (date)";
                 }
                 break;
                 // This is the units of the value. Not the actual value! Still need to get value in this record.
                 // Tricky eh, see 6.3 plain text VIF
             // This is the units of the value. Not the actual value! Still need to get value in this record.
             // Tricky eh, see 6.3 plain text VIF
             case $vifNoExt == 0x7c:
                 if ($data_length <= 0xbf) {
                     return mbus_utils::data_str_decode($data);
                 }
                 break;
         }
     }
     switch ($dif & 0xf) {
         case 0x0:
             // no data
             return "No Data";
             break;
         case 0x1:
             // 1 byte integer (8 bit)
         // 1 byte integer (8 bit)
         case 0x2:
             // 2 byte integer (16 bit)
         // 2 byte integer (16 bit)
         case 0x3:
             // 3 byte integer (24 bit)
         // 3 byte integer (24 bit)
         case 0x4:
             // 4 byte integer (32 bit)
         // 4 byte integer (32 bit)
         case 0x6:
             // 6 byte integer (48 bit)
         // 6 byte integer (48 bit)
         case 0x7:
             // 8 byte integer (64 bit)
             return mbus_utils::data_int_decode($data);
             break;
         case 0x9:
             // 2 digit BCD (8 bit)
         // 2 digit BCD (8 bit)
         case 0xa:
             // 4 digit BCD (16 bit)
         // 4 digit BCD (16 bit)
         case 0xb:
             // 6 digit BCD (24 bit)
         // 6 digit BCD (24 bit)
         case 0xc:
             // 8 digit BCD (32 bit)
         // 8 digit BCD (32 bit)
         case 0xe:
             // 12 digit BCD
             return mbus_utils::data_bcd_decode($data);
             break;
         case 0xe:
             // Special Functions
             return "Special Functions";
             break;
         case 0xd:
             // variable length ASCII
             if ($data_length <= 0xbf) {
                 return mbus_utils::data_str_decode($data);
                 break;
             }
             // FALLTHROUGH
         // FALLTHROUGH
         default:
             return "Unknown DIF (0x" . dechex($dif) . ")";
             break;
     }
     return "";
 }