/** * Generate a number of sentences from an nmeaINFO structure. * * @param s a pointer to the buffer in which to generate the sentences * @param len the size of the buffer * @param info the structure * @param generate_mask the mask of which sentences to generate * @return the total length of the generated sentences */ int nmea_generate(char *s, const int len, const nmeaINFO *info, const int generate_mask) { int gen_count = 0; int pack_mask = generate_mask; if (!s || !len || !info || !generate_mask) return 0; while (pack_mask) { if (pack_mask & GPGGA) { nmeaGPGGA gga; nmea_info2GPGGA(info, &gga); gen_count += nmea_gen_GPGGA(s + gen_count, len - gen_count, &gga); pack_mask &= ~GPGGA; } else if (pack_mask & GPGSA) { nmeaGPGSA gsa; nmea_info2GPGSA(info, &gsa); gen_count += nmea_gen_GPGSA(s + gen_count, len - gen_count, &gsa); pack_mask &= ~GPGSA; } else if (pack_mask & GPGSV) { nmeaGPGSV gsv; int gsv_it; int gsv_count = nmea_gsv_npack(info->satinfo.inview); for (gsv_it = 0; gsv_it < gsv_count && len - gen_count > 0; gsv_it++) { nmea_info2GPGSV(info, &gsv, gsv_it); gen_count += nmea_gen_GPGSV(s + gen_count, len - gen_count, &gsv); } pack_mask &= ~GPGSV; } else if (pack_mask & GPRMC) { nmeaGPRMC rmc; nmea_info2GPRMC(info, &rmc); gen_count += nmea_gen_GPRMC(s + gen_count, len - gen_count, &rmc); pack_mask &= ~GPRMC; } else if (pack_mask & GPVTG) { nmeaGPVTG vtg; nmea_info2GPVTG(info, &vtg); gen_count += nmea_gen_GPVTG(s + gen_count, len - gen_count, &vtg); pack_mask &= ~GPVTG; } else { /* no more known sentences to process */ break; } if (len - gen_count <= 0) break; } return gen_count; }
/** * Convert an nmeaINFO structure into an nmeaGPGSV structure * * @param info a pointer to the nmeaINFO structure * @param pack a pointer to the nmeaGPGSV structure * @param pack_idx pack index (zero based) */ void nmea_info2GPGSV(const nmeaINFO *info, nmeaGPGSV *pack, int pack_idx) { assert(pack); assert(info); nmea_zero_GPGSV(pack); pack->present = info->present; nmea_INFO_unset_present(&pack->present, SMASK); if (nmea_INFO_is_present(info->present, SATINVIEW)) { int sit; int pit; int toskip; pack->sat_count = (info->satinfo.inview < NMEA_MAXSAT) ? info->satinfo.inview : NMEA_MAXSAT; pack->pack_count = nmea_gsv_npack(pack->sat_count); if (pack_idx >= pack->pack_count) pack->pack_index = pack->pack_count; else pack->pack_index = pack_idx + 1; /* now skip the first ((pack->pack_index - 1) * NMEA_SATINPACK) in view sats */ toskip = ((pack->pack_index - 1) * NMEA_SATINPACK); sit = 0; while ((toskip > 0) && (sit < NMEA_MAXSAT)) { if (info->satinfo.sat[sit].id) { toskip--; } sit++; } for (pit = 0; pit < NMEA_SATINPACK; sit++) { if (sit < NMEA_MAXSAT) { if (info->satinfo.sat[sit].id) { pack->sat_data[pit] = info->satinfo.sat[sit]; pit++; } } else { memset(&pack->sat_data[pit], 0, sizeof(pack->sat_data[pit])); pit++; } } } }