signalk-to-stalk
Version:
Signal K server plugin and read-only WebApp converting navigation data to SeaTalk1 with coherent settings, waypoint, units, lights, diagnostics, and calibration advice
17 lines (16 loc) • 545 B
JavaScript
const { parseDate, toDatagram } = require('../stalk')
module.exports = () => ({
datagram: '0x56',
title: '0x56 UTC date',
keys: ['navigation.datetime'],
f(value) {
if (value == null) return undefined
const date = parseDate(value)
const year = date.getUTCFullYear() - 2000
if (year < 0 || year > 255) throw new RangeError('date year must be between 2000 and 2255')
const month = date.getUTCMonth() + 1
const day = date.getUTCDate()
return toDatagram([0x56, (month << 4) | 0x01, day, year])
}
})