| 1 | #ifndef __CHDK_PTP_H
|
|---|
| 2 | #define __CHDK_PTP_H
|
|---|
| 3 | #define PTP_CHDK_VERSION_MAJOR 2 // increase only with backwards incompatible changes (and reset minor)
|
|---|
| 4 | #define PTP_CHDK_VERSION_MINOR 1 // increase with extensions of functionality
|
|---|
| 5 | /*
|
|---|
| 6 | protocol version history
|
|---|
| 7 | 0.1 - initial proposal from mweerden, + luar
|
|---|
| 8 | 0.2 - Added ScriptStatus and ScriptSupport, based on work by ultimA
|
|---|
| 9 | 1.0 - removed old script result code (luar), replace with message system
|
|---|
| 10 | 2.0 - return PTP_CHDK_TYPE_TABLE for tables instead of TYPE_STRING, allow return of empty strings
|
|---|
| 11 | */
|
|---|
| 12 |
|
|---|
| 13 | #define PTP_OC_CHDK 0x9999
|
|---|
| 14 |
|
|---|
| 15 | // PTP constants - only need to be defined in CHDK, not PC side
|
|---|
| 16 | #ifndef PTP_RC_OK
|
|---|
| 17 | #define PTP_RC_OK 0x2001
|
|---|
| 18 | #define PTP_RC_GeneralError 0x2002
|
|---|
| 19 | #define PTP_RC_ParameterNotSupported 0x2006
|
|---|
| 20 | #define PTP_RC_InvalidParameter 0x201D
|
|---|
| 21 | #endif
|
|---|
| 22 |
|
|---|
| 23 | // N.B.: unused parameters should be set to 0
|
|---|
| 24 | enum ptp_chdk_command {
|
|---|
| 25 | PTP_CHDK_Version = 0, // return param1 is major version number
|
|---|
| 26 | // return param2 is minor version number
|
|---|
| 27 | PTP_CHDK_GetMemory, // param2 is base address (not NULL; circumvent by taking 0xFFFFFFFF and size+1)
|
|---|
| 28 | // param3 is size (in bytes)
|
|---|
| 29 | // return data is memory block
|
|---|
| 30 | PTP_CHDK_SetMemory, // param2 is address
|
|---|
| 31 | // param3 is size (in bytes)
|
|---|
| 32 | // data is new memory block
|
|---|
| 33 | PTP_CHDK_CallFunction, // param2 are flags: 0x1 means use rest of params for pointer and args to allow function to send back data
|
|---|
| 34 | // (return) data is either:
|
|---|
| 35 | // - array of function pointer and (long) arguments if flag 0x1 is not set (max: 10 args)
|
|---|
| 36 | // - return data provided by called function if flag 0x1 is set
|
|---|
| 37 | // return param1 is return value
|
|---|
| 38 | PTP_CHDK_TempData, // data is data to be stored for later
|
|---|
| 39 | // param2 is for the TD flags below
|
|---|
| 40 | PTP_CHDK_UploadFile, // data is 4-byte length of filename, followed by filename and contents
|
|---|
| 41 | PTP_CHDK_DownloadFile, // preceded by PTP_CHDK_TempData with filename
|
|---|
| 42 | // return data are file contents
|
|---|
| 43 | PTP_CHDK_ExecuteScript, // data is script to be executed
|
|---|
| 44 | // param2 is language of script
|
|---|
| 45 | // return param1 is script id, like a process id
|
|---|
| 46 | // return param2 is status, PTP_CHDK_S_ERRTYPE*
|
|---|
| 47 | PTP_CHDK_ScriptStatus, // Script execution status
|
|---|
| 48 | // return param1 bits
|
|---|
| 49 | // PTP_CHDK_SCRIPT_STATUS_RUN is set if a script running, cleared if not
|
|---|
| 50 | // PTP_CHDK_SCRIPT_STATUS_MSG is set if script messages from script waiting to be read
|
|---|
| 51 | // all other bits and params are reserved for future use
|
|---|
| 52 | PTP_CHDK_ScriptSupport, // Which scripting interfaces are supported in this build
|
|---|
| 53 | // param1 CHDK_PTP_SUPPORT_LUA is set if lua is supported, cleared if not
|
|---|
| 54 | // all other bits and params are reserved for future use
|
|---|
| 55 | PTP_CHDK_ReadScriptMsg, // read next message from camera script system
|
|---|
| 56 | // return param1 is chdk_ptp_s_msg_type
|
|---|
| 57 | // return param2 is message subtype:
|
|---|
| 58 | // for script return and users this is ptp_chdk_script_data_type
|
|---|
| 59 | // for error ptp_chdk_script_error_type
|
|---|
| 60 | // return param3 is script id of script that generated the message
|
|---|
| 61 | // return param4 is length of the message data.
|
|---|
| 62 | // return data is message.
|
|---|
| 63 | // A minimum of 1 bytes of zeros is returned if the message has no data (empty string or type NONE)
|
|---|
| 64 | PTP_CHDK_WriteScriptMsg, // write a message for scripts running on camera
|
|---|
| 65 | // input param2 is target script id, 0=don't care. Messages for a non-running script will be discarded
|
|---|
| 66 | // data length is handled by ptp data phase
|
|---|
| 67 | // input messages do not have type or subtype, they are always a string destined for the script (similar to USER/string)
|
|---|
| 68 | // output param1 is ptp_chdk_script_msg_status
|
|---|
| 69 | };
|
|---|
| 70 |
|
|---|
| 71 | // data types as used by ReadScriptMessage
|
|---|
| 72 | enum ptp_chdk_script_data_type {
|
|---|
| 73 | PTP_CHDK_TYPE_UNSUPPORTED = 0, // type name will be returned in data
|
|---|
| 74 | PTP_CHDK_TYPE_NIL,
|
|---|
| 75 | PTP_CHDK_TYPE_BOOLEAN,
|
|---|
| 76 | PTP_CHDK_TYPE_INTEGER,
|
|---|
| 77 | PTP_CHDK_TYPE_STRING, // Empty strings are returned with length=0
|
|---|
| 78 | PTP_CHDK_TYPE_TABLE, // tables are converted to a string by usb_msg_table_to_string,
|
|---|
| 79 | // this function can be overridden in lua to change the format
|
|---|
| 80 | // the string may be empty for an empty table
|
|---|
| 81 | };
|
|---|
| 82 |
|
|---|
| 83 | // TempData flags
|
|---|
| 84 | #define PTP_CHDK_TD_DOWNLOAD 0x1 // download data instead of upload
|
|---|
| 85 | #define PTP_CHDK_TD_CLEAR 0x2 // clear the stored data; with DOWNLOAD this
|
|---|
| 86 | // means first download, then clear and
|
|---|
| 87 | // without DOWNLOAD this means no uploading,
|
|---|
| 88 | // just clear
|
|---|
| 89 |
|
|---|
| 90 | // Script Languages - for execution only lua is supported for now
|
|---|
| 91 | #define PTP_CHDK_SL_LUA 0
|
|---|
| 92 | #define PTP_CHDK_SL_UBASIC 1
|
|---|
| 93 |
|
|---|
| 94 | // bit flags for script status
|
|---|
| 95 | #define PTP_CHDK_SCRIPT_STATUS_RUN 0x1 // script running
|
|---|
| 96 | #define PTP_CHDK_SCRIPT_STATUS_MSG 0x2 // messages waiting
|
|---|
| 97 | // bit flags for scripting support
|
|---|
| 98 | #define PTP_CHDK_SCRIPT_SUPPORT_LUA 0x1
|
|---|
| 99 |
|
|---|
| 100 | // message types
|
|---|
| 101 | enum ptp_chdk_script_msg_type {
|
|---|
| 102 | PTP_CHDK_S_MSGTYPE_NONE = 0, // no messages waiting
|
|---|
| 103 | PTP_CHDK_S_MSGTYPE_ERR, // error message
|
|---|
| 104 | PTP_CHDK_S_MSGTYPE_RET, // script return value
|
|---|
| 105 | PTP_CHDK_S_MSGTYPE_USER, // message queued by script
|
|---|
| 106 | // TODO chdk console data ?
|
|---|
| 107 | };
|
|---|
| 108 |
|
|---|
| 109 | // error subtypes for PTP_CHDK_S_MSGTYPE_ERR and script startup status
|
|---|
| 110 | enum ptp_chdk_script_error_type {
|
|---|
| 111 | PTP_CHDK_S_ERRTYPE_NONE = 0,
|
|---|
| 112 | PTP_CHDK_S_ERRTYPE_COMPILE,
|
|---|
| 113 | PTP_CHDK_S_ERRTYPE_RUN,
|
|---|
| 114 | };
|
|---|
| 115 |
|
|---|
| 116 | // message status
|
|---|
| 117 | enum ptp_chdk_script_msg_status {
|
|---|
| 118 | PTP_CHDK_S_MSGSTATUS_OK = 0, // queued ok
|
|---|
| 119 | PTP_CHDK_S_MSGSTATUS_NOTRUN, // no script is running
|
|---|
| 120 | PTP_CHDK_S_MSGSTATUS_QFULL, // queue is full
|
|---|
| 121 | PTP_CHDK_S_MSGSTATUS_BADID, // specified ID is not running
|
|---|
| 122 | };
|
|---|
| 123 | #endif // __CHDK_PTP_H
|
|---|