mbgtools-lx  4.2.8
mbgutil.c
Go to the documentation of this file.
1 
2 /**************************************************************************
3  *
4  * $Id: mbgutil.c 1.10 2018/09/21 14:59:44 martin REL_M $
5  *
6  * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
7  *
8  * Description:
9  * Utility function used by Meinberg device drivers.
10  *
11  * -----------------------------------------------------------------------
12  * $Log: mbgutil.c $
13  * Revision 1.10 2018/09/21 14:59:44 martin
14  * Fixed return value for mbg_snprintf().
15  * Revision 1.9 2018/08/13 14:53:40 martin
16  * Doxygen updates.
17  * Revision 1.8 2018/06/25 12:30:14Z martin
18  * Use int rather than size_t in many places internally.
19  * Use predefined format string for firmware version string.
20  * Use macros to get major / minor version numbers.
21  * Revision 1.7 2017/07/05 16:40:35Z martin
22  * Use functions from new module timeutil.
23  * Use safe string functions from str_util.c.
24  * Quieted some compiler warninges.
25  * Account for frac_sec_from_bin() obsoleted by bin_frac_32_to_dec_frac().
26  * Account for renamed library symbols.
27  * Added doxygen comments.
28  * Revision 1.6 2012/10/15 13:12:17 martin
29  * Fixed build under DOS.
30  * Fixed format/type mismatch when printing UTC offset.
31  * Fixed generation of firmware and ASIC version string.
32  * Revision 1.5 2009/03/19 09:09:55Z daniel
33  * Fixed ambiguous syntax in mbg_str_dev_name().
34  * Support TAI and GPS time scales in mbg_str_pcps_hr_tstamp_loc().
35  * In mbg_str_pcps_hr_time_offs() append offset only if != 0.
36  * Revision 1.4 2009/01/12 09:34:12Z daniel
37  * Added function mbg_str_dev_name().
38  * Revision 1.3 2006/05/10 10:57:44Z martin
39  * Generally use and export mbg_snprintf().
40  * Revision 1.2 2005/02/18 15:12:13Z martin
41  * Made functions mbg_strncpy() and mbg_strchar() public.
42  * New function mbg_str_tm_gps_date_time().
43  * Don't expand year number if already expanded.
44  * Revision 1.1 2005/02/18 10:39:49Z martin
45  * Initial revision
46  *
47  **************************************************************************/
48 
49 #define _MBGUTIL
50  #include <mbgutil.h>
51 #undef _MBGUTIL
52 
53 #include <cfg_hlp.h>
54 #include <mbgerror.h>
55 #include <pcpsutil.h>
56 #include <charcode.h>
57 #include <pcpsdev.h>
58 #include <str_util.h>
59 #include <qsdefs.h>
60 
61 #include <stdio.h>
62 #include <time.h>
63 #include <limits.h>
64 
65 // required at least for Linux:
66 #include <stdarg.h>
67 #include <stdlib.h>
68 #include <string.h>
69 
70 
71 #if defined( MBG_TGT_WIN32 )
72  #include <tchar.h>
73 #else
74 // #include <>
75 #endif
76 
77 
78 static int mbg_date_time_dist = 2;
79 //##++ static int mbg_time_tz_dist = 1;
80 static int mbg_pos_dist = 2;
81 
82 static uint16_t mbg_year_lim = 1980;
83 static const char str_inv_cnv[] = "(invalid conversion)";
84 
85 
86 
87 /*HDR*/
103 {
104  return MBGUTIL_VERSION;
105 
106 } // mbgutil_get_version
107 
108 
109 
110 /*HDR*/
129 {
130  if ( header_version >= MBGUTIL_COMPAT_VERSION )
131  return MBG_SUCCESS;
132 
134 
135 } // mbgutil_check_version
136 
137 
138 
139 /*HDR*/
156 __attribute__( ( format( printf, 3, 4 ) ) )
157 _MBG_API_ATTR int _MBG_API mbg_snprintf( char *s, size_t max_len, const char * fmt, ... )
158 {
159  int n;
160  va_list args;
161 
162  va_start( args, fmt );
163  n = vsnprintf_safe( s, max_len, fmt, args );
164  va_end( args );
165 
166  return n;
167 
168 } // mbg_snprintf
169 
170 
171 
172 /*HDR*/
184 _MBG_API_ATTR int _MBG_API mbg_strncpy( char *s, size_t max_len, const char *src )
185 {
186  return sn_cpy_str_safe( s, max_len, src );
187 
188 } // mbg_strncpy
189 
190 
191 
192 /*HDR*/
205 _MBG_API_ATTR int _MBG_API mbg_strchar( char *s, size_t max_len, char c, size_t n )
206 {
207  size_t i;
208 
209  max_len--;
210 
211  for ( i = 0; i < n; i++ )
212  {
213  if ( i >= max_len )
214  break;
215 
216  if ( i >= ( INT_MAX - 1 ) )
217  break;
218 
219  s[i] = c;
220  }
221 
222  s[i] = 0;
223 
224  return (int) i;
225 
226 } // mbg_strchar
227 
228 
229 
230 /*HDR*/
243 _MBG_API_ATTR int _MBG_API mbg_str_date_short( char *s, int max_len,
244  int mday, int month )
245 {
246  int n = snprintf_safe( s, max_len, "%02u.%02u.", mday, month );
247 
248  return n;
249 
250 } // mbg_str_date_short
251 
252 
253 
254 /*HDR*/
268 _MBG_API_ATTR int _MBG_API mbg_str_date( char *s, int max_len,
269  int mday, int month, int year )
270 {
271  int n = mbg_str_date_short( s, max_len, mday, month );
272 
273  n += snprintf_safe( &s[n], max_len - n, "%04u",
274  ( year < 256 ) ?
275  pcps_exp_year( (uint8_t) year, mbg_year_lim ) :
276  year );
277 
278  return n;
279 
280 } // mbg_str_date
281 
282 
283 
284 /*HDR*/
297 _MBG_API_ATTR int _MBG_API mbg_str_time_short( char *s, int max_len,
298  int hour, int min )
299 {
300  return snprintf_safe( s, max_len, "%2u:%02u", hour, min );
301 
302 } // mbg_str_time_short
303 
304 
305 
306 /*HDR*/
320 _MBG_API_ATTR int _MBG_API mbg_str_time( char *s, int max_len,
321  int hour, int min, int sec )
322 {
323  int n = mbg_str_time_short( s, max_len, hour, min );
324  n += snprintf_safe( &s[n], max_len - n, ":%02u", sec );
325 
326  return n;
327 
328 } // mbg_str_time
329 
330 
331 
332 /*HDR*/
348 _MBG_API_ATTR int _MBG_API mbg_str_time_long( char *s, int max_len,
349  int hour, int min, int sec, int sec100 )
350 {
351  int n = mbg_str_time( s, max_len, hour, min, sec );
352  n += snprintf_safe( &s[n], max_len - n, ".%02u", sec100 );
353 
354  return n;
355 
356 } // mbg_str_time_long
357 
358 
359 
360 /*HDR*/
376  const TM_GPS *pt )
377 {
378  int n = mbg_str_date( s, max_len, pt->mday, pt->month, pt->year );
379  n += mbg_strchar( &s[n], max_len - n, ' ', mbg_date_time_dist );
380  n += mbg_str_time( &s[n], max_len - n, pt->hour, pt->min, pt->sec );
381 
382  return n;
383 
384 } // mbg_str_tm_gps_date_time
385 
386 
387 
388 /*HDR*/
401  const PCPS_TIME *pt )
402 {
403  return mbg_str_date_short( s, max_len, pt->mday, pt->month );
404 
405 } // mbg_str_pcps_date_short
406 
407 
408 
409 /*HDR*/
421 _MBG_API_ATTR int _MBG_API mbg_str_pcps_date( char *s, int max_len,
422  const PCPS_TIME *pt )
423 {
424  return mbg_str_date( s, max_len, pt->mday, pt->month, pt->year );
425 
426 } // mbg_str_pcps_date
427 
428 
429 
430 /*HDR*/
443  const PCPS_TIME *pt )
444 {
445  return mbg_str_time_short( s, max_len, pt->hour, pt->min );
446 
447 } // mbg_str_pcps_time_short
448 
449 
450 
451 /*HDR*/
463 _MBG_API_ATTR int _MBG_API mbg_str_pcps_time( char *s, int max_len,
464  const PCPS_TIME *pt )
465 {
466  return mbg_str_time( s, max_len, pt->hour, pt->min, pt->sec );
467 
468 } // mbg_str_pcps_time
469 
470 
471 
472 /*HDR*/
485  const PCPS_TIME *pt )
486 {
487  return mbg_str_time_long( s, max_len, pt->hour, pt->min, pt->sec, pt->sec100 );
488 
489 } // mbg_str_pcps_time_long
490 
491 
492 
493 /*HDR*/
510  const PCPS_TIME *pt,
511  const char *tz_str )
512 {
513  int n = mbg_str_pcps_date( s, max_len, pt );
514  n += mbg_strchar( &s[n], max_len - n, ' ', mbg_date_time_dist );
515  n += mbg_str_pcps_time( &s[n], max_len - n, pt );
516  // FIXME Use tz_str ?
517 
518  return n;
519 
520 } // mbg_str_pcps_date_time
521 
522 
523 
524 /*HDR*/
536 _MBG_API_ATTR int _MBG_API mbg_str_pcps_hr_date( char *s, int max_len,
537  uint32_t sec )
538 {
539  struct tm tm = { 0 };
540  time_t t = cvt_to_time_t( sec );
541  int rc = mbg_gmtime( &tm, &t );
542 
543  return mbg_rc_is_success( rc ) ?
544  mbg_str_date( s, max_len, tm.tm_mday, tm.tm_mon + 1, tm.tm_year ) :
545  sn_cpy_str_safe( s, max_len, str_inv_cnv );
546 
547 } // mbg_str_pcps_hr_date
548 
549 
550 
551 /*HDR*/
563 _MBG_API_ATTR int _MBG_API mbg_str_pcps_hr_time( char *s, int max_len,
564  uint32_t sec )
565 {
566  struct tm tm = { 0 };
567  time_t t = cvt_to_time_t( sec );
568  int rc = mbg_gmtime( &tm, &t );
569 
570  return mbg_rc_is_success( rc ) ?
571  mbg_str_time( s, max_len, tm.tm_hour, tm.tm_min, tm.tm_sec ) :
572  sn_cpy_str_safe( s, max_len, str_inv_cnv );
573 
574 } // mbg_str_pcps_hr_time
575 
576 
577 
578 static /*HDR*/
579 /* (explicitly excluded from Doxygen)
580  * @brief Write UTC date and time given as ::PCPS_HR_TIME structure to a string buffer
581  *
582  * The number of space characters between date and time
583  * is determined by the global variable ::mbg_date_time_dist.
584  *
585  * The output string buffer is in any case properly terminated by 0.
586  *
587  * @param[out] s Pointer to the output buffer
588  * @param[in] max_len Size of the output buffer
589  * @param[in] p_t Pointer to a time_t variable providing date and time
590  *
591  * @return the number of characters written to the output buffer, except the terminating 0
592  */
593 int do_str_pcps_hr_date_time( char *s, int max_len, const time_t *p_t )
594 {
595  struct tm tm = { 0 };
596  int n = 0;
597  int rc = mbg_gmtime( &tm, p_t );
598 
599  if ( mbg_rc_is_success( rc ) )
600  {
601  n = mbg_str_date( s, max_len, tm.tm_mday , tm.tm_mon + 1, tm.tm_year );
602  n += mbg_strchar( &s[n], max_len - n, ' ', mbg_date_time_dist );
603  n += mbg_str_time( &s[n], max_len - n, tm.tm_hour, tm.tm_min, tm.tm_sec );
604  }
605  else
606  n = sn_cpy_str_safe( s, max_len, str_inv_cnv );
607 
608  return n;
609 
610 } // do_str_pcps_hr_date_time
611 
612 
613 
614 /*HDR*/
630  const PCPS_HR_TIME *pt )
631 {
632  time_t t = cvt_to_time_t( pt->tstamp.sec );
633 
634  return do_str_pcps_hr_date_time( s, max_len, &t );
635 
636 } // mbg_str_pcps_hr_date_time_utc
637 
638 
639 
640 /*HDR*/
656  const PCPS_HR_TIME *pt )
657 {
658  long l = (long) pt->tstamp.sec + pt->utc_offs;
659  time_t t = cvt_to_time_t( l );
660 
661  return do_str_pcps_hr_date_time( s, max_len, &t );
662 
663 } // mbg_str_pcps_hr_date_time_loc
664 
665 
666 
667 /*HDR*/
680  uint32_t frac )
681 {
682  return snprintf_safe( s, max_len, PCPS_HRT_FRAC_SCALE_FMT,
684 
685 } // mbg_str_pcps_hr_time_frac
686 
687 
688 
689 /*HDR*/
704  const PCPS_HR_TIME *pt,
705  const char *info )
706 {
707  int n = snprintf_safe( s, max_len, "%s", info );
708 
709  if ( pt->utc_offs )
710  {
711  ldiv_t ldt = ldiv( labs( pt->utc_offs ) / 60, 60 );
712 
713  n += snprintf_safe( &s[n], max_len - n, "%c%02lu:%02luh",
714  ( pt->utc_offs < 0 ) ? '-' : '+',
715  ldt.quot, ldt.rem );
716  }
717 
718  return n;
719 
720 } // mbg_str_pcps_hr_time_offs
721 
722 
723 
724 /*HDR*/
737  const PCPS_HR_TIME *pt )
738 {
739  int n = mbg_str_pcps_hr_date_time_utc( s, max_len, pt );
740 
741  if ( n < ( max_len - 1 ) )
742  {
743  s[n++] = '.';
744  n += mbg_str_pcps_hr_time_frac( &s[n], max_len - n, pt->tstamp.frac );
745  }
746 
747  return n;
748 
749 } // mbg_str_pcps_hr_tstamp_utc
750 
751 
752 
753 /*HDR*/
766  const PCPS_HR_TIME *pt )
767 {
768  int n = mbg_str_pcps_hr_date_time_loc( s, max_len, pt );
769 
770  if ( n < ( max_len - 1 ) )
771  {
772  s[n++] = '.';
773  n += mbg_str_pcps_hr_time_frac( &s[n], max_len - n, pt->tstamp.frac );
774  }
775 
776  if ( n < ( max_len - 1 ) )
777  {
778  const char *cp = "UTC";
779 
780  if ( pt->status & PCPS_SCALE_TAI )
781  cp = "TAI";
782  else
783  if ( pt->status & PCPS_SCALE_GPS )
784  cp = "GPS";
785 
786  s[n++] = ' ';
787  n += mbg_str_pcps_hr_time_offs( &s[n], max_len - n, pt, cp );
788  }
789 
790  return n;
791 
792 } // mbg_str_pcps_hr_tstamp_loc
793 
794 
795 
796 /*HDR*/
809  const PCPS_TIME_STAMP *pt )
810 {
811  return snprintf_safe( s, max_len, "%08lX.%08lX", (ulong) pt->sec, (ulong) pt->frac );
812 
813 } // mbg_str_pcps_tstamp_raw
814 
815 
816 
817 /*HDR*/
832  const PCPS_HR_TIME *pt )
833 {
834  int n = mbg_str_pcps_tstamp_raw( s, max_len, &pt->tstamp );
835  n += mbg_str_pcps_hr_time_offs( &s[n], max_len - n, pt, ", Loc: " );
836  n += snprintf_safe( &s[n], max_len - n, ", st: 0x%04X", pt->status );
837 
838  return n;
839 
840 } // mbg_str_pcps_hr_time_raw
841 
842 
843 
844 /*HDR*/
856 _MBG_API_ATTR int _MBG_API mbg_str_ucap( char *s, int max_len,
857  const PCPS_HR_TIME *pt )
858 {
859  int n = snprintf_safe( s, max_len, "CAP%u: ", pt->signal );
860  n += mbg_str_pcps_hr_tstamp_loc( &s[n], max_len - n, pt );
861 
862  return n;
863 
864 } // mbg_str_ucap
865 
866 
867 
868 /*HDR*/
881 _MBG_API_ATTR int _MBG_API mbg_str_pos_dms( char *s, int max_len,
882  const DMS *pdms, int prec )
883 {
884  return snprintf_safe( s, max_len, "%c %i" DEG "%02i'%02.*f\"",
885  pdms->prefix, pdms->deg, pdms->min,
886  prec, pdms->sec );
887 
888 } // mbg_str_pos_dms
889 
890 
891 
892 /*HDR*/
904 _MBG_API_ATTR int _MBG_API mbg_str_pos_alt( char *s, int max_len, double alt )
905 {
906  return snprintf_safe( s, max_len, "%.0fm", alt );
907 
908 } // mbg_str_pos_alt
909 
910 
911 
912 /*HDR*/
925 _MBG_API_ATTR int _MBG_API mbg_str_pos( char *s, int max_len,
926  const POS *ppos, int prec )
927 {
928  int n;
929 
930  if ( ppos->lla[LON] || ppos->lla[LAT] || ppos->lla[ALT] )
931  {
932  n = mbg_str_pos_dms( s, max_len, &ppos->latitude, prec );
933  n += mbg_strchar( &s[n], max_len - n, ',', 1 );
934  n += mbg_strchar( &s[n], max_len - n, ' ', mbg_pos_dist );
935  n += mbg_str_pos_dms( &s[n], max_len - n, &ppos->longitude, prec );
936  n += mbg_strchar( &s[n], max_len - n, ',', 1 );
937  n += mbg_strchar( &s[n], max_len - n, ' ', mbg_pos_dist );
938  n += mbg_str_pos_alt( &s[n], max_len - n, ppos->lla[ALT] );
939  }
940  else
941  n = mbg_strncpy( s, max_len, str_not_avail );
942 
943  return n;
944 
945 } // mbg_str_pos
946 
947 
948 
949 /*HDR*/
963 _MBG_API_ATTR int _MBG_API mbg_str_dev_name( char *s, int max_len, const char *short_name,
964  uint16_t fw_rev_num, PCI_ASIC_VERSION asic_ver_num )
965 {
966  MBG_DEV_NAME dev_name = { 0 };
967  PCPS_SN_STR sernum = { 0 };
968  unsigned int i = 0;
969  size_t n = 0;
970  size_t l = strlen( short_name );
971 
972  if ( l > 0 )
973  {
974  // For a serial port string specifies we just
975  // copy the short_name.
976  if ( device_id_is_serial( short_name ) )
977  {
978  n = sn_cpy_str_safe( s, max_len, short_name );
979  goto out;
980  }
981 
982  // If the short_name has more than sizeof( dev_name ) characters
983  // then we have to reduce the maximum length.
984  // For a bus level device the short_name usually consists of
985  // the model name, followed by an underscore '_', followed
986  // by the serial number, e.g. "PZF180PEX_046411000030".
987  // See ::MBG_DEV_NAME.
988  if ( l > sizeof( dev_name ) )
989  l = sizeof( dev_name );
990 
991  for ( i = 0; i < l; i++ )
992  {
993  if ( short_name[i] == '_' )
994  {
995  i++;
996  break;
997  }
998 
999  dev_name[i] = short_name[i];
1000  }
1001 
1002  strncpy_safe( sernum, &short_name[i], sizeof( sernum ) );
1003 
1004  //### TODO
1005  // Legal serial numbers have MBG_GRP_SERNUM_LEN characters, which is
1006  // less than the maximum length of a PCPS_SN_STR type string.
1007  // Do we really have to check and truncate the PCPS_SN_STR sernum?
1008  if ( sernum[MBG_GRP_SERNUM_LEN] == ' ' )
1009  sernum[MBG_GRP_SERNUM_LEN] = '\0';
1010  }
1011 
1012  n = snprintf_safe( s, max_len, "%s, S/N %s", dev_name, sernum );
1013 
1014  if ( fw_rev_num || asic_ver_num )
1015  n += sn_cpy_str_safe( &s[n], max_len - n, " (" );
1016 
1017  if ( fw_rev_num )
1018  {
1019  n += snprintf_safe( &s[n], max_len - n, "FW v" PCPS_FW_STR_FMT,
1020  _pcps_fw_rev_num_major( fw_rev_num ),
1021  _pcps_fw_rev_num_minor( fw_rev_num ) );
1022  // Append a separator if ASIC version will follow.
1023  if ( asic_ver_num )
1024  n += sn_cpy_str_safe( &s[n], max_len - n, " / " );
1025  }
1026 
1027  if ( asic_ver_num )
1028  {
1029  asic_ver_num = _convert_asic_version_number( asic_ver_num ); // TODO Do we need this?
1030 
1031  n += snprintf_safe( &s[n], max_len - n, "ASIC v" PCPS_ASIC_STR_FMT,
1032  _pcps_asic_version_major( asic_ver_num ),
1033  _pcps_asic_version_minor( asic_ver_num ) );
1034  }
1035 
1036  if ( fw_rev_num || asic_ver_num )
1037  n += sn_cpy_str_safe( &s[n], max_len - n, ")" );
1038 
1039 out:
1040  return _int_from_size_t( n );
1041 
1042 } // mbg_str_dev_name
1043 
1044 
1045 
1046 
1047 #if defined( MBG_TGT_WIN32 )
1048 
1049 BOOL APIENTRY DllMain( HANDLE hModule,
1050  DWORD ul_reason_for_call,
1051  LPVOID lpReserved )
1052 {
1053  return TRUE;
1054 }
1055 
1056 #endif // defined( MBG_TGT_WIN32 )
1057 
1058 
1059 
DMS longitude
Longitude broken down to degrees, minutes, seconds.
Definition: mbggeo.h:117
#define PCPS_HRT_FRAC_SCALE
Scale to be used to print PCPS_TIME_STAMP::frac values.
Definition: pcpsdefs.h:996
int mbg_str_tm_gps_date_time(char *s, int max_len, const TM_GPS *pt)
Write a full date and time string to a string buffer.
Definition: mbgutil.c:375
uint8_t year
year of the century, 0..99
Definition: pcpsdefs.h:1138
time stamp is GPS scale
Definition: pcpsdefs.h:1275
#define _pcps_fw_rev_num_minor(_v)
Definition: pcpsdev.h:1486
#define _pcps_fw_rev_num_major(_v)
Definition: pcpsdev.h:1483
int mbgutil_check_version(int header_version)
Check if the DLL/shared library is compatible with a given version.
Definition: mbgutil.c:128
static char * dev_name
Definition: mbgctrl.c:131
char * strncpy_safe(char *dst, const char *src, size_t max_len)
A portable, safe implementation of strncpy()
Definition: str_util.c:247
uint8_t mday
day of month, 0..31
Definition: pcpsdefs.h:1135
uint8_t sec100
hundredths of seconds, 0..99, 10 ms resolution
Definition: pcpsdefs.h:1130
#define _pcps_asic_version_major(_v)
Extract the major part of an ASIC version number.
Definition: pci_asic.h:339
#define DEG
Definition: charcode.h:197
int mbg_snprintf(char *s, size_t max_len, const char *fmt,...)
A portable, safer implementation of snprintf().
Definition: mbgutil.c:157
Local date and time computed from GPS time.
Definition: gpsdefs.h:2593
int mbg_str_ucap(char *s, int max_len, const PCPS_HR_TIME *pt)
Write time capture / user capture time stamp to a string buffer.
Definition: mbgutil.c:856
unsigned short uint16_t
Definition: words.h:213
PCPS_SECONDS sec
seconds since 1970, usually UTC scale
Definition: pcpsdefs.h:974
int8_t sec
seconds, 0..59, or 60 in case of inserted leap second
Definition: gpsdefs.h:2602
static int mbg_pos_dist
Definition: mbgutil.c:80
#define _int_from_size_t(_n)
Definition: words.h:662
int mbg_strchar(char *s, size_t max_len, char c, size_t n)
Write a character multiple times to a string buffer.
Definition: mbgutil.c:205
int mbg_str_pos(char *s, int max_len, const POS *ppos, int prec)
Write geographic coordinates to a string buffer.
Definition: mbgutil.c:925
int sn_cpy_str_safe(char *dst, size_t max_len, const char *src)
A function to copy a string safely, returning the number of characters copied.
Definition: str_util.c:276
#define mbg_rc_is_success(_rc)
Definition: mbgerror.h:618
DMS latitude
Latitude broken down to degrees, minutes, seconds.
Definition: mbggeo.h:118
static __mbg_inline bool device_id_is_serial(const char *dev_id)
Check if a device ID refers to a serial port.
Definition: cfg_hlp.h:1055
int8_t mday
day of month, 1..31
Definition: gpsdefs.h:2597
#define PCPS_ASIC_STR_FMT
Definition: pci_asic.h:334
int16_t year
year number, 0..9999
Definition: gpsdefs.h:2595
int mbg_str_time(char *s, int max_len, int hour, int min, int sec)
Write a time string "hh:mm:ss" to a string buffer.
Definition: mbgutil.c:320
int8_t hour
hours, 0..23
Definition: gpsdefs.h:2600
#define PCPS_HRT_FRAC_SCALE_FMT
Format specifier used to print PCPS_TIME_STAMP::frac values.
Definition: pcpsdefs.h:1008
int8_t min
minutes, 0..59
Definition: gpsdefs.h:2601
#define _MBG_API_ATTR
Definition: mbg_tgt.h:1024
int mbg_str_pos_dms(char *s, int max_len, const DMS *pdms, int prec)
Write a geographic coordinate in degrees - minutes - seconds to a string buffer.
Definition: mbgutil.c:881
int32_t utc_offs
UTC offs [sec] (loc_time = tstamp + utc_offs)
Definition: pcpsdefs.h:1088
Definition: gpsdefs.h:2754
static __mbg_inline time_t cvt_to_time_t(mbg_time_t t)
Definition: timeutil.h:108
PCPS_TIME_STATUS_X status
status bits, see PCPS_TIME_STATUS_FLAGS
Definition: pcpsdefs.h:1089
Geographic longitude or latitude in [degrees, minutes, seconds].
Definition: mbggeo.h:90
int mbg_str_pcps_hr_date_time_loc(char *s, int max_len, const PCPS_HR_TIME *pt)
Write local date and time given as PCPS_HR_TIME structure to a string buffer.
Definition: mbgutil.c:655
#define MBG_ERR_LIB_NOT_COMPATIBLE
Installed shared library version not compatible with version used at build time.
Definition: mbgerror.h:290
int mbg_str_dev_name(char *s, int max_len, const char *short_name, uint16_t fw_rev_num, PCI_ASIC_VERSION asic_ver_num)
Write device info to a string buffer.
Definition: mbgutil.c:963
int mbg_str_pcps_hr_time_frac(char *s, int max_len, uint32_t frac)
Print binary PCPS_FRAC_32 fractions in decimal to a string buffer.
Definition: mbgutil.c:679
uint16_t prefix
&#39;N&#39;, &#39;E&#39;, &#39;S&#39; or &#39;W&#39;
Definition: mbggeo.h:92
uint16_t deg
[0...90 (lat) or 0...180 (lon)]
Definition: mbggeo.h:93
PCPS_FRAC_32 frac
binary fractions of second, see PCPS_FRAC_32
Definition: pcpsdefs.h:975
char PCPS_SN_STR[(16+1)]
A buffer for a serial number string, including terminating 0.
Definition: pcpsdefs.h:925
PCPS_TIME_STAMP tstamp
High resolution time stamp (UTC)
Definition: pcpsdefs.h:1087
#define MBG_GRP_SERNUM_LEN
Definition: qsdefs.h:41
const char * str_not_avail
int vsnprintf_safe(char *s, size_t max_len, const char *fmt, va_list args)
A portable, safe implementation of vsnprintf()
Definition: str_util.c:121
int mbg_str_pcps_hr_tstamp_loc(char *s, int max_len, const PCPS_HR_TIME *pt)
Write a high resolution local time stamp including fractions to a string buffer.
Definition: mbgutil.c:765
unsigned char uint8_t
Definition: words.h:210
int mbg_str_pcps_hr_date_time_utc(char *s, int max_len, const PCPS_HR_TIME *pt)
Write UTC date and time given as PCPS_HR_TIME structure to a string buffer.
Definition: mbgutil.c:629
char MBG_DEV_NAME[10+(16+1)+1]
A string buffer for a unique device ID.
Definition: pcpsdev.h:1524
int mbg_str_date(char *s, int max_len, int mday, int month, int year)
Write a date string "dd.mm.yyyy" to a string buffer.
Definition: mbgutil.c:268
int mbg_str_pos_alt(char *s, int max_len, double alt)
Write a position&#39;s altitude parameter to a string buffer.
Definition: mbgutil.c:904
int mbg_str_time_long(char *s, int max_len, int hour, int min, int sec, int sec100)
Write a long time string "hh:mm:ss.cc" to a string buffer.
Definition: mbgutil.c:348
int mbg_str_pcps_hr_time(char *s, int max_len, uint32_t sec)
Write time derived from seconds-since-epoch to a string buffer.
Definition: mbgutil.c:563
#define MBG_SUCCESS
Error codes used with Meinberg devices and drivers.
Definition: mbgerror.h:259
int mbgutil_get_version(void)
Get the version number of the precompiled DLL/shared object library.
Definition: mbgutil.c:102
static __mbg_inline int mbg_gmtime(struct tm *p_tm, const time_t *p_time)
Definition: timeutil.h:118
uint8_t hour
hours, 0..23
Definition: pcpsdefs.h:1133
A geographic position represented in different formats.
Definition: mbggeo.h:113
uint32_t DWORD
Definition: mbgerror.h:222
int mbg_str_pcps_hr_time_raw(char *s, int max_len, const PCPS_HR_TIME *pt)
Write a raw high resolution time stamp plus converted local time to a string buffer.
Definition: mbgutil.c:831
int mbg_str_pcps_hr_tstamp_utc(char *s, int max_len, const PCPS_HR_TIME *pt)
Write a high resolution UTC time stamp including fractions to a string buffer.
Definition: mbgutil.c:736
static __mbg_inline int pcps_exp_year(int year, int year_lim)
Expand a 2-digit year number to a 4-digit year number.
Definition: pcpsutil.h:113
static __mbg_inline uint32_t bin_frac_32_to_dec_frac(uint32_t bin, uint32_t scale)
Convert a 32 bit binary fraction to a scaled decimal.
Definition: mbgtime.h:439
static const char str_inv_cnv[]
Definition: mbgutil.c:83
High resolution time including status and local time offset.
Definition: pcpsdefs.h:1085
int mbg_str_date_short(char *s, int max_len, int mday, int month)
Write a short date string "dd.mm." to a string buffer.
Definition: mbgutil.c:243
int mbg_str_pcps_date(char *s, int max_len, const PCPS_TIME *pt)
Write the date given as PCPS_TIME structure to a string buffer.
Definition: mbgutil.c:421
#define MBGUTIL_VERSION
Definition: mbgutil.h:78
static int mbg_date_time_dist
Definition: mbgutil.c:78
int mbg_str_pcps_date_time(char *s, int max_len, const PCPS_TIME *pt, const char *tz_str)
Write date and time given as PCPS_TIME structure to a string buffer.
Definition: mbgutil.c:509
uint32_t PCI_ASIC_VERSION
A data type to hold the PCI ASIC version code.
Definition: pci_asic.h:151
PCPS_SIG_VAL signal
signal strength, see PCPS_SIG_VAL_DEFS, or capture input channel number
Definition: pcpsdefs.h:1090
Local calendar date and time, plus sync status.
Definition: pcpsdefs.h:1128
uint16_t min
[0...59]
Definition: mbggeo.h:94
LLA lla
Longitude, latitude and altitude, depending on the ellipsoid used for reference.
Definition: mbggeo.h:116
time stamp is TAI scale
Definition: pcpsdefs.h:1276
A high resolution time stamp.
Definition: pcpsdefs.h:972
int mbg_str_time_short(char *s, int max_len, int hour, int min)
Write a short time string "hh:mm" to a string buffer.
Definition: mbgutil.c:297
int mbg_str_pcps_time(char *s, int max_len, const PCPS_TIME *pt)
Write the time given as PCPS_TIME structure to a string buffer.
Definition: mbgutil.c:463
int snprintf_safe(char *s, size_t max_len, const char *fmt,...)
A portable, safe implementation of snprintf()
Definition: str_util.c:156
#define _MBG_API
Definition: mbg_tgt.h:1020
#define _pcps_asic_version_minor(_v)
Extract the minor part of an ASIC version number.
Definition: pci_asic.h:346
int mbg_str_pcps_hr_date(char *s, int max_len, uint32_t sec)
Write date derived from seconds-since-epoch to a string buffer.
Definition: mbgutil.c:536
double sec
[0...59.99999...]
Definition: mbggeo.h:95
static uint16_t mbg_year_lim
Definition: mbgutil.c:82
uint8_t min
minutes, 0..59
Definition: pcpsdefs.h:1132
#define _convert_asic_version_number(_n)
Version number conversion macro.
Definition: pci_asic.h:329
int mbg_strncpy(char *s, size_t max_len, const char *src)
A portable, safe implementation of strncpy()
Definition: mbgutil.c:184
int8_t month
month, 1..12
Definition: gpsdefs.h:2596
unsigned long ulong
Definition: words.h:292
static int do_str_pcps_hr_date_time(char *s, int max_len, const time_t *p_t)
Definition: mbgutil.c:593
int mbg_str_pcps_time_short(char *s, int max_len, const PCPS_TIME *pt)
Write the short time given as PCPS_TIME structure to a string buffer.
Definition: mbgutil.c:442
#define PCPS_FW_STR_FMT
Definition: pcpsdev.h:1481
Definition: gpsdefs.h:2754
int mbg_str_pcps_hr_time_offs(char *s, int max_len, const PCPS_HR_TIME *pt, const char *info)
Print the UTC offset from a PCPS_HR_TIME structure to a string buffer.
Definition: mbgutil.c:703
uint8_t month
month, 1..12
Definition: pcpsdefs.h:1137
int mbg_str_pcps_date_short(char *s, int max_len, const PCPS_TIME *pt)
Write the short date given as PCPS_TIME structure to a string buffer.
Definition: mbgutil.c:400
int mbg_str_pcps_tstamp_raw(char *s, int max_len, const PCPS_TIME_STAMP *pt)
Write a raw high resolution time stamp to a string buffer.
Definition: mbgutil.c:808
uint8_t sec
seconds, 0..59, or 60 if leap second
Definition: pcpsdefs.h:1131
int mbg_str_pcps_time_long(char *s, int max_len, const PCPS_TIME *pt)
Write the time including sec100ths given as PCPS_TIME structure to a string buffer.
Definition: mbgutil.c:484
Definition: gpsdefs.h:2754
#define MBGUTIL_COMPAT_VERSION
Definition: mbgutil.h:80