0.2.1 - fixed bug where decimal was string instead of number

add uci logging
master
David Kebler 2019-02-26 10:13:00 -08:00
parent 80b50b3b9a
commit fd40a27dae
2 changed files with 17 additions and 10 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@uci-utils/byte",
"version": "0.2.0",
"version": "0.2.1",
"description": "Byte Class and related functions",
"main": "src/byte.js",
"scripts": {

View File

@ -8,6 +8,10 @@ import writeByte from 'bitwise/byte/write'
//local
import * as array from './array'
import logger from '@uci-utils/logger'
let log = logger({package:'@uci-utils/byte'})
// Classes
// Byte Class is a single byte value with an attached format designation which allows easy
@ -106,7 +110,7 @@ class Byte {
bwop = bits.and
break
}
// console.log('byte and state as passed', byte, this.value)
log.debug({msg:'byte and state as passed', byte:byte, value:this.value})
let opbyte = bwop(
this.toFmt('ARY'),
byteFormat(byte, { in: format.in, out: 'ARY' })
@ -196,12 +200,10 @@ function stateChanges(curr, prev) {
if (!bitchanges) {
return false
}
console.log(prev)
console.log(curr)
console.log(bitchanges)
log.debug({prev:prev, cur:curr, bitchanges:bitchanges, msg:'state changes'})
let nowon = curr.map((bit, i) => {
console.log(bit, bitchanges[i], bit & bitchanges[i])
log.debug({bit:bit, bitchangesi:bitchanges[i], msg:'now on state '})
return bit & bitchanges[i]
})
nowon = byteFormat(nowon, {
@ -209,7 +211,7 @@ function stateChanges(curr, prev) {
out: 'PLC'
})
console.log('nowon', nowon)
log.debug({nowon:nowon, msg:'now on state '})
return byteFormat(bitchanges, {
in: 'ARY',
@ -246,7 +248,7 @@ const format = function(byte, fmt) {
let ofmt = fmt.out || 'DEC' // default DEC
// debug.L2('input: ', byte, ' input format: ', ifmt, ' output format:', ofmt);
let decimal = NaN
let decimal = 0
switch (ifmt) {
case 'STR':
decimal = writeByte(toBits(byte.padStart(8,'0')))
@ -255,7 +257,7 @@ const format = function(byte, fmt) {
decimal = readUInt(byte, 0, 8)
break
case 'DEC':
decimal = byte
decimal = +byte // make decimal as string is a number
break
case 'HEX':
decimal = parseInt(byte, 16)
@ -271,6 +273,11 @@ const format = function(byte, fmt) {
break
}
if ( decimal<0 || decimal >255) {
log.warn ({byte:byte, fmt:fmt, msg:'error - invalid byte - not able to convert to decmial, converting to 0'})
decimal = 0
}
let output
//TODO only BIT and DEC are working
switch (ofmt) {
@ -293,7 +300,7 @@ const format = function(byte, fmt) {
output = dec2plc(decimal)
break
default:
console.log('unknown input or output format')
log.warn({byte:byte, fmt:fmt, msg:'error - unkown output format'})
output = false
break
}