You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've successfully compiled your lovely NMEA0183 library with the arm-none-eabi toolchain for running on an ARM1176. While doing so I ran into an issue with the AddDoubleField method of tNMEA0183Msg; it depends on dtostrf which I'm pretty sure is an Arduino specific function. I solved this by creating an extern C library (noniso.c) which declares a substitute dtostrf as follows (shamelessly stolen from the ESP32 Arduino Core):
char*dtostrf(doublenumber, signed intwidth, unsigned intprec, char*s) {
boolnegative= false;
if (isnan(number)) {
strcpy(s, "nan");
returns;
}
if (isinf(number)) {
strcpy(s, "inf");
returns;
}
char*out=s;
intfillme=width; // how many cells to fill for the integer partif (prec>0) {
fillme-= (prec+1);
}
// Handle negative numbersif (number<0.0) {
negative= true;
fillme--;
number=-number;
}
// Round correctly so that print(1.999, 2) prints as "2.00"// I optimized out most of the divisionsdoublerounding=2.0;
for (unsigned inti=0; i<prec; ++i) {
rounding *= 10.0;
}
rounding=1.0 / rounding;
number+=rounding;
// Figure out how big our number really isdoubletenpow=1.0;
unsigned intdigitcount=1;
while (number >= 10.0*tenpow) {
tenpow *= 10.0;
digitcount++;
}
number /= tenpow;
fillme-=digitcount;
// Pad unused cells with spaceswhile (fillme-->0) {
*out++=' ';
}
// Handle negative signif (negative) {
*out++='-';
}
// Print the digits, and if necessary, the decimal pointdigitcount+=prec;
int8_tdigit=0;
while (digitcount-->0) {
digit= (int8_t)number;
if (digit>9) {
digit=9; // insurance
}
*out++= (char)('0' | digit);
if ((digitcount==prec) && (prec>0)) {
*out++='.';
}
number-=digit;
number *= 10.0;
}
// make sure the string is terminated*out=0;
returns;
}
I haven't done any thorough testing (yet), but so far it seems to do what's expected. It might be worth providing something similar as a default substitute in the NMEA0183 library for non-Arduino builds. Alternatively it looks like dtostrf could be dropped in favour of a sprintf call?
Furthermore, I also needed the millis() and delay() functions - as is clearly explained in the NMEA0183Msg.cpp source (thank you!). The assumption is that these would be C library functions, but I'm using a C++ framework which already provides native ARM timer functions, so I changed the externs to C++ and created a small C++ wrapper (avr.cpp) for these two methods:
This too seems to work, though it's entirely possible that I've made some mistake or that I've misunderstood something fundamental; C/C++ are not my first languages, or even my second :) Let me know what you think - and many thanks for all your hard work on this great library!
Edit: Having read up on extern I realised that's not how extern works, and that those stanzas were not needed.
The text was updated successfully, but these errors were encountered:
I've successfully compiled your lovely NMEA0183 library with the
arm-none-eabi
toolchain for running on an ARM1176. While doing so I ran into an issue with theAddDoubleField
method oftNMEA0183Msg
; it depends ondtostrf
which I'm pretty sure is an Arduino specific function. I solved this by creating an extern C library (noniso.c
) which declares a substitutedtostrf
as follows (shamelessly stolen from the ESP32 Arduino Core):I haven't done any thorough testing (yet), but so far it seems to do what's expected. It might be worth providing something similar as a default substitute in the NMEA0183 library for non-Arduino builds. Alternatively it looks like
dtostrf
could be dropped in favour of asprintf
call?Furthermore, I also needed the
millis()
anddelay()
functions - as is clearly explained in theNMEA0183Msg.cpp
source (thank you!). The assumption is that these would be C library functions, but I'm using a C++ framework which already provides native ARM timer functions, so I changed theexterns
to C++ and created a small C++ wrapper (avr.cpp
) for these two methods:In
NMEA0183Msg.cpp
:This too seems to work, though it's entirely possible that I've made some mistake or that I've misunderstood something fundamental; C/C++ are not my first languages, or even my second :) Let me know what you think - and many thanks for all your hard work on this great library!
Edit: Having read up on
extern
I realised that's not howextern
works, and that those stanzas were not needed.The text was updated successfully, but these errors were encountered: