void GPS::read(void) { char c = 0; if (paused) return; if(!pSerial->available()) return; c = pSerial->read(); linebuf[lineidx++] = c; if (lineidx == (MAXLINELENGTH-1)) { --lineidx; } if (c == '\n') { linebuf[lineidx] = 0; lineidx = 0; if (sentenceCallback) sentenceCallback(linebuf); char *p = linebuf; while (*p) { switch (*p) { case '\r': break; case '\n': if (currentSentence == SENTENCE_RMC) { rmcready = true; } if (currentSentence == SENTENCE_GGA) { ggaready = true; } endOfField(); break; case ',': endOfField(); break; case '*': endOfField(); break; default: field[fieldidx++] = *p; if (fieldidx >= MAXFIELDLENGTH) { fieldidx = MAXFIELDLENGTH-1; } break; } ++p; } } }
// -------------------------------------------------------------------------------------------- void DatabaseLoader::writeRecord(std::vector<struct aq::column_info_t>& columns_infos, const char * record) const { size_t len_rec = strlen(record); int cur_col = 0; bool end_of_field = false; int indice_car; char field[k_field_size_max]; // for each field in record size_t i = 0; while (i < len_rec) { if (csv_format && (record[i] == '"')) { i++; } indice_car = 0 ; end_of_field = false; while (!end_of_field) { const char& c = record[i]; if (csv_format) { if ((c == '"') && (record[i - 1] != '\\')) { i++; end_of_field = true; } } else if (endOfField(c)) { end_of_field = true; } if (end_of_field) { if (indice_car == 0) strcpy(field, "NULL"); else field[indice_car] = '\0'; auto& ci = columns_infos[cur_col]; this->FileWriteEnreg(ci, field); cur_col++; } else { field[indice_car] = c; indice_car++; } i++; } } }