-
Notifications
You must be signed in to change notification settings - Fork 197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
REQUEST FOR COMMENT make arduino optional #36
base: master
Are you sure you want to change the base?
Conversation
src/NMEAGPS.cpp
Outdated
@@ -445,7 +447,7 @@ static const char * const std_nmea[] __PROGMEM = | |||
const NMEAGPS::msg_table_t NMEAGPS::nmea_msg_table __PROGMEM = | |||
{ | |||
NMEAGPS::NMEA_FIRST_MSG, | |||
(const msg_table_t *) NULL, | |||
(const msg_table_t *) 0x00, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you saying NULL
is not defined on your platform? Wow.
Please try nullptr
instead. This is a newer language feature intended to mean "a pointer to nothing", not just a #define
to zero.
Yes, actually. It has been a while since I tried to minimize the includes, so some of the differences might go away. As you have discovered, the biggest change is the use of |
replace 0x00 with nullptr
also deactivate copying of string in parse.
to use Platform.h fix PI (std:atan(1)*4 is not a constexpr)
untested. My gps module did not get a fix :(
using dummy input.
Hi @SlashDevin I have (partially) adapted your library so that it might be used for other frameworks / systems. I guess you have to decide how you want to see your library. Should it stay an arduino library which might also be used in other systems. Or do you want this library to be a "standalone" library which can be used in an arduino. My current approach is more in line with the first version. IMO the biggest part missing is some kind of build system support (cmake?) for other platforms. If you like this approach I will resolve merge conflicts. |
Well... I always prefer a platform-independent approach, with the minimum number of "connections" to a specific platform. I think that's your second choice. I think NeoGPS is platform-dependent in its use of FLASH memory storage specifiers and the output functions ( I think I'm having trouble with the templates for I wonder if it might be better to switch NeoGPS output functions to use the streaming operator on a platform-specific output stream. For example:
This is perhaps more portable than requiring the shim classes to be written for each platform. Also, I have never like how template implementations must go in the headers. I understand why, but it has a significant impact on readability. I have not considered how the Arduino examples (INO extension, egad) might also be platform-independent. Perhaps the LINUX examples (i.e., This is a good exercise! |
Why not put the implementation into another header file: NMEAGPS.impl.h Personally I would remove all cpp files. This library will probably always be used in situations where compile time is not an issue. I started my implementation with shims. However this meant that even if I didn't use any print statements a shim implementation had to be present. By making those function template functions they are only compiled when used and the corresponding shims don't need to be implemented. I think that we should never do something like:
For instance my original intention was to use NeoGPS on an stm32. We should at least add another guard:
I would also move those Platform dependent OT: you mentioned that you don't like the |
LOL, just rename all the
Are you saying you don't do that on Linux? That's the default on the Arduino, so I have always been able to confirm that unused methods are removed from the executable image. Since compile time is not an issue, why would you not do this?
Yes, definitely. Bad example. Two different
Interesting! I'm not very familiar with templates, so it never occurred to me that the compiler would "ignore" a template implementation where the template argument is an undefined class. Kinda cool, kinda half-way to a preprocessor macro. I had to look closer at which files really include I think I don't mind requiring a shim, because the default could be do-nothing. For new platforms, that would serve as an implementation starting point. That would also remove the template noise from the header, and surely all platforms would either remove do-nothing code (the default shim) or remove unreferenced code (shim provided but never used). Surely?
Hmm, I'm not sure what you mean by "read the values". In general, I don't like the noise of preprocessor directives mixed in with code. When I can, I have started using I'm ok with I also don't like that I have to use conditionals for optional class/structure members (e.g., What is your opinion about using the streaming operators to provide some of the platform independence? Perhaps a shim/template isn't needed if all I am also thinking about how the Arduino sketches have to poll continuously because there is no OS, while Linux programs can just use a blocking read. There's something irritating about requiring Linux programs to poll via |
I do now. But you have to know that those flags exist. I've never used the Arduino platform and for instance avr-libc doesn't mention those flags. The first search result for 'avr makefile' is avr-libc. Also And not having any
Well, then shims it is.
If a compiler can remove variables without the programmer noting a difference it usually will. So even if you write to a variable, but then never read from it, the compiler will remove the whole code, which writes to the variable. I have to admit, that this is not something easily verified and even taking the pointer of a variable might force the compiler to add unused variables again.
with
Note that there are not even any variables any longer. And r25 is overwritten twice as the value is not needed. However adding those 2 lines directly before
will increase the asm code of the main function to 74 lines and put the objects into ram. I don't think that all |
Yes, I have spent some time reviewing the optimization of variables. I wondered if you thought that data members would be optimized out of a class/structure if they are never referenced. Optional member declaration and usage must remain guarded by
I keep wondering how much
If |
add non working CMakeLists.txt
which encapsulate platform dependent functionality.
move code into GpsPort directly.
std::cout treats uint_t like chars
if number is uint8_t std::cout will print the character (usually uint8_t is typedef'd to unsigned char. adding a + in front of the number tells << to print the number: outs << number → outs << +number
This reverts commit 8a1ec52.
This reverts commit d3f96eb.
This reverts commit e9f328f.
This reverts commit a8b7fbe.
This reverts commit 9058e01.
This reverts commit cfe0977.
This reverts commit c714716.
This reverts commit 44153e6.
This reverts commit 491cf1d.
This reverts commit e9706e3.
This reverts commit 852821b.
This reverts commit 31fc161.
This reverts commit 813f8be.
This reverts commit 39f3911.
Hello @SlashDevin I've spent some time to modify my PR. Platform dependent code is now included through There are 3 classes which should be implemented: I've added a tests order (which currently doesn't test anything) showing how to use a fakeGPS and stdout. |
}; | ||
|
||
Print & operator << ( Print & print, char ) { return print; } | ||
Print & operator << ( Print & print, uint8_t ) { return print; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this function is not necessary and should be removed.
uint8_t
is usually typedef
'd to unsigned char
and for instance std::cout
will not print a number but the corresponding ascii char.
I've added a + in front of all uint8_t
prints which automatically casts them them to int
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::cout
prints the ASCII character for unsigned char
? How are you supposed to print the number? unsigned short
? Cast it to int
? Hmmm...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. You need to cast.
The easiest way to cast is by adding + in front of an uint8_t
std::cout << n;
becomes std::cout << +n;
This will cast uint8_t to ints. All other types stay the same. I've added a +
in front of all << aNumber
. Regardless of the actual number type. All numbers are now output as outs << +aNumber;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doh! Now your previous comment makes sense:
I've added a + in front of all uint8_t prints which automatically casts them them to int.
I was totally derailed by the source code diffs above that show "+" at the beginning of the line...
It will take me a while to go through all of this, and coordinate it with my works in progress. Thanks! |
Just a note to let you know I'm still working on this... I'm investigating the Windows platform, too. |
this branch tries to make the arduino platform optional, so that the library may be used on other platforms.
Is this something you would even consider merging?
Note that I haven't yet tested anything, but if there is no chance of this branch being merged I would rather just copy the code I need instead of working on the fork.
DO NOT MERGE (YET)