This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Position, waypoint and route confidence tester | |
function compareWaypoints(waypoint1, waypoint2){ | |
// compares two waypoints and displays any mismatches. | |
// returns true if error else false if OK | |
function display(attribute){ | |
if (!displaying) printOrange("The following attributes of waypoints do not match:\n"); | |
displaying = true; | |
printOrange(attribute, "\n"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// constructs route from NMEA WPL & RTE sentences | |
// optional simulator to synthesis NMEA data | |
// Updated v0.2.1 2 Sep 2020 to fix bugs when no routes and be consistent with NMEA message as object | |
// Updated v0.2.2 7 Sep 2020 several changes to correct when waypoints updated and to include Danish similation data | |
// Updated v0.2.3 9 Sep 2020 to fix when loading existing routes and there are none | |
// options | |
replaceExitingRoutes = true; // if true, any exiting OpenCPN route with the same name will be updated | |
testMode = true; // if true, uses simulated data rather than listening for real NMEA sentences |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add hyperlinks to an existing waypoint with markName of 'lunch stop' | |
wpName = "lunch stop"; | |
guids = OCPNgetWaypointGUIDs(); | |
foundIt = false; | |
for (i = 0; i < guids.length; i++){ | |
// look for our waypoint | |
lunchWaypoint = OCPNgetSingleWaypoint(guids[i]); | |
if (lunchWaypoint.markName == wpName){ | |
foundIt = true; | |
break; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// insert magnetic variation into RMC sentence | |
// corrected 22 Dec 2020 for NMEA sentence as structure | |
var vardegs = ""; | |
var varEW = ""; | |
OCPNonNMEAsentence(processNMEA); | |
function processNMEA(input){ | |
if (input.OK){ | |
sentence = input.value; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fibonacci(n) { | |
function fib(n) { | |
if (n == 0) return 0; | |
if (n == 1) return 1; | |
return fib(n-1) + fib(n-2); | |
}; | |
var res = []; | |
for (i = 0; i < n; i++) res.push(fib(i)); | |
return(res.join(' ')); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Waypoint = require("Waypoint"); | |
newWaypoint = new Waypoint(50.33, -1.3); | |
newWaypoint.markName = "Demo Waypoint"; | |
newWaypoint.iconName = "anchor"; | |
newWaypoint.isVisible = true; | |
newWaypoint.description = "Good pub close by ashore"; | |
newWaypoint.hyperlinkList.push({description:"Pub website", link: | |
"https://coachandhorses.co.uk"}); | |
GUID = OCPNaddSingleWaypoint(newWaypoint); | |
newWaypoint.GUID = GUID; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
myWaypoint = OCPNgetSingleWaypoint("137eecdd-e3e0-4eea-9d72-6cec0e500dbe"); | |
if (!myWaypoint){ | |
print("No waypoint with that GUID\n"); | |
} | |
else{ | |
print("Waypoint name is ", myWaypoint.markName, "\n"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
APRgpx = OCPNgetARPgpx(); // get Active Route Point as GPX | |
if (APRgpx.length > 0){ | |
waypointPart = /<name>.*<\/name>/.exec(APRgpx); | |
waypointName = waypointPart[0].slice(6, -7); | |
print("Active waypoint is ", waypointName, "\n"); | |
} | |
else print("No active waypoint\n"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
routeGUID = "48cf3bc5-3abb-4f73-8ad2-994e796289eb"; | |
OCPNonMessageName(handleRT, "OCPN_ROUTE_RESPONSE"); | |
OCPNsendMessage("OCPN_ROUTE_REQUEST",JSON.stringify({"GUID":routeGUID})); | |
function handleRT(routeJS){ | |
route = JSON.parse(routeJS); | |
try {print("RouteGUID ", routeGUID, " has the name ", | |
route.name, "\n");} | |
catch(err){print("No such route\n");} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This script sends any active route out as WPT and RTE sentences so that iNavX shows the up-to-date active route. | |
// If the route or its waypoints are updated, iNavX will update to reflect this | |
Position = require("Position); // load position constructor | |
// here we define stuff we need outside the functions | |
const repeatInterval = 20; // repeat after this number of seconds | |
var activeWaypointName = “”; // to hold the active waypoint name, else “” | |
var activeRouteName = ""; // the name of the active route | |
var lastRoutePoint; // these two are needed to fix up RMB sentences and synthesise a BOD sentence… |