| 1 | #ifndef __CHDK_PTP_H |
|---|
| 2 | #define __CHDK_PTP_H |
|---|
| 3 | |
|---|
| 4 | // CHDK PTP protocol interface (can also be used in client PTP progams) |
|---|
| 5 | |
|---|
| 6 | // Note: used in modules and platform independent code. |
|---|
| 7 | // Do not add platform dependent stuff in here (#ifdef/#endif compile options or camera dependent values) |
|---|
| 8 | |
|---|
| 9 | #define PTP_CHDK_VERSION_MAJOR 2 // increase only with backwards incompatible changes (and reset minor) |
|---|
| 10 | #define PTP_CHDK_VERSION_MINOR 4 // increase with extensions of functionality |
|---|
| 11 | |
|---|
| 12 | /* |
|---|
| 13 | protocol version history |
|---|
| 14 | 0.1 - initial proposal from mweerden, + luar |
|---|
| 15 | 0.2 - Added ScriptStatus and ScriptSupport, based on work by ultimA |
|---|
| 16 | 1.0 - removed old script result code (luar), replace with message system |
|---|
| 17 | 2.0 - return PTP_CHDK_TYPE_TABLE for tables instead of TYPE_STRING, allow return of empty strings |
|---|
| 18 | 2.1 - experimental live view, not formally released |
|---|
| 19 | 2.2 - live view (work in progress) |
|---|
| 20 | 2.3 - live view - released in 1.1 |
|---|
| 21 | 2.4 - live view protocol 2.1 |
|---|
| 22 | */ |
|---|
| 23 | |
|---|
| 24 | #define PTP_OC_CHDK 0x9999 |
|---|
| 25 | |
|---|
| 26 | // N.B.: unused parameters should be set to 0 |
|---|
| 27 | enum ptp_chdk_command { |
|---|
| 28 | PTP_CHDK_Version = 0, // return param1 is major version number |
|---|
| 29 | // return param2 is minor version number |
|---|
| 30 | PTP_CHDK_GetMemory, // param2 is base address (not NULL; circumvent by taking 0xFFFFFFFF and size+1) |
|---|
| 31 | // param3 is size (in bytes) |
|---|
| 32 | // return data is memory block |
|---|
| 33 | PTP_CHDK_SetMemory, // param2 is address |
|---|
| 34 | // param3 is size (in bytes) |
|---|
| 35 | // data is new memory block |
|---|
| 36 | PTP_CHDK_CallFunction, // data is array of function pointer and (long) arguments (max: 10 args) |
|---|
| 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 | PTP_CHDK_GetDisplayData, // Return camera display data |
|---|
| 70 | // This is defined as separate sub protocol in live_view.h |
|---|
| 71 | // Changes to the sub-protocol will always be considered a minor change to the main protocol |
|---|
| 72 | // param2 bitmask of data |
|---|
| 73 | // output param1 = total size of data |
|---|
| 74 | // return data is protocol information, frame buffer descriptions and selected display data |
|---|
| 75 | // Currently a data phase is always returned. Future versions may define other behavior |
|---|
| 76 | // for values in currently unused parameters. |
|---|
| 77 | }; |
|---|
| 78 | |
|---|
| 79 | // data types as used by ReadScriptMessage |
|---|
| 80 | enum ptp_chdk_script_data_type { |
|---|
| 81 | PTP_CHDK_TYPE_UNSUPPORTED = 0, // type name will be returned in data |
|---|
| 82 | PTP_CHDK_TYPE_NIL, |
|---|
| 83 | PTP_CHDK_TYPE_BOOLEAN, |
|---|
| 84 | PTP_CHDK_TYPE_INTEGER, |
|---|
| 85 | PTP_CHDK_TYPE_STRING, // Empty strings are returned with length=0 |
|---|
| 86 | PTP_CHDK_TYPE_TABLE, // tables are converted to a string by usb_msg_table_to_string, |
|---|
| 87 | // this function can be overridden in lua to change the format |
|---|
| 88 | // the string may be empty for an empty table |
|---|
| 89 | }; |
|---|
| 90 | |
|---|
| 91 | // TempData flags |
|---|
| 92 | #define PTP_CHDK_TD_DOWNLOAD 0x1 // download data instead of upload |
|---|
| 93 | #define PTP_CHDK_TD_CLEAR 0x2 // clear the stored data; with DOWNLOAD this |
|---|
| 94 | // means first download, then clear and |
|---|
| 95 | // without DOWNLOAD this means no uploading, |
|---|
| 96 | // just clear |
|---|
| 97 | |
|---|
| 98 | // Script Languages - for execution only lua is supported for now |
|---|
| 99 | #define PTP_CHDK_SL_LUA 0 |
|---|
| 100 | #define PTP_CHDK_SL_UBASIC 1 |
|---|
| 101 | |
|---|
| 102 | // bit flags for script status |
|---|
| 103 | #define PTP_CHDK_SCRIPT_STATUS_RUN 0x1 // script running |
|---|
| 104 | #define PTP_CHDK_SCRIPT_STATUS_MSG 0x2 // messages waiting |
|---|
| 105 | // bit flags for scripting support |
|---|
| 106 | #define PTP_CHDK_SCRIPT_SUPPORT_LUA 0x1 |
|---|
| 107 | |
|---|
| 108 | // message types |
|---|
| 109 | enum ptp_chdk_script_msg_type { |
|---|
| 110 | PTP_CHDK_S_MSGTYPE_NONE = 0, // no messages waiting |
|---|
| 111 | PTP_CHDK_S_MSGTYPE_ERR, // error message |
|---|
| 112 | PTP_CHDK_S_MSGTYPE_RET, // script return value |
|---|
| 113 | PTP_CHDK_S_MSGTYPE_USER, // message queued by script |
|---|
| 114 | // TODO chdk console data ? |
|---|
| 115 | }; |
|---|
| 116 | |
|---|
| 117 | // error subtypes for PTP_CHDK_S_MSGTYPE_ERR and script startup status |
|---|
| 118 | enum ptp_chdk_script_error_type { |
|---|
| 119 | PTP_CHDK_S_ERRTYPE_NONE = 0, |
|---|
| 120 | PTP_CHDK_S_ERRTYPE_COMPILE, |
|---|
| 121 | PTP_CHDK_S_ERRTYPE_RUN, |
|---|
| 122 | }; |
|---|
| 123 | |
|---|
| 124 | // message status |
|---|
| 125 | enum ptp_chdk_script_msg_status { |
|---|
| 126 | PTP_CHDK_S_MSGSTATUS_OK = 0, // queued ok |
|---|
| 127 | PTP_CHDK_S_MSGSTATUS_NOTRUN, // no script is running |
|---|
| 128 | PTP_CHDK_S_MSGSTATUS_QFULL, // queue is full |
|---|
| 129 | PTP_CHDK_S_MSGSTATUS_BADID, // specified ID is not running |
|---|
| 130 | }; |
|---|
| 131 | |
|---|
| 132 | #endif // __CHDK_PTP_H |
|---|