@connectedyard/node-intelhex
Advanced tools
Comparing version 1.1.0 to 1.1.2
@@ -32,3 +32,4 @@ ( function(){ | ||
* verbose: logs processing to console | ||
* littleEndian: display data as little endian | ||
* | ||
* @returns binary file data | ||
@@ -35,0 +36,0 @@ */ |
( function(){ | ||
const utils = require('./utils'); | ||
const _ = require('lodash'); | ||
@@ -77,8 +78,12 @@ /* | ||
function Processor( options ){ | ||
this.options = ( options === void 0 ) ? {} : options; | ||
this.options.maxBinaryAddress = this.options.maxBinaryAddress || 512 * 1024 * 1024; | ||
this.options = _.extend({ | ||
maxBinaryAddress : 512 * 1024 * 1024, | ||
littleEndian: false, | ||
verbose: false | ||
}, options ); | ||
this.parser = new Parser(); | ||
this.contents = false; | ||
this.verboseData = { | ||
this.verboseStats = { | ||
blockStartAddress: 0, | ||
@@ -91,21 +96,46 @@ blockStartBytes: null, | ||
Processor.prototype.explainSetAddress = function( address ){ | ||
if( this.options.verbose ){ | ||
if( this.verboseData.blockNumBytes !== 0 ){ | ||
console.log( "Block starts: " + this.verboseData.blockStartBytes ); | ||
console.log( "Block length: 0x" + utils.numberToHexString( this.verboseData.blockNumBytes, 8 ) + " bytes\n" ); | ||
this.verboseData.blockNumBytes = 0; | ||
} | ||
this.verboseData.blockStartAddress = address; | ||
console.log("Block start at: 0x" + utils.numberToHexString( address, 8 )); | ||
Processor.prototype._setExplainBlockStartAddress = function( address ){ | ||
if( this.verboseStats.blockNumBytes > 0 ){ | ||
this._endExplainBlock(); | ||
} | ||
this.verboseStats.blockNumBytes = 0; | ||
this.verboseStats.blockStartAddress = address; | ||
}; | ||
Processor.prototype.explainAddBytes = function( buffer ){ | ||
Processor.prototype._startExplainBlock = function( buffer, address ){ | ||
this.verboseStats.blockStartAddress = address; | ||
this.verboseStats.blockStartBytes = new Buffer( buffer ); | ||
this.verboseStats.blockNumBytes = buffer.length; | ||
console.log(_.padEnd( "Block start at:", 20) + "0x" + utils.numberToHexString( address, 8 )); | ||
console.log(_.padEnd( "Block bytes begin:", 20) + _hexDumpWords( this.verboseStats.blockStartBytes, this.options.littleEndian )); | ||
}; | ||
Processor.prototype._continueExplainBlock = function( buffer, address ){ | ||
this.verboseStats.totalBytes += buffer.length; | ||
if( address === this.verboseStats.blockStartAddress + this.verboseStats.blockNumBytes ){ | ||
this.verboseStats.blockNumBytes += buffer.length; | ||
return true; | ||
} | ||
return false; | ||
}; | ||
Processor.prototype._endExplainBlock = function(){ | ||
if( this.verboseStats.blockNumBytes > 0 ){ | ||
console.log( _.padEnd( "Block length:", 20) + "0x" + utils.numberToHexString( this.verboseStats.blockNumBytes, 8 ) + " (" + this.verboseStats.blockNumBytes + ")\n" ); | ||
} | ||
}; | ||
Processor.prototype.explainAddBytesAtAddress = function( buffer, address ){ | ||
if( this.options.verbose ){ | ||
if( this.verboseData.blockNumBytes === 0 ){ | ||
this.verboseData.blockStartBytes = new Buffer( buffer ); | ||
if( !buffer ){ | ||
this._setExplainBlockStartAddress( address ); | ||
}else{ | ||
var continueCurrentBlock = this. _continueExplainBlock( buffer, address ); | ||
if( !continueCurrentBlock ){ | ||
this._endExplainBlock(); | ||
this._startExplainBlock( buffer, address ); | ||
} | ||
} | ||
this.verboseData.blockNumBytes += buffer.length; | ||
this.verboseData.totalBytes += buffer.length; | ||
} | ||
@@ -116,7 +146,6 @@ }; | ||
if( this.options.verbose ){ | ||
if( this.verboseData.blockNumBytes !== 0 ){ | ||
console.log( "Block starts: " + this.verboseData.blockStartBytes.toString('hex') ); | ||
console.log( "Block length: 0x" + utils.numberToHexString( this.verboseData.blockNumBytes, 8 ) + "\n" ); | ||
if( this.verboseStats.blockNumBytes !== 0 ){ | ||
this._endExplainBlock(); | ||
} | ||
console.log( "EOF. Total Bytes 0x" + utils.numberToHexString( this.verboseData.totalBytes, 8 ) ); | ||
console.log( _.padEnd( "EOF. Total Bytes:", 20) + "0x" + utils.numberToHexString( this.verboseStats.totalBytes, 8 ) + " (" + this.verboseStats.totalBytes + ")\n" ); | ||
} | ||
@@ -143,5 +172,4 @@ }; | ||
baseAddress = parsedLine.baseAddress << 16; | ||
this.explainAddBytesAtAddress( null, baseAddress ); | ||
this.explainSetAddress( baseAddress ); | ||
} else if ( parsedLine.recordType === RECORD_TYPE_DATA ){ | ||
@@ -152,3 +180,3 @@ | ||
this.explainAddBytes( parsedLine.payload ); | ||
this.explainAddBytesAtAddress( parsedLine.payload, lineAddress ); | ||
@@ -173,4 +201,8 @@ maximumAddress = Math.max( (lineAddress + linePayload.length), maximumAddress ); | ||
function _hexDumpWords( buffer, littleEndian ){ | ||
return utils.hexStringByWords( buffer.toString('hex'), littleEndian ); | ||
} | ||
module.exports = Processor; | ||
})(); |
@@ -31,2 +31,20 @@ ( function(){ | ||
exports.hexStringByWords = function( hex, littleEndian ){ | ||
if( !hex || hex.length % 8 !== 0 ) throw new Error("hexStringByWords requires a word-aligned hex string"); | ||
littleEndian = !!littleEndian; | ||
hex = hex.toUpperCase(); | ||
const wordStrings = []; | ||
for( var i=0; i < hex.length; i += 8 ){ | ||
var ws = hex.substring( i, i+8 ); | ||
if( littleEndian ){ | ||
ws = ws.substring( 6, 8 ) + ws.substring( 4, 6 ) + ws.substring( 2, 4 ) + ws.substring( 0, 2 ); | ||
} | ||
wordStrings.push( ws ); | ||
} | ||
return wordStrings.join(' '); | ||
}; | ||
exports.hexToDecimal = function( hexString ){ | ||
@@ -33,0 +51,0 @@ try{ |
{ | ||
"name": "@connectedyard/node-intelhex", | ||
"version": "1.1.0", | ||
"version": "1.1.2", | ||
"description": "Building and converting between intel-hex and binary data", | ||
@@ -29,3 +29,4 @@ "bin": { | ||
"bluebird": "^3.4.6", | ||
"commander": "^2.9.0" | ||
"commander": "^2.9.0", | ||
"lodash": "^4.17.2" | ||
}, | ||
@@ -32,0 +33,0 @@ "devDependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
64218
34
707
3
+ Addedlodash@^4.17.2
+ Addedlodash@4.17.21(transitive)