kfsw-modules/gpredict/parameters/gpredict_table.c
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include <stdint.h> | ||
| 2 | #include <string.h> | ||
| 3 | |||
| 4 | #include <zephyr/sys/util.h> | ||
| 5 | |||
| 6 | #include <kfsw/modules/gpredict.h> | ||
| 7 | #include <kfsw/services/parameter.h> | ||
| 8 | |||
| 9 | #include "gpredict_internal.h" | ||
| 10 | |||
| 11 | /* | ||
| 12 | * What an operator can see and change during a pass. Everything except the | ||
| 13 | * grace period is owned by the tracker, so everything except the grace period | ||
| 14 | * is read-only: a writable state would let the ground claim a pass that the | ||
| 15 | * rotator is not flying. | ||
| 16 | */ | ||
| 17 | |||
| 18 | static uint8_t gp_state; | ||
| 19 | static int32_t gp_azimuth_mdeg; | ||
| 20 | static int32_t gp_elevation_mdeg; | ||
| 21 | static int32_t gp_actual_azimuth_mdeg; | ||
| 22 | static int32_t gp_actual_elevation_mdeg; | ||
| 23 | static uint64_t gp_frequency_hz; | ||
| 24 | static uint32_t gp_silence_ms; | ||
| 25 | static uint32_t gp_grace_ms = CONFIG_KFSW_GPREDICT_GRACE_MS; | ||
| 26 | static uint32_t gp_bearings; | ||
| 27 | static uint32_t gp_refusals; | ||
| 28 | static uint32_t gp_passes_ended; | ||
| 29 | static uint32_t gp_faults; | ||
| 30 | static int32_t gp_last_error; | ||
| 31 | |||
| 32 | /* Reserved for no selection: 0 is a real slot and a real policy. */ | ||
| 33 | #define GP_NONE UINT8_MAX | ||
| 34 | |||
| 35 | static uint8_t gp_profile = GP_NONE; | ||
| 36 | static uint8_t gp_policy = GP_NONE; | ||
| 37 | static uint8_t gp_profiles; | ||
| 38 | static uint8_t gp_profiles_on; | ||
| 39 | static uint32_t gp_catalogue; | ||
| 40 | static char gp_profile_name[KFSW_GPREDICT_PROFILE_NAME_MAX]; | ||
| 41 | |||
| 42 | 6 | static void sample_tracker(void) | |
| 43 | { | ||
| 44 | struct kfsw_gpredict_status status; | ||
| 45 | |||
| 46 | 6 | if (kfsw_gpredict_get_status(&status) != 0) { | |
| 47 | ✗ | return; | |
| 48 | } | ||
| 49 | 6 | gp_state = status.state; | |
| 50 | 6 | gp_azimuth_mdeg = status.azimuth_mdeg; | |
| 51 | 6 | gp_elevation_mdeg = status.elevation_mdeg; | |
| 52 | 6 | gp_actual_azimuth_mdeg = status.actual_azimuth_mdeg; | |
| 53 | 6 | gp_actual_elevation_mdeg = status.actual_elevation_mdeg; | |
| 54 | 6 | gp_frequency_hz = status.frequency_hz; | |
| 55 | 6 | gp_silence_ms = status.silence_ms; | |
| 56 | 6 | gp_grace_ms = status.grace_ms; | |
| 57 | 6 | gp_bearings = status.bearings; | |
| 58 | 6 | gp_refusals = status.refusals; | |
| 59 | 6 | gp_passes_ended = status.passes_ended; | |
| 60 | 6 | gp_faults = status.faults; | |
| 61 | 6 | gp_last_error = (int32_t)status.last_error; | |
| 62 | } | ||
| 63 | |||
| 64 | #define GPREDICT_SAMPLE(field, type) \ | ||
| 65 | static void sample_##field(void *value) \ | ||
| 66 | { \ | ||
| 67 | sample_tracker(); \ | ||
| 68 | *(type *)value = gp_##field; \ | ||
| 69 | } | ||
| 70 | |||
| 71 | 2 | GPREDICT_SAMPLE(state, uint8_t) | |
| 72 | ✗ | GPREDICT_SAMPLE(azimuth_mdeg, int32_t) | |
| 73 | ✗ | GPREDICT_SAMPLE(elevation_mdeg, int32_t) | |
| 74 | ✗ | GPREDICT_SAMPLE(actual_azimuth_mdeg, int32_t) | |
| 75 | ✗ | GPREDICT_SAMPLE(actual_elevation_mdeg, int32_t) | |
| 76 | ✗ | GPREDICT_SAMPLE(frequency_hz, uint64_t) | |
| 77 | ✗ | GPREDICT_SAMPLE(silence_ms, uint32_t) | |
| 78 | 2 | GPREDICT_SAMPLE(grace_ms, uint32_t) | |
| 79 | 2 | GPREDICT_SAMPLE(bearings, uint32_t) | |
| 80 | ✗ | GPREDICT_SAMPLE(refusals, uint32_t) | |
| 81 | ✗ | GPREDICT_SAMPLE(passes_ended, uint32_t) | |
| 82 | ✗ | GPREDICT_SAMPLE(faults, uint32_t) | |
| 83 | ✗ | GPREDICT_SAMPLE(last_error, int32_t) | |
| 84 | |||
| 85 | 24 | static void sample_slots(void) | |
| 86 | { | ||
| 87 | 24 | const int selected = kfsw_gpredict_profile_selected(); | |
| 88 | struct kfsw_gpredict_profile profile; | ||
| 89 | |||
| 90 | 24 | gp_profile = GP_NONE; | |
| 91 | 24 | gp_policy = GP_NONE; | |
| 92 | 24 | gp_profiles = 0U; | |
| 93 | 24 | gp_profiles_on = 0U; | |
| 94 | 24 | gp_catalogue = 0U; | |
| 95 | 24 | gp_profile_name[0] = '\0'; | |
| 96 | |||
| 97 | 96 | for (uint8_t index = 0U; index < CONFIG_KFSW_GPREDICT_PROFILES; index++) { | |
| 98 | 72 | if (kfsw_gpredict_profile_get(index, &profile) != 0) { | |
| 99 | 44 | continue; | |
| 100 | } | ||
| 101 | 28 | gp_profiles++; | |
| 102 | 28 | if (profile.enabled) { | |
| 103 | 16 | gp_profiles_on++; | |
| 104 | } | ||
| 105 | 28 | if ((int)index == selected) { | |
| 106 | 14 | gp_profile = index; | |
| 107 | 14 | gp_policy = profile.policy; | |
| 108 | 14 | gp_catalogue = profile.catalogue; | |
| 109 | 14 | (void)memcpy(gp_profile_name, profile.name, sizeof(gp_profile_name)); | |
| 110 | } | ||
| 111 | } | ||
| 112 | 24 | } | |
| 113 | |||
| 114 | #define PROFILE_SAMPLE(field, type) \ | ||
| 115 | static void sample_##field(void *value) \ | ||
| 116 | { \ | ||
| 117 | sample_slots(); \ | ||
| 118 | *(type *)value = gp_##field; \ | ||
| 119 | } | ||
| 120 | |||
| 121 | 4 | PROFILE_SAMPLE(profile, uint8_t) | |
| 122 | 4 | PROFILE_SAMPLE(policy, uint8_t) | |
| 123 | 4 | PROFILE_SAMPLE(profiles, uint8_t) | |
| 124 | 4 | PROFILE_SAMPLE(profiles_on, uint8_t) | |
| 125 | 4 | PROFILE_SAMPLE(catalogue, uint32_t) | |
| 126 | |||
| 127 | 4 | static void sample_profile_name(void *value) | |
| 128 | { | ||
| 129 | /* value is gp_profile_name, which sample_slots() has just filled. */ | ||
| 130 | ARG_UNUSED(value); | ||
| 131 | 4 | sample_slots(); | |
| 132 | 4 | } | |
| 133 | |||
| 134 | 10 | static int validate_grace(const union kfsw_param_scalar *value) | |
| 135 | { | ||
| 136 | 10 | return gpredict_grace_validate(value->u32); | |
| 137 | } | ||
| 138 | |||
| 139 | 6 | static void grace_changed(const union kfsw_param_scalar *value) | |
| 140 | { | ||
| 141 | 6 | gpredict_grace_set(value->u32); | |
| 142 | 6 | } | |
| 143 | |||
| 144 | static const struct kfsw_param_definition gpredict_param_definitions[] = { | ||
| 145 | { | ||
| 146 | .offset = 0x00U, | ||
| 147 | .type = KFSW_PARAM_U8, | ||
| 148 | .flags = KFSW_PARAM_FLAG_READ_ONLY | KFSW_PARAM_FLAG_LIVE, | ||
| 149 | .name = "gp_state", | ||
| 150 | .description = "parked, tracking, holding, parking or fault", | ||
| 151 | .value = &gp_state, | ||
| 152 | .sample = sample_state, | ||
| 153 | }, | ||
| 154 | { | ||
| 155 | .offset = 0x04U, | ||
| 156 | .type = KFSW_PARAM_I32, | ||
| 157 | .flags = KFSW_PARAM_FLAG_READ_ONLY | KFSW_PARAM_FLAG_LIVE, | ||
| 158 | .name = "gp_az_mdeg", | ||
| 159 | .unit = "mdeg", | ||
| 160 | .description = "Azimuth last accepted from the predictor", | ||
| 161 | .value = &gp_azimuth_mdeg, | ||
| 162 | .sample = sample_azimuth_mdeg, | ||
| 163 | }, | ||
| 164 | { | ||
| 165 | .offset = 0x08U, | ||
| 166 | .type = KFSW_PARAM_I32, | ||
| 167 | .flags = KFSW_PARAM_FLAG_READ_ONLY | KFSW_PARAM_FLAG_LIVE, | ||
| 168 | .name = "gp_el_mdeg", | ||
| 169 | .unit = "mdeg", | ||
| 170 | .description = "Elevation last accepted from the predictor", | ||
| 171 | .value = &gp_elevation_mdeg, | ||
| 172 | .sample = sample_elevation_mdeg, | ||
| 173 | }, | ||
| 174 | { | ||
| 175 | .offset = 0x0cU, | ||
| 176 | .type = KFSW_PARAM_I32, | ||
| 177 | .flags = KFSW_PARAM_FLAG_READ_ONLY | KFSW_PARAM_FLAG_LIVE, | ||
| 178 | .name = "gp_actual_az_mdeg", | ||
| 179 | .unit = "mdeg", | ||
| 180 | .description = "Azimuth the rotator last reported, not the commanded one", | ||
| 181 | .value = &gp_actual_azimuth_mdeg, | ||
| 182 | .sample = sample_actual_azimuth_mdeg, | ||
| 183 | }, | ||
| 184 | { | ||
| 185 | .offset = 0x10U, | ||
| 186 | .type = KFSW_PARAM_I32, | ||
| 187 | .flags = KFSW_PARAM_FLAG_READ_ONLY | KFSW_PARAM_FLAG_LIVE, | ||
| 188 | .name = "gp_actual_el_mdeg", | ||
| 189 | .unit = "mdeg", | ||
| 190 | .description = "Elevation the rotator last reported, not the commanded one", | ||
| 191 | .value = &gp_actual_elevation_mdeg, | ||
| 192 | .sample = sample_actual_elevation_mdeg, | ||
| 193 | }, | ||
| 194 | { | ||
| 195 | .offset = 0x18U, | ||
| 196 | .type = KFSW_PARAM_U64, | ||
| 197 | .flags = KFSW_PARAM_FLAG_READ_ONLY | KFSW_PARAM_FLAG_LIVE, | ||
| 198 | .name = "gp_frequency_hz", | ||
| 199 | .unit = "Hz", | ||
| 200 | .description = "Doppler-corrected frequency last accepted; 0 if none", | ||
| 201 | .value = &gp_frequency_hz, | ||
| 202 | .sample = sample_frequency_hz, | ||
| 203 | }, | ||
| 204 | { | ||
| 205 | .offset = 0x20U, | ||
| 206 | .type = KFSW_PARAM_U32, | ||
| 207 | .flags = KFSW_PARAM_FLAG_READ_ONLY | KFSW_PARAM_FLAG_LIVE, | ||
| 208 | .name = "gp_silence_ms", | ||
| 209 | .unit = "ms", | ||
| 210 | .description = "Since the last bearing; 0 while none has arrived", | ||
| 211 | .value = &gp_silence_ms, | ||
| 212 | .sample = sample_silence_ms, | ||
| 213 | }, | ||
| 214 | { | ||
| 215 | .offset = 0x24U, | ||
| 216 | .type = KFSW_PARAM_U32, | ||
| 217 | .flags = KFSW_PARAM_FLAG_CONFIGURATION, | ||
| 218 | .name = "gp_grace_ms", | ||
| 219 | .unit = "ms", | ||
| 220 | .description = "Silence the antenna holds through before it parks", | ||
| 221 | .value = &gp_grace_ms, | ||
| 222 | .default_value.u32 = CONFIG_KFSW_GPREDICT_GRACE_MS, | ||
| 223 | .validate = validate_grace, | ||
| 224 | .changed = grace_changed, | ||
| 225 | .sample = sample_grace_ms, | ||
| 226 | }, | ||
| 227 | { | ||
| 228 | .offset = 0x28U, | ||
| 229 | .type = KFSW_PARAM_U32, | ||
| 230 | .flags = KFSW_PARAM_FLAG_READ_ONLY, | ||
| 231 | .name = "gp_bearings", | ||
| 232 | .description = "Bearings accepted since boot; saturates", | ||
| 233 | .value = &gp_bearings, | ||
| 234 | .sample = sample_bearings, | ||
| 235 | }, | ||
| 236 | { | ||
| 237 | .offset = 0x2cU, | ||
| 238 | .type = KFSW_PARAM_U32, | ||
| 239 | .flags = KFSW_PARAM_FLAG_READ_ONLY, | ||
| 240 | .name = "gp_refusals", | ||
| 241 | .description = "Bearings refused outside the travel or in fault; saturates", | ||
| 242 | .value = &gp_refusals, | ||
| 243 | .sample = sample_refusals, | ||
| 244 | }, | ||
| 245 | { | ||
| 246 | .offset = 0x30U, | ||
| 247 | .type = KFSW_PARAM_U32, | ||
| 248 | .flags = KFSW_PARAM_FLAG_READ_ONLY, | ||
| 249 | .name = "gp_passes_ended", | ||
| 250 | .description = "Passes that ended because the predictor went quiet", | ||
| 251 | .value = &gp_passes_ended, | ||
| 252 | .sample = sample_passes_ended, | ||
| 253 | }, | ||
| 254 | { | ||
| 255 | .offset = 0x34U, | ||
| 256 | .type = KFSW_PARAM_U32, | ||
| 257 | .flags = KFSW_PARAM_FLAG_READ_ONLY, | ||
| 258 | .name = "gp_faults", | ||
| 259 | .description = "Entries into fault since boot; saturates", | ||
| 260 | .value = &gp_faults, | ||
| 261 | .sample = sample_faults, | ||
| 262 | }, | ||
| 263 | { | ||
| 264 | .offset = 0x38U, | ||
| 265 | .type = KFSW_PARAM_I32, | ||
| 266 | .flags = KFSW_PARAM_FLAG_READ_ONLY, | ||
| 267 | .name = "gp_last_error", | ||
| 268 | .description = "Why the last refusal or fault happened, or 0", | ||
| 269 | .value = &gp_last_error, | ||
| 270 | .sample = sample_last_error, | ||
| 271 | }, | ||
| 272 | { | ||
| 273 | .offset = 0x3cU, | ||
| 274 | .type = KFSW_PARAM_U8, | ||
| 275 | .flags = KFSW_PARAM_FLAG_READ_ONLY | KFSW_PARAM_FLAG_LIVE, | ||
| 276 | .name = "gp_profile", | ||
| 277 | .description = "Selected profile slot; 255 when none is selected", | ||
| 278 | .value = &gp_profile, | ||
| 279 | .sample = sample_profile, | ||
| 280 | }, | ||
| 281 | { | ||
| 282 | .offset = 0x3dU, | ||
| 283 | .type = KFSW_PARAM_U8, | ||
| 284 | .flags = KFSW_PARAM_FLAG_READ_ONLY | KFSW_PARAM_FLAG_LIVE, | ||
| 285 | .name = "gp_policy", | ||
| 286 | .description = "Frequency policy: 0 follow, 1 hold, 2 ignore; 255 when none", | ||
| 287 | .value = &gp_policy, | ||
| 288 | .sample = sample_policy, | ||
| 289 | }, | ||
| 290 | { | ||
| 291 | .offset = 0x3eU, | ||
| 292 | .type = KFSW_PARAM_U8, | ||
| 293 | .flags = KFSW_PARAM_FLAG_READ_ONLY, | ||
| 294 | .name = "gp_profiles", | ||
| 295 | .description = "Profile slots holding a profile", | ||
| 296 | .value = &gp_profiles, | ||
| 297 | .sample = sample_profiles, | ||
| 298 | }, | ||
| 299 | { | ||
| 300 | .offset = 0x3fU, | ||
| 301 | .type = KFSW_PARAM_U8, | ||
| 302 | .flags = KFSW_PARAM_FLAG_READ_ONLY, | ||
| 303 | .name = "gp_profiles_on", | ||
| 304 | .description = "Defined profiles that may be selected", | ||
| 305 | .value = &gp_profiles_on, | ||
| 306 | .sample = sample_profiles_on, | ||
| 307 | }, | ||
| 308 | { | ||
| 309 | .offset = 0x40U, | ||
| 310 | .type = KFSW_PARAM_U32, | ||
| 311 | .flags = KFSW_PARAM_FLAG_READ_ONLY | KFSW_PARAM_FLAG_LIVE, | ||
| 312 | .name = "gp_catalogue", | ||
| 313 | .description = "Catalogue number of the selected profile; 0 when none", | ||
| 314 | .value = &gp_catalogue, | ||
| 315 | .sample = sample_catalogue, | ||
| 316 | }, | ||
| 317 | { | ||
| 318 | .offset = 0x44U, | ||
| 319 | .type = KFSW_PARAM_STRING, | ||
| 320 | .capacity = KFSW_GPREDICT_PROFILE_NAME_MAX, | ||
| 321 | .flags = KFSW_PARAM_FLAG_READ_ONLY | KFSW_PARAM_FLAG_LIVE, | ||
| 322 | .name = "gp_profile_name", | ||
| 323 | .description = "Name of the selected profile; empty when none", | ||
| 324 | .value = gp_profile_name, | ||
| 325 | .sample = sample_profile_name, | ||
| 326 | }, | ||
| 327 | }; | ||
| 328 | |||
| 329 | KFSW_PARAM_TABLE_FITS_THE_LINK(gpredict_param_definitions); | ||
| 330 | |||
| 331 | const struct kfsw_param_definition_set kfsw_gpredict_param_definitions = { | ||
| 332 | .table = KFSW_GPREDICT_TABLE_ID, | ||
| 333 | .name = KFSW_GPREDICT_TABLE_NAME, | ||
| 334 | .description = "Pass tracking state, bearings and grace period", | ||
| 335 | .definitions = gpredict_param_definitions, | ||
| 336 | .count = ARRAY_SIZE(gpredict_param_definitions), | ||
| 337 | }; | ||
| 338 |