CHDK PTP interface - page 33 - General Discussion and Assistance - CHDK Forum  

CHDK PTP interface

  • 1227 Replies
  • 371359 Views
*

Offline reyalp

  • ******
  • 13387
Re: CHDK PTP interface
« Reply #320 on: 24 / December / 2010, 15:25:17 »
Advertisements
and what need change in chdkcam to get it working ?
Two things.
- you need to build it, which requires borland c builder
- the current minimal CHDK protocol doesn't support all the features of chdkcam, so they would need to be implemented again, or taken out of CHDK cam. In the long term we want to have something like this, but it will take time to implement it in a way that we can support all cameras, and have a tool we can all work on.
Quote
there is for Ixus 1000 trunk 958 trunk 969 and trunk 1004 working

I can revert to an old trunk,

Do you get not such a message on ptpcam --chdk ?

"""""
error: camera has unsupported camera version 0.1; some functionality may be miss
ing or cause unintented consequences
""""""

Camera protocol version should be 0.2 if using current trunk code, but using 0.2 ptpcam with 0.1 chdk is fine, only the new script-support and script-status commands will fail.
Don't forget what the H stands for.

*

Offline reyalp

  • ******
  • 13387
Re: CHDK PTP interface
« Reply #321 on: 24 / December / 2010, 19:14:39 »
Updated ptpcam

This has the cli and auto-reconnect stuff from fudgeys post http://chdk.setepontos.com/index.php?topic=4338.msg54414#msg54414

the cli stuff could use some cleanup, but should be useful as is.

corrected sleep() for win32. as it was before, it would have used seconds on linux and milliseconds on win32.

I didn't add the luaw stuff

code in http://tools.assembla.com/chdkde/changeset/515
Don't forget what the H stands for.

*

Offline reyalp

  • ******
  • 13387
Re: CHDK PTP interface
« Reply #322 on: 25 / December / 2010, 04:07:06 »
Here's an idea I've been thinking about for a while for a better (?) PTP <> script interface. Finally got around to working on it  :xmas
The code is functional but basically at the proof of concept stage.

The basic idea is to let PTP talk to a running script, instead of just running snippets of lua.

Here's how it works:
The CHDK ptp code has two queues of "messages", one for PC->camera (input queue) and one for camera->PC (output queue)

A message is a sequence of bytes, size limited by available memory. From lua it is a string but lua strings are binary safe so it can be anything. The queues just store pointers to the messages.

No task synchronization is needed between the script task and the PTP task, because Lua only reads from the input queue and writes to the output queue, while PTP only does the reverse.

This is implemented with two new PTP commands WriteScriptMsg and ReadScriptMsg and two new lua functions write_usb_msg and read_usb_msg

PC sends WriteScriptMsg to add a message to the input queue. read_usb_msg fetches the message in lua
write_usb_msg adds a message to the output queue. ReadScriptMsg fetches the message on the PC

read*/write* return indications if the queue is empty or full, respectively.

Now a lua script can call read_usb_msg in a loop, and do something based on the content of the messages. This could be commands, or could be lua code. It can send output back with write_usb_msg

Plan is to make the lua functions optionally block with a timeout (like wait_click) but this isn't implemented yet.

Some benefits
- No need to stall PTP waiting for lua results. Long executing lua calls work be fine, as long as they sleep just like other lua scripts. The PC side can just poll until the response message(s) appear.
- you can return arbitrary data.
- You can maintain state between commands on the camera, unlike the current lua command which start from scratch every time.
- The need to expand the core protocol is reduced, because you can implement arbitrary protocols in lua

Other thoughts
- Taking full advantage of this will require a more flexible client than the current ptpcam. Something we need anyway.
- right now there is only one message channel. You can always send messages, even if there is nothing listening, and any script that starts later will see them if it reads. It would be possible to add some listen/connect/close semantics and have multiple channels, but I'm not sure if this is needed.
- it would be useful to be able to send data without going through a lua string, e.g. directly from a pointer

Attached files
chdk-ptpmsg-1.patch - patch against chdk code trunk
ptpcam-chdkde-ptpmsg-1.patch - patch against chdkde ptpcam
ptpmsg.lua - example script

example
Code: [Select]
ptpcam --chdk
upload ptpmsg.lua A/ptpmsg.lua
lua loadfile('A/ptpmsg.lua')()
putm ls A/
getm
exec return 1+1
getm
Don't forget what the H stands for.

Re: CHDK PTP interface
« Reply #323 on: 25 / December / 2010, 11:48:47 »
@reyalp
>- you need to build it, which requires borland c builder

hope this is not too complicate and use special borland libs, i can try when i have time to compile with wxdevcpp.it use then wxwidgets(work on win /Linux/Mac OS/ Unix too).

http://wxdsgn.sourceforge.net/

its free and its easy too use (at least i understand a little how it work).i use this also for crosscompile, so to make some day a linux version for chdkcam (if that not use specific win) functions is possible.there need only a gui switrch change to set the target platform.

every target have a dialogbox that contain dir, path to compiler ,C++, assembler, linker.i know eclipse can do more, but i dont understand how make a compiler set.

what do you think about that ?
« Last Edit: 25 / December / 2010, 12:01:41 by Bernd R »
Ixus 1000 HS


*

Offline reyalp

  • ******
  • 13387
Re: CHDK PTP interface
« Reply #324 on: 25 / December / 2010, 13:36:36 »
@reyalp
>- you need to build it, which requires borland c builder

hope this is not too complicate and use special borland libs, i can try when i have time to compile with wxdevcpp.it use then wxwidgets(work on win /Linux/Mac OS/ Unix too).
It's a C++ builder app, so it needs the corresponding c++ builder libs. Definitely not portable. I don't know whether the free Borland command line tools (linked earlier in this thread) are sufficient to build it, and I'm not really interested in spending the time to find out.
Don't forget what the H stands for.

Re: CHDK PTP interface
« Reply #325 on: 25 / December / 2010, 14:01:44 »
I use now the newest chdk files, no

"""""
error: camera has unsupported camera version 0.1; some functionality may be miss
ing or cause unintented consequences
""""""

error come and i can now upload files.
only i see that ptpcam do no full init after a conn command.

for example when i do this lines

C:\Users\pc>e:chdk\ptpcam.exe --chdk
<conn> upload ps.fi2 A/ps.fi2
<conn> upload ps.fi2 A/ps.fi2

work 2 times

now i remove the USB cable on camera and then i put it in again

then i get that output

<conn> upload ps.fi2 A/ps.fi2
unexpected return code 0x2ff
upload failed!
<conn>

so there seem on every conn command no full usb init as --chdk do.

Is that possible to change ?
also a good idea is to have a command to transfer a chdk zip to Camera
 then you need only do

ptpcam --chdkupd ......zip

then the SD Card change is not need.

I see only little Problem in Ixus  1000 that when the USB cable is plug in, the firmware keys do not work.So when i switch camera on in play mode, i can not press menu to do firmware update.

I need remove the USB cable
is this on other camera same ?
« Last Edit: 25 / December / 2010, 14:14:15 by Bernd R »
Ixus 1000 HS

*

Offline reyalp

  • ******
  • 13387
Re: CHDK PTP interface
« Reply #326 on: 25 / December / 2010, 14:13:13 »
error come and i can now upload files.
only i see that ptpcam do no full init after a conn command.

for example when i do this lines

C:\Users\pc>e:chdk\ptpcam.exe --chdk
<conn> upload ps.fi2 A/ps.fi2
<conn> upload ps.fi2 A/ps.fi2

now i remove the USB cable on camera and then i put it in again

then i get that output

<conn> upload ps.fi2 A/ps.fi2
unexpected return code 0x2ff
upload failed!
<conn>
This seems normal to me. If you unplug the camera, then you need to do reset command to reconnect.
The newest ptpcam will try to reconnect if you reboot.
Quote
ptpcam --chdkupd ......zip
The fugeys cli stuff that I added in the latest ptpcam also lets you do
ptpcam --chdk="upload diskboot.bin A/diskboot.bin"

You should also be able to write a "batch file" of chdk ptpcommands and then redirect input, e.g.
ptpcam --chdk < mycommands.txt
Don't forget what the H stands for.

*

Offline reyalp

  • ******
  • 13387
Re: CHDK PTP interface
« Reply #327 on: 25 / December / 2010, 21:42:47 »
I see only little Problem in Ixus  1000 that when the USB cable is plug in, the firmware keys do not work.So when i switch camera on in play mode, i can not press menu to do firmware update.

I need remove the USB cable
is this on other camera same ?
Yes, cannon keys are disabled. Alt mode should still work.

To load your new FI2, use the reboot command. If the appropriate bits of CHDK are implemented, you can do lua reboot("A/PS.FI2") and it will do the right thing. See the code and comments in lib/armutil/reboot.c

edit:
a plain reboot() should work on almost any camera, but if you are using a multipartition card, you won't be able to upload a diskboot to the non-active partition.
Don't forget what the H stands for.


*

Offline reyalp

  • ******
  • 13387
Re: CHDK PTP interface
« Reply #328 on: 25 / December / 2010, 22:04:06 »
Updated usb script message code. Timeouts now implemented for read_usb_msg and write_usb_msg

ptpmsg.lua updated to use this. the lsa command shows blocking writes. The low timeouts are just for testing.

ptpcam code is unchanged

note that you don't have to use the message loop, you can use write_usb_msg() to return a value, e.g.

Code: [Select]
<conn> lua write_usb_msg(tostring(1 + 1))
<conn> getm
message 1 size=1
2
<conn>
Don't forget what the H stands for.

Re: CHDK PTP interface
« Reply #329 on: 26 / December / 2010, 08:36:20 »
@reyalp
>To load your new FI2, use the reboot command. If the appropriate bits of CHDK are implemented, you can >do lua reboot("A/PS.FI2") and it will do the right thing. See the code and comments in lib/armutil/reboot.c

thanks, this work great.chdk is new start after upload.

I do

C:\Users\pc>e:\chdk\ptpcam.exe --chdk < chdkupd.txt
<conn> <conn> <conn>

C:\Users\pc>

with that chdkupd.txt file content

upload ps.fi2 A/PS.FI2
lua reboot("A/PS.FI2")

there is only a very little problem in ptpcam.when start it without Camera is on, there come after some checks a crash of ptpcam r515 StackHash_0a9e error code c0000005 on my win 7 64 bit.

here is output, but in front is german text

"""""
 Problemereignisname:   APPCRASH
  Anwendungsname:   ptpcam.exe
  Anwendungsversion:   0.0.0.0
  Anwendungszeitstempel:   4d15364c
  Fehlermodulname:   StackHash_0a9e
  Fehlermodulversion:   0.0.0.0
  Fehlermodulzeitstempel:   00000000
  Ausnahmecode:   c0000005
  Ausnahmeoffset:   00000000
.....
""""""



"""""
C:\Users\pc>e:\chdk\ptpcam.exe --chdk < chdkupd.txt
Could not find any device matching given bus/dev numbers, retrying in 1 s...
Could not find any device matching given bus/dev numbers, retrying in 1 s...
Could not find any device matching given bus/dev numbers, retrying in 1 s...
Could not find any device matching given bus/dev numbers, retrying in 1 s...
Could not find any device matching given bus/dev numbers, retrying in 1 s...
Could not find any device matching given bus/dev numbers, retrying in 1 s...
Could not find any device matching given bus/dev numbers, retrying in 1 s...
Could not find any device matching given bus/dev numbers, retrying in 1 s...
Could not find any device matching given bus/dev numbers, retrying in 1 s...
Could not find any device matching given bus/dev numbers, retrying in 1 s...
could not find any device matching given bus/dev numbers
<    >
C:\Users\pc>
"""""

maybe it can add too in the chdkshell buildscript, when a new version is compile, file is upload to camera and reboot is done automatic.but for automatic, i think its better when the automatic poll if camera is on, can be disable or is only do for 10 sec.
« Last Edit: 26 / December / 2010, 08:38:21 by Bernd R »
Ixus 1000 HS

 

Related Topics