ISUtilities.h
Go to the documentation of this file.
1 /*
2 MIT LICENSE
3 
4 Copyright (c) 2014-2021 Inertial Sense, Inc. - http://inertialsense.com
5 
6 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions :
7 
8 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9 
10 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11 */
12 
13 #ifndef IS_UTILITIES_H
14 #define IS_UTILITIES_H
15 
16 #include <stdlib.h>
17 #include <inttypes.h>
18 #include <stdio.h>
19 #include "data_sets.h"
20 
21 // C++ API
22 #ifdef __cplusplus
23 
24 #include <string>
25 #include <vector>
26 
27 using namespace std;
28 
35 string base64Encode(const unsigned char* bytes_to_encode, unsigned int in_len);
36 
42 string base64Decode(const string& encoded_string);
43 
51 size_t splitString(const string& s, const string& delimiter, vector<string>& result);
52 
56 class cMutex
57 {
58 public:
62  cMutex();
63 
67  virtual ~cMutex();
68 
72  void Lock();
73 
77  void Unlock();
78 
79 private:
80  void* m_handle;
81 };
82 
86 class cMutexLocker
87 {
88 public:
93  cMutexLocker(cMutex* mutex);
94 
98  virtual ~cMutexLocker();
99 
100 private:
101  cMutex* m_mutex;
102 };
103 
104 #endif
105 
106 // C API...
107 #ifdef __cplusplus
108 extern "C" {
109 #endif
110 
111 #if PLATFORM_IS_WINDOWS
112 
113 void usleep(__int64 usec);
114 
115 #define DEFAULT_COM_PORT "COM4"
116 
117 #ifndef SLEEP_MS
118 #define SLEEP_MS(milliseconds) Sleep(milliseconds);
119 #endif
120 
121 #ifndef SLEEP_US
122 #define SLEEP_US(timeUs) usleep(timeUs);
123 #endif
124 
125 #else // LINUX
126 
127 #include <unistd.h>
128 #include <sys/time.h>
129 #include <stdarg.h>
130 
131 #define DEFAULT_COM_PORT "/dev/ttyUSB0"
132 
133 #ifndef SLEEP_MS
134 #define SLEEP_MS(timeMs) usleep(timeMs * 1000);
135 #endif
136 
137 #ifndef SLEEP_US
138 #define SLEEP_US(timeUs) usleep(timeUs);
139 #endif
140 
141 #endif
142 
143 int current_timeSec();
144 int current_timeMs();
145 uint64_t current_timeUs();
146 
147 uint64_t timerUsStart();
148 uint64_t timerUsEnd(uint64_t start);
149 uint64_t timerRawStart();
150 uint64_t timerRawEnd(uint64_t start);
151 
152 uint64_t getTickCount(void);
153 
154 int bootloadUploadProgress(const void* port, float percent);
155 int bootloadVerifyProgress(const void* port, float percent);
156 void bootloadStatusInfo(const void* port, const char* str);
157 float step_sinwave(float *sig_gen, float freqHz, float amplitude, float periodSec);
158 
159 FILE* openFile(const char* path, const char* mode);
160 const char* tempPath(); // ends with dir separator
161 
166 const unsigned char* getHexLookupTable();
167 
173 uint8_t getHexValue(unsigned char hex);
174 
181 void* threadCreateAndStart(void(*function)(void* info), void* info);
182 
187 void threadJoinAndFree(void* handle);
188 
189 /*
190 * Create a mutex which allows exclusive access to a shared resource
191 * @return the mutex handle
192 */
193 void* mutexCreate(void);
194 
199 void mutexLock(void* handle);
200 
205 void mutexUnlock(void* handle);
206 
211 void mutexFree(void* handle);
212 
213 // taken from http://www.leapsecond.com/tools/gpsdate.c, uses UTC time
214 int32_t convertDateToMjd(int32_t year, int32_t month, int32_t day);
215 int32_t convertGpsToMjd(int32_t gpsWeek, int32_t gpsSeconds);
216 void convertMjdToDate(int32_t mjd, int32_t* year, int32_t* month, int32_t* day);
217 void convertGpsToHMS(int32_t gpsSeconds, int32_t* hour, int32_t* minutes, int32_t* seconds);
218 uint32_t dateToWeekDay(uint32_t ul_year, uint32_t ul_month, uint32_t ul_day);
219 
220 gen_1axis_sensor_t gen1AxisSensorData(double time, const float val);
221 gen_3axis_sensor_t gen3AxisSensorData(double time, const float val[3]);
222 gen_dual_3axis_sensor_t genDual3AxisSensorData(double time, const float val1[3], const float val2[3]);
223 gen_3axis_sensord_t gen3AxisSensorDataD(double time, const double val[3]);
224 
225 #ifdef __cplusplus
226 } // extern C
227 #endif
228 
229 #endif // IS_UTILITIES_H
int current_timeMs()
void * mutexCreate(void)
int bootloadVerifyProgress(const void *port, float percent)
uint64_t timerRawEnd(uint64_t start)
const char * tempPath()
uint32_t dateToWeekDay(uint32_t ul_year, uint32_t ul_month, uint32_t ul_day)
uint64_t getTickCount(void)
uint64_t timerUsStart()
size_t splitString(const string &s, const string &delimiter, vector< string > &result)
int bootloadUploadProgress(const void *port, float percent)
float step_sinwave(float *sig_gen, float freqHz, float amplitude, float periodSec)
Initialize signal generator.
Definition: sig_gen.cpp:20
void bootloadStatusInfo(const void *port, const char *str)
const unsigned char * getHexLookupTable()
string base64Encode(const unsigned char *bytes_to_encode, unsigned int in_len)
Definition: ISUtilities.cpp:53
uint64_t timerUsEnd(uint64_t start)
FILE * openFile(const char *path, const char *mode)
void mutexLock(void *handle)
gen_3axis_sensord_t gen3AxisSensorDataD(double time, const double val[3])
void * threadCreateAndStart(void(*function)(void *info), void *info)
gen_3axis_sensor_t gen3AxisSensorData(double time, const float val[3])
uint64_t timerRawStart()
void mutexFree(void *handle)
void threadJoinAndFree(void *handle)
int32_t convertGpsToMjd(int32_t gpsWeek, int32_t gpsSeconds)
gen_1axis_sensor_t gen1AxisSensorData(double time, const float val)
void mutexUnlock(void *handle)
gen_dual_3axis_sensor_t genDual3AxisSensorData(double time, const float val1[3], const float val2[3])
uint8_t getHexValue(unsigned char hex)
uint64_t current_timeUs()
int current_timeSec()
void convertMjdToDate(int32_t mjd, int32_t *year, int32_t *month, int32_t *day)
void convertGpsToHMS(int32_t gpsSeconds, int32_t *hour, int32_t *minutes, int32_t *seconds)
int32_t convertDateToMjd(int32_t year, int32_t month, int32_t day)
string base64Decode(const string &encoded_string)


inertial_sense_ros
Author(s):
autogenerated on Sun Feb 28 2021 03:17:57