@@ -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 ;
@@ -100,81 +100,79 @@ struct sim_baro_data {
100100 uint32_t sample_count ;
101101};
102102
103-
104-
105103// Helper to get Nth field from CSV line
106- static const char * get_csv_field (const char * line , int field_index , char * buffer , size_t buf_size )
104+ static const char * get_csv_field (const char * line , int field_index , char * buffer , size_t buf_size )
107105{
108106 const char * start = line ;
109107 const char * end ;
110108 int current_field = 0 ;
111-
109+
112110 // Skip to the desired field
113111 while (current_field < field_index && * start ) {
114112 if (* start == ',' ) {
115113 current_field ++ ;
116114 }
117115 start ++ ;
118116 }
119-
117+
120118 if (current_field != field_index ) {
121- return NULL ; // Field not found
119+ return NULL ; // Field not found
122120 }
123-
121+
124122 // Find the end of this field
125123 end = start ;
126124 while (* end && * end != ',' && * end != '\n' && * end != '\r' ) {
127125 end ++ ;
128126 }
129-
127+
130128 // Copy to buffer
131129 size_t len = end - start ;
132130 if (len >= buf_size ) {
133131 len = buf_size - 1 ;
134132 }
135-
133+
136134 strncpy (buffer , start , len );
137135 buffer [len ] = '\0' ;
138-
136+
139137 return buffer ;
140138}
141139
142-
143-
144140// Helper macro to extract and parse a field
145- #define GET_CSV_INT64 (line , col , dest ) do { \
146- char _buf[64]; \
147- if (!get_csv_field(line, col, _buf, sizeof(_buf))) return -1; \
148- dest = atoll(_buf); \
149- } while(0)
141+ #define GET_CSV_INT64 (line , col , dest ) \
142+ do { \
143+ char _buf[64]; \
144+ if (!get_csv_field(line, col, _buf, sizeof(_buf))) \
145+ return -1; \
146+ dest = atoll(_buf); \
147+ } while (0)
150148
151149// Helper macro to extract and parse a field
152- #define GET_CSV_FLOAT (line , col , dest ) do { \
153- char _buf[64]; \
154- if (!get_csv_field(line, col, _buf, sizeof(_buf))) return -1; \
155- dest = atof(_buf); \
156- } while(0)
150+ #define GET_CSV_FLOAT (line , col , dest ) \
151+ do { \
152+ char _buf[64]; \
153+ if (!get_csv_field(line, col, _buf, sizeof(_buf))) \
154+ return -1; \
155+ dest = atof(_buf); \
156+ } while (0)
157157
158158static int parse_csv_line (const char * line , struct csv_row * row )
159159{
160160 float pressure_raw , temp_raw , timestamp_raw , altitude_raw ;
161-
161+
162162 GET_CSV_FLOAT (line , CSV_COL_TIMESTAMP , timestamp_raw );
163163 GET_CSV_FLOAT (line , CSV_COL_ALTITUDE , altitude_raw );
164164 GET_CSV_FLOAT (line , CSV_COL_AIR_PRESSURE , pressure_raw );
165165 GET_CSV_FLOAT (line , CSV_COL_AIR_TEMP , temp_raw );
166-
166+
167167 // Apply unit conversions
168168 row -> timestamp_ms = timestamp_raw * 1000.0f ; // Convert from seconds to milliseconds
169169 row -> altitude_m = altitude_raw ;
170- row -> pressure_mbar = pressure_raw ; // mbar = hPa
170+ row -> pressure_mbar = pressure_raw ; // mbar = hPa
171171 row -> temperature_c = temp_raw ;
172-
172+
173173 return 0 ;
174174}
175175
176-
177-
178176static int load_csv_data (struct sim_baro_data * data )
179177{
180178 LOG_INF ("═══════════════════════════════════════════════" );
0 commit comments