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

vessel-state

v1.0.5

Published

Takes a stream of data and decodes it into a reactive Vuex store for use in Vue components.

Downloads

4

Readme

vessel-state

Takes a stream of data and decodes it into a reactive Vuex store for use in Vue components.

This library uses ricardoboss/extended-nmea to decode NMEA0183 sentences. The decoded sentences get used to update the module state. You can use this library in your Vue.js project to reactively bind to specific values extracted from an NMEA0183 data stream.


API

  1. Register the plugin:
// ./src/store/index.ts

import Vue from "vue"
import Vuex from "vuex"
import {createPlugin as createVesselStatePlugin} from "vessel-state";
import {RootState} from "./states/RootState";

Vue.use(Vuex)

export default new Vuex.Store<RootState>({
	plugins: [createVesselStatePlugin<RootState>()],
});
  1. Bind a value:
<!-- ./src/views/ROT.vue -->

<template>
	<span>ROT: {{ rateOfTurn }}</span>
</template>

<script>
export default {
	name: "ROT",

	computed: {
		...mapState("vessel", {
			rateOfTurn: state => state.route.rateOfTurn
		})
	}
}
</script>
  1. Update the value using the vessel/update action with the NMEA0183 sentence as the payload:
// somewhere in your code...

this.$store.dispatch('vessel/update', "$--ROT,-1.31,A*38"); // will update the value of rateOfTurn to -1.31

Vessel State Object

The vessel store has the following structure:

{
	"location": {
		"latitude": {
			"quadrant": "N",
			"degrees": 0,
			"decimal": 0
		},
		"longitude": {
			"quadrant": "E",
			"degrees": 0,
			"decimal": 0
		},
		"altitude": 0,
		"geoidalSeparation": 0
	},
	"gps": {
		"dilutionOfPrecision": {
			"position": 0,
			"vertical": 0,
			"horizontal": 0
		},
		"satellites": {},
		"time": {
			"totalMilliseconds": 0
		},
		"date": {
			"day": 0,
			"month": 0,
			"year": 0
		},
		"fix": 0
	},
	"orientation": {
		"heading": 0,
		"pitch": 0,
		"roll": 0
	},
	"route": {
		"rateOfTurn": 0,
		"course": 0,
		"speed": 0,
		"magneticTrackAngle": 0
	},
	"source": {
		"manufacturer": {
			"name": ""
		},
		"battery": {
			"voltage": 0,
			"percent": 0
		}
	},
	"stats": {
		"lastUpdate": 0,
		"messages": {
			"count": 0,
			"invalid": 0,
			"errors": 0
		}
	}
}

Custom NMEA sentences

Since ricardoboss/extended-nmea supports the addition of custom sentences, this library also propagates this feature to you.

Create your TalkerSentence implementation and register it in a CustomVesselStateMutationRegistrar:

// ./src/sentences/NAV.ts

import {TalkerSentence} from "extended-nmea/dist/types/sentences/TalkerSentence";
import {RawNmeaSentence} from "extended-nmea/dist/types/sentences/RawNmeaSentence";
import {RootState} from "@/store/states/RootState";
import {VesselStateActionContext, CustomVesselStateMutationRegistrar} from "vessel-state";

export class NAV extends TalkerSentence {
	public static readonly ID = "NAV";

	constructor(data: RawNmeaSentence) {
		super(data);
	}

	public get roll(): number {
		return parseFloat(this.dataFields[0]);
	}

	public get pitch(): number {
		return parseFloat(this.dataFields[1]);
	}
}

export const registrar = {
	id: NAV.ID, decoder: NAV, mutator: (context: VesselStateActionContext<RootState>, sentence: NAV) => {
		context.commit('roll', sentence.roll);
		context.commit('pitch', sentence.pitch);
	}
} as CustomVesselStateMutationRegistrar<RootState, NAV>;

Then, in your store, register the registrar via dispatch:

import {registrar as NavRegistrar} from "@/sentences/NAV";

const store = new Vuex.Store<...>(...);

store.dispatch('vessel/register', NavRegistrar);

export default store;

Custom state properties

If you need/want to add custom properties to the vessel state, use the custom mutation and a CustomMutationPayload:

// in a registrar mutator...

context.commit('custom', {
  path: 'my.custom.property',
  value: sentence.myCustomValue
});

License

This project is licensed under the MIT license. Please review the LICENSE file for more information.