sbgVersion.h
Go to the documentation of this file.
1 
34 #ifndef SBG_VERSION_H
35 #define SBG_VERSION_H
36 
37 //----------------------------------------------------------------------//
38 //- Header (open extern C block) -//
39 //----------------------------------------------------------------------//
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
44 #include <sbgCommon.h>
45 
46 //----------------------------------------------------------------------//
47 //- Version related definitions -//
48 //----------------------------------------------------------------------//
49 #define SBG_VERSION_SOFT_SCHEME (0x00000001u << 31)
51 #define SBG_VERSION_SOFT_SCHEME_QUALIFIER_MASK (0x07)
52 #define SBG_VERSION_SOFT_SCHEME_QUALIFIER_SHIFT (28)
54 #define SBG_VERSION_SOFT_SCHEME_MAJOR_MASK (0x3F)
55 #define SBG_VERSION_SOFT_SCHEME_MAJOR_SHIFT (22)
57 #define SBG_VERSION_SOFT_SCHEME_MINOR_MASK (0x3F)
58 #define SBG_VERSION_SOFT_SCHEME_MINOR_SHIFT (16)
60 #define SBG_VERSION_SOFT_SCHEME_BUILD_MASK (0xFFFF)
61 #define SBG_VERSION_SOFT_SCHEME_BUILD_SHIFT (0)
68 typedef enum _SbgVersionQualifier
69 {
77 
84 {
91 
96 typedef struct _SbgVersion
97 {
100  uint8_t major;
101  uint8_t minor;
102  uint8_t rev;
103  uint16_t build;
104 } SbgVersion;
105 
106 //----------------------------------------------------------------------//
107 //- Macro definitions for encode versions -//
108 //----------------------------------------------------------------------//
109 
118 #define SBG_VERSION_BASIC(major, minor, rev, build) ( (((uint32_t)(major)) << 24) | \
119  (((uint32_t)(minor)) << 16) | \
120  (((uint32_t)(rev)) << 8) | \
121  (((uint32_t)(build))) )
122 
131 #define SBG_VERSION_SOFTWARE(major, minor, build, qualifier) ( SBG_VERSION_SOFT_SCHEME | \
132  ((((uint32_t)(qualifier)) & SBG_VERSION_SOFT_SCHEME_QUALIFIER_MASK) << SBG_VERSION_SOFT_SCHEME_QUALIFIER_SHIFT) | \
133  ((((uint32_t)(major)) & SBG_VERSION_SOFT_SCHEME_MAJOR_MASK) << SBG_VERSION_SOFT_SCHEME_MAJOR_SHIFT) | \
134  ((((uint32_t)(minor)) & SBG_VERSION_SOFT_SCHEME_MINOR_MASK) << SBG_VERSION_SOFT_SCHEME_MINOR_SHIFT) | \
135  ((((uint32_t)(build)) & SBG_VERSION_SOFT_SCHEME_BUILD_MASK) << SBG_VERSION_SOFT_SCHEME_BUILD_SHIFT) )
136 
137 //----------------------------------------------------------------------//
138 //- Version encoding / decoding methods -//
139 //----------------------------------------------------------------------//
140 
146 SBG_COMMON_LIB_API void sbgVersionDecode(uint32_t encodedVersion, SbgVersion *pVersionInfo);
147 
153 SBG_COMMON_LIB_API uint32_t sbgVersionEncode(const SbgVersion *pVersionInfo);
154 
155 //----------------------------------------------------------------------//
156 //- Version parameters methods -//
157 //----------------------------------------------------------------------//
158 
164 SBG_INLINE bool sbgVersionIsUsingSoftwareScheme(uint32_t encodedVersion)
165 {
166  SbgVersion decodedVersion;
167 
168  //
169  // Decode the version first
170  //
171  sbgVersionDecode(encodedVersion, &decodedVersion);
172 
173  //
174  // Returns if the version is using a software scheme
175  //
176  return decodedVersion.softwareScheme;
177 }
178 
179 //----------------------------------------------------------------------//
180 //- Version comparaison methods -//
181 //----------------------------------------------------------------------//
182 
193 SBG_COMMON_LIB_API int32_t sbgVersionCompare(const SbgVersion *pVersionA, const SbgVersion *pVersionB, SbgVersionCmpThresold thresold);
194 
205 SBG_COMMON_LIB_API int32_t sbgVersionCompareEncoded(uint32_t versionA, uint32_t versionB, SbgVersionCmpThresold thresold);
206 
218 SBG_COMMON_LIB_API int32_t sbgVersionIsWithinRange(const SbgVersion *pLowerVersion, const SbgVersion *pHigherVersion, const SbgVersion *pVersion);
219 
231 SBG_COMMON_LIB_API int32_t sbgVersionIsWithinRangeEncoded(uint32_t lowerVersion, uint32_t higherVersion, uint32_t version);
232 
233 
234 //----------------------------------------------------------------------//
235 //- Version to string methods -//
236 //----------------------------------------------------------------------//
237 
246 SBG_COMMON_LIB_API SbgErrorCode sbgVersionToString(const SbgVersion *pVersionInfo, char *pBuffer, uint32_t sizeOfBuffer);
247 
256 SBG_COMMON_LIB_API SbgErrorCode sbgVersionToStringEncoded(uint32_t version, char *pBuffer, uint32_t sizeOfBuffer);
257 
258 //----------------------------------------------------------------------//
259 //- String to version methods -//
260 //----------------------------------------------------------------------//
261 
268 SBG_COMMON_LIB_API SbgErrorCode sbgVersionFromString(const char *pVersionStr, SbgVersion *pVersionInfo);
269 
276 SBG_COMMON_LIB_API SbgErrorCode sbgVersionFromStringEncoded(const char *pVersionStr, uint32_t *pVersion);
277 
278 //----------------------------------------------------------------------//
279 //- Legacy version system methods -//
280 //----------------------------------------------------------------------//
281 
285 SBG_DEPRECATED(SBG_INLINE uint32_t SBG_VERSION(uint8_t major, uint8_t minor, uint8_t rev, uint8_t build));
286 SBG_DEPRECATED(SBG_INLINE uint8_t SBG_VERSION_GET_MAJOR(uint32_t encodedVersion));
287 SBG_DEPRECATED(SBG_INLINE uint8_t SBG_VERSION_GET_MINOR(uint32_t encodedVersion));
288 SBG_DEPRECATED(SBG_INLINE uint8_t SBG_VERSION_GET_REV(uint32_t encodedVersion));
289 SBG_DEPRECATED(SBG_INLINE uint8_t SBG_VERSION_GET_BUILD(uint32_t encodedVersion));
290 
300 SBG_INLINE uint32_t SBG_VERSION(uint8_t major, uint8_t minor, uint8_t rev, uint8_t build)
301 {
302  //
303  // The SBG_VERSION macro is the basic version scheme.
304  //
305  return SBG_VERSION_BASIC(major, minor, rev, build);
306 }
307 
314 SBG_INLINE uint8_t SBG_VERSION_GET_MAJOR(uint32_t encodedVersion)
315 {
316  SbgVersion versionInfo;
317 
318  //
319  // Decode the version information
320  //
321  sbgVersionDecode(encodedVersion, &versionInfo);
322 
323  //
324  // Return the major version
325  //
326  return versionInfo.major;
327 }
328 
335 SBG_INLINE uint8_t SBG_VERSION_GET_MINOR(uint32_t encodedVersion)
336 {
337  SbgVersion versionInfo;
338 
339  //
340  // Decode the version information
341  //
342  sbgVersionDecode(encodedVersion, &versionInfo);
343 
344  //
345  // Return the major version
346  //
347  return versionInfo.minor;
348 }
349 
356 SBG_INLINE uint8_t SBG_VERSION_GET_REV(uint32_t encodedVersion)
357 {
358  SbgVersion versionInfo;
359 
360  //
361  // Decode the version information
362  //
363  sbgVersionDecode(encodedVersion, &versionInfo);
364 
365  //
366  // Return the major version
367  //
368  return versionInfo.rev;
369 }
370 
377 SBG_INLINE uint8_t SBG_VERSION_GET_BUILD(uint32_t encodedVersion)
378 {
379  SbgVersion versionInfo;
380 
381  //
382  // Decode the version information
383  //
384  sbgVersionDecode(encodedVersion, &versionInfo);
385 
386  //
387  // Return the major version
388  //
389  return (uint8_t)versionInfo.build;
390 }
391 
392 //----------------------------------------------------------------------//
393 //- Footer (close extern C block) -//
394 //----------------------------------------------------------------------//
395 #ifdef __cplusplus
396 }
397 #endif
398 
399 #endif /* SBG_VERSION_H */
struct _SbgVersion SbgVersion
#define SBG_COMMON_LIB_API
Definition: sbgDefines.h:58
SBG_COMMON_LIB_API SbgErrorCode sbgVersionFromString(const char *pVersionStr, SbgVersion *pVersionInfo)
Definition: sbgVersion.c:439
_SbgVersionCmpThresold
Definition: sbgVersion.h:83
SBG_INLINE bool sbgVersionIsUsingSoftwareScheme(uint32_t encodedVersion)
Definition: sbgVersion.h:164
SBG_INLINE uint8_t SBG_VERSION_GET_MAJOR(uint32_t encodedVersion)
Definition: sbgVersion.h:314
SBG_COMMON_LIB_API SbgErrorCode sbgVersionToStringEncoded(uint32_t version, char *pBuffer, uint32_t sizeOfBuffer)
Definition: sbgVersion.c:414
SBG_COMMON_LIB_API int32_t sbgVersionCompareEncoded(uint32_t versionA, uint32_t versionB, SbgVersionCmpThresold thresold)
Definition: sbgVersion.c:226
SBG_COMMON_LIB_API SbgErrorCode sbgVersionFromStringEncoded(const char *pVersionStr, uint32_t *pVersion)
Definition: sbgVersion.c:560
enum _SbgVersionCmpThresold SbgVersionCmpThresold
SBG_COMMON_LIB_API int32_t sbgVersionIsWithinRange(const SbgVersion *pLowerVersion, const SbgVersion *pHigherVersion, const SbgVersion *pVersion)
Definition: sbgVersion.c:254
uint8_t major
Definition: sbgVersion.h:100
SBG_COMMON_LIB_API int32_t sbgVersionCompare(const SbgVersion *pVersionA, const SbgVersion *pVersionB, SbgVersionCmpThresold thresold)
Definition: sbgVersion.c:123
bool softwareScheme
Definition: sbgVersion.h:98
SBG_INLINE uint8_t SBG_VERSION_GET_REV(uint32_t encodedVersion)
Definition: sbgVersion.h:356
uint16_t build
Definition: sbgVersion.h:103
SBG_DEPRECATED(SBG_INLINE uint32_t SBG_VERSION(uint8_t major, uint8_t minor, uint8_t rev, uint8_t build))
enum _SbgVersionQualifier SbgVersionQualifier
#define SBG_INLINE
Definition: sbgDefines.h:186
Main header file for SBG Systems common C library.
SBG_COMMON_LIB_API int32_t sbgVersionIsWithinRangeEncoded(uint32_t lowerVersion, uint32_t higherVersion, uint32_t version)
Definition: sbgVersion.c:277
SBG_COMMON_LIB_API SbgErrorCode sbgVersionToString(const SbgVersion *pVersionInfo, char *pBuffer, uint32_t sizeOfBuffer)
Definition: sbgVersion.c:317
SBG_COMMON_LIB_API void sbgVersionDecode(uint32_t encodedVersion, SbgVersion *pVersionInfo)
Definition: sbgVersion.c:12
SBG_INLINE uint8_t SBG_VERSION_GET_MINOR(uint32_t encodedVersion)
Definition: sbgVersion.h:335
SBG_COMMON_LIB_API uint32_t sbgVersionEncode(const SbgVersion *pVersionInfo)
Definition: sbgVersion.c:69
uint8_t rev
Definition: sbgVersion.h:102
uint8_t minor
Definition: sbgVersion.h:101
SBG_INLINE uint32_t SBG_VERSION(uint8_t major, uint8_t minor, uint8_t rev, uint8_t build)
Definition: sbgVersion.h:300
enum _SbgErrorCode SbgErrorCode
#define SBG_VERSION_BASIC(major, minor, rev, build)
Definition: sbgVersion.h:118
SbgVersionQualifier qualifier
Definition: sbgVersion.h:99
SBG_INLINE uint8_t SBG_VERSION_GET_BUILD(uint32_t encodedVersion)
Definition: sbgVersion.h:377


sbg_driver
Author(s): SBG Systems
autogenerated on Sat Sep 3 2022 02:53:36