CHDK PTP Java + remoteshoot (was Re: alternative ptp client)

  • 17 Replies
  • 2160 Views
Advertisements
Hi All.

Does anybody support https://github.com/acamilo/CHDK-PTP-Java ? It's Java client for CHDK PTP.

I see great function "remoteshoot"(shoot and download without saving to SD) in the https://www.assembla.com/code/chdkptp/ and would like to implement the same for CHDK-PTP-Java.

As far as I understand, remoteshoot implemented in the rsint.lua. Could anybody please to point me into some doc that describes USB commands for remoteshoot ? Or describe a little bit how it works ? (400 lines lua code is a little bit complex for me yet).

*

Offline reyalp

  • ******
  • 10835
Re: CHDK PTP Java + remoteshoot (was Re: alternative ptp client)
« Reply #1 on: 16 / June / 2015, 16:06:16 »
Hi All.

Does anybody support https://github.com/acamilo/CHDK-PTP-Java ? It's Java client for CHDK PTP.
Thanks for linking that, I wasn't aware of it.

Quote
I see great function "remoteshoot"(shoot and download without saving to SD) in the https://www.assembla.com/code/chdkptp/ and would like to implement the same for CHDK-PTP-Java.

As far as I understand, remoteshoot implemented in the rsint.lua. Could anybody please to point me into some doc that describes USB commands for remoteshoot ? Or describe a little bit how it works ? (400 lines lua code is a little bit complex for me yet).
rsint implements the rsint command, which is a special cli command for remote shooting quickly interactively or under the control of an external program. The actual remote shoot logic is mostly in chdku.lua. Only 1900 lines :p (but most of them aren't related to remoteshoot).

See this post I wrote to someone else who asked about implementing remoteshoot http://chdk.setepontos.com/index.php?topic=11330.msg111397#msg111397 for some details.

Note the links to source go to a somewhat older version, but this code hasn't changed significantly.


Don't forget what the H stands for.

Re: CHDK PTP Java + remoteshoot (was Re: alternative ptp client)
« Reply #2 on: 17 / June / 2015, 01:55:24 »
Hi reyalp.

See this post I wrote to someone else who asked about implementing remoteshoot http://chdk.setepontos.com/index.php?topic=11330.msg111397#msg111397 for some details.

Thank you very much. I hope to I will be able to reproduce it in java.

*

Offline reyalp

  • ******
  • 10835
Re: CHDK PTP Java + remoteshoot (was Re: alternative ptp client)
« Reply #3 on: 17 / June / 2015, 16:39:21 »
Thank you very much. I hope to I will be able to reproduce it in java.
Great. Feel free to post any questions.

I split this into a new thread because the chdkptp one is already quite long.
Don't forget what the H stands for.


Re: CHDK PTP Java + remoteshoot (was Re: alternative ptp client)
« Reply #4 on: 19 / June / 2015, 03:28:23 »
Hi reyalp.

If I understand correctly, handlers just used for store chunks in files. chdkptp desktop code requests camera in one thread. I.e. there is no any forks for read data from camera. Am I right ?

*

Offline reyalp

  • ******
  • 10835
Re: CHDK PTP Java + remoteshoot (was Re: alternative ptp client)
« Reply #5 on: 19 / June / 2015, 20:56:01 »
If I understand correctly, handlers just used for store chunks in files.
In the case of DNG, it also handles byte reversing, badpixel patching and combining the raw data with the header.
Quote
chdkptp desktop code requests camera in one thread. I.e. there is no any forks for read data from camera. Am I right ?
Correct. The handlers are just an abstraction to separate out dealing with the data from capture_get_data logic.
Don't forget what the H stands for.

Re: CHDK PTP Java + remoteshoot (was Re: alternative ptp client)
« Reply #6 on: 21 / June / 2015, 14:54:06 »
Hi reyalp.

I reviewed chdkptp code for remote shooting and implemented about a half of own code for that. But... you spend many time for testing chdkptp and implemented so many options. Since I should have to use camera's part of chdkptp code, I tried to find way how to parse rlibs.lua from my software for send to camera.

I understood that I can implement only small set of chdkptp functionality and I'm not planning to improve it so much because it's only one small part of my application.

It will be one more small framework only for my application that will not be useful for many people. If somebody will want to use and improve my java framework, we will have to always synchronize code with chdkptp.

Instead, I tried to implement more general solution. I found Lua interpreter for java - luaj. So, I need to reimplement only C part of chdkptp and will be able to use full power of chdkptp options.

You can see result of my 2 days hacking at https://github.com/alex73/chdkptp/tree/master/java/src. I'm not sure that I implemented Lua object model so good, but it works and can be improved.

For support full chdkptp functionality, more methods should be implemented, but it's already good skeleton. Also, need to make some code cleanup and commenting.

I used CHDK-PTP-Java for USB access, but I'm planning to remove it. This framework can be simplified, but there are not any place for discussion with authors and looks like authors lost interest to it. Today I know enough for implement USB code myself like in the ptp.c.

So, my implementation are using full Lua code from chdkptp(camera side and desktop side). I used command line method for run remote shooting(see SysLib.java), but it will be better to create binding for all chdkptp command for java. It's enough simple thing but requires little changes in the main.lua or other thing.

There is only one "fix" for lua code - connection should be prepared in java code because connect/disconnect in Lua code doesn't do anything. It's required for integrate framework into application and call Lua code many times for open connection. It can be fixed if need after binding to lua command will be prepared.

GPL is good license, and it will be better to improve one good framework instead create new one.
reyalp, what do you think about just include my java code after some cleanup into chdkptp ?

WBR, Alex.

*

Offline reyalp

  • ******
  • 10835
Re: CHDK PTP Java + remoteshoot (was Re: alternative ptp client)
« Reply #7 on: 21 / June / 2015, 16:35:53 »
I reviewed chdkptp code for remote shooting and implemented about a half of own code for that. But... you spend many time for testing chdkptp and implemented so many options. Since I should have to use camera's part of chdkptp code, I tried to find way how to parse rlibs.lua from my software for send to camera.
One thing I've wanted to do, but haven't got around to is allowing the camera side rlib code to be in separate files. That would make this kind of thing simpler.

Quote
It will be one more small framework only for my application that will not be useful for many people. If somebody will want to use and improve my java framework, we will have to always synchronize code with chdkptp.
This isn't necessarily a bad thing, if people need more, they can add the parts they need.

Quote
Instead, I tried to implement more general solution. I found Lua interpreter for java - luaj. So, I need to reimplement only C part of chdkptp and will be able to use full power of chdkptp options.
This is an interesting approach.

A similar but slightly different approach is what jbaiter did for python with https://github.com/jbaiter/chdkptp.py - but in this case the C code is compiled as a DLL and loaded as a Lua module, rather than re-implementing the APIs. Building the C code as a module requires some minor changes (see diff above github), which I haven't yet put in the chdkptp trunk because there are issues making it cleanly cross platform. There can also be problems if chdkptp is linked against a different C runtime than the Lua interpreter.

Quote
You can see result of my 2 days hacking at https://github.com/alex73/chdkptp/tree/master/java/src. I'm not sure that I implemented Lua object model so good, but it works and can be improved.

For support full chdkptp functionality, more methods should be implemented, but it's already good skeleton.
This seems like a very impressive start, nice work :D
Quote
There is only one "fix" for lua code - connection should be prepared in java code because connect/disconnect in Lua code doesn't do anything. It's required for integrate framework into application and call Lua code many times for open connection. It can be fixed if need after binding to lua command will be prepared.
I haven't really understood this.

Quote
GPL is good license, and it will be better to improve one good framework instead create new one.
reyalp, what do you think about just include my java code after some cleanup into chdkptp ?
If there are changes in the chdkptp C APIs or Lua code that can make your project work more simply without negative impact, than I am happy to consider including them.

As far as including the java code: I'm not much of a java programmer, and I have enough trouble finding time to maintain chdkptp as it is. There's a lot of stuff I'd like to do that I haven't found time for, so I'd rather not have another host API to maintain.

Duplicating all the C code (chdkptp itself, plus lbuf, liveimg, rawimg etc) seems like a lot of work if you want a really complete implementation.
Don't forget what the H stands for.


Re: CHDK PTP Java + remoteshoot (was Re: alternative ptp client)
« Reply #8 on: 22 / June / 2015, 04:39:12 »
Hi reyalp.

Quote
Instead, I tried to implement more general solution. I found Lua interpreter for java - luaj. So, I need to reimplement only C part of chdkptp and will be able to use full power of chdkptp options.
This is an interesting approach.

A similar but slightly different approach is what jbaiter did for python with https://github.com/jbaiter/chdkptp.py - but in this case the C code is compiled as a DLL and loaded as a Lua module, rather than re-implementing the APIs. Building the C code as a module requires some minor changes (see diff above github), which I haven't yet put in the chdkptp trunk because there are issues making it cleanly cross platform. There can also be problems if chdkptp is linked against a different C runtime than the Lua interpreter.

I though about just use native calls from java to chdkptp, but the main problem - I will not be able to control camera connection so good from java code.

Quote
There is only one "fix" for lua code - connection should be prepared in java code because connect/disconnect in Lua code doesn't do anything. It's required for integrate framework into application and call Lua code many times for open connection. It can be fixed if need after binding to lua command will be prepared.
I haven't really understood this.

When I started chdkptp from Java, it tries to connect to camera. If connection already exist, then chdkptp tries to disconnect and connect again.
Anyway, I need different process that just start chdkptp/lua, work with camera then disconnect. I need chdkptp/lua code as library for some complex things only. I.e. my application should connect to camera, then call chdkptp/lua sometimes with exist camera connection. Anyway, after better java<->chdkptp/lua binding implementation looks like there will no any difference in connection handling with chdkptp.c.

If there are changes in the chdkptp C APIs or Lua code that can make your project work more simply without negative impact, than I am happy to consider including them.

As far as including the java code: I'm not much of a java programmer, and I have enough trouble finding time to maintain chdkptp as it is. There's a lot of stuff I'd like to do that I haven't found time for, so I'd rather not have another host API to maintain.

Yes, you are right.

I will ask you for some minor changes in lua scripts when will be ready for that.

Re: CHDK PTP Java + remoteshoot (was Re: alternative ptp client)
« Reply #9 on: 23 / June / 2015, 06:22:44 »
Hi reyalp.

I made code cleanup, removed CHDK-PTP-Java and pushed project to git: https://github.com/alex73/chdkptpJ. Code is not so stable yet, but works enough good.

So, I'm ready to ask some changes in chdkptp :)

1. Luaj requires to load Lua script and call it for declare functions, etc. Currently, I'm calling main.lua, but it starts to chdkptp itself, with calls to dngcli.init_cli(), etc. i.e. many things that not need to my framework. Could you move startup code that initializes some thing and includes all required lua files("fsutil=require'fsutils'") into separate file (probably init.lua ?) ? After that, main.lua can just include this startup code and run usual methods. I will use init.lua, then will get required function and call from java. main.lua will not be loaded in my code, but will be still used in chdktptp.

2. It would be good all functions (that can be called in chdkptp from java) as separate functions with table parameters. I.e. something like this:

function remoteshoot(params)
  if (params.raw) ...
  if (params.isomode>200) ...
...

But I understand that is big changes. I will send just array with text parameters yet. But how can I get remoteshoot function ? I see cli:add_commands but I don't know Lua so good to understand hot to get function by name. Could you please to write me simple Lua script for just get and call 'remoteshoot' function ? Somethins like :
  func = table.get('remoteshoot')
  func(['-raw','-isomode=100'])

3. If capture_get_data_pcall throws some error, script just dumps this error and continues to work. I.e. I can't know from my code was remoteshoot processed good or not. Is it possible to change code somehow(additional error throing or status return) for be able to check status on the remoteshoot function end ?

 

Related Topics