Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bs2-programmer

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bs2-programmer - npm Package Compare versions

Comparing version 0.1.1 to 1.0.0

lib/timeouterror.js

8

examples/hi-update.js

@@ -0,1 +1,3 @@

/*eslint-disable no-process-exit */
// chrome doesnt have the brk functionality so we can fake it with a

@@ -57,3 +59,3 @@ // slow baud send of 0x00 and an update instead of open/close so we

function bootload(){
return bs2.bootload(serialPort, bs2.revisions.bs2, hex);
return bs2.bootload(serialPort, bs2.revisions.bs2, hex, 1000);
}

@@ -93,3 +95,3 @@

{
upload(process.argv[2], function(error, board){
upload(process.argv[2], function(error){
if(error)

@@ -99,3 +101,3 @@ {

}else{
console.log('success ', board);
console.log('success');
}

@@ -102,0 +104,0 @@ process.exit(0);

@@ -0,1 +1,2 @@

/*eslint-disable no-process-exit */
'use strict';

@@ -45,3 +46,3 @@

function bootload(){
return bs2.bootload(serialPort, bs2.revisions.bs2, hex);
return bs2.bootload(serialPort, bs2.revisions.bs2, hex, 1000);
}

@@ -79,3 +80,3 @@

{
upload(process.argv[2], function(error, board){
upload(process.argv[2], function(error){
if(error)

@@ -85,3 +86,3 @@ {

}else{
console.log('success ', board);
console.log('success');
}

@@ -88,0 +89,0 @@ process.exit(0);

@@ -0,1 +1,2 @@

/*eslint-disable no-process-exit */
'use strict';

@@ -14,13 +15,3 @@

// soo ... infinite promise chain instead? or bach?
function search(path, done){
var serialPort = new com.SerialPort(path, {
baudrate: 9600
}, false);
var promise = identify(serialPort, bs2.revisions.bs2);
return nodefn.bindCallback(promise, done);
}
function identify(stream, rev){

@@ -84,2 +75,13 @@

function search(path, done){
var serialPort = new com.SerialPort(path, {
baudrate: 9600
}, false);
var promise = identify(serialPort, bs2.revisions.bs2);
return nodefn.bindCallback(promise, done);
}
if(process && process.argv && process.argv[2])

@@ -86,0 +88,0 @@ {

@@ -9,2 +9,4 @@ 'use strict';

var TimeoutError = require('./lib/timeouterror.js');
function challenge(stream, options, cb){

@@ -27,3 +29,3 @@ if(!options.hasOwnProperty('challenge')){

if(response !== options.response[index]){
throw new Error('Incorrect Response: ' + response);
throw new Error('Incorrect Response: ' + response + '. Board might not be a ' + options.name);
}

@@ -45,3 +47,11 @@ });

.then(version)
.then(options.lookup);
.then(options.lookup)
// rewrite timeout errors
.catch(function(e){
if(e instanceof TimeoutError)
{
throw new Error(options.name + ' did not respond. Check power, connection, or maybe this is not a ' + options.name);
}
throw e;
});

@@ -51,19 +61,35 @@ return nodefn.bindCallback(promise, cb);

function bootload(stream, type, hex, cb){
function bootload(stream, type, hex, timeout, cb){
var pageSize = 18;
function upload(version){
return send(stream, 1000, hex)
.then(function(response){
if(response){
throw new Error('Bad bootload response: ' + response);
}
return version;
});
if(!hex || hex.length % pageSize !== 0){
throw new Error('Data must be in multiples of 18 bytes');
}
function signoff(version){
function unspool(index) {
return index + pageSize;
}
function predicate(index) {
return index >= hex.length;
}
function handler(index) {
return send(stream, timeout, hex.slice(index, index + pageSize))
.then(function(response){
if(response){
throw new Error('Board nacked packet ' + (index / pageSize) + ' with code: ' + response);
}
});
}
function upload(){
return when.iterate(unspool, predicate, handler, 0);
}
function signoff(){
return when.promise(function(resolve, reject) {
stream.write(new Buffer([0]), function(err){
if(err){ return reject(err); }
return resolve(version);
return resolve();
});

@@ -70,0 +96,0 @@ });

@@ -0,3 +1,6 @@

/*eslint-disable no-use-before-define */
'use strict';
var TimeoutError = require('./timeouterror.js');
module.exports = function (stream, timeout, responseLength, callback) {

@@ -26,3 +29,3 @@ var buffer = new Buffer(0);

timeoutId = null;
finished(new Error('receiveData timeout after ' + timeout + 'ms'));
finished(new TimeoutError('receiveData timeout after ' + timeout + 'ms ' + buffer.length + ' < ' + responseLength));
}, timeout);

@@ -29,0 +32,0 @@ }

@@ -11,12 +11,9 @@ 'use strict';

stream.write(data, function (err) {
var error;
if (err) {
error = new Error('Sending ' + data.toString('hex') + ': ' + err.message);
return reject(error);
stream.write(data, function (writeError) {
if (writeError) {
return reject(writeError);
}
receiveData(stream, timeout, data.length + 1, function (err, response) {
if (err) {
error = new Error('Sending ' + data.toString('hex') + ': ' + err.message);
return reject(error);
receiveData(stream, timeout, data.length + 1, function (receiveError, response) {
if (receiveError) {
return reject(receiveError);
}

@@ -23,0 +20,0 @@

{
"name": "bs2-programmer",
"version": "0.1.1",
"version": "1.0.0",
"description": "Upload tokenized hex to Basic Stamp 2",

@@ -24,4 +24,7 @@ "main": "index.js",

},
"bugs": {
"url": "https://github.com/jacobrosenthal/bs2-programmer/issues"
},
"author": "Jacob Rosenthal",
"license": "MIT"
}

@@ -10,2 +10,4 @@ 'use strict';

var hi = new Buffer([0xFF, 0x00, 0x00, 0x00, 0x00, 0x30, 0xA0, 0xC7, 0x92, 0x66, 0x48, 0x13, 0x84, 0x4C, 0x35, 0x07, 0xC0, 0x4B]);
var blink = new Buffer([0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x14, 0x20, 0x8c, 0x0e, 0xd8, 0xc8, 0x7c, 0xff, 0x0e, 0x60, 0x4a, 0xae, 0xe8, 0x9f, 0x49, 0xc1, 0x50, 0xc3, 0x6f, 0x8d, 0xd1, 0x03, 0x07, 0xc0, 0x60]);

@@ -25,3 +27,3 @@ lab.experiment('bs2', function () {

Code.expect(error).to.exist();
Code.expect(error.message).to.equal('Sending 42: receiveData timeout after 1000ms');
Code.expect(error.message).to.equal('BS2 did not respond. Check power, connection, or maybe this is not a BS2');
done();

@@ -37,3 +39,3 @@ });

Code.expect(error).to.exist();
Code.expect(error.message).to.equal('Incorrect Response: 200');
Code.expect(error.message).to.equal('Incorrect Response: 200. Board might not be a BS2');
done();

@@ -308,10 +310,19 @@ });

lab.test('bootload bs2', function (done) {
lab.test('bootload throws with non multiple of 18 byte data', function (done) {
var throws = function () {
bs2.bootload(hw, bs2.revisions.bs2, new Buffer([0x00, 0x01, 0x02, 0x03]), 1000, function(){});
};
Code.expect(throws).to.throw(Error, 'Data must be in multiples of 18 bytes');
done();
});
lab.test('bootload bs2 with 18 byte packet', function (done) {
//send bs2 response bytes, then the success byte
hw.setData(new Buffer([0xBE, 0xAD, 0xCE, 0x10, 0x00]));
bs2.bootload(hw, bs2.revisions.bs2, new Buffer([0x00, 0x01, 0x02, 0x03]), function(error, result){
bs2.bootload(hw, bs2.revisions.bs2, hi, 1000, function(error){
Code.expect(error).to.not.exist();
Code.expect(result).to.deep.equal({name: 'BS2', version: '1.0'});
done();

@@ -321,11 +332,21 @@ });

lab.test('bootload bs2 with 36 byte packet', function (done) {
//send bs2 response bytes, then 2 success bytes, 1 for each packet
hw.setData(new Buffer([0xBE, 0xAD, 0xCE, 0x10, 0x00, 0x00]));
bs2.bootload(hw, bs2.revisions.bs2, blink, 1000, function(error){
Code.expect(error).to.not.exist();
done();
});
});
lab.test('bootload bs2 error byte', function (done) {
//send bs2 response bytes, then the error byte
//send bs2 response bytes, then the error byte which should stop bootload at first 18 byte packet
hw.setData(new Buffer([0xBE, 0xAD, 0xCE, 0x10, 0x01]));
bs2.bootload(hw, bs2.revisions.bs2, new Buffer([0x00, 0x01, 0x02, 0x03]), function(error){
bs2.bootload(hw, bs2.revisions.bs2, blink, 1000, function(error){
Code.expect(error).to.exist();
Code.expect(error.message).to.equal('Bad bootload response: 1');
Code.expect(error.message).to.equal('Board nacked packet 0 with code: 1');
done();

@@ -332,0 +353,0 @@ });

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc