From 87386bc16b2d422bc50487553e08b9fb9c0183cd Mon Sep 17 00:00:00 2001 From: Marcus Meissner Date: Wed, 2 Dec 2015 10:52:55 +0100 Subject: [PATCH] first stab at implementing a generic opcode emitter via config variables no data sending or receiving yet see https://github.com/gphoto/libgphoto2/issues/21 --- camlibs/ptp2/config.c | 47 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/camlibs/ptp2/config.c b/camlibs/ptp2/config.c index c4fefe688..235ff9c7d 100644 --- a/camlibs/ptp2/config.c +++ b/camlibs/ptp2/config.c @@ -5649,6 +5649,52 @@ _put_PowerDown(CONFIG_PUT_ARGS) return GP_OK; } +static int +_get_Generic_OPCode(CONFIG_GET_ARGS) { + gp_widget_new (GP_WIDGET_TEXT, _(menu->label), widget); + gp_widget_set_name (*widget,menu->name); + gp_widget_set_value (*widget, "0x1001,0xparam1,0xparam2"); + return GP_OK; +} + +static int +_put_Generic_OPCode(CONFIG_PUT_ARGS) +{ + PTPParams *params = &(camera->pl->params); + char *val, *x; + int opcode; + int nparams; + uint32_t xparams[5]; + uint16_t ret; + PTPContainer ptp; + + CR (gp_widget_get_value(widget, &val)); + + if (!sscanf(val,"0x%x", &opcode)) + return GP_ERROR_BAD_PARAMETERS; + nparams = 0; x = val; + while ((x = strchr(x,',')) && (nparams<5)) { + if (!sscanf(val,"0x%x", &xparams[nparams])) + return GP_ERROR_BAD_PARAMETERS; + nparams++; + } + ptp.Code = opcode; + ptp.Nparam = nparams; + ptp.Param1 = xparams[0]; + ptp.Param2 = xparams[1]; + ptp.Param3 = xparams[2]; + ptp.Param4 = xparams[3]; + ptp.Param5 = xparams[4]; + + /* FIXME: handle in data */ + + ret = ptp_transaction (params, &ptp, 0, 0, NULL, NULL); + + /* FIXME: handle out data (store locally?) */ + + return translate_ptp_result (ret); +} + static int _get_Sony_Movie(CONFIG_GET_ARGS) { int val; @@ -6540,6 +6586,7 @@ static struct submenu camera_actions_menu[] = { { N_("Movie Capture"), "movie", 0, 0, PTP_OC_InitiateOpenCapture, _get_OpenCapture, _put_OpenCapture }, { N_("Movie Capture"), "movie", 0, PTP_VENDOR_NIKON, PTP_OC_NIKON_StartMovieRecInCard, _get_Nikon_Movie, _put_Nikon_Movie }, { N_("Movie Capture"), "movie", 0, PTP_VENDOR_SONY, PTP_OC_SONY_SDIOConnect, _get_Sony_Movie, _put_Sony_Movie }, + { N_("PTP Opcode"), "opcode", 0, 0, PTP_OC_GetDeviceInfo, _get_Generic_OPCode, _put_Generic_OPCode }, { 0,0,0,0,0,0,0 }, };