Git Product home page Git Product logo

node-serialport-enocean-parser's People

Contributors

codlab avatar holger-will avatar rafaelka avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

nonopn enocean-js

node-serialport-enocean-parser's Issues

clarify how to log

we need to log some fails in byte stream e.g.:

  1. fetchCRC8ForHeaderAndCheck(byte) {
    if (this.getCrc8(this.tmp.header) != byte) {
    this.callbackForNextByte = this.waitForSyncByte;
    // @todo : Log this fail
    return;
    }
    this.currentESP3Packet.crc8Header = byte;
    this.currentESP3Packet.data = Buffer.alloc(this.currentESP3Packet.header.dataLength);
    // @todo: is 0 bytes buffer really needed? -> maybe "if (currentESP3Packet.header.optionalLength > 0)"?
    this.currentESP3Packet.optionalData = Buffer.alloc(this.currentESP3Packet.header.optionalLength);
    this.callbackForNextByte = this.fillData;
    }
  2. fetchCRC8ForDataAndCheck(byte){
    this.callbackForNextByte = this.waitForSyncByte;
    var datas = Buffer.concat(
    [this.currentESP3Packet.data, this.currentESP3Packet.optionalData],
    (this.currentESP3Packet.header.dataLength + this.currentESP3Packet.header.optionalLength)
    );
    if (this.getCrc8(datas) != byte) {
    // todo : Log this fail
    return;
    }
    this.currentESP3Packet.crc8Data = byte;
    this.emitFetchedESP3Packet();
    }
  • Is there standard logger in node or serial port available?
  • Is it possible and makes it sense to pass some Prototype/Object/Callback to pass messages?

clarify _flush() functionality in serialport context

We must evaluate functionality of _flush() properly.

_flush(cb) {
this.push(this.currentESP3Packet)
this.currentESP3Packet = new ESP3Packet();
cb()
}

  • Is it possible, that not fulfilled Packet will be pushed, if _flush() is called?
  • Is it possible, that the same Packet can be emitted twice? Also for example if _flush() is called in same tick with emitFetchedESP3Packet().

Something else is important?

Packet dropped due to bug when sending data

When sending data to a compatible device and having a response from the TCMXXX, it is common that the packet does not have optional data (optional data length == 0), is then causes a fault in the state machine which does not trigger the "data" event and makes the next packet to be dropped in order to the machine to be in its correct state.

A fix is proposed in the #5 Pull Request

evaluate test and code for checking CRC8 for Datas

if (this.getCrc8(datas) != byte) {
// todo : Log this fail
return;
}

is not covered by

it(`packet SHOULD NOT be emitted, if data or optional data is invalid`, function () {
const spy = sinon.spy();
esp3parser.on('data', spy);
const withBrokenCRC8Data = telegrams.slice(0).map(
telegramAsString => Buffer.from(
telegramAsString.substring(0, telegramAsString.length - 2) + '00',
'hex'
)
);
const byteStream = Buffer.concat(withBrokenCRC8Data);
assert.equal(spy.callCount, 0, `Broken packets are emitted.`);
});

See: https://coveralls.io/builds/20408130/source?filename=ESP3Parser.js#L101

Originally posted by @RafaelKa in #27

support for serialport 5.x

this parser does not seem to work with serialport 5.x. Would be great having support for it, going forward. cheers.

version outdated

The current version 0.1.0 is now outdated. Any ETA to have the corresponding changes pushed to npmjs?

add proper error handling and failure tests

check every function and method for proper error handling and add tests passing invalid data everywhere.
I propose to try to recover from most bogus inputs as much as we can and only throw if absolutely necessary.
For cases where we recover it's best to log somewhere and outside of the parser we are not in a stream so emit("error") does not work... :-(
the question is again how to log.

code split (Parser - ESP3)

i propose to split the code into two repositories. Following the Unix principle of doing one thing,well.
Here is the place for the simple parser with the only purpose of detecting packets.
it's a transformable stream that emits structs which should be immutable.
It' should be configurable to emit string or buffer instead.

Everithing else should move to the ESP3 Protocol implementation.

include complete Buffer in ESP3Packet returned from Parser.

I'm using your parser in node-enocean now. My receiving and testing code relies on having the complete telegram avaiable as a Buffer. currently i have to convert the ESPPackat returned by the parser back to a Buffer. It woud be very convienient if this would be part of the ESPPacket.

{
  syncByte: 85,
  header: { dataLength: 5, optionalLength: 1, packetType: 2 },
  crc8Header: 219,
  data: <Buffer 00 ff a0 87 00>,
  optionalData: <Buffer 09>,
  crc8Data: 228,
  buffer: <Buffer 55 00 05 00 01...the complete packet as a Buffer...> 
}

export classes, structs, and helper functions

we should not only export the parsers, but also the classes and structs.

the crc8 calculation is useful in many places in a full enocean implementation. i would like to export that as well.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.