n2k-signalk icon indicating copy to clipboard operation
n2k-signalk copied to clipboard

Support for canboat's '-nv' option

Open chacal opened this issue 7 years ago • 3 comments

For some use cases (e.g. signalk-socketcan-device) it is useful to run canboat's analyzer with its -nv option that adds 'raw' values for various look-up style fields in PGNs in addition to normal human readable ones. Eg. field "COG Reference":"True" becomes "COG Reference":{"value":0,"name":"True"}.

This change in input naturally breaks n2k-signalk as it expects its input in the former form.

I'm planning on adding transparent support for the latter input format for n2k-signalk, but wanted to create this issue first to discuss the matter and gather ideas on implementation. The idea at the moment is to change the implementation for all PGNs that use these 'lookup' style fields in a way that the input format is detected automatically by first checking if the value is Object and if it is, using .name instead of the field itself.

The following PGNs use 'lookup' style fields and would thus need to be changed:

127488
127489
127505
129026
129029
129038
129040
129041
129283
129284
129291
129794
129810
130306
130311
130312
130577
130842

chacal avatar Jul 21 '17 18:07 chacal

Sounds like a good plan to me.

2017-07-21 20:00 GMT+02:00 Jouni Hartikainen [email protected]:

For some use cases (e.g. signalk-socketcan-device https://github.com/chacal/signalk-socketcan-device) it is useful to run canboat's analyzer with its -nv option that adds 'raw' values for various look-up style fields in PGNs in addition to normal human readable ones. Eg. field "COG Reference":"True" becomes "COG Reference":{"value":0,"name":" True"}.

This change in input naturally breaks n2k-signalk as it expects its input in the former form.

I'm planning on adding transparent support for the latter input format for n2k-signalk, but wanted to create this issue first to discuss the matter and gather ideas on implementation. The idea at the moment is to change the implementation for all PGNs that use these 'lookup' style fields in a way that the input format is detected automatically by first checking if the value is Object and if it is, using .name instead of the field itself.

The following PGNs use 'lookup' style fields and would thus need to be changed:

127488 127489 127505 129026 129029 129038 129040 129041 129283 129284 129291 129794 129810 130306 130311 130312 130577 130842

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/SignalK/n2k-signalk/issues/79, or mute the thread https://github.com/notifications/unsubscribe-auth/ABiJesVIr3sxDocm2nzxnfIgOBqWZRMrks5sQOcrgaJpZM4Oftmy .

keesverruijt avatar Jul 22 '17 06:07 keesverruijt

I poked around with the code and came up with a solution that - albeit a bit hackily - adds support for the -nv style input transparently to all PGNs.

Commit is here: https://github.com/chacal/n2k-signalk/commit/623cf6a0b0d36d41220bc17331ab1b5c6777bec8

I also thought about how to add test cases for -nv style input and came up with something like this: https://github.com/chacal/n2k-signalk/commit/695407622e0bdb33888ff42bd3b8a67abd7728ed

What do you think? If this looks good, I can add tests for the other affected PGNs as well.

chacal avatar Jul 23 '17 07:07 chacal

Added a small helper for constructing -nv style input fields for test JSON as I noticed that its quite error prone to write JSON strings by hand: https://github.com/chacal/n2k-signalk/commit/00b6f056200a23170b11251eea9df190ca7de560

chacal avatar Jul 23 '17 07:07 chacal