npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bglib

v0.0.9

Published

Create and parse packets for the BlueGiga BLE112 and BLE113

Downloads

84

Readme

##BGLib BGLib is a Node library for sending and receiving packets from BlueGiga BLE devices (currently supports ble112 and ble113). It is currently being developed by Technical Machine to support our Tessel BLE module.

##Install

npm install bglib

##Examples

###Creating a packet

var bg = require('bglib');

var bglib = new bg()
bglib.getPacket(bg.api.systemHello, function(err, packet) {
  console.log(packet.getByteArray()); // Returns buf< 0, 0, 0, 1 >
}); 

// Use Packet Mode if you don't have flow control
// It adds a length byte to the front of every packet
bglib.setPacketMode(true);

bglib.getPacket(bg.api.systemHello, function(err, packet) {
  console.log(packet.getByteArray()); // Returns buf< 4, 0, 0, 0, 1 >
});

bglib.getPacket(bg.api.gapDiscover, [1, 0], function(err, response) {
  bglib.getPacket(bg.api.systemHello, function(err, packet) {
  console.log(packet); 
  /* Returns { mType: 0,
  tType: 0,
  payloadHighBits: 0,
  payloadLowBits: 0,
  cClass: 0,
  cID: 1,
  payload: <Buffer >,
  packetMode: true,
  callback: null }
  */
});

###Parsing Incoming Data

var incomingBytes = new Buffer([ 128, 38, 6, 0, 189, 0, 108, 189, 40, 93, 28, 216, 1, 255, 27, 2, 1, 6, 17, 6, 186, 86, 137, 166, 250, 191, 162, 189, 1, 70, 125, 110, 56, 88, 171, 173, 5, 22, 10, 24, 7, 4]);

bglib.parseIncoming(incomingBytes, function(err, parsedPackets) {
  console.log("Parsed packets: ", parsedPackets);

  // BGLib will automatically parse each packet into the values stated by the datasheet
  // depending on what type of event/response it is. Below is an example for the discovered
  // peripheral event that was passed in:
  console.log(parsedPackets[0].response.packet_type) // 0
  console.log(parsedPackets[0].response.sender) //  buf< 108, 189, 40, 93, 28, 216>
  console.log(parsedPackets[0].response.address_type) // 1
  console.log(parsedPackets[0].response.bond) // 255
  console.log(parsedPackets[0].response.data) //  data object with flag types, raw data, etc
  console.log(parsedPackets[0].rssi) // -67
});

The library will hold the current state of the packets so you can pass in pieces of a packet and it will return the entire parsed packet when it has all been passed in.

###Thanks JRowberg deserves a special shout-out. Some of the code is modeled after his Arduino bglib work.