About 6 months ago I received a patch from Hedi Hamzaoui  from Parrot. It enabled ptpcam to send any arbitrary operation to the PTP device (raw requests). The patch was quite neat and generic so I released libptp2 1.2.0 with it. Its help says a lot about how one can use it:

-R reqCode[,P1,P2,P3,P4,P5,d] Send a raw generic request with parameters
                             parameters Pn are optionnal and can be set to 0
                             if not used (params values must be hexadecimal)
                             d, is the data direction (r=read, n=no data, 
                             filename or value to send in hexadecimal).
                             The default data direction is 'r'.
                             If you want to send data, give the file name
                             containing data to send, or, if the data is short,
                             you can directly write the value in hexadecimal.
                             The result data and response will be displayed
                    example: ptpcam -R 0x1015,0x5003,0,0,0,0,r
                             ptpcam -R 0x1016,0x5003,0,0,0,0,image_size.bin
                             ptpcam -R 0x1016,0x501b,0,0,0,0,0x88130000
                             ptpcam -R 0x100e,0,0,0,0,0,n

Few days ago I was contacted by Xiaoming Yang who was having a hard time interfacing with RICOH THETA S. He was seeking help setting vendor extension properties:

I am using ptpcam –show-properties to find properties of Theta S, a 360 camera. It use extended PTP property to define shutter speed. Its API is at (https://developers.theta360.com/en/docs/v2/usb_reference/property/shutter_speed.html). Ptpcam could not get/set property of with address 0xd00f. It is displayed as “Unknown”. Do you think this is because the property value is defined as standard Rational? Is there any way to add surport to read these values?

It turned out that to set the property one has to send its value in rational format, it means a numerator and denominator packed together. Since PTP specification says nothing about rational number data type I never implemented it in ptpcam. The new functionality of sending raw requests came to the rescue. Here’s what I wrote to Xiaoming:

ptpcam -R 0x1014,0xd00f,0,0,0,r
is roughly an equivalent of
 ptpcam -s 0xd00f -v
Just set what you want like this:
ptpcam -s 0xd00f -v --val 2
(now I realizes that this might fail due to unknown property value type if that is the case try the following example)
ptpcam -R 0x1016,0xd00f,0,0,0,0,0x2\n"

Later we figured the proper encoding and endiannes of the arguments which Xiaomi posted on the theta developers forum:

With ptpcam -R, it can send a raw generic PTP request with parameters. The returned result could be reformated to shutter speed settings of Theta S. First read properties available, 0x1014 for reading device property description and 0xd00f for shutter speed. In the returned values, all the possible shutter speed is listed. For example, 01 00 00 00 a0 0f 00 are two 4-bype integers, 01 00 00 00 is 1 and a0 0f 00 00 is actually 0f a0 which is 6400.

$ ptpcam -R 0x1014,0xd00f,0,0,0,r
Sending generic request: reqCode=0x1014, params=[0x0000d00f,0x00000000,0x00000000,0x00000000,0x00000000]
0f d0 08 00 01 00 00 00 00 00 00 00 00 01 00 00 - ................
00 3c 00 00 00 02 37 00 01 00 00 00 00 19 00 00 - .<....7.........
01 00 00 00 88 13 00 00 01 00 00 00 a0 0f 00 00 - ................
01 00 00 00 80 0c 00 00 01 00 00 00 c4 09 00 00 - ................
01 00 00 00 d0 07 00 00 01 00 00 00 40 06 00 00 - ............@...

To get current setting of a property, 0x1015 for get property and 0xd00f for shutter speed:

$ptpcam -R 0x1015,0xd00f,0,0,0,r

Sending generic request: reqCode=0x1015, params=[0x0000d00f,0x00000000,0x00000000,0x00000000,0x00000000]
01 00 00 00 3c 00 00 00 00 00 00 00 - ....<.......
PTP: response OK

The result 01 00 00 00 3c 00 00 00 could be read as (01)/(3c) = 1/60
To set shutter speed, could send binary data with ptpcam -R. To send 1/8, use 0x1016 for set property:

echo -e -n '\x01\x00\x00\x00\x08\x00\x00\x00' > shutter.bin
ptpcam -R 0x1016,0x00f,0,0,0,0,shuuter.bin

This all wouldn’t be possible without the patch from Hedi. Thank you!

I hope this little story explains the potential of the raw requests feature.  :)