Cruisers Forum
 


Reply
  This discussion is proudly sponsored by:
Please support our sponsors and let them know you heard about their products on Cruisers Forums. Advertise Here
 
Thread Tools Search this Thread Rate Thread Display Modes
Old 12-12-2020, 02:35   #16
Registered User

Join Date: Dec 2005
Location: Helsingborg
Boat: Dufour 35
Posts: 3,891
Re: JavaScript Plugin

@Antipole
OK trying here instead. drop the ".pdf" as usual.

Package for Ubuntu 20.04, compiled with gtk 3.
JavaScript_pi_0.3.0-1_amd64.deb.pdf
cagney is offline   Reply With Quote
Old 05-04-2021, 01:17   #17
Registered User

Join Date: Aug 2016
Location: Stockholm, Sweden
Posts: 272
Re: JavaScript Plugin

Antipole,
testing JavaScript to generate date as you recommended in the NmeaConverter thread and are getting some issues and two questions:
a) Had to compile from your source as the deb refused to install, claims it is not a debian package, not even when I compiled and made a package on my virtual test machine. Have no idea why. I'm using Linux Ubuntu 20.04 (Focal Fossa) and OpenCPN v.5.2.4
b) The left side icon displays the green puzzle, not the JS icon.
c) OpenCPN hangs if using 'splut[0] = "$JSRMC";' as in the description 'Process and edit NMEA sentences'. Leaving the dollar sign out seems ok and seems accepted by OpenCPN.
The Questions:
- Being a total novice on JS, how do one keep a leading '0' for the date string if the date is e.g. '05'. There should always be 6 digits for date in RMC.
- How can I make the JavaScript plugin autostart and run a generated script at boot? There should be no need to activate JS -> select script -> click Run.
/LennartG
LennartG is offline   Reply With Quote
Old 05-04-2021, 02:00   #18
Registered User
 
Antipole's Avatar

Join Date: Oct 2019
Location: Emsworth, UK
Boat: Alubat Ovni 395
Posts: 287
Re: JavaScript Plugin

@LennartG...
I will ask Mike about (a) & (b) as I am Mac only and he did the testing for deb.
(c) I do not understand why you have this - maybe PM me your whole script?

Regarding formatting the date string, you could use
Code:
("000" + date).slice(-n)
which puts zeros on the front and then takes the last n characters, leaving leading zeros.

It so happens that I have just completed a suggested script for you, which I append below. I use a different approach of getting the data from OpenCPN rather than NMEA sentences. If you need the variation, enable the WMM plugin to get variation included in the OCPN navigational data. Or you could extract variation from NMEA data if you prefer.

Regarding your last point, I am just finishing v0.4 of the plugin, which has the ability to autoload and run a script. v0.4 needs to go to Mike for cross-platform testing. Expect it released soon.

Code:
// generate RMC sentence every few seconds

// we will use a position object to convert position to format used in NMEA sentences
Position = require("Position");	// load the position constructor

tick = 2;	// how often to generate
onSeconds(generate, tick);

function generate(){
	navData = OCPNgetNavigation();
	dateObject = new Date();
	dateObject.setSeconds(navData.fixTime);	// sets date object to fix date & time
	// convert date & time to format as used in RMC
	time = dateObject.toUTCString();
	print(time, "\n");	// remove this line once you understand the next
	UTC = time.slice(11,13) + time.slice(14,16) + time.slice(17,19);
	date = time.slice(8,10) + time.slice(05,07) + time.slice(02,04);
	print(UTC, " on ", date, "\n");  // remove once happy with it

	position = new Position(navData.position);	// see user guide for explanation
	RMC = "$JSRMC," + UTC + ",A,"+ position.NMEA + "," + 
		navData.SOG.toFixed(2) + "," + navData.COG.toFixed(2) + "," + date + "," +
		Math.abs(navData.variation).toFixed(3) + "," + ((navData.variation < 0)?"W":"E");
	print(RMC, "\n");	// remove when satisfied with it
	OCPNpushNMEA(RMC);
	onSeconds(generate, tick);	// repeat
	}
Antipole is offline   Reply With Quote
Old 05-04-2021, 03:04   #19
Registered User

Join Date: May 2012
Posts: 1,207
Re: JavaScript Plugin

Quote:
Originally Posted by LennartG View Post
a) Had to compile from your source as the deb refused to install, claims it is not a debian package, not even when I compiled and made a package on my virtual test machine. Have no idea why. I'm using Linux Ubuntu 20.04 (Focal Fossa) and OpenCPN v.5.2.4
b) The left side icon displays the green puzzle, not the JS icon.
Tony asked me to reply. Out of interest what processor are you running please?

Ref b) I get the green puzzle with legacy plugins sometimes. It is a bug that has been reported. The plugin should still start ok.

https://github.com/OpenCPN/plugins/issues/194

I am just about to compile a Ubuntu 20.04 version to see what happens.

Mike
Rasbats is offline   Reply With Quote
Old 05-04-2021, 04:48   #20
Registered User

Join Date: Aug 2016
Location: Stockholm, Sweden
Posts: 272
Re: JavaScript Plugin

Antipole / Mike,
had gone a bit further before I saw your replies and actually almost got it to do what I want. Added the date slicing function so here is what I have now. Not so educated but easy for an old sysadm used to scripting and easy to follow:

Code:
// Generate RMC sentence
var vartime = "";      // UTC time from ZDA field 1
var varvalid = "";     // Data valid from GLL field 6
var varlat = "";       // Latitude from GLL field 1
var varlatNS = "";     // Latitude N/S from GLL field 2
var varlong = "";      // Latitude from GLL field 3
var varlongEW = "";    // Latitude N/S from GLL field 4
var varSOG = "";       // Speed in knots from VTG field 5
var varCOG = "";       // Track in degrees from VTG field 1
var vardd = "";        // Date day from ZDA field 2
var varmm = "";        // Date month from ZDA field 3
var varyy = "";        // Date year from ZDA field 4
var varddmmyy = "";    // Date from ZDA fields 2-4 
var varmagvar = "";    // Declination in degrees from HDG field 2
var varmagvarEW = "";  // Declination direction East/West from HDG field 3 

OCPNonNMEAsentence(processNMEA);

function processNMEA(input){
  if (input.OK){
    sentence = input.value;
    if (sentence.slice(3,6) == "GLL"){
      splut = sentence.split(",");
      varlat = splut [1];
      varlatNS = splut [2];
      varlong = splut [3];
      varlongEW = splut [4];
      varvalid = splut [6];
    } else if (sentence.slice(3,6) == "HDG"){
      splut = sentence.split(",");
      varmagvar = splut [4];
      varmagvarEW = splut [5];
    } else if (sentence.slice(3,6) == "VTG"){
      splut = sentence.split(",");
      varSOG = splut [5];
      varCOG = splut [1];
    } else if (sentence.slice(3,6) == "ZDA"){
      splut = sentence.split(",");
      vartime = splut [1];
      vardd = splut [2];
      varmm = splut [3];
      varyy = splut [4];
      varddmmyy = (10000*vardd)+(100*varmm)+(varyy-2000);
    } else if (sentence.slice(3,6) == "RMD"){
      // RMC generated from NmeaConverter
      splut = sentence.split(",");
      splut[0] = "$IIRMC";
      splut[1] = vartime;
      splut[2] = varvalid;
      splut[3] = varlat;
      splut[4] = varlatNS;
      splut[5] = varlong;
      splut[6] = varlongEW;
      splut[7] = varSOG;
      splut[8] = varCOG;
      splut[9] = ("000" + varddmmyy).slice(-6);
     if (varmagvar != ""){
        // HDG will be added if available
        splut[10] = varmagvar;
        splut[11] = varmagvarEW;
     }
      result = splut.join(",");
      OCPNpushNMEA(result);
    }
  }
OCPNonNMEAsentence(processNMEA);
};
The only thing lacking in this is how to initialize the RMC sentence, currently fooling by generating a RMD in NmeaConverter.

I will follow up what Antipole suggested and see if I can understad it.

Regarding my 'boat system, this is what lshw says (part of):
Code:
 

 *-cpu                     
       description: CPU
       product: Intel(R) Celeron(R) CPU  J1900  @ 1.99GHz
       vendor: Intel Corp.
       physical id: 14
       bus info: cpu@0
       version: Intel(R) Celeron(R) CPU J1900 @ 1.99GHz
       slot: CPUSocket
       size: 1333MHz
       capacity: 2416MHz
       width: 64 bits
       clock: 83MHz
LennartG is offline   Reply With Quote
Old 05-04-2021, 05:05   #21
Registered User

Join Date: May 2012
Posts: 1,207
Re: JavaScript Plugin

My Ubuntu 20.04 version for testing is here:

https://github.com/Rasbats/JavaScrip...ses/tag/v0.3.1

It may not work because it is compiled on an amd64 machine.

Mike
Rasbats is offline   Reply With Quote
Old 05-04-2021, 05:23   #22
Registered User

Join Date: Aug 2016
Location: Stockholm, Sweden
Posts: 272
Re: JavaScript Plugin

Mike,
it closes within a tenth of a second with nothing in syslog or whatever..
/LennartG
LennartG is offline   Reply With Quote
Old 05-04-2021, 09:03   #23
Registered User

Join Date: May 2012
Posts: 1,207
Re: JavaScript Plugin

Thanks for the feedback. I will compile on Intel when time allows.

Mike
Rasbats is offline   Reply With Quote
Old 05-04-2021, 10:45   #24
Registered User

Join Date: May 2012
Posts: 1,207
Re: JavaScript Plugin

Quote:
Code:
 
 *-cpu                     
       description: CPU
       product: Intel(R) Celeron(R) CPU  J1900  @ 1.99GHz
       vendor: Intel Corp.
       physical id: 14
       bus info: cpu@0
       version: Intel(R) Celeron(R) CPU J1900 @ 1.99GHz
       slot: CPUSocket
       size: 1333MHz
       capacity: 2416MHz
       width: 64 bits
       clock: 83MHz
Fresh build on an Intel machine here:
https://github.com/Rasbats/JavaScrip...ses/tag/v0.3.1

For a test when time allows if possible.

Thanks,
Mike
Rasbats is offline   Reply With Quote
Old 05-04-2021, 23:55   #25
Registered User

Join Date: Aug 2016
Location: Stockholm, Sweden
Posts: 272
Re: JavaScript Plugin

Antipole: Just tested your script from #18: The time and date is incorrect. Just got, reading the string from line 18, '125266 on 100772' so both time and date is wrong.
I'll play around and see what happens.

Rasbats: The latest version from last night works just fine, thanks.

/LennartG
LennartG is offline   Reply With Quote
Old 06-04-2021, 04:26   #26
Registered User

Join Date: Aug 2016
Location: Stockholm, Sweden
Posts: 272
Re: JavaScript Plugin

Antipole / Rasbats,
since installing the JavaScript plugin I am frequently (50%?) getting problems that the config file is not properly saved. The last line should say 'MyApp exiting cleanly...'.
The only clues in the logfile is 'chart1.cpp:8814 Changing NMEA datasource for JSRMC to (Priority:0)': Note the empty space after 'to'.
I have also noted that the left side menu opens 'in steps', sometimes in sections and sometimes all of it. Something fishy is going on.

Never seen these problems before, everything has been rock solid.
/LennartG
LennartG is offline   Reply With Quote
Old 11-04-2021, 22:34   #27
Registered User
 
Antipole's Avatar

Join Date: Oct 2019
Location: Emsworth, UK
Boat: Alubat Ovni 395
Posts: 287
Re: JavaScript Plugin

@LennartG ... I acknowledge that JavaScript plugin v0.3 may cause OpenCPN not to exit cleanly - and hence no 'MyApp exiting cleanly...'. message. This is especially the case if a script is running or has call-backs outstanding when OpenCPN quits. I think it is because memory allocations have not been freed up and this can lead to odd other apparently unrelated errors.

I have done a lot of work on cleaning up properly for the next version (release imminent) and now see 'MyApp exiting cleanly...' and no issues when restarting OpenCPN even if I quit OpenCPN while a script is running. I will not be doing anything further with v0.3.
Antipole is offline   Reply With Quote
Old 04-10-2021, 10:42   #28
Registered User
 
Antipole's Avatar

Join Date: Oct 2019
Location: Emsworth, UK
Boat: Alubat Ovni 395
Posts: 287
JavaScript plugin updated to v0.4

This is a big update following major restructuring to handle multiple consoles.

New features:
  • Multiple consoles
 - you can now create multiple consoles, each having their own script window. 
This allows several scripts to be run independently.
  • Inter-console actions
 - Scripts can create or delete other consoles, run scripts in other consoles and collect the results. 
Scripts can also communicate via the OpenCPN messaging system.
  • Scripts can be loaded and run automatically when OpenCPN starts
  • Scripts can be chained to run in succession
  • onExit( ) sets a function to be run on termination, including when OpenCPN quits
  • You can now write to a text file
  • Scripts can now access the OpenCPN configuration information
  • The Position, Waypoint and Route constructors can now accept a position, waypoint or route as an argument thus going the methods.

Fixes/improvements
  • Errors thrown within the plugin now show line number of invoking script steps and the call stack if from a function.
  • The precision of the position.NMEA attribute has been increased from 3 to 5 decimal places to improve results with small changes of position
  • Tidying up on script exit has been much improved, e.g. open dialogues are closed
  • Quitting OpenCPN or disabling the plugin while a script is running no longer crashes OpenCPN next time.

The UserGuide details the new features and includes further example applications.

I have started a script library for sharing scripts with other users.

The release is available here.

There is a new OpenCPN manual page for the plugin here.

A huge thanks to Mike @Rasbats for testing and sterling work on the non-macOS builds
Antipole is offline   Reply With Quote
Old 21-10-2021, 06:53   #29
Registered User
 
Antipole's Avatar

Join Date: Oct 2019
Location: Emsworth, UK
Boat: Alubat Ovni 395
Posts: 287
JavaScript plugin minor update to v0.4.1

If you have downloaded the JavaScript plugin, please install a fresh copy as it has been updated to v0.4.1 (aka v0.4 Update 1).

Fixed: Deactivating the plugin (or quitting OpenCPN) while the plugin tools window was open could crash OpenCPN.

The old-style installer for MacOS and OpenCPN v5.2 is not being updated in view of the imminent release of v5.5. If you are using this combination, close the tools window after use.
Antipole is offline   Reply With Quote
Old 29-11-2021, 09:09   #30
Registered User

Join Date: Dec 2011
Posts: 27
Re: JavaScript Plugin

Hi,
I have found the JavaScript Plugin crucial in formatting NMEA 0183 wind speed and direction data coming from an old Dataline aggregator box and sending to a Raymarine autopilot. I am running OpenCPN 5.2 on Windows 10 and want to upgrade to the latest version of the JavaScript Plugin which promises better startup and window handling...
Is there an updated version for Windows, and if so where? I freely admit that the answer may be entirely obvious!
Cheers
Ted
tedcoats is offline   Reply With Quote
Reply

Tags
plug, plugin


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
JavaScript Plugin for OpenCPN? Antipole OpenCPN 2 16-02-2022 06:44
OpenCPN PlugIn Development bdbcat OpenCPN 161 04-09-2019 12:50
Plugin development... How to receive chart objects in my plugin? dmartinez OpenCPN 6 04-08-2017 00:56
Winlink Express problems with GRIB map and Javascript Slow Boat To... Marine Electronics 0 29-04-2017 14:23
Driving Revenue JavaScript S/V_Surya Forum Tech Support & Site Help 22 06-04-2011 12:26

Advertise Here


All times are GMT -7. The time now is 19:23.


Google+
Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Social Knowledge Networks
Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2024, vBulletin Solutions, Inc.

ShowCase vBulletin Plugins by Drive Thru Online, Inc.