📄 ptp.c
字号:
}/** * ptp_sendobjectinfo: * params: PTPParams* * uint32_t* store - destination StorageID on Responder * uint32_t* parenthandle - Parent ObjectHandle on responder * uint32_t* handle - see Return values * PTPObjectInfo* objectinfo- ObjectInfo that is to be sent * * Sends ObjectInfo of file that is to be sent via SendFileObject. * * Return values: Some PTP_RC_* code. * Upon success : uint32_t* store - Responder StorageID in which * object will be stored * uint32_t* parenthandle- Responder Parent ObjectHandle * in which the object will be stored * uint32_t* handle - Responder's reserved ObjectHandle * for the incoming object **/uint16_tptp_sendobjectinfo (PTPParams* params, uint32_t* store, uint32_t* parenthandle, uint32_t* handle, PTPObjectInfo* objectinfo){ uint16_t ret; PTPContainer ptp; unsigned char* oidata=NULL; uint32_t size; PTP_CNT_INIT(ptp); ptp.Code=PTP_OC_SendObjectInfo; ptp.Param1=*store; ptp.Param2=*parenthandle; ptp.Nparam=2; size=ptp_pack_OI(params, objectinfo, &oidata); ret = ptp_transaction(params, &ptp, PTP_DP_SENDDATA, size, &oidata, NULL); free(oidata); *store=ptp.Param1; *parenthandle=ptp.Param2; *handle=ptp.Param3; return ret;}/** * ptp_sendobject: * params: PTPParams* * char* object - contains the object that is to be sent * uint32_t size - object size * * Sends object to Responder. * * Return values: Some PTP_RC_* code. * */uint16_tptp_sendobject (PTPParams* params, unsigned char* object, uint32_t size){ PTPContainer ptp; PTP_CNT_INIT(ptp); ptp.Code=PTP_OC_SendObject; ptp.Nparam=0; return ptp_transaction(params, &ptp, PTP_DP_SENDDATA, size, &object, NULL);}/** * ptp_sendobject_fromfd: * params: PTPParams* * fd - File descriptor to read() object from * uint32_t size - File/object size * * Sends object from file descriptor by consecutive reads from this * descriptor. * * Return values: Some PTP_RC_* code. **/uint16_tptp_sendobject_fromfd (PTPParams* params, int fd, uint32_t size){ PTPContainer ptp; PTP_CNT_INIT(ptp); ptp.Code=PTP_OC_SendObject; ptp.Nparam=0; return ptp_transaction_fd(params, &ptp, PTP_DP_SENDDATA, size, fd, NULL);}/** * ptp_initiatecapture: * params: PTPParams* * storageid - destination StorageID on Responder * ofc - object format code * * Causes device to initiate the capture of one or more new data objects * according to its current device properties, storing the data into store * indicated by storageid. If storageid is 0x00000000, the object(s) will * be stored in a store that is determined by the capturing device. * The capturing of new data objects is an asynchronous operation. * * Return values: Some PTP_RC_* code. **/uint16_tptp_initiatecapture (PTPParams* params, uint32_t storageid, uint32_t ofc){ PTPContainer ptp; PTP_CNT_INIT(ptp); ptp.Code=PTP_OC_InitiateCapture; ptp.Param1=storageid; ptp.Param2=ofc; ptp.Nparam=2; return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL);}uint16_tptp_getdevicepropdesc (PTPParams* params, uint16_t propcode, PTPDevicePropDesc* devicepropertydesc){ PTPContainer ptp; uint16_t ret; unsigned int len; unsigned char* dpd=NULL; PTP_CNT_INIT(ptp); ptp.Code=PTP_OC_GetDevicePropDesc; ptp.Param1=propcode; ptp.Nparam=1; len=0; ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &dpd, &len); if (ret == PTP_RC_OK) ptp_unpack_DPD(params, dpd, devicepropertydesc, len); free(dpd); return ret;}uint16_tptp_getdevicepropvalue (PTPParams* params, uint16_t propcode, PTPPropertyValue* value, uint16_t datatype){ PTPContainer ptp; uint16_t ret; unsigned int len; int offset; unsigned char* dpv=NULL; PTP_CNT_INIT(ptp); ptp.Code=PTP_OC_GetDevicePropValue; ptp.Param1=propcode; ptp.Nparam=1; len=offset=0; ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &dpv, &len); if (ret == PTP_RC_OK) ptp_unpack_DPV(params, dpv, &offset, len, value, datatype); free(dpv); return ret;}uint16_tptp_setdevicepropvalue (PTPParams* params, uint16_t propcode, PTPPropertyValue *value, uint16_t datatype){ PTPContainer ptp; uint16_t ret; uint32_t size; unsigned char* dpv=NULL; PTP_CNT_INIT(ptp); ptp.Code=PTP_OC_SetDevicePropValue; ptp.Param1=propcode; ptp.Nparam=1; size=ptp_pack_DPV(params, value, &dpv, datatype); ret=ptp_transaction(params, &ptp, PTP_DP_SENDDATA, size, &dpv, NULL); free(dpv); return ret;}/** * ptp_ek_sendfileobjectinfo: * params: PTPParams* * uint32_t* store - destination StorageID on Responder * uint32_t* parenthandle - Parent ObjectHandle on responder * uint32_t* handle - see Return values * PTPObjectInfo* objectinfo- ObjectInfo that is to be sent * * Sends ObjectInfo of file that is to be sent via SendFileObject. * * Return values: Some PTP_RC_* code. * Upon success : uint32_t* store - Responder StorageID in which * object will be stored * uint32_t* parenthandle- Responder Parent ObjectHandle * in which the object will be stored * uint32_t* handle - Responder's reserved ObjectHandle * for the incoming object **/uint16_tptp_ek_sendfileobjectinfo (PTPParams* params, uint32_t* store, uint32_t* parenthandle, uint32_t* handle, PTPObjectInfo* objectinfo){ uint16_t ret; PTPContainer ptp; unsigned char* oidata=NULL; uint32_t size; PTP_CNT_INIT(ptp); ptp.Code=PTP_OC_EK_SendFileObjectInfo; ptp.Param1=*store; ptp.Param2=*parenthandle; ptp.Nparam=2; size=ptp_pack_OI(params, objectinfo, &oidata); ret=ptp_transaction(params, &ptp, PTP_DP_SENDDATA, size, &oidata, NULL); free(oidata); *store=ptp.Param1; *parenthandle=ptp.Param2; *handle=ptp.Param3; return ret;}/** * ptp_ek_getserial: * params: PTPParams* * char** serial - contains the serial number of the camera * uint32_t* size - contains the string length * * Gets the serial number from the device. (ptp serial) * * Return values: Some PTP_RC_* code. * */uint16_tptp_ek_getserial (PTPParams* params, unsigned char **data, unsigned int *size){ PTPContainer ptp; PTP_CNT_INIT(ptp); ptp.Code = PTP_OC_EK_GetSerial; ptp.Nparam = 0; return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, data, size); }/** * ptp_ek_setserial: * params: PTPParams* * char* serial - contains the new serial number * uint32_t size - string length * * Sets the serial number of the device. (ptp serial) * * Return values: Some PTP_RC_* code. * */uint16_tptp_ek_setserial (PTPParams* params, unsigned char *data, unsigned int size){ PTPContainer ptp; PTP_CNT_INIT(ptp); ptp.Code = PTP_OC_EK_SetSerial; ptp.Nparam = 0; return ptp_transaction(params, &ptp, PTP_DP_SENDDATA, size, &data, NULL); }/* unclear what it does yet */uint16_tptp_ek_9007 (PTPParams* params, unsigned char **data, unsigned int *size){ PTPContainer ptp; PTP_CNT_INIT(ptp); ptp.Code = 0x9007; ptp.Nparam = 0; return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, data, size); }/* unclear what it does yet */uint16_tptp_ek_9009 (PTPParams* params, uint32_t *p1, uint32_t *p2){ PTPContainer ptp; uint16_t ret; PTP_CNT_INIT(ptp); ptp.Code = 0x9009; ptp.Nparam = 0; ret = ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL); *p1 = ptp.Param1; *p2 = ptp.Param2; return ret;}/* unclear yet, but I guess it returns the info from 9008 */uint16_tptp_ek_900c (PTPParams* params, unsigned char **data, unsigned int *size){ PTPContainer ptp; PTP_CNT_INIT(ptp); ptp.Code = 0x900c; ptp.Nparam = 0; return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, data, size); /* returned data is 16bit,16bit,32bit,32bit */}/** * ptp_ek_settext: * params: PTPParams* * PTPEKTextParams* - contains the texts to display. * * Displays the specified texts on the TFT of the camera. * * Return values: Some PTP_RC_* code. * */uint16_tptp_ek_settext (PTPParams* params, PTPEKTextParams *text){ PTPContainer ptp; uint16_t ret; unsigned int size; unsigned char *data; PTP_CNT_INIT(ptp); ptp.Code = PTP_OC_EK_SetText; ptp.Nparam = 0; if (0 == (size = ptp_pack_EK_text(params, text, &data))) return PTP_ERROR_BADPARAM; ret = ptp_transaction(params, &ptp, PTP_DP_SENDDATA, size, &data, NULL); free(data); return ret;}/** * ptp_ek_sendfileobject: * params: PTPParams* * char* object - contains the object that is to be sent * uint32_t size - object size * * Sends object to Responder. * * Return values: Some PTP_RC_* code. * */uint16_tptp_ek_sendfileobject (PTPParams* params, unsigned char* object, uint32_t size){ PTPContainer ptp; PTP_CNT_INIT(ptp); ptp.Code=PTP_OC_EK_SendFileObject; ptp.Nparam=0; return ptp_transaction(params, &ptp, PTP_DP_SENDDATA, size, &object, NULL);}/************************************************************************* * * Canon PTP extensions support * * (C) Nikolai Kopanygin 2003 * *************************************************************************//** * ptp_canon_getpartialobjectinfo: * params: PTPParams* * uint32_t handle - ObjectHandle * uint32_t p2 - Not fully understood parameter * 0 - returns full size * 1 - returns thumbnail size (or EXIF?) * * Gets form the responder the size of the specified object. * * Return values: Some PTP_RC_* code. * Upon success : uint32_t* size - The object size * uint32_t* rp2 - Still unknown return parameter * (perhaps upper 32bit of size) * * **/uint16_tptp_canon_getpartialobjectinfo (PTPParams* params, uint32_t handle, uint32_t p2, uint32_t* size, uint32_t* rp2) { uint16_t ret; PTPContainer ptp; PTP_CNT_INIT(ptp); ptp.Code=PTP_OC_CANON_GetPartialObjectInfo; ptp.Param1=handle; ptp.Param2=p2; ptp.Nparam=2; ret=ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL); *size=ptp.Param1; *rp2=ptp.Param2; return ret;}/** * ptp_canon_get_mac_address: * params: PTPParams* * value 0 works. * Gets the MAC address of the wireless transmitter. * * Return values: Some PTP_RC_* code. * Upon success : unsigned char* mac - The MAC address * **/uint16_tptp_canon_get_mac_address (PTPParams* params, unsigned char **mac){ PTPContainer ptp; unsigned int size = 0; PTP_CNT_INIT(ptp); ptp.Code=PTP_OC_CANON_GetMACAddress; ptp.Nparam=0; *mac = NULL; return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, mac, &size);}/** * ptp_canon_get_directory: * params: PTPParams* * Gets the full directory of the camera. * * Return values: Some PTP_RC_* code. * Upon success : PTPObjectHandles *handles - filled out with handles * PTPObjectInfo **oinfos - allocated array of PTP Object Infos * uint32_t **flags - allocated array of CANON Flags * **/uint16_tptp_canon_get_directory (PTPParams* params, PTPObjectHandles *handles, PTPObjectInfo **oinfos, /* size(handles->n) */ uint32_t **flags /* size(handles->n) */) { PTPContainer ptp; unsigned char *dir = NULL; unsigned int size = 0; uint16_t ret; PTP_CNT_INIT(ptp); ptp.Code=PTP_OC_CANON_GetDirectory; ptp.Nparam=0; ret = ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &dir, &size); if (ret != PTP_RC_OK) return ret; ret = ptp_unpack_canon_directory(params, dir, ptp.Param1, handles, oinfos, flags); free (dir); return ret;}/** * ptp_canon_setobjectarchive: * * params: PTPParams* * uint32_t objectid * uint32_t flags * * Return values: Some PTP_RC_* code. * **/uint16_tptp_canon_setobjectarchive (PTPParams* params, uint32_t oid, uint32_t flags){ PTPContainer ptp; PTP_CNT_INIT(ptp); ptp.Code=PTP_OC_CANON_SetObjectArchive; ptp.Nparam=2; ptp.Param1=oid; ptp.Param2=flags; return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL);}/** * ptp_canon_startshootingmode: * params: PTPParams* * * Starts shooting session. It emits a StorageInfoChanged * event via the interrupt pipe and pushes the StorageInfoChanged * and CANON_CameraModeChange events onto the event stack * (see operation PTP_OC_CANON_CheckEvent). * * Return values: Some PTP_RC_* code. * **/uint16_tptp_canon_startshootingmode (PTPParams* params){ PTPContainer ptp; PTP_CNT_INIT(ptp); ptp.Code=PTP_OC_CANON_StartShootingMode; ptp.Nparam=0; return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL);}/** * ptp_canon_initiate_direct_transfer: * params: PTPParams* * uint32_t *out *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -