diff options
author | Marcus Meissner <marcus@jet.franken.de> | 2012-04-07 15:49:54 +0000 |
---|---|---|
committer | Marcus Meissner <marcus@jet.franken.de> | 2012-04-07 15:49:54 +0000 |
commit | 01b54d1750d8328d14d8c88d000bbae3cf69460a (patch) | |
tree | 7d4cca52aeb4dc0cecd3237b8214c88de7c6b0ad | |
parent | 26995ff508e3744d04e8325c3069e8b6ac7dfa96 (diff) | |
download | libgphoto2-01b54d1750d8328d14d8c88d000bbae3cf69460a.tar.gz |
customfuncex handling
git-svn-id: https://svn.code.sf.net/p/gphoto/code/branches/libgphoto2-2_4/libgphoto2@13963 67ed7778-7388-44ab-90cf-0a291f65f57c
-rw-r--r-- | camlibs/ptp2/config.c | 1 | ||||
-rw-r--r-- | camlibs/ptp2/ptp-pack.c | 47 | ||||
-rw-r--r-- | camlibs/ptp2/ptp.c | 9 |
3 files changed, 55 insertions, 2 deletions
diff --git a/camlibs/ptp2/config.c b/camlibs/ptp2/config.c index e179bd441..391cfdf5c 100644 --- a/camlibs/ptp2/config.c +++ b/camlibs/ptp2/config.c @@ -5196,6 +5196,7 @@ static struct submenu camera_settings_menu[] = { { N_("Artist"), "artist", PTP_DPC_CANON_EOS_Artist, PTP_VENDOR_CANON, PTP_DTC_STR, _get_STR, _put_STR}, { N_("Copyright"), "copyright", PTP_DPC_CANON_EOS_Copyright, PTP_VENDOR_CANON, PTP_DTC_STR, _get_STR, _put_STR}, { N_("Clean Sensor"), "cleansensor", PTP_DPC_NIKON_CleanImageSensor, PTP_VENDOR_CANON, PTP_DTC_UINT8, _get_Nikon_CleanSensor, _put_Nikon_CleanSensor}, + { N_("Custom Functions Ex"), "customfuncex", PTP_DPC_CANON_EOS_CustomFuncEx, PTP_VENDOR_CANON, PTP_DTC_STR, _get_STR, _put_STR}, /* virtual */ { N_("Fast Filesystem"), "fastfs", 0, PTP_VENDOR_NIKON, 0, _get_Nikon_FastFS, _put_Nikon_FastFS }, diff --git a/camlibs/ptp2/ptp-pack.c b/camlibs/ptp2/ptp-pack.c index 9d698b8a6..b46401b68 100644 --- a/camlibs/ptp2/ptp-pack.c +++ b/camlibs/ptp2/ptp-pack.c @@ -1348,6 +1348,41 @@ ptp_pack_EOS_ImageFormat (PTPParams* params, unsigned char* data, uint16_t value return s; } +static inline char* +ptp_unpack_EOS_CustomFuncEx (PTPParams* params, unsigned char** data ) +{ + uint32_t s = dtoh32a( *data ); + uint32_t n = s/4, i; + char* str = (char*)malloc( s ); // n is size in uint32, average len(itoa(i)) < 4 -> alloc n chars + if (!str) + return str; + char* p = str; + + for (i=0; i < n; ++i) + p += sprintf(p, "%x,", dtoh32a( *data + 4*i )); + + return str; +} + +static inline uint32_t +ptp_pack_EOS_CustomFuncEx (PTPParams* params, unsigned char* data, char* str) +{ + uint32_t s = strtoul(str, NULL, 16); + uint32_t n = s/4, i, v; + + if (!data) + return s; + + for (i=0; i<n; i++) + { + v = strtoul(str, &str, 16); + str++; // skip the ',' delimiter + htod32a(data + i*4, v); + } + + return s; +} + /* PTP EOS Changes Entry unpack */ @@ -1668,7 +1703,6 @@ ptp_unpack_CANON_changes (PTPParams *params, unsigned char* data, int datasize, case PTP_DPC_CANON_EOS_MovSize: case PTP_DPC_CANON_EOS_DepthOfField: case PTP_DPC_CANON_EOS_LvViewTypeSelect: - case PTP_DPC_CANON_EOS_CustomFuncEx: dpd->DataType = PTP_DTC_UINT32; ptp_debug (params, "event %d: Unknown EOS property %04x, datasize is %d, using uint32", i ,proptype, size-PTP_ece_Prop_Val_Data); if ((size-PTP_ece_Prop_Val_Data) % sizeof(uint32_t) != 0) @@ -1681,6 +1715,7 @@ ptp_unpack_CANON_changes (PTPParams *params, unsigned char* data, int datasize, case PTP_DPC_CANON_EOS_ImageFormatCF: case PTP_DPC_CANON_EOS_ImageFormatSD: case PTP_DPC_CANON_EOS_ImageFormatExtHD: + case PTP_DPC_CANON_EOS_CustomFuncEx: break; default: ptp_debug (params, "event %d: Unknown EOS property %04x, datasize is %d", i ,proptype, size-PTP_ece_Prop_Val_Data); @@ -1724,7 +1759,7 @@ ptp_unpack_CANON_changes (PTPParams *params, unsigned char* data, int datasize, break; } - /* ImageFormat special handling (WARNING: dont move this in front of the dpd->DataType switch!) */ + /* ImageFormat and customFuncEx special handling (WARNING: dont move this in front of the dpd->DataType switch!) */ switch (proptype) { case PTP_DPC_CANON_EOS_ImageFormat: case PTP_DPC_CANON_EOS_ImageFormatCF: @@ -1735,6 +1770,14 @@ ptp_unpack_CANON_changes (PTPParams *params, unsigned char* data, int datasize, dpd->CurrentValue.u16 = dpd->FactoryDefaultValue.u16; ptp_debug (params,"event %d: decoded imageformat, currentvalue of %x is %x", i, proptype, dpd->CurrentValue.u16); break; + case PTP_DPC_CANON_EOS_CustomFuncEx: + dpd->DataType = PTP_DTC_STR; + if (dpd->FactoryDefaultValue.str) free (dpd->FactoryDefaultValue.str); + if (dpd->CurrentValue.str) free (dpd->CurrentValue.str); + dpd->FactoryDefaultValue.str = ptp_unpack_EOS_CustomFuncEx( params, &data ); + dpd->CurrentValue.str = strdup( (char*)dpd->FactoryDefaultValue.str ); + ptp_debug (params,"event %d: decoded custom function, currentvalue of %x is %s", i, proptype, dpd->CurrentValue.str); + break; } break; diff --git a/camlibs/ptp2/ptp.c b/camlibs/ptp2/ptp.c index 9f2ec3637..856000217 100644 --- a/camlibs/ptp2/ptp.c +++ b/camlibs/ptp2/ptp.c @@ -1976,6 +1976,15 @@ ptp_canon_eos_setdevicepropvalue (PTPParams* params, params->canon_props[i].dpd.CurrentValue.u16 = value->u16; ptp_pack_EOS_ImageFormat( params, data + 8, value->u16 ); break; + case PTP_DPC_CANON_EOS_CustomFuncEx: + /* special handling of CustomFuncEx properties */ + ptp_debug (params, "ptp2/ptp_canon_eos_setdevicepropvalue: setting EOS prop %x to %s",propcode,value->str); + size = 8 + ptp_pack_EOS_CustomFuncEx( params, NULL, value->str ); + data = malloc( size ); + if (!data) return PTP_RC_GeneralError; + params->canon_props[i].dpd.CurrentValue.str = strdup( value->str ); + ptp_pack_EOS_CustomFuncEx( params, data + 8, value->str ); + break; default: if (datatype != PTP_DTC_STR) { data = calloc(sizeof(uint32_t),3); |