UNPKG

nixfilter-uartrfid

Version:

Filters for decoding the data sent by certain RFID readers connected via UART

64 lines (58 loc) 1.93 kB
#!/usr/bin/env node 'use strict'; var nixfilter, utils, indexOf = [].indexOf; // Require the "nixfilter" module nixfilter = require('nixfilter'); // Import/Require the local "utils" module utils = require('./utils'); // Define the filter and register it on the module nixfilter.filter(module, { description: 'Parse and output the data sent by certain EM4100-125kHz-RFID-Readers connected via UART 9600 8N1 (e.g. RDM630, RDM6300)', input_reader: nixfilter.reader.byte(), add_arguments: function(argument_parser) { argument_parser.addArgument(['--format', '-f'], { choices: Object.keys(utils.formats), defaultValue: '08H>10D', help: 'The output format (default: "08H>10D")' }); }, setup: function() { return this.state = 'read_start'; }, on_input: function(input_byte) { var checksum, data, i, index, input_character; switch (this.state) { case 'read_start': if (input_byte === 0x02) { this.data_string = ''; this.state = 'read_data'; } break; case 'read_data': input_character = String.fromCharCode(input_byte); if ((indexOf.call('0123456789ABCDEF', input_character) >= 0)) { this.data_string += input_character; if (this.data_string.length === 12) { this.state = 'read_stop'; } } else { this.state = 'read_start'; } break; case 'read_stop': if (input_byte === 0x03) { checksum = 0; for (index = i = 0; i < 5; index = ++i) { checksum ^= utils.get_data_byte_at(this.data_string, index); } if (checksum === utils.get_data_byte_at(this.data_string, 5)) { data = utils.parse_data(this.data_string); this.output(data[this.args.format]); } } this.state = 'read_start'; } } }); //# sourceMappingURL=rdm63.js.map