This product is licensed for use and distribution under the BSD Open Source License.
see the file COPYING for more details.
This product is licensed for use and distribution under the BSD Open Source License.
see the file COPYING for more details.
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
-LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
-OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
-OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
-OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
-EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
+OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "../inc/nmeap.h"
+
+#include <cfg/debug.h>
+
+#define assert(x) ASSERT(x)
+
+#include "cfg/cfg_nmea.h"
+
+#define LOG_LEVEL NMEA_LOG_LEVEL
+#define LOG_FORMAT NMEA_LOG_FORMAT
+#include <cfg/log.h>
+
+#ifdef _DEBUG
+ #undef NDEBUG
+ #define printf(str,...) LOG_INFO(str, ## __VA_ARGS__)
+#endif
/* this only works if you are sure you have an upper case hex digit */
#define HEXTOBIN(ch) ((ch <= '9') ? ch - '0' : ch - ('A' - 10))
/* this only works if you are sure you have an upper case hex digit */
#define HEXTOBIN(ch) ((ch <= '9') ? ch - '0' : ch - ('A' - 10))
/* latitude is degrees, minutes, fractional minutes */
/* no validation is performed on the token. it better be good.*/
/* if it comes back 0.0 then probably the token was bad */
lat = atof(plat);
/* latitude is degrees, minutes, fractional minutes */
/* no validation is performed on the token. it better be good.*/
/* if it comes back 0.0 then probably the token was bad */
lat = atof(plat);
/* longitude is degrees, minutes, fractional minutes */
/* no validation is performed on the token. it better be good.*/
/* if it comes back 0.0 then probably the token was bad */
lon = atof(plon);
/* longitude is degrees, minutes, fractional minutes */
/* no validation is performed on the token. it better be good.*/
/* if it comes back 0.0 then probably the token was bad */
lon = atof(plon);
/* copy the input to a debug buffer */
/* remove debug_input when everything is working. */
strncpy(context->debug_input,context->input,sizeof(context->debug_input));
/* copy the input to a debug buffer */
/* remove debug_input when everything is working. */
strncpy(context->debug_input,context->input,sizeof(context->debug_input));
/* try to find a matching sentence parser */
/* this search is O(n). it has a lot of potential for optimization, at the expense of complexity, if you have a lot of sentences */
/* binary search instead of linear (have to keep sentences in sorted order) O(NlogN) */
/* try to find a matching sentence parser */
/* this search is O(n). it has a lot of potential for optimization, at the expense of complexity, if you have a lot of sentences */
/* binary search instead of linear (have to keep sentences in sorted order) O(NlogN) */
+------+ +------+ +------+
|3-cks |--xdigit-->|4-cks |-xdigit->| 5-CR |
+------+ +------+ +------+
+------+ +------+ +------+
|3-cks |--xdigit-->|4-cks |-xdigit->| 5-CR |
+------+ +------+ +------+
/* input buffer overrun, restart state machine */
context->input_state = 0;
/* reset input count */
context->input_count = 0;
}
/* input buffer overrun, restart state machine */
context->input_state = 0;
/* reset input count */
context->input_count = 0;
}
/* got first checksum byte */
context->input_state = 4;
context->icks = HEXTOBIN(ch) << 4;
/* got first checksum byte */
context->input_state = 4;
context->icks = HEXTOBIN(ch) << 4;
/* got second checksum byte */
context->input_state = 5;
context->icks += HEXTOBIN(ch);
/* got second checksum byte */
context->input_state = 5;
context->icks += HEXTOBIN(ch);
/* if the checksums match, process the sentence */
if (context->ccks == context->icks) {
/* process */
status = nmeap_process(context);
/* if the checksums match, process the sentence */
if (context->ccks == context->icks) {
/* process */
status = nmeap_process(context);
* parse a buffer of nmea data
*/
int nmeap_parseBuffer(nmeap_context_t *context,const char *buffer,int *length)
* parse a buffer of nmea data
*/
int nmeap_parseBuffer(nmeap_context_t *context,const char *buffer,int *length)
/* if there is a data element, extract data from the tokens */
if (gga != 0) {
gga->latitude = nmeap_latitude(context->token[2],context->token[3]);
/* if there is a data element, extract data from the tokens */
if (gga != 0) {
gga->latitude = nmeap_latitude(context->token[2],context->token[3]);
/* print raw input string */
printf("%s",context->debug_input);
/* print raw input string */
printf("%s",context->debug_input);
/* print some validation data */
printf("%s==%s %02x==%02x\n",context->input_name,sentence->name,context->icks,context->ccks);
/* print some validation data */
printf("%s==%s %02x==%02x\n",context->input_name,sentence->name,context->icks,context->ccks);
/* print the tokens */
for(i=0;i<context->tokens;i++) {
printf("%d:%s\n",i,context->token[i]);
}
/* print the tokens */
for(i=0;i<context->tokens;i++) {
printf("%d:%s\n",i,context->token[i]);
}
/* if the sentence has a callout, call it */
if (sentence->callout != 0) {
(*sentence->callout)(context,gga,context->user_data);
}
/* if the sentence has a callout, call it */
if (sentence->callout != 0) {
(*sentence->callout)(context,gga,context->user_data);
}
/* if there is a data element, use it */
if (rmc != 0) {
/* extract data from the tokens */
/* if there is a data element, use it */
if (rmc != 0) {
/* extract data from the tokens */
/* print raw input string */
printf("%s",context->debug_input);
/* print raw input string */
printf("%s",context->debug_input);
/* print some validation data */
printf("%s==%s %02x==%02x\n",context->input_name,sentence->name,context->icks,context->ccks);
/* print some validation data */
printf("%s==%s %02x==%02x\n",context->input_name,sentence->name,context->icks,context->ccks);
/* print the tokens */
for(i=0;i<context->tokens;i++) {
printf("%d:%s\n",i,context->token[i]);
}
/* print the tokens */
for(i=0;i<context->tokens;i++) {
printf("%d:%s\n",i,context->token[i]);
}
/* if the sentence has a callout, call it */
if (sentence->callout != 0) {
(*sentence->callout)(context,rmc,context->user_data);
}
/* if the sentence has a callout, call it */
if (sentence->callout != 0) {
(*sentence->callout)(context,rmc,context->user_data);
}