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

node-msp

v0.2.0

Published

MultiWii serial protocol library specialised for cleanflight

Downloads

13

Readme

node-msp

MultiWii serial protocol library specialized for usage with Cleanflight. It should also work with varying degrees of success with BaseFlight, MultiWii and other flight-controllers that support the MultiWii protocol.

The library has no dependencies, for real world usage communication using the serial port would be required. and example of this is included within the example.js file.

Both deserialization of MSP messages and serialization of messages is supported. Much of the functionality is untested therefore things may not work. Most of the MSP (except a few functions) are implemented.

You will have the look at the code for further documentation unfortunately. I may update this read-me at sometime.

Syntax

Basics

The library itself does not handle communication of the serial port (UART). To do this you will need to use a library such as serialport

var msp = require('node-msp');
var reader = new msp.reader();

var serialport = require('serialport');

var portLocation = '/dev/cu.PL2303-00001014'; //Path to serialport

var port = new serialport.SerialPort(portLocation, {
  baudrate : 115200 //Usual baud rate for flight controller
});

reader.on('error', function (error) {
  console.log('There was an error - ', error);
});

reader.on('message', function (message) {
  console.log(message);
});

port.on('open', function () {
  console.log('port connected');

  setInterval(function () {
    var message = msp.send('MSP_MOTOR');
    port.write(message, function (error) {
      //console.log(error);
    });
  }, 200);

  port.on('data', function (data) {
    reader.handleBuffer(data);
  });
});

port.on('close', function () {
  console.log('port closed');
});

Events (inbound messages)

Events are deserialized and emitted from a instance of the reader class within the node-msp module.

var reader = new require('node-msp').reader();

Data from the serial port needs to be fed into the reader class.

var reader = new require('node-msp').reader();
var serialport = require('serialport');;

var port = new serialport.SerialPort('/dev/cu.PL2303-00001014', {
  baudrate : 115200 //Usual baud rate for flight controller
});

port.on('open', function () {
  port.on('data', function (data) {
    //Feed the data in
    reader.handleBuffer(data);
  });
});

Two events can be emitted from the reader class. Error and Message. Messages can are partially abstracted you will have to look at the code or experiment for more details.

reader.on('error', function (error) {
  console.log('There was an error - ', error);
});

reader.on('message', function (message) {
  //Will contain the message name (from the ID number and the payload)
  console.log(message);
});

Outbound requests/messages

Messages can be serialized by the module.

var reader = new require('node-msp').reader();
var serialport = require('serialport');;

var port = new serialport.SerialPort('/dev/cu.PL2303-00001014', {
  baudrate : 115200 //Usual baud rate for flight controller
});

port.on('open', function () {
  port.on('data', function (data) {
    //Feed the data in
    reader.handleBuffer(data);
  });
});

Two events can be emitted from the reader class. Error and Message. Messages can are partially abstracted you will have to look at the code or experiment for more details.

msp.send('MSP_MOTOR');

Supported functions

Sending

When sending messages either the message id or name can be used. Where messages are sending data to the flight controller payload can be included as the second argument of the send function (this is optional)

var payload = {
  motors : [1000, 1000, 1000, 2000]
};
var message = msp.send('MSP_MOTOR', payload);

Messages with numbers starting with 1 are messages from the flight controller, requests for these messages require no payload. Messages beginning with 2 are requests to the flight controller, they will never be received but have a payload when sent. Supported messages are : 100. MSP_IDENT 101. MSP_STATUS 102. MSP_RAW_IMU 103. MSP_SERVO 104. MSP_MOTOR 105. MSP_RC 106. MSP_RAW_GPS 107. MSP_COMP_GPS 108. MSP_ATTITUDE 109. MSP_ALTITUDE 110. MSP_ANALOG 111. MSP_RC_TUNING 112. MSP_PID 114. MSP_MISC 115. MSP_MOTOR_PINS 118. MSP_WP 200. MSP_SET_RAW_RC 201. MSP_SET_RAW_GPS 202. MSP_SET_PID 205. MSP_ACC_CALIBRATION 206. MSP_MAG_CALIBRATION 207. MSP_SET_MISC 208. MSP_RESET_CONF 209. MSP_SET_WP 210. MSP_SELECT_SETTING 211. MSP_SET_HEAD 214. MSP_SET_MOTOR 240. MSP_BIND 250. MSP_EEPROM_WRITE

Recieving

Messages are decoded as they arrive. Messages will have the name of the command and partially abstracted payload.

More

More information of MSP messages can be found on the MultiWii wiki