📄 ptp.c
字号:
{ uint16_t ret; PTPContainer ptp; char* data=NULL; PTP_CNT_INIT(ptp); ptp.Code=PTP_OC_CANON_GetChanges; ptp.Nparam=0; ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &data); if (ret == PTP_RC_OK) *propnum=ptp_unpack_uint16_t_array(params,data,0,props); free(data); return ret;}/** * ptp_canon_getfolderentries: * * This command reads a specified object's record in a device's filesystem, * or the records of all objects belonging to a specified folder (association). * * params: PTPParams* * uint32_t store - StorageID, * uint32_t p2 - Yet unknown (0 value works OK) * uint32_t parent - Parent Object Handle * # If Parent Object Handle is 0xffffffff, * # the Parent Object is the top level folder. * uint32_t handle - Object Handle * # If Object Handle is 0, the records of all objects * # belonging to the Parent Object are read. * # If Object Handle is not 0, only the record of this * # Object is read. * * Return values: Some PTP_RC_* code. * PTPCANONFolderEntry** entries - the pointer to the folder entry array * uint32_t* entnum - the number of elements of the array * **/uint16_tptp_canon_getfolderentries (PTPParams* params, uint32_t store, uint32_t p2, uint32_t parent, uint32_t handle, PTPCANONFolderEntry** entries, uint32_t* entnum){ uint16_t ret; PTPContainer ptp; char *data = NULL; PTP_CNT_INIT(ptp); ptp.Code=PTP_OC_CANON_GetFolderEntries; ptp.Param1=store; ptp.Param2=p2; ptp.Param3=parent; ptp.Param4=handle; ptp.Nparam=4; ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &data); if (ret == PTP_RC_OK) { int i; *entnum=ptp.Param1; *entries=calloc(*entnum, sizeof(PTPCANONFolderEntry)); if (*entries!=NULL) { for(i=0; i<(*entnum); i++) ptp_unpack_Canon_FE(params, data+i*PTP_CANON_FolderEntryLen, &((*entries)[i]) ); } else { ret=PTP_ERROR_IO; /* Cannot allocate memory */ } } free(data); return ret;}/* Nikon extension code */uint16_tptp_nikon_setcontrolmode (PTPParams* params, uint32_t mode){ PTPContainer ptp; PTP_CNT_INIT(ptp); ptp.Code=PTP_OC_NIKON_SetControlMode; ptp.Param1=mode; ptp.Nparam=1; return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL);}uint16_tptp_nikon_directcapture (PTPParams* params, uint32_t unknown){ PTPContainer ptp; PTP_CNT_INIT(ptp); ptp.Code=PTP_OC_NIKON_DirectCapture; ptp.Param1=unknown; /* as of yet unknown parameter */ ptp.Nparam=1; return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL);}uint16_tptp_nikon_checkevent (PTPParams* params, PTPUSBEventContainer** event, uint16_t* evnum){ uint16_t ret; PTPContainer ptp; char *evdata = NULL; PTP_CNT_INIT(ptp); ptp.Code=PTP_OC_NIKON_CheckEvent; ptp.Nparam=0; ret = ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &evdata); if (ret == PTP_RC_OK) ptp_nikon_unpack_EC(params, evdata, event, evnum); free (evdata); return ret;}uint16_tptp_nikon_keepalive (PTPParams* params){ PTPContainer ptp; PTP_CNT_INIT(ptp); ptp.Code=PTP_OC_NIKON_KeepAlive; ptp.Nparam=0; return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL);}/* Non PTP protocol functions *//* devinfo testing functions */intptp_operation_issupported(PTPParams* params, uint16_t operation){ int i=0; for (;i<params->deviceinfo.OperationsSupported_len;i++) { if (params->deviceinfo.OperationsSupported[i]==operation) return 1; } return 0;}/* ptp structures feeing functions */voidptp_free_devicepropdesc(PTPDevicePropDesc* dpd){ uint16_t i; free(dpd->FactoryDefaultValue); free(dpd->CurrentValue); switch (dpd->FormFlag) { case PTP_DPFF_Range: free (dpd->FORM.Range.MinimumValue); free (dpd->FORM.Range.MaximumValue); free (dpd->FORM.Range.StepSize); break; case PTP_DPFF_Enumeration: for (i=0;i<dpd->FORM.Enum.NumberOfValues;i++) free(dpd->FORM.Enum.SupportedValue[i]); free(dpd->FORM.Enum.SupportedValue); }}/* report PTP errors */void ptp_perror(PTPParams* params, uint16_t error) { int i; /* PTP error descriptions */ static struct { uint16_t error; const char *txt; } ptp_errors[] = { {PTP_RC_Undefined, N_("PTP: Undefined Error")}, {PTP_RC_OK, N_("PTP: OK!")}, {PTP_RC_GeneralError, N_("PTP: General Error")}, {PTP_RC_SessionNotOpen, N_("PTP: Session Not Open")}, {PTP_RC_InvalidTransactionID, N_("PTP: Invalid Transaction ID")}, {PTP_RC_OperationNotSupported, N_("PTP: Operation Not Supported")}, {PTP_RC_ParameterNotSupported, N_("PTP: Parameter Not Supported")}, {PTP_RC_IncompleteTransfer, N_("PTP: Incomplete Transfer")}, {PTP_RC_InvalidStorageId, N_("PTP: Invalid Storage ID")}, {PTP_RC_InvalidObjectHandle, N_("PTP: Invalid Object Handle")}, {PTP_RC_DevicePropNotSupported, N_("PTP: Device Prop Not Supported")}, {PTP_RC_InvalidObjectFormatCode, N_("PTP: Invalid Object Format Code")}, {PTP_RC_StoreFull, N_("PTP: Store Full")}, {PTP_RC_ObjectWriteProtected, N_("PTP: Object Write Protected")}, {PTP_RC_StoreReadOnly, N_("PTP: Store Read Only")}, {PTP_RC_AccessDenied, N_("PTP: Access Denied")}, {PTP_RC_NoThumbnailPresent, N_("PTP: No Thumbnail Present")}, {PTP_RC_SelfTestFailed, N_("PTP: Self Test Failed")}, {PTP_RC_PartialDeletion, N_("PTP: Partial Deletion")}, {PTP_RC_StoreNotAvailable, N_("PTP: Store Not Available")}, {PTP_RC_SpecificationByFormatUnsupported, N_("PTP: Specification By Format Unsupported")}, {PTP_RC_NoValidObjectInfo, N_("PTP: No Valid Object Info")}, {PTP_RC_InvalidCodeFormat, N_("PTP: Invalid Code Format")}, {PTP_RC_UnknownVendorCode, N_("PTP: Unknown Vendor Code")}, {PTP_RC_CaptureAlreadyTerminated, N_("PTP: Capture Already Terminated")}, {PTP_RC_DeviceBusy, N_("PTP: Device Busy")}, {PTP_RC_InvalidParentObject, N_("PTP: Invalid Parent Object")}, {PTP_RC_InvalidDevicePropFormat, N_("PTP: Invalid Device Prop Format")}, {PTP_RC_InvalidDevicePropValue, N_("PTP: Invalid Device Prop Value")}, {PTP_RC_InvalidParameter, N_("PTP: Invalid Parameter")}, {PTP_RC_SessionAlreadyOpened, N_("PTP: Session Already Opened")}, {PTP_RC_TransactionCanceled, N_("PTP: Transaction Canceled")}, {PTP_RC_SpecificationOfDestinationUnsupported, N_("PTP: Specification Of Destination Unsupported")}, {PTP_ERROR_IO, N_("PTP: I/O error")}, {PTP_ERROR_BADPARAM, N_("PTP: Error: bad parameter")}, {PTP_ERROR_DATA_EXPECTED, N_("PTP: Protocol error: data expected")}, {PTP_ERROR_RESP_EXPECTED, N_("PTP: Protocol error: response expected")}, {0, NULL} }; static struct { uint16_t error; const char *txt; } ptp_errors_EK[] = { {PTP_RC_EK_FilenameRequired, N_("PTP EK: Filename Required")}, {PTP_RC_EK_FilenameConflicts, N_("PTP EK: Filename Conflicts")}, {PTP_RC_EK_FilenameInvalid, N_("PTP EK: Filename Invalid")}, {0, NULL} }; static struct { uint16_t error; const char *txt; } ptp_errors_NIKON[] = { {PTP_RC_NIKON_PropertyReadOnly, N_("PTP NIKON: Property Read Only")}, {0, NULL} }; for (i=0; ptp_errors[i].txt!=NULL; i++) if (ptp_errors[i].error == error){ ptp_error(params, ptp_errors[i].txt); return; } /*if (error|PTP_RC_EXTENSION_MASK==PTP_RC_EXTENSION)*/ switch (params->deviceinfo.VendorExtensionID) { case PTP_VENDOR_EASTMAN_KODAK: for (i=0; ptp_errors_EK[i].txt!=NULL; i++) if (ptp_errors_EK[i].error==error) { ptp_error(params, ptp_errors_EK[i].txt); return; } break; case PTP_VENDOR_NIKON: for (i=0; ptp_errors_NIKON[i].txt!=NULL; i++) if (ptp_errors_NIKON[i].error==error) { ptp_error(params, ptp_errors_NIKON[i].txt); return; } break; } ptp_error(params, "PTP: Error 0x%04x", error); }/* return DataType description */const char*ptp_get_datatype_name(PTPParams* params, uint16_t dt){ int i; /* Data Types */ static struct { uint16_t dt; const char *txt; } ptp_datatypes[] = { {PTP_DTC_UNDEF, N_("UndefinedType")}, {PTP_DTC_INT8, N_("INT8")}, {PTP_DTC_UINT8, N_("UINT8")}, {PTP_DTC_INT16, N_("INT16")}, {PTP_DTC_UINT16, N_("UINT16")}, {PTP_DTC_INT32, N_("INT32")}, {PTP_DTC_UINT32, N_("UINT32")}, {PTP_DTC_INT64, N_("INT64")}, {PTP_DTC_UINT64, N_("UINT64")}, {PTP_DTC_INT128, N_("INT128")}, {PTP_DTC_UINT128, N_("UINT128")}, {PTP_DTC_AINT8, N_("ArrayINT8")}, {PTP_DTC_AUINT8, N_("ArrayUINT8")}, {PTP_DTC_AINT16, N_("ArrayINT16")}, {PTP_DTC_AUINT16, N_("ArrayUINT16")}, {PTP_DTC_AINT32, N_("ArrayINT32")}, {PTP_DTC_AUINT32, N_("ArrayUINT32")}, {PTP_DTC_AINT64, N_("ArrayINT64")}, {PTP_DTC_AUINT64, N_("ArrayUINT64")}, {PTP_DTC_AINT128, N_("ArrayINT128")}, {PTP_DTC_AUINT128, N_("ArrayUINT128")}, {PTP_DTC_STR, N_("String")}, {0,NULL} }; for (i=0; ptp_datatypes[i].txt!=NULL; i++) if (ptp_datatypes[i].dt == dt){ return (ptp_datatypes[i].txt); } return NULL;}/* return ptp operation name */const char*ptp_get_operation_name(PTPParams* params, uint16_t oc){ int i; /* Operation Codes */ static struct { uint16_t oc; const char *txt; } ptp_operations[] = { {PTP_OC_Undefined, N_("UndefinedOperation")}, {PTP_OC_GetDeviceInfo, N_("GetDeviceInfo")}, {PTP_OC_OpenSession, N_("OpenSession")}, {PTP_OC_CloseSession, N_("CloseSession")}, {PTP_OC_GetStorageIDs, N_("GetStorageIDs")}, {PTP_OC_GetStorageInfo, N_("GetStorageInfo")}, {PTP_OC_GetNumObjects, N_("GetNumObjects")}, {PTP_OC_GetObjectHandles, N_("GetObjectHandles")}, {PTP_OC_GetObjectInfo, N_("GetObjectInfo")}, {PTP_OC_GetObject, N_("GetObject")}, {PTP_OC_GetThumb, N_("GetThumb")}, {PTP_OC_DeleteObject, N_("DeleteObject")}, {PTP_OC_SendObjectInfo, N_("SendObjectInfo")}, {PTP_OC_SendObject, N_("SendObject")}, {PTP_OC_InitiateCapture, N_("InitiateCapture")}, {PTP_OC_FormatStore, N_("FormatStore")}, {PTP_OC_ResetDevice, N_("ResetDevice")}, {PTP_OC_SelfTest, N_("SelfTest")}, {PTP_OC_SetObjectProtection, N_("SetObjectProtection")}, {PTP_OC_PowerDown, N_("PowerDown")}, {PTP_OC_GetDevicePropDesc, N_("GetDevicePropDesc")}, {PTP_OC_GetDevicePropValue, N_("GetDevicePropValue")}, {PTP_OC_SetDevicePropValue, N_("SetDevicePropValue")}, {PTP_OC_ResetDevicePropValue, N_("ResetDevicePropValue")}, {PTP_OC_TerminateOpenCapture, N_("TerminateOpenCapture")}, {PTP_OC_MoveObject, N_("MoveObject")}, {PTP_OC_CopyObject, N_("CopyObject")}, {PTP_OC_GetPartialObject, N_("GetPartialObject")}, {PTP_OC_InitiateOpenCapture, N_("InitiateOpenCapture")}, {0,NULL} }; static struct { uint16_t oc; const char *txt; } ptp_operations_EK[] = { {PTP_OC_EK_SendFileObjectInfo, N_("EK SendFileObjectInfo")}, {PTP_OC_EK_SendFileObject, N_("EK SendFileObject")}, {0,NULL} }; static struct { uint16_t oc; const char *txt; } ptp_operations_CANON[] = { {PTP_OC_CANON_GetObjectSize, N_("CANON GetObjectSize")}, {PTP_OC_CANON_StartShootingMode,N_("CANON StartShootingMode")}, {PTP_OC_CANON_EndShootingMode, N_("CANON EndShootingMode")}, {PTP_OC_CANON_ViewfinderOn, N_("CANON ViewfinderOn")}, {PTP_OC_CANON_ViewfinderOff, N_("CANON ViewfinderOff")}, {PTP_OC_CANON_ReflectChanges, N_("CANON ReflectChanges")}, {PTP_OC_CANON_CheckEvent, N_("CANON CheckEvent")}, {PTP_OC_CANON_FocusLock, N_("CANON FocusLock")}, {PTP_OC_CANON_FocusUnlock, N_("CANON FocusUnlock")}, {PTP_OC_CANON_InitiateCaptureInMemory, N_("CANON InitiateCaptureInMemory")}, {PTP_OC_CANON_GetPartialObject, N_("CANON GetPartialObject")}, {PTP_OC_CANON_GetViewfinderImage, N_("CANON GetViewfinderImage")}, {PTP_OC_CANON_GetChanges, N_("CANON GetChanges")}, {PTP_OC_CANON_GetFolderEntries, N_("CANON GetFolderEntries")}, {0,NULL} }; static struct { uint16_t oc; const char *txt; } ptp_operations_NIKON[] = { {PTP_OC_NIKON_DirectCapture, N_("NIKON DirectCapture")}, {PTP_OC_NIKON_SetControlMode, N_("NIKON SetControlMode")}, {PTP_OC_NIKON_CheckEvent, N_("NIKON Check Event")}, {PTP_OC_NIKON_KeepAlive, N_("NIKON Keep Alive (?)")}, {0,NULL} }; switch (params->deviceinfo.VendorExtensionID) { case PTP_VENDOR_EASTMAN_KODAK: for (i=0; ptp_operations_EK[i].txt!=NULL; i++) if (ptp_operations_EK[i].oc==oc) return (ptp_operations_EK[i].txt); break; case PTP_VENDOR_CANON: for (i=0; ptp_operations_CANON[i].txt!=NULL; i++) if (ptp_operations_CANON[i].oc==oc) return (ptp_operations_CANON[i].txt); break; case PTP_VENDOR_NIKON: for (i=0; ptp_operations_NIKON[i].txt!=NULL; i++) if (ptp_operations_NIKON[i].oc==oc) return (ptp_operations_NIKON[i].txt); break; } for (i=0; ptp_operations[i].txt!=NULL; i++) if (ptp_operations[i].oc == oc){ return (ptp_operations[i].txt); } return NULL;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -