Skip to content

Commit

Permalink
autopilot console
Browse files Browse the repository at this point in the history
  • Loading branch information
panaaj committed Oct 23, 2023
1 parent 196b992 commit 9f68486
Show file tree
Hide file tree
Showing 84 changed files with 1,826 additions and 1,234 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# CHANGELOG: Freeboard

### v2.3.0

- **Added**: Display a badge on menu icon when server has security enabled and client is not authenticated.
- **Added**: Autopilot console for use with built-in PyPyilot integration.
- **Added**: Display location of Man Overboard alarm on map.
- **Updated**: Align anchor watch UI to anchor-alarm API operation.
- **Updated**: Display the waypoint name when a route point is a reference to a waypoint resource.
- **Updated**: Use updated typings in `@signalk/server-api`.

### v2.2.6

- **Fixed**: Issue where anchor watch could not be set when Signal K server had security enabled. _(Requires signalk-anchoralarm-plugin v1.13.0 or later)_
Expand Down
54 changes: 32 additions & 22 deletions helper/alarms/alarms.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// **** Signal K Standard ALARMS notifier ****
import { NextFunction, Request, Response } from 'express';
import {
Notification,
DeltaMessage,
ActionResult,
ALARM_METHOD,
ALARM_STATE
} from '../lib/types';
ALARM_STATE,
Path,
PathValue
} from '@signalk/server-api';
import { FreeboardHelperApp } from '../index';

const STANDARD_ALARMS = [
Expand Down Expand Up @@ -65,7 +64,7 @@ const initAlarmEndpoints = () => {

const r = handlePutAlarmState(
'vessels.self',
`notifications.${req.params.alarmType}`,
`notifications.${req.params.alarmType}` as Path,
{
message: msg,
method: [ALARM_METHOD.sound, ALARM_METHOD.visual],
Expand Down Expand Up @@ -95,7 +94,7 @@ const initAlarmEndpoints = () => {
try {
const r = handlePutAlarmState(
'vessels.self',
`notifications.${req.params.alarmType}`,
`notifications.${req.params.alarmType}` as Path,
null
);
res.status(200).json(r);
Expand All @@ -112,13 +111,13 @@ const initAlarmEndpoints = () => {

const handlePutAlarmState = (
context: string,
path: string,
path: Path,
value: {
message: string;
state: ALARM_STATE;
method: ALARM_METHOD[];
}
): ActionResult => {
) => {
server.debug(context);
server.debug(path);
server.debug(JSON.stringify(value));
Expand All @@ -135,14 +134,21 @@ const handlePutAlarmState = (
const pa = path.split('.');
const alarmType = pa[pa.length - 1];
server.debug(JSON.stringify(alarmType));
let noti: Notification | DeltaMessage;
let noti: PathValue;
if (value) {
noti = new Notification(
alarmType,
buildAlarmMessage(value.message, alarmType),
value.state ?? null,
value.method ?? null
);
const alm = buildAlarmMessage(value.message, alarmType);
noti = {
path: `notifications.${alarmType}` as Path,
value: {
state: value.state ?? null,
method: value.method ?? null,
message: alm.message
}
};
if (alm.data) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(noti.value as any).data = alm.data;
}
} else {
noti = {
path,
Expand All @@ -164,19 +170,23 @@ const handlePutAlarmState = (
}
};

const buildAlarmMessage = (message: string, alarmType?: string): string => {
let msgAttrib = '';
const buildAlarmMessage = (message: string, alarmType?: string) => {
let data = null;
if (['mob', 'sinking'].includes(alarmType)) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const pos: any = server.getSelfPath('navigation.position');
msgAttrib = pos ? JSON.stringify(pos?.value) : '';
data = {
position: pos ? pos.value : null
};
}
return `${message}\n\r${msgAttrib}`;
return {
message: message,
data: data
};
};

// ** send notification delta message **
const emitNotification = (n: Notification | DeltaMessage) => {
const msg = n instanceof Notification ? n.message : n;
const emitNotification = (msg: PathValue) => {
const delta = {
updates: [{ values: [msg] }]
};
Expand Down
30 changes: 9 additions & 21 deletions helper/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import {
Plugin,
PluginServerApp,
ResourceProviderRegistry
} from '@signalk/server-api';
import { Plugin, ServerAPI } from '@signalk/server-api';
import { IRouter, Application, Request, Response } from 'express';
import { initAlarms } from './alarms/alarms';
import { ActionResult } from './lib/types';

import {
WEATHER_SERVICES,
Expand Down Expand Up @@ -118,18 +113,7 @@ interface OpenApiPlugin extends Plugin {

export interface FreeboardHelperApp
extends Application,
PluginServerApp,
ResourceProviderRegistry {
statusMessage?: () => string;
error: (...msg: any) => void;
debug: (...msg: any) => void;
setPluginStatus: (pluginId: string, status?: string) => void;
setPluginError: (pluginId: string, status?: string) => void;
setProviderStatus: (providerId: string, status?: string) => void;
setProviderError: (providerId: string, status?: string) => void;
getSelfPath: (path: string) => void;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
savePluginOptions: (options: any, callback: () => void) => void;
Omit<ServerAPI, 'registerPutHandler'> {
config: {
ssl: boolean;
configPath: string;
Expand All @@ -138,7 +122,7 @@ export interface FreeboardHelperApp
};

// eslint-disable-next-line @typescript-eslint/no-explicit-any
handleMessage: (id: string | null, msg: any, version?: string) => void;
//handleMessage: (id: string | null, msg: any, version?: string) => void;
streambundle: {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
getSelfBus: (path: string | void) => any;
Expand All @@ -151,8 +135,10 @@ export interface FreeboardHelperApp
path: string,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
value: any,
actionResultCallback: (actionResult: ActionResult) => void
) => ActionResult
// eslint-disable-next-line @typescript-eslint/no-explicit-any
actionResultCallback: (actionResult: any) => void
// eslint-disable-next-line @typescript-eslint/no-explicit-any
) => any
) => void;
}

Expand Down Expand Up @@ -280,9 +266,11 @@ module.exports = (server: FreeboardHelperApp): OpenApiPlugin => {
},
// eslint-disable-next-line @typescript-eslint/no-explicit-any
setResource: (id: string, value: any) => {
server.debug(`${id}, ${value}`);
throw 'Not implemented!';
},
deleteResource: (id: string) => {
server.debug(`${id}`);
throw 'Not implemented!';
}
}
Expand Down
8 changes: 6 additions & 2 deletions helper/lib/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import * as https from 'https';
import * as url from 'url';
import * as http from 'http';
import { ActionResult } from './types';

// HTTP GET
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const fetch = (href: string): Promise<any> => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const opt: any = url.parse(href);
opt.headers = { 'User-Agent': 'Mozilla/5.0' };

const req = href.indexOf('https') !== -1 ? https : http;

return new Promise((resolve, reject) => {
req
// eslint-disable-next-line @typescript-eslint/no-explicit-any
.get(opt, (res: any) => {
let data = '';
res.on('data', (chunk: string) => {
Expand All @@ -33,7 +35,8 @@ export const fetch = (href: string): Promise<any> => {
};

// HTTP POST
export const post = (href: string, data: string): Promise<ActionResult> => {
export const post = (href: string, data: string) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const opt: any = url.parse(href);
(opt.method = 'POST'),
(opt.headers = {
Expand All @@ -44,6 +47,7 @@ export const post = (href: string, data: string): Promise<ActionResult> => {

return new Promise((resolve, reject) => {
const postReq = req
// eslint-disable-next-line @typescript-eslint/no-explicit-any
.request(opt, (res: any) => {
let resText = '';
res.on('data', (chunk: string) => {
Expand Down
75 changes: 0 additions & 75 deletions helper/lib/types.ts

This file was deleted.

Loading

0 comments on commit 9f68486

Please sign in to comment.