ISUtilities.h
Go to the documentation of this file.
1 /*
2 MIT LICENSE
3 
4 Copyright (c) 2014-2020 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 int current_weekMs();
146 uint64_t current_weekUs();
147 
148 uint64_t timerUsStart();
149 uint64_t timerUsEnd(uint64_t start);
150 uint64_t timerRawStart();
151 uint64_t timerRawEnd(uint64_t start);
152 
153 uint64_t getTickCount(void);
154 
155 int bootloadUploadProgress(const void* port, float percent);
156 int bootloadVerifyProgress(const void* port, float percent);
157 void bootloadStatusInfo(const void* port, const char* str);
158 float step_sinwave(float *sig_gen, float freqHz, float amplitude, float periodSec);
159 
160 FILE* openFile(const char* path, const char* mode);
161 const char* tempPath(); // ends with dir separator
162 
167 const unsigned char* getHexLookupTable();
168 
174 uint8_t getHexValue(unsigned char hex);
175 
182 void* threadCreateAndStart(void(*function)(void* info), void* info);
183 
188 void threadJoinAndFree(void* handle);
189 
190 /*
191 * Create a mutex which allows exclusive access to a shared resource
192 * @return the mutex handle
193 */
194 void* mutexCreate(void);
195 
200 void mutexLock(void* handle);
201 
206 void mutexUnlock(void* handle);
207 
212 void mutexFree(void* handle);
213 
214 // taken from http://www.leapsecond.com/tools/gpsdate.c, uses UTC time
215 int32_t convertDateToMjd(int32_t year, int32_t month, int32_t day);
216 int32_t convertGpsToMjd(int32_t gpsWeek, int32_t gpsSeconds);
217 void convertMjdToDate(int32_t mjd, int32_t* year, int32_t* month, int32_t* day);
218 void convertGpsToHMS(int32_t gpsSeconds, int32_t* hour, int32_t* minutes, int32_t* seconds);
219 uint32_t dateToWeekDay(uint32_t ul_year, uint32_t ul_month, uint32_t ul_day);
220 
221 gen_1axis_sensor_t gen1AxisSensorData(double time, const float val);
222 gen_3axis_sensor_t gen3AxisSensorData(double time, const float val[3]);
223 gen_dual_3axis_sensor_t genDual3AxisSensorData(double time, const float val1[3], const float val2[3]);
224 gen_3axis_sensord_t gen3AxisSensorDataD(double time, const double val[3]);
225 
226 #ifdef __cplusplus
227 } // extern C
228 #endif
229 
230 #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)
int current_weekMs()
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 current_weekUs()
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)
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 Sat Sep 19 2020 03:19:04