navdata.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * =====================================================================================
  3. *
  4. * Filename: navdata.c
  5. *
  6. * Description: Nav data source file
  7. *
  8. * Version: 1.0
  9. * Created: 2018/8/15 17:31:22
  10. * Revision: none
  11. * Compiler: gcc
  12. *
  13. * Author: Jarod Lee
  14. * Organization:
  15. *
  16. * =====================================================================================
  17. */
  18. #include <stdlib.h>
  19. #include <string.h>
  20. #include <stdio.h>
  21. #include "navdata.h"
  22. #define PRN_PLUS_GLN 64
  23. #define PRN_PLUS_BDS 200
  24. /*
  25. * PRN and SVID
  26. * PRN is the satellite's NO. in NMEA protocol.
  27. * SVID is the satellite's id in all constellations.
  28. * 1-64: GPS
  29. * 65-96: GLNONASS
  30. * 201-264: Beidou
  31. */
  32. /*
  33. * Convert prn and constell to svid
  34. * @prn: prn of the satellite
  35. * @constell: constellation type
  36. * @return: svid of the satellite
  37. */
  38. int prn2svid(int prn, int constell)
  39. {
  40. switch (constell) {
  41. case CONSTELL_TYPE_GPS:
  42. break;
  43. case CONSTELL_TYPE_GLN:
  44. if (prn > 0 && prn < 33)
  45. prn += PRN_PLUS_GLN;
  46. break;
  47. case CONSTELL_TYPE_BDS:
  48. if (prn > 0 && prn < 65)
  49. prn += PRN_PLUS_BDS;
  50. break;
  51. default:
  52. break;
  53. }
  54. return prn;
  55. }
  56. /*
  57. * Tell the constellation type of a SVID
  58. * @sivd: the SVID
  59. * @return: the constellationtype
  60. */
  61. int tell_constell(int svid)
  62. {
  63. if (svid > 0 && svid < 65) {
  64. return CONSTELL_TYPE_GPS;
  65. }
  66. else if (svid > 64 && svid < 97) {
  67. return CONSTELL_TYPE_GLN;
  68. }
  69. else if (svid > 200 && svid < 265) {
  70. return CONSTELL_TYPE_BDS;
  71. }
  72. return CONSTELL_TYPE_UNKNOWN;
  73. }
  74. /*
  75. * Get constellation's name string
  76. * @constell: constellation type
  77. * @return: the name string
  78. */
  79. const char *constell_name(int constell)
  80. {
  81. switch(constell) {
  82. case CONSTELL_TYPE_GPS:
  83. return "GPS";
  84. case CONSTELL_TYPE_GLN:
  85. return "GLN";
  86. case CONSTELL_TYPE_BDS:
  87. return "BDS";
  88. default:
  89. return "UNKNOWN";
  90. }
  91. }
  92. /*
  93. * Init navigation data to 0
  94. * @navdata: the navigation data
  95. */
  96. void navdata_init(struct nav_data *navdata)
  97. {
  98. memset(navdata, 0, sizeof(struct nav_data));
  99. }