version.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #ifndef _VERSION_H
  2. #define _VERSION_H
  3. // These variables are autogenerated and compiled
  4. // into the library by the version.cmake script
  5. extern "C"
  6. {
  7. extern const char *GIT_TAG;
  8. extern const char *GIT_REV;
  9. extern const char *GIT_BRANCH;
  10. extern const char *BUILD_TIME;
  11. }
  12. #include <string>
  13. #include <string.h>
  14. #include "Helper.h"
  15. #include <fstream>
  16. #include <algorithm>
  17. const char *build_time(void)
  18. {
  19. return BUILD_TIME;
  20. }
  21. const char *libfive_git_version(void)
  22. {
  23. return GIT_TAG;
  24. }
  25. const char *libfive_git_revision(void)
  26. {
  27. return GIT_REV;
  28. }
  29. const char *libfive_git_branch(void)
  30. {
  31. return GIT_BRANCH;
  32. }
  33. std::string getFwVersion(void)
  34. {
  35. std::string buf;
  36. if (std::string(GIT_TAG) == "")
  37. {
  38. // Tag not set, show branch
  39. buf = "Development-Branch: " + std::string(GIT_BRANCH);
  40. }
  41. else
  42. {
  43. // Tag is set, ignore branch
  44. buf = "Release: " + std::string(GIT_TAG);
  45. }
  46. buf = buf + " (Commit: " + std::string(GIT_REV) + ")";
  47. return buf;
  48. }
  49. std::string getHTMLversion(void)
  50. {
  51. char buf[100] = "?\0";
  52. string fn = format_filename("/sdcard/html/version.txt");
  53. FILE *pFile = fopen(fn.c_str(), "r");
  54. if (pFile == NULL)
  55. {
  56. return std::string(buf);
  57. }
  58. fgets(buf, sizeof(buf), pFile); // Line 1: Version
  59. fclose(pFile);
  60. string value = string(buf);
  61. value.erase(std::remove(value.begin(), value.end(), '\n'), value.end()); // Remove any newlines
  62. return value;
  63. }
  64. std::string getHTMLcommit(void)
  65. {
  66. char buf[100] = "?\0";
  67. string fn = format_filename("/sdcard/html/version.txt");
  68. FILE *pFile = fopen(fn.c_str(), "r");
  69. if (pFile == NULL)
  70. {
  71. return std::string(buf);
  72. }
  73. fgets(buf, sizeof(buf), pFile); // Line 1: Version -> ignored
  74. fgets(buf, sizeof(buf), pFile); // Line 2: Commit
  75. fclose(pFile);
  76. string value = string(buf);
  77. value.erase(std::remove(value.begin(), value.end(), '\n'), value.end()); // Remove any newlines
  78. return value;
  79. }
  80. #endif // _VERSION_H