Loading...
Searching...
No Matches
camera_control.c
Go to the documentation of this file.
30 for (size_t index = 0; index < 4; ++index) bytes[offset + index] = (uint8_t)(value >> (8 * index));
38 for (size_t index = 0; index < 4; ++index) *value |= (uint32_t)bytes[offset + index] << (8 * index);
48bool usher_control_encode_request(uint8_t *bytes, size_t size, const struct usher_control_request *request)
61bool usher_control_decode_request(const uint8_t *bytes, size_t size, struct usher_control_request *request)
63 if (!bytes || !request || size != USHER_CONTROL_COMMAND_SIZE || bytes[0] != USHER_CONTROL_VERSION
65 *request = (struct usher_control_request){.camera_mask = bytes[1], .command = bytes[10], .value = bytes[11]};
71bool usher_control_encode_result(uint8_t *bytes, size_t size, const struct usher_control_result *result)
88bool usher_control_decode_result(const uint8_t *bytes, size_t size, struct usher_control_result *result)
115bool usher_control_client_hello(struct usher_control_client *client, const uint8_t *bytes, size_t size, uint32_t now_us)
118 if (!client->negotiating || !bytes || size != USHER_CONTROL_HELLO_SIZE || bytes[0] != USHER_CONTROL_VERSION
135 return client->session && client->confirmed && (uint32_t)(now_us - client->hello_us) < USHER_CONTROL_LEASE_US;
142 if (slot->status == CAM_CONTROL_PENDING && (uint32_t)(now_us - slot->sent_us) >= USHER_CONTROL_TIMEOUT_US)
147bool usher_control_client_prepare(struct usher_control_client *client, uint8_t mask, uint8_t command,
152 || !usher_control_client_ready(client, now_us) || client->next_request_id == UINT32_MAX) return false;
155 *request = (struct usher_control_request){.session = client->session, .request_id = client->next_request_id + 1,
160void usher_control_client_commit(struct usher_control_client *client, const struct usher_control_request *request,
167 client->slots[index] = (struct usher_control_slot){.request_id = request->request_id, .sent_us = now_us,
173bool usher_control_client_receive(struct usher_control_client *client, const uint8_t *bytes, size_t size,
178 if (!usher_control_client_ready(client, now_us) || !usher_control_decode_result(bytes, size, &result)
185 || (slot->command != CAM_CMD_LENS_RETRACT && result.evidence != CAM_CONTROL_EVIDENCE_VALUE))) return false;
186 if (result.status != CAM_CONTROL_APPLIED && result.evidence != CAM_CONTROL_EVIDENCE_NONE) return false;
196uint8_t usher_control_client_camera_result(const struct usher_control_client *client, uint32_t ticket, uint8_t camera_id)
199 if (camera_id < 1 || camera_id > 8 || client->slots[camera_id - 1].request_id != ticket) return CAM_CONTROL_UNKNOWN;
209 if (client->slots[index].request_id == ticket) { mask = client->slots[index].camera_mask; break; }
214 const uint8_t current = usher_control_client_camera_result(client, ticket, (uint8_t)(index + 1));
bool usher_control_client_hello(struct usher_control_client *client, const uint8_t *bytes, size_t size, uint32_t now_us)
Accept only a HELLO matching the current nonce-bound negotiation.
Definition camera_control.c:115
bool usher_control_encode_request(uint8_t *bytes, size_t size, const struct usher_control_request *request)
Encode one command payload with the fixed wire size and field order.
Definition camera_control.c:48
uint8_t usher_control_client_result(const struct usher_control_client *client, uint32_t ticket)
Aggregate per-camera results for one group ticket.
Definition camera_control.c:203
bool usher_control_client_ready(const struct usher_control_client *client, uint32_t now_us)
Check confirmed-session readiness and the bounded HELLO lease.
Definition camera_control.c:133
bool usher_control_encode_result(uint8_t *bytes, size_t size, const struct usher_control_result *result)
Encode one camera's correlated control result.
Definition camera_control.c:71
bool usher_control_decode_result(const uint8_t *bytes, size_t size, struct usher_control_result *result)
Validate and decode one camera result payload.
Definition camera_control.c:88
void usher_control_client_reset(struct usher_control_client *client, uint32_t nonce)
Reset session state and invalidate outstanding tickets without replay.
Definition camera_control.c:101
uint8_t usher_control_client_camera_result(const struct usher_control_client *client, uint32_t ticket, uint8_t camera_id)
Read one camera's status for a group request.
Definition camera_control.c:196
void usher_control_client_expire(struct usher_control_client *client, uint32_t now_us)
Mark expired pending commands UNKNOWN; never resubmit them.
Definition camera_control.c:138
bool usher_control_put_u32(uint8_t *bytes, size_t size, size_t offset, uint32_t value)
Encode a 32-bit value as four little-endian protocol bytes.
Definition camera_control.c:27
bool usher_control_get_u32(const uint8_t *bytes, size_t size, size_t offset, uint32_t *value)
Decode a bounded four-byte little-endian protocol value.
Definition camera_control.c:34
bool usher_control_value_valid(uint8_t command, uint8_t value)
Validate the command-specific legal value range.
Definition camera_control.c:42
void usher_control_client_commit(struct usher_control_client *client, const struct usher_control_request *request, uint32_t now_us)
Commit a prepared request after full-frame UART admission.
Definition camera_control.c:160
bool usher_control_client_prepare(struct usher_control_client *client, uint8_t mask, uint8_t command, uint8_t value, uint32_t now_us, struct usher_control_request *request)
Prepare a request without consuming its ticket before UART admission.
Definition camera_control.c:147
bool usher_control_client_receive(struct usher_control_client *client, const uint8_t *bytes, size_t size, uint32_t now_us)
Accept a result only when session, ticket, camera, and evidence correlate.
Definition camera_control.c:173
bool usher_control_decode_request(const uint8_t *bytes, size_t size, struct usher_control_request *request)
Validate and decode one fixed-size command payload.
Definition camera_control.c:61
Fixed-size camera-control wire codec and FC-side ticket state.
Handshake, capability cache, and eight-camera ticket state.
Definition camera_control.h:64
One addressed command request shared with the companion protocol.
Definition camera_control.h:36
Result evidence for one camera selected by a request mask.
Definition camera_control.h:44
Fixed pending/result slot retained for one addressable camera.
Definition camera_control.h:52
uint8_t camera_mask
Original command plus returned observation/status/evidence.
Definition camera_control.h:56
uint32_t request_id
Request ticket and monotonic send timestamp in microseconds.
Definition camera_control.h:54