@@ -19,60 +19,60 @@ LOG_MODULE_REGISTER(sim_baro, LOG_LEVEL_INF);
1919#define MAX_CSV_ROWS 10000
2020
2121// OpenRocket CSV Column definitions
22- #define CSV_COL_TIMESTAMP 0
23- #define CSV_COL_ALTITUDE 1
24- #define CSV_COL_VERTICAL_VELO 2
25- #define CSV_COL_VERTICAL_ACCEL 3
26- #define CSV_COL_TOTAL_VELO 4
27- #define CSV_COL_TOTAL_ACCEL 5
28- #define CSV_COL_POS_EAST 6
29- #define CSV_COL_POS_NORTH 7
30- #define CSV_COL_GPS_LAT_DIST 8
31- #define CSV_COL_GPS_LAT_DIR 9
32- #define CSV_COL_GPS_LAT_VELO 10
33- #define CSV_COL_GPS_LAT_ACCEL 11
34- #define CSV_COL_LATITUDE 12
35- #define CSV_COL_LONGITUDE 13
36- #define CSV_COL_GRAVITY 14
37- #define CSV_COL_ANGLE_ATTACK 15
38- #define CSV_COL_ROLL_RATE 16
39- #define CSV_COL_PITCH_RATE 17
40- #define CSV_COL_YAW_RATE 18
41- #define CSV_COL_MASS 19
42- #define CSV_COL_MOTOR_MASS 20
43- #define CSV_COL_LONG_MMOI 21
44- #define CSV_COL_ROT_MMOI 22
45- #define CSV_COL_CP_LOCATION 23
46- #define CSV_COL_CG_LOCATION 24
47- #define CSV_COL_STABILITY 25
48- #define CSV_COL_MACH_NUMBER 26
49- #define CSV_COL_REYNOLDS_NUMBER 27
50- #define CSV_COL_THRUST 28
51- #define CSV_COL_DRAG 29
52- #define CSV_COL_DRAG_COEFF 30
53- #define CSV_COL_AXIAL_DRAG_COEFF 31
54- #define CSV_COL_FRIC_DRAG_COEFF 32
55- #define CSV_COL_PRESSURE_DRAG_COEFF 33
56- #define CSV_COL_BASE_DRAG_COEFF 34
57- #define CSV_COL_NORM_FORCE_COEFF 35
58- #define CSV_COL_PITCH_MOM_COEFF 36
59- #define CSV_COL_YAW_MOM_COEFF 37
60- #define CSV_COL_SIDE_FORCE_COEFF 38
61- #define CSV_COL_ROLL_MOM_COEFF 39
62- #define CSV_COL_ROLL_FORCING_COEFF 40
63- #define CSV_COL_ROLL_DAMPING_COEFF 41
64- #define CSV_COL_PITCH_DAMPING_COEFF 42
65- #define CSV_COL_CORIOLIS_ACCEL 43
66- #define CSV_COL_REF_LENGTH 44
67- #define CSV_COL_REF_AREA 45
68- #define CSV_COL_VERTICAL_ORIENT 46
69- #define CSV_COL_LATERAL_ORIENT 47
70- #define CSV_COL_WIND_SPEED 48
71- #define CSV_COL_AIR_TEMP 49
72- #define CSV_COL_AIR_PRESSURE 50
73- #define CSV_COL_SPEED_OF_SOUND 51
74- #define CSV_COL_SIM_TIMESTEP 52
75- #define CSV_COL_COMPUTATION_TIME 53
22+ #define CSV_COL_TIMESTAMP 0
23+ #define CSV_COL_ALTITUDE 1
24+ #define CSV_COL_VERTICAL_VELO 2
25+ #define CSV_COL_VERTICAL_ACCEL 3
26+ #define CSV_COL_TOTAL_VELO 4
27+ #define CSV_COL_TOTAL_ACCEL 5
28+ #define CSV_COL_POS_EAST 6
29+ #define CSV_COL_POS_NORTH 7
30+ #define CSV_COL_GPS_LAT_DIST 8
31+ #define CSV_COL_GPS_LAT_DIR 9
32+ #define CSV_COL_GPS_LAT_VELO 10
33+ #define CSV_COL_GPS_LAT_ACCEL 11
34+ #define CSV_COL_LATITUDE 12
35+ #define CSV_COL_LONGITUDE 13
36+ #define CSV_COL_GRAVITY 14
37+ #define CSV_COL_ANGLE_ATTACK 15
38+ #define CSV_COL_ROLL_RATE 16
39+ #define CSV_COL_PITCH_RATE 17
40+ #define CSV_COL_YAW_RATE 18
41+ #define CSV_COL_MASS 19
42+ #define CSV_COL_MOTOR_MASS 20
43+ #define CSV_COL_LONG_MMOI 21
44+ #define CSV_COL_ROT_MMOI 22
45+ #define CSV_COL_CP_LOCATION 23
46+ #define CSV_COL_CG_LOCATION 24
47+ #define CSV_COL_STABILITY 25
48+ #define CSV_COL_MACH_NUMBER 26
49+ #define CSV_COL_REYNOLDS_NUMBER 27
50+ #define CSV_COL_THRUST 28
51+ #define CSV_COL_DRAG 29
52+ #define CSV_COL_DRAG_COEFF 30
53+ #define CSV_COL_AXIAL_DRAG_COEFF 31
54+ #define CSV_COL_FRIC_DRAG_COEFF 32
55+ #define CSV_COL_PRESSURE_DRAG_COEFF 33
56+ #define CSV_COL_BASE_DRAG_COEFF 34
57+ #define CSV_COL_NORM_FORCE_COEFF 35
58+ #define CSV_COL_PITCH_MOM_COEFF 36
59+ #define CSV_COL_YAW_MOM_COEFF 37
60+ #define CSV_COL_SIDE_FORCE_COEFF 38
61+ #define CSV_COL_ROLL_MOM_COEFF 39
62+ #define CSV_COL_ROLL_FORCING_COEFF 40
63+ #define CSV_COL_ROLL_DAMPING_COEFF 41
64+ #define CSV_COL_PITCH_DAMPING_COEFF 42
65+ #define CSV_COL_CORIOLIS_ACCEL 43
66+ #define CSV_COL_REF_LENGTH 44
67+ #define CSV_COL_REF_AREA 45
68+ #define CSV_COL_VERTICAL_ORIENT 46
69+ #define CSV_COL_LATERAL_ORIENT 47
70+ #define CSV_COL_WIND_SPEED 48
71+ #define CSV_COL_AIR_TEMP 49
72+ #define CSV_COL_AIR_PRESSURE 50
73+ #define CSV_COL_SPEED_OF_SOUND 51
74+ #define CSV_COL_SIM_TIMESTEP 52
75+ #define CSV_COL_COMPUTATION_TIME 53
7676
7777struct csv_row {
7878 int64_t timestamp_ms ;
@@ -155,80 +155,79 @@ static const char *get_csv_field(const char *line, int field_index, char *buffer
155155 dest = atof(_buf); \
156156 } while (0)
157157
158-
159158// Helper to get Nth field from CSV line
160- static const char * get_csv_field (const char * line , int field_index , char * buffer , size_t buf_size )
159+ static const char * get_csv_field (const char * line , int field_index , char * buffer , size_t buf_size )
161160{
162161 const char * start = line ;
163162 const char * end ;
164163 int current_field = 0 ;
165-
164+
166165 // Skip to the desired field
167166 while (current_field < field_index && * start ) {
168167 if (* start == ',' ) {
169168 current_field ++ ;
170169 }
171170 start ++ ;
172171 }
173-
172+
174173 if (current_field != field_index ) {
175- return NULL ; // Field not found
174+ return NULL ; // Field not found
176175 }
177-
176+
178177 // Find the end of this field
179178 end = start ;
180179 while (* end && * end != ',' && * end != '\n' && * end != '\r' ) {
181180 end ++ ;
182181 }
183-
182+
184183 // Copy to buffer
185184 size_t len = end - start ;
186185 if (len >= buf_size ) {
187186 len = buf_size - 1 ;
188187 }
189-
188+
190189 strncpy (buffer , start , len );
191190 buffer [len ] = '\0' ;
192-
191+
193192 return buffer ;
194193}
195194
196-
197-
198195// Helper macro to extract and parse a field
199- #define GET_CSV_INT64 (line , col , dest ) do { \
200- char _buf[64]; \
201- if (!get_csv_field(line, col, _buf, sizeof(_buf))) return -1; \
202- dest = atoll(_buf); \
203- } while(0)
196+ #define GET_CSV_INT64 (line , col , dest ) \
197+ do { \
198+ char _buf[64]; \
199+ if (!get_csv_field(line, col, _buf, sizeof(_buf))) \
200+ return -1; \
201+ dest = atoll(_buf); \
202+ } while (0)
204203
205204// Helper macro to extract and parse a field
206- #define GET_CSV_FLOAT (line , col , dest ) do { \
207- char _buf[64]; \
208- if (!get_csv_field(line, col, _buf, sizeof(_buf))) return -1; \
209- dest = atof(_buf); \
210- } while(0)
205+ #define GET_CSV_FLOAT (line , col , dest ) \
206+ do { \
207+ char _buf[64]; \
208+ if (!get_csv_field(line, col, _buf, sizeof(_buf))) \
209+ return -1; \
210+ dest = atof(_buf); \
211+ } while (0)
211212
212213static int parse_csv_line (const char * line , struct csv_row * row )
213214{
214215 float pressure_raw , temp_raw , timestamp_raw , altitude_raw ;
215-
216+
216217 GET_CSV_FLOAT (line , CSV_COL_TIMESTAMP , timestamp_raw );
217218 GET_CSV_FLOAT (line , CSV_COL_ALTITUDE , altitude_raw );
218219 GET_CSV_FLOAT (line , CSV_COL_AIR_PRESSURE , pressure_raw );
219220 GET_CSV_FLOAT (line , CSV_COL_AIR_TEMP , temp_raw );
220-
221+
221222 // Apply unit conversions
222223 row -> timestamp_ms = timestamp_raw * 1000.0f ; // Convert from seconds to milliseconds
223224 row -> altitude_m = altitude_raw ;
224- row -> pressure_mbar = pressure_raw ; // mbar = hPa
225+ row -> pressure_mbar = pressure_raw ; // mbar = hPa
225226 row -> temperature_c = temp_raw ;
226-
227+
227228 return 0 ;
228229}
229230
230-
231-
232231static int load_csv_data (struct sim_baro_data * data )
233232{
234233 LOG_INF ("═══════════════════════════════════════════════" );
0 commit comments