Loading...
Searching...
No Matches
chdkbridge.c
Go to the documentation of this file.
55 int (*active_config)(const struct usbfs_device *, uint8_t *, size_t, const uint8_t **, size_t *);
61 int (*bulk_transfer)(struct usbfs_handle *, unsigned char, unsigned char *, int, int *, unsigned);
69};
159 if ((interrupted && !transport->closing_session) || !now || now >= transport->deadline_ms) return 0;
173 case USBFS_ERROR_NO_DEVICE: return "camera disconnected; check camera power, data cable and hub; rediscover with --list";
174 case USBFS_ERROR_ACCESS: return "grant the USHER service user read/write access to the camera USB device (plugdev); do not run the service as root";
175 case USBFS_ERROR_BUSY: return "selected desktop camera mount could not be released or another PTP client still owns the camera; no USB reset is attempted";
176 case USBFS_ERROR_TIMEOUT: return "check camera power, USB cable/hub, SD-card readiness and active scripts; a shot may already exist on SD";
177 case USBFS_ERROR_IO: return "check USB power and cable/hub integrity; other cameras are not reset";
265 fprintf(stderr, "USB receive failed: %s; %s\n", usbfs_error_name(result), usb_failure_hint(result));
355 if (transport->output_packet_size && (12 + outgoing_size) % transport->output_packet_size == 0 &&
371 size_t maximum = file ? (transport->max_download ? transport->max_download : MAX_DOWNLOAD) : capacity;
457 fprintf(stderr, "Recovering camera PTP state left by an earlier run (class reset, no USB port reset)\n");
474 if (result < 0) fprintf(stderr, "PTP device reset request failed: %s\n", usbfs_error_name(result));
532/** @brief Validate known message types and payload lengths, including empty-message zero padding. */
565/** @brief Sleep to a monotonic poll target without extending it on EINTR or exceeding the deadline. */
626 int script_length = snprintf(script, sizeof(script), "%s%s", enter_record ? record_mode_script : "", body);
643 fprintf(stderr, "Camera script startup transaction failed; execution state is unknown, not retried\n");
647 if (response.count >= 2 && response.parameters[1] == CHDK_ERROR_RUNNING && wait_script_idle(transport) &&
650 fprintf(stderr, "Camera script startup transaction failed; execution state is unknown, not retried\n");
789 "type(get_tick_count)~='function' or type(sleep)~='function' then error('missing playback API') end\n"
810 if (!run_script_operation(transport, retract_lens_script, result, sizeof(result), NULL, false) ||
822 "if type(policy)~='number' or policy<0 or policy>3 or policy%1~=0 then error('power policy unavailable') end\n"
823 "local report='idle_shutdown_policy='..tostring(policy)..'; keep_awake='..(policy==3 and '1' or '0')\n"
826 " if type(millivolts)=='number' then report=report..'; battery_mv='..tostring(millivolts) end\n"
832 " if type(celsius)=='number' and celsius>-100 then report=report..'; '..names[which+1]..'_c='..tostring(celsius) end\n"
838 " if ok and type(value)=='number' then report=report..'; '..entry[1]..'='..tostring(value) end\n"
844 " for _,entry in ipairs{{'focus_mode',props.FOCUS_MODE},{'af_lock',props.AF_LOCK},{'canon_mode',props.SHOOTING_MODE},{'iso_mode',props.ISO_MODE}} do\n"
847 " if valid and type(value)=='number' then report=report..'; '..entry[1]..'='..tostring(value) end\n"
854 " if valid and type(mode)=='number' then report=report..'; mode='..tostring(bitand(mode,255)) end\n"
856 "for _,entry in ipairs{{'overrides_off',2003},{'tv_ovr',1110},{'iso_ovr',1130},{'iso_ovr_koef',1131},{'sd_ovr_koef',1141},{'autoiso',1160}} do\n"
858 " if valid and type(value)=='number' then report=report..'; '..entry[1]..'='..tostring(value) end\n"
871 if (!run_script_operation(transport, power_status_script, result, sizeof(result), NULL, false) ||
928 "if type(os)~='table' or type(os.stat)~='function' or type(os.remove)~='function' then error('log filesystem API unavailable') end\n"
929 "if type(get_config_value)~='function' or get_config_value(1999)~=1 then error('Enable Lua native calls in CHDK menu, or use Save ROM crash log') end\n"
930 "if call_event_proc('SystemEventInit')==-1 and call_event_proc('System.Create')==-1 then error('log export initialization failed') end\n"
934 "if call_event_proc('GetLogToFile','A/ROMLOG.LOG',1)~=0 then error('GetLogToFile failed') end\n"
937 "if type(info)~='table' or type(info.size)~='number' or info.size<1 or info.size>65536 then error('missing or oversized ROM log') end\n"
979 size_t position = response.parameters[2] == UINT32_MAX ? download->cursor : response.parameters[2];
1096static bool focus_script(const struct focus_policy *focus, char *body, size_t capacity, bool exposure_cleanup)
1102 ((focus->mode == FOCUS_AUTO || focus->mode == FOCUS_MANUAL) && !focus->distance_present)) return false;
1104 if (focus->distance_present && snprintf(distance, sizeof(distance), "%d", focus->distance_mm) < 0) return false;
1108 "for _,name in ipairs{'set_mf','set_aflock','get_focus','get_focus_ok','get_shooting','press','release'} do\n"
1111 "if type(props.AF_LOCK)~='number' or type(props.FOCUS_MODE)~='number' then error('missing focus properties') end\n"
1114 " if type(get_sd_over_modes)~='function' or type(set_focus)~='function' then error('missing distance API') end\n"
1119 " if supported(4) then mode=3 elseif supported(2) then mode=2 else error('no MF/AFL distance support') end\n"
1139 " return get_prop(props.AF_LOCK)==(mode==2 and 1 or 0) and get_prop(props.FOCUS_MODE)==(mode==3 and 1 or 0)\n"
1149 " wait(function() return (mode==2 or get_prop(props.AF_LOCK)==0) and (mode==3 or get_prop(props.FOCUS_MODE)==0) end,'unlock rejected')\n"
1178static bool settings_script(const struct capture_settings *settings, char *body, size_t capacity)
1180 if (!focus_script(&settings->focus, body, capacity, exposure_requested(&settings->exposure))) return false;
1197 {"TV96", "set_tv96_direct", "get_tv96", "set_tv96_direct"}, {"SV96", "set_sv96", "get_sv96", "set_sv96"},
1198 {"AV96", "set_av96_direct", "get_av96", "set_av96_direct"}, {"ND", "set_nd_filter", "get_nd_current_ev96", "set_nd_filter"}
1221 "if type(real_iso)~='number' or real_iso%%1~=0 or real_iso<=0 or real_iso>32767 then error('invalid real ISO conversion') end\n",
1223 exposure->iso_kind == EXPOSURE_ISO_MARKET ? "iso_market_to_real" : "", exposure->values[index]);
1231 "if type(get_nd_present)~='function' or type(get_min_av96)~='function' or type(get_max_av96)~='function' then error('iris/range unavailable') end\n"
1232 "local iris_type=get_nd_present() if iris_type~=0 and iris_type~=2 then error('no verified iris capability') end\n");
1247 "if type(get_nd_present)~='function' or type(get_nd_value_ev96)~='function' then error('ND filter unavailable') end\n"
1248 "local nd_type=get_nd_present() if nd_type~=1 and nd_type~=2 then error('ND filter unavailable') end\n"
1249 "local nd_value=get_nd_value_ev96() if type(nd_value)~='number' or nd_value<=0 then error('unknown ND attenuation') end\n");
1266 " for _,slot in ipairs{2,3,7} do entry[slot]=_G[entry[slot]] if type(entry[slot])~='function' then error('missing '..entry[1]..' API') end end\n"
1267 " if type(entry[4])~='number' or type(entry[5])~='number' or entry[4]%%1~=0 or entry[5]%%1~=0 then error('invalid exposure conversion: '..entry[1]) end\n"
1271 "function restore() if get_shooting()==false then for _,entry in ipairs(overrides) do entry[7](entry[8]) end end end\n"
1274 " while get_shooting()~=false do if bitand(get_tick_count()-stopped,2147483647)>=1000 then error('exposure cleanup: camera still shooting') end sleep(20) end restore()\n"
1282 " if bitand(get_tick_count()-started,2147483647)>=exp_timeout then exp_fail('half-press timeout') end sleep(20)\n"
1287 " if type(low)~='number' or type(high)~='number' or low<=0 or high<=low or entry[5]<low or entry[5]>high then exp_fail('aperture outside verified iris range') end\n"
1296 " if type(actual)~='number' or actual~=actual or actual-entry[5]>entry[6] or actual-entry[5]<-entry[6] then bad=entry break end\n"
1298 " if bitand(get_tick_count()-started,2147483647)>=exp_timeout then exp_fail(bad and (bad[1]..' rejected; actual='..tostring(bad[3]())..'; expected='..bad[5]) or 'verification timeout') end\n"
1323 " if type(set_prop_str)~='function' or type(get_prop_str)~='function' then error('missing JPEG quality property API') end\n"
1328 "if type(get_mode)=='function' then local _,_,mode=get_mode() if type(mode)=='number' then capture_mode=bitand(mode,255) end end\n"
1330 " for index=#requested,1,-1 do if requested[index][1]=='ISO_MODE' then table.remove(requested,index) end end\n"
1337 "if type(get_config_value)~='function' or type(set_config_value)~='function' then error('missing keep-awake API') end\n"
1339 "if type(shutdown)~='number' or shutdown<0 or shutdown>3 or shutdown%%1~=0 then error('keep-awake setting unavailable') end\n"
1347 "local function setting(entry) return entry[3] and get_prop_str(props[entry[1]],4) or get_prop(props[entry[1]]) end\n"
1352 " if set_prop_str(props[entry[1]],entry[3])~=true then error('property rejected QUALITY') end\n"
1365 "if get_raw()~=(%u~=0) then set_raw(%u) end\nif get_raw()~=(%u~=0) then error('raw setting rejected') end\n",
1366 settings->values[CAMERA_SETTING_COUNT - 1], settings->values[CAMERA_SETTING_COUNT - 1], settings->values[CAMERA_SETTING_COUNT - 1]);
1394static bool configure_script(const struct capture_settings *settings, char *body, size_t capacity)
1398 int length = snprintf(body + used, capacity - used, "local report='Configured'\n%s%s%s%sreturn report\n",
1399 settings->keep_awake_present ? "report=report..'; keep_awake='..(get_config_value(1221)==3 and 1 or 0)\n" : "",
1413static bool configure_camera(struct transport *transport, const struct capture_settings *settings)
1418 (!settings->keep_awake_present && settings->focus.mode == FOCUS_UNCHANGED && !exposure_requested(&settings->exposure) ? strcmp(result, "Configured") :
1431static bool capture_script(const struct capture_settings *settings, char *body, size_t capacity)
1463static bool capture(struct transport *transport, FILE *file, const struct capture_settings *settings)
1485 "for _,name in ipairs{'get_usb_capture_support','get_usb_capture_target','init_usb_capture','set_usb_capture_timeout','write_usb_msg','read_usb_msg','get_drive_mode'} do\n"
1488 "if type(support)~='number' or support%%2~=1 then error('direct JPEG unsupported; USB capture mask='..tostring(support)) end\n"
1489 "local _,video=get_mode() if video or get_drive_mode()~=0 then error('single still-photo mode required') end\n"
1490 "if get_usb_capture_target()~=0 then error('remote capture already enabled; not replaced') end\n");
1499 "local function direct_release() if owned then init_usb_capture(0) set_usb_capture_timeout() owned=false end end\n"
1503 "if not write_usb_msg('Direct ready') then direct_release() error('direct readiness message failed') end\n"
1525static bool capture_direct(struct transport *transport, FILE *file, const struct capture_settings *settings)
1531 !direct_capture_script(settings, (unsigned)(transport->deadline_ms - now_ms), body, sizeof(body))) {
1640static bool find_interface(const struct usbfs_device *device, int *interface_number, int *alternate,
1712static bool parse_scaled(const char *text, unsigned scale, unsigned minimum, unsigned maximum, unsigned *value)
1972 if (!remaining_ms(transport)) return interrupted ? USBFS_ERROR_INTERRUPTED : USBFS_ERROR_TIMEOUT;
1985 int delay = deadline - now < DESKTOP_RECLAIM_POLL_MS ? (int)(deadline - now) : DESKTOP_RECLAIM_POLL_MS;
2009 " --power-status Read-only: report idle power-off prevention, battery and temperatures; fails unless prevention is Always.\n"
2010 " --romlog OUTPUT Export and download the Canon ROM crash log (max 64 KiB); no record mode, shoot, zoom or power-off.\n"
2016 " --port BUS-P[.P] Select physical USB port path from --list (survives device readdressing).\n"
2029 " --focus-mode MODE af: refocus; aflock: preserve/acquire lock; manual: fixed distance; auto: supported MF/AFL distance.\n"
2030 " --focus-distance MM|inf Distance in millimeters, 1..1000000, or infinity; requires manual/auto/aflock.\n"
2031 " --focus-timeout MS Total focus-wait budget, 50..60000 (default: 5000); less than --timeout.\n"
2032 " --focus-tolerance MM Distance readback tolerance, 0..100000 (default: 100); infinity requires -1 readback.\n\n"
2033 " --shutter SECONDS Shutter override: decimal seconds or fraction (e.g. 0.001 or 1/1000), 1 us..64 s.\n"
2045 "Lens retraction timing is camera-dependent; set Canon Lens Retraction to 0 sec. for immediate retraction.\n"
2059static bool publish_control_reply(unsigned descriptor, uint8_t command, uint8_t observed, uint8_t evidence)
2064 do { written = write((int)descriptor, reply, sizeof(reply)); } while (written < 0 && errno == EINTR);
2082 if (!parse_number(argv[2], 255, &helper_bus) || !parse_number(argv[3], 255, &helper_address)) return 2;
2138 !parse_signed(argv[index], apex_options[option].minimum, apex_options[option].maximum, &settings.exposure.values[parameter])) {
2139 fprintf(stderr, "Invalid, duplicate or conflicting value for %s\n", apex_options[option].name);
2147 for (size_t option = 0; option < sizeof(numeric_options) / sizeof(numeric_options[0]); ++option) {
2151 : parse_range(argv[index], numeric_options[option].minimum, numeric_options[option].maximum, numeric_options[option].value))) {
2168 if (control_result_fd || ++index >= argc || !parse_range(argv[index], 3, 31, &control_result_fd)
2203 if (settings.exposure.present[EXPOSURE_TV] || ++index >= argc || !parse_shutter(argv[index], &settings.exposure)) {
2204 fprintf(stderr, "--shutter requires one decimal/fraction from 1 us to 64 seconds; do not combine with --tv96\n");
2211 if (settings.exposure.present[EXPOSURE_SV] || ++index >= argc || !parse_number(argv[index], 32767, &iso)) {
2212 fprintf(stderr, "Choose exactly one --iso-real, --iso-market or --sv96 override; ISO requires 1..32767\n");
2221 fprintf(stderr, "--aperture requires one f-number from 1 to 64; do not combine with --av96\n");
2264 if (port_selection.depth || ++index >= argc || !parse_usb_port(argv[index], &port_selection)) {
2287 ((settings.focus.mode == FOCUS_MANUAL || settings.focus.mode == FOCUS_AUTO) && !settings.focus.distance_present) ||
2289 (settings.focus.mode != FOCUS_UNCHANGED && settings.focus.timeout_ms >= timeout_seconds * 1000)) {
2290 fprintf(stderr, "Focus requires an explicit compatible mode/distance and a focus timeout shorter than --timeout\n");
2294 (exposure_requested(&settings.exposure) && settings.exposure.timeout_ms >= timeout_seconds * 1000) ||
2296 fprintf(stderr, "Exposure limits require overrides and a shorter wait than --timeout; real ISO overrides conflict with nonzero --iso-mode\n");
2299 uint64_t requested_ms = settings.focus.mode == FOCUS_UNCHANGED ? 0 : settings.focus.timeout_ms;
2300 if (exposure_requested(&settings.exposure)) requested_ms += settings.exposure.timeout_ms + 1000U;
2305 requested_ms += (uint64_t)ceil(exp2(-(double)settings.exposure.values[EXPOSURE_TV] / 96.0) * 1000.0);
2307 fprintf(stderr, "--timeout must exceed combined focus/exposure waits, exposure cleanup and the requested shutter duration; leave time for record mode and download\n");
2311 (bus == 0) != (address == 0) || (port_selection.depth && bus) || action_count != 1 || (remote_download && !output) ||
2312 (romlog_requested && (!output || remote_download || direct_requested || settings_requested(&settings))) ||
2313 (direct_requested && (!output || remote_download || list_only || info_requested || zoom_requested || configure_requested || runtime_requested || power_requested)) ||
2315 (settings_requested(&settings) && (list_only || info_requested || zoom_requested || remote_download || runtime_requested || retract_requested || power_requested))) {
2316 fprintf(stderr, "Select one action; specify both --bus and --device OR --port. Use --help for usage\n");
2346 fprintf(stderr, "chdkbridge: USB device enumeration failed: %s\n", usbfs_error_name(usb_result));
2352 if (!remaining_ms(&transport)) { fprintf(stderr, "USB discovery cancelled or operation deadline reached\n"); goto cleanup; }
2362 printf("bus=%u device=%u Canon %04x:%04x", candidate.bus, candidate.address, candidate.vendor, candidate.product);
2365 for (int port = 0; port < candidate.depth; ++port) printf("%s%u", port ? "." : "", candidate.ports[port]);
2378 fprintf(stderr, "chdkbridge: USB device enumeration failed: %s\n", usbfs_error_name(usb_result));
2382 if (!matches) fprintf(stderr, "No matching Canon PTP camera on USB; check power, CHDK firmware, USB mode, data cable and selected port\n");
2386 if (!matches) fprintf(stderr, "No matching Canon PTP camera on USB; check power, CHDK firmware, USB mode, data cable and selected port; run --list\n");
2387 else fprintf(stderr, "Found %u matching Canon PTP cameras; use --list and select --port or --bus/--device\n", matches);
2409 fprintf(stderr, "Cannot open camera: %s; %s\n", usbfs_error_name(usb_result), usb_failure_hint(usb_result));
2418 fprintf(stderr, "Cannot claim camera: %s; %s\n", usbfs_error_name(usb_result), usb_failure_hint(usb_result));
2422 if (alternate && (usb_result = usb.set_alternate(&handle, interface_number, alternate)) != 0) {
2423 fprintf(stderr, "Cannot select camera interface setting: %s; %s\n", usbfs_error_name(usb_result), usb_failure_hint(usb_result));
2439 else fprintf(stderr, "Lens retract request failed or timed out; camera state may have changed, no automatic retry\n");
2464 if (!(romlog_requested ? download_romlog(&transport, file) : remote_download ? download_file(&transport, remote_download, file) :
2465 direct_requested ? capture_direct(&transport, file, &settings) : capture(&transport, file, &settings))) {
2474 if (!romlog_requested && (fread(signature, 1, 2, file) != 2 || signature[0] != 0xff || signature[1] != 0xd8 ||
2482 if (fstat(fileno(file), &status) != 0 || status.st_size < 1 || status.st_size > 65536) goto cleanup;
2488 if (link(temporary, output) != 0) { perror("Publishing output without overwrite"); goto cleanup; }
static void close_session(struct transport *transport)
Best-effort close of an owned session, even after cancellation, within one second.
Definition chdkbridge.c:429
static const char * script_error_name(uint32_t error)
Translate a CHDK script status for diagnostics.
Definition chdkbridge.c:521
static bool download_romlog(struct transport *transport, FILE *file)
Export and download the camera's bounded ROM crash log.
Definition chdkbridge.c:946
#define DESKTOP_SYMBOL(FIELD, NAME)
static bool parse_signed(const char *text, int minimum, int maximum, int *value)
Parse a bounded signed decimal command-line value.
Definition chdkbridge.c:1692
static bool download_direct_chunk(struct transport *transport, FILE *file, struct direct_download *download)
Receive one direct JPEG chunk into the private output stream.
Definition chdkbridge.c:961
static bool valid_script_message(const struct response *response, const uint8_t *message)
Validate known message types and payload lengths, including empty-message zero padding.
Definition chdkbridge.c:533
static void interrupt_handler(int signal_number)
Request cancellation without allocation, I/O, or USB calls in a signal handler.
Definition chdkbridge.c:134
static int claim_camera_interface(struct transport *transport, int interface_number, unsigned bus, unsigned address, bool(*release_mount)(struct transport *, unsigned, unsigned))
Claim an interface, optionally releasing its selected desktop mount.
Definition chdkbridge.c:1968
static bool configure_script(const struct capture_settings *settings, char *body, size_t capacity)
Build a configuration-only script with an observed-state report.
Definition chdkbridge.c:1394
static bool run_script(struct transport *transport, const char *body, char *result, size_t result_capacity)
Execute a capture-path script without direct-download output.
Definition chdkbridge.c:781
static unsigned remaining_ms(const struct transport *transport)
Compute the next USB call's timeout within the operation deadline.
Definition chdkbridge.c:156
static bool settings_requested(const struct capture_settings *settings)
Check whether a capture needs camera configuration before shooting.
Definition chdkbridge.c:1079
static bool configure_camera(struct transport *transport, const struct capture_settings *settings)
Apply settings without capturing a picture.
Definition chdkbridge.c:1413
static bool capture_direct(struct transport *transport, FILE *file, const struct capture_settings *settings)
Capture and stream a JPEG via CHDK's direct-download protocol.
Definition chdkbridge.c:1525
static struct @262112006143041137011017150364274145303116271316 usb
USB operations used by the application; tests substitute fakes.
static bool publish_control_reply(unsigned descriptor, uint8_t command, uint8_t observed, uint8_t evidence)
Emit the control operation's fixed-size binary receipt.
Definition chdkbridge.c:2059
int main(int argc, char **argv)
Select one camera, execute one operation, and release owned resources.
Definition chdkbridge.c:2078
static bool valid_camera_path(const char *path)
Validate a bounded printable camera pathname with no traversal components.
Definition chdkbridge.c:886
static void print_help(const char *program)
Print build identity and CLI usage without initializing USB.
Definition chdkbridge.c:1993
static bool parse_scaled(const char *text, unsigned scale, unsigned minimum, unsigned maximum, unsigned *value)
Parse a decimal setting and convert it to rounded integer units.
Definition chdkbridge.c:1712
static volatile sig_atomic_t interrupted
Signal-safe cancellation flag checked before blocking USB calls.
Definition chdkbridge.c:131
static bool parse_shutter(const char *text, struct exposure_policy *exposure)
Convert a decimal or rational shutter time to an exposure ratio.
Definition chdkbridge.c:1729
static int unmount_desktop_camera(unsigned bus, unsigned address)
Resolve one optional desktop camera mount and invoke its unmount.
Definition chdkbridge.c:1865
static void encode32(uint8_t *bytes, uint32_t value)
Encode a wire value into four writable bytes.
Definition chdkbridge.c:209
static bool power_status(struct transport *transport)
Print the camera's idle power-off policy and available telemetry.
Definition chdkbridge.c:867
static bool transaction(struct transport *transport, uint16_t operation, const uint32_t *parameters, size_t parameter_count, const uint8_t *outgoing, size_t outgoing_size, uint8_t *incoming, size_t capacity, FILE *file, struct response *response)
Perform command, optional data, and response phases for one PTP operation.
Definition chdkbridge.c:329
static const char * usb_failure_hint(int error)
Select a recovery hint for a USB transport failure.
Definition chdkbridge.c:170
static const char * ptp_response_name(uint16_t code)
Describe standard PTP response failures without triggering recovery actions.
Definition chdkbridge.c:298
static bool chdk_call(struct transport *transport, uint32_t command, uint32_t argument, const uint8_t *outgoing, size_t size, uint8_t *incoming, size_t capacity, FILE *file, struct response *response)
Place a CHDK subcommand and argument in vendor operation 0x9999.
Definition chdkbridge.c:419
static bool valid_ptp_interface(const struct usbfs_interface *descriptor, uint8_t *input, uint8_t *output)
Validate one USB still-image interface without opening the device.
Definition chdkbridge.c:1589
static bool find_interface(const struct usbfs_device *device, int *interface_number, int *alternate, uint8_t *input, uint8_t *output, unsigned *output_packet_size)
Find a still-image PTP interface and its bulk endpoints.
Definition chdkbridge.c:1640
static bool settings_script(const struct capture_settings *settings, char *body, size_t capacity)
Assemble bounded Lua for applying the requested camera settings.
Definition chdkbridge.c:1178
static bool refill_buffer(struct transport *transport)
Refill empty bounded USB storage without replaying a command.
Definition chdkbridge.c:245
static bool direct_capture_script(const struct capture_settings *settings, unsigned timeout_ms, char *body, size_t capacity)
Build the direct JPEG handshake and its camera-side cleanup.
Definition chdkbridge.c:1481
int(* control_transfer)(struct usbfs_handle *, uint8_t, uint8_t, uint16_t, uint16_t, unsigned char *, uint16_t, unsigned)
Definition chdkbridge.c:62
static void encode16(uint8_t *bytes, uint16_t value)
Encode a wire value into two writable bytes.
Definition chdkbridge.c:200
static bool retract_lens(struct transport *transport)
Ask the camera to enter playback and confirm the resulting mode.
Definition chdkbridge.c:807
static bool parse_range(const char *text, unsigned minimum, unsigned maximum, unsigned *value)
Parse unsigned decimal CLI input with inclusive bounds.
Definition chdkbridge.c:1668
static bool release_desktop_camera(struct transport *transport, unsigned bus, unsigned address)
Supervise a targeted desktop unmount helper.
Definition chdkbridge.c:1919
static bool set_zoom(struct transport *transport, unsigned level, uint8_t *observed)
Set normalized optical zoom without taking or downloading a photo.
Definition chdkbridge.c:1550
static bool focus_script(const struct focus_policy *focus, char *body, size_t capacity, bool exposure_cleanup)
Build the focus setup and readback portion of a CHDK script.
Definition chdkbridge.c:1096
static bool download_file(struct transport *transport, const char *remote_path, FILE *file)
Stream an existing SD-card file without executing a camera script.
Definition chdkbridge.c:913
static uint64_t monotonic_ms(void)
Read a wall-clock-independent time base; return zero if the clock fails.
Definition chdkbridge.c:141
static bool parse_usb_port(const char *text, struct usb_port_selection *selection)
Parse a stable USB bus and port-chain selector.
Definition chdkbridge.c:1761
static bool run_script_operation(struct transport *transport, const char *body, char *result, size_t result_capacity, FILE *direct_file, bool enter_record)
Run camera-side Lua and wait for its correlated string return value.
Definition chdkbridge.c:621
static bool exposure_requested(const struct exposure_policy *exposure)
Check whether an explicit exposure override is present.
Definition chdkbridge.c:1068
int(* active_config)(const struct usbfs_device *, uint8_t *, size_t, const uint8_t **, size_t *)
Definition chdkbridge.c:55
static bool send_packet(struct transport *transport, uint8_t *bytes, size_t length)
Submit one complete, small outbound PTP container.
Definition chdkbridge.c:223
static bool camera_info(struct transport *transport)
Report CHDK protocol and script capabilities without executing a script.
Definition chdkbridge.c:502
static uint32_t decode32(const uint8_t *bytes)
Decode a 32-bit little-endian value without native-endian casts.
Definition chdkbridge.c:191
static bool capture(struct transport *transport, FILE *file, const struct capture_settings *settings)
Capture to the camera's SD card and download the resulting JPEG.
Definition chdkbridge.c:1463
static bool capture_script(const struct capture_settings *settings, char *body, size_t capacity)
Build the ordinary SD-backed still-capture script.
Definition chdkbridge.c:1431
static uint16_t decode16(const uint8_t *bytes)
Decode a 16-bit little-endian value without alignment assumptions.
Definition chdkbridge.c:184
static bool parse_number(const char *text, unsigned maximum, unsigned *value)
Parse a positive CLI number; zero is reserved for unspecified selection.
Definition chdkbridge.c:1680
int(* bulk_transfer)(struct usbfs_handle *, unsigned char, unsigned char *, int, int *, unsigned)
Definition chdkbridge.c:61
static bool usb_port_matches(const struct usb_port_selection *selection, unsigned bus, const uint8_t *ports, int depth)
Compare a discovered device with the optional port selector.
Definition chdkbridge.c:1789
static bool desktop_camera_uri(const struct desktop_api *api, const char *device, char *uri, size_t capacity)
Find the unique desktop mount attached to the selected USB node.
Definition chdkbridge.c:1821
static bool wait_script_poll(const struct transport *transport, unsigned interval_ms)
Sleep to a monotonic poll target without extending it on EINTR or exceeding the deadline.
Definition chdkbridge.c:566
int(* devices_next)(struct usbfs_devices *, struct usbfs_device *)
Definition chdkbridge.c:53
static bool receive_bytes(struct transport *transport, uint8_t *destination, size_t length)
Read an exact bounded payload across arbitrary USB transfer splits.
Definition chdkbridge.c:281
static bool recover_ptp(struct transport *transport, int interface_number)
Clear a session or stale data left by an interrupted earlier run.
Definition chdkbridge.c:454
static bool wait_script_idle(struct transport *transport)
Wait within the deadline until no camera script is running; never interrupts one.
Definition chdkbridge.c:586
Source fallback for CHDKbridge build identity.
Shoot to the camera SD card and stream the resulting JPEG to a local file.
Definition chdkbridge.c:1018
Definition chdkbridge.c:1055
Definition chdkbridge.c:1799
char *(* identifier_get)(void *, const char *)
Definition chdkbridge.c:1804
void(* list_free_full)(void *, void(*)(void *))
Definition chdkbridge.c:1810
Definition chdkbridge.c:121
Definition chdkbridge.c:1047
Definition chdkbridge.c:1037
Validated successful PTP response and optional data-phase length.
Definition chdkbridge.c:116
Definition chdkbridge.c:1750
One enumerated USB device; a value copy, valid after enumeration ends.
Definition usbfs.h:73
Definition usbfs.h:92
Definition usbfs.h:81
Definition usbfs.h:86
Minimal header-only Linux usbfs access for one CHDKbridge camera.
static bool usbfs_next_interface(const uint8_t *config, size_t length, size_t *offset, struct usbfs_interface *interface)
Return the next complete interface/alternate setting in a configuration.
Definition usbfs.h:293
static int usbfs_clear_halt(struct usbfs_handle *handle, unsigned char endpoint)
Clear a halted endpoint of a claimed interface; data toggles are reset by the kernel.
Definition usbfs.h:465
static bool usbfs_available(void)
True when sysfs device listing and usbfs nodes are reachable.
Definition usbfs.h:127
static const char * usbfs_error_name(int error)
Get the diagnostic name of a usbfs result.
Definition usbfs.h:107
static int usbfs_release_interface(struct usbfs_handle *handle, int interface)
Release the numbered interface on an open device.
Definition usbfs.h:411
static int usbfs_bulk_transfer(struct usbfs_handle *handle, unsigned char endpoint, unsigned char *data, int length, int *transferred, unsigned timeout)
Synchronous bulk transfer with libusb_bulk_transfer() semantics.
Definition usbfs.h:563
static int usbfs_active_config(const struct usbfs_device *device, uint8_t *buffer, size_t capacity, const uint8_t **config, size_t *config_length)
Read the active configuration into buffer; config points inside it.
Definition usbfs.h:256
static void usbfs_devices_close(struct usbfs_devices *devices)
Release the sysfs enumeration stream.
Definition usbfs.h:225
static int usbfs_devices_open(struct usbfs_devices *devices)
Start a streaming sysfs enumeration.
Definition usbfs.h:192
static int usbfs_control_transfer(struct usbfs_handle *handle, uint8_t request_type, uint8_t request, uint16_t value, uint16_t index, unsigned char *data, uint16_t length, unsigned timeout)
Synchronous control transfer on endpoint zero.
Definition usbfs.h:444
static int usbfs_open(const struct usbfs_device *device, struct usbfs_handle *handle)
Open the device node, rejecting a node now owned by a different device.
Definition usbfs.h:343
static int usbfs_set_alternate(struct usbfs_handle *handle, int interface, int alternate)
Select an alternate setting for an interface.
Definition usbfs.h:423
static int usbfs_devices_next(struct usbfs_devices *devices, struct usbfs_device *device)
Definition usbfs.h:200
static int usbfs_claim_interface(struct usbfs_handle *handle, int interface)
Claim without detaching another owner; EBUSY is reported to the caller.
Definition usbfs.h:400
static void usbfs_close(struct usbfs_handle *handle)
Close the node; the kernel releases claimed interfaces and kills pending URBs.
Definition usbfs.h:371