Are these software upgrades possible? - page 5 - General Help and Assistance on using CHDK stable releases - CHDK Forum supplierdeeply

Are these software upgrades possible?

  • 187 Replies
  • 36755 Views
Re: Are these software upgrades possible?
« Reply #40 on: 12 / May / 2011, 20:31:36 »
Advertisements
that works but while using that I realized I that a time-stamp isn't the best solution. What happens in the camera crashes for whatever reason and my program just keeps sending it commands anyway. So when I come and check it all I see is the hundreds of error messages. It only stores so many commands so the useful info is already gone if I try to scroll up and look at it. What I'd like to do is change the way it handles errors. This may not be possible but I'd it to ignore a command if that command produces a camera not responding/connected error. This way, when I come and check on it I can actually see the log of what happened which allows me to tell where specifically it crashed and better adjust the timing of the commands. Is that possible? Where would I start?

If that doesn't work, how about a log.txt file that is erased each time chdkptp is started? I can look through that instead of the cmd window.
« Last Edit: 12 / May / 2011, 20:39:21 by John1234 »

*

Offline reyalp

  • ******
  • 13719
Re: Are these software upgrades possible?
« Reply #41 on: 12 / May / 2011, 22:43:49 »
Maybe your program should read the output and stop sending input if there is an error ?

You could certainly modify it to exit on error, or send output to a log file.

The following will override the cli execute function to quit if any command returns a fail status.
Code: [Select]
___> !local old_exec=cli.execute;cli.execute=function(self,line) local status,output=old_exec(self,line) ; if not status then error(output) end return status,output end
You could do something similar to make it ignore all commands after the first error.

If you want to redirect to a log, you could either do it using standard os functionality ( > log.txt 2>&1) or reopen the standard output handles, or wrap the output functions. chdkptp isn't currently very consistent where it uses the various output functions and whether it uses stdout or stderr, so there's a fair chance you wouldn't get everything unless you use the first method.

edit:
edited code to make it correctly return values.
« Last Edit: 13 / May / 2011, 17:06:16 by reyalp »
Don't forget what the H stands for.

Re: Are these software upgrades possible?
« Reply #42 on: 12 / May / 2011, 23:37:23 »
Quote
Maybe your program should read the output and stop sending input if there is an error ?
I tried going that route already with no success.

I don't want the chdkptp program to quit if there is an error because that won't help me figure out what happened. The log.txt file would be best but I'm not familiar with the lua language or your code enough to implement it. It would just write everything it would normally write to the cmd window to a log.txt file. Whatever function processes text input (cli:execute(line)?)
would write the command being executed to the log file. Then the function that handles errors would write any error it found to that log file on the next line. (When the program is started it will clear the log file or else the log file would grow infinitely.)

*

Offline reyalp

  • ******
  • 13719
Re: Are these software upgrades possible?
« Reply #43 on: 13 / May / 2011, 00:31:46 »
You could use something like
Code: [Select]
!logfile=io.open("log.txt","w") ; logfile:close()
!function log(s) logfile=io.open("log.txt","a"); logfile:write(string.format("%s %s\n",os.date("%H:%M:%S"),s)) ; logfile:close(); end
!local old_exec=cli.execute;cli.execute=function(self,line) log(line); local status,output=old_exec(self,line); if output then log(output) end return status,output end
That will log the commands and most of the output. There's a few things the use print directly or output in C code you'll miss.

The first open with "w" and close truncates the log text. Opening and closing the log for each item might not be needed but it ensures you get a log if the program crashes.

I'm happy to give suggestions or point out where to look in the code, but I'm not really interested in implementing stuff specifically for your project. Lua is a straightforward, well documented language. If you have some programming skill, picking up enough to customize the chdkptp code should not be a huge deal. As a bonus, it learning it will help you write scripts for the camera too.
Don't forget what the H stands for.


Re: Are these software upgrades possible?
« Reply #44 on: 13 / May / 2011, 09:01:52 »
instead of pasting that modification in everytime the program starts, I'd like to modify cli.lua. I see generally what you did; created a variable 'logfile', a function that writes to the log, but this last line is confusing. It looks like the cli:execute function gets modified. So here's the unmodified function:
Code: [Select]
function cli:execute(line)
-- single char shortcuts
local s,e,cmd = string.find(line,'^[%c%s]*([!?.#=])[%c%s]*')
if not cmd then
s,e,cmd = string.find(line,'^[%c%s]*([%w_]+)[%c%s]*')
end
if s then
local args = string.sub(line,e+1)
if self.names[cmd] then
local status,msg = self.names[cmd](args)
if not status and not msg then
msg=cmd .. " failed"
end
return status,msg
else
return false,string.format("unknown command '%s'\n",cmd)
end
elseif string.find(line,'[^%c%s]') then
return false, string.format("bad input '%s'\n",line)
end
-- blank input is OK
return true,""
end
1. what changes/gets modified in the execute() function?

2. where does the logfile variable get declared? at the top of the cli.lua file?

3. I'm guessing the log() function can be pasted anywhere in the cli.lua file?
« Last Edit: 13 / May / 2011, 09:28:13 by John1234 »

*

Offline reyalp

  • ******
  • 13719
Re: Are these software upgrades possible?
« Reply #45 on: 13 / May / 2011, 17:05:03 »
1. what changes/gets modified in the execute() function?
The original execute function is not actually changed. A new function is created, which logs the command, calls the old function, and logs the output. In lua, functions are values. The orginal cli.execute is saved in old_exec, and then the new function is assigned to cli.execute.

Even if you modify the file, I would suggest using this approach, because
1) if I change the guts of cli.execute, you code doesn't have to change.
2) the cli.execute returns from several places. You'd have to log in all these places (or have some additional logic) if you wanted to modify the original function.
Quote
2. where does the logfile variable get declared? at the top of the cli.lua file?
Lua does not require global variables to be declared. They just spring into existence the first time you use them. The initial open and close, as I said before, is just to make sure any existing file is cleared. This just needs to run once somewhere, so the later calls can use append mode.

Quote
3. I'm guessing the log() function can be pasted anywhere in the cli.lua file?
Or in any of the lua files.

To achieve the same effect as the cli commands I posted earlier, you could past the following immediately after    cli=require('cli') in main.lua

Code: [Select]
logfile=io.open("log.txt","w")
logfile:close()
function log(s)
 logfile=io.open("log.txt","a")
 logfile:write(string.format("%s %s\n",os.date("%H:%M:%S"),s))
 logfile:close()
end
local old_exec=cli.execute;
cli.execute=function(self,line)
 log(line);
 local status,output=old_exec(self,line)
 if output then
  log(output)
 end
 return status,output
end
Note the above is untested, but it's just a the CLI commands re-formatted so it's probably ok.
Don't forget what the H stands for.

Re: Are these software upgrades possible?
« Reply #46 on: 13 / May / 2011, 19:16:05 »
Awesome. It works. Now I may be able to solve some of these timing problems.

Another angle I thought of is the error handling on the camera. It seems like there is none in CHDK hence the crashing. here are the 2 scenarios that I've noticed that cause it to crash so far:
1. lua commands are sent before it is done downloading images.
2. It is told to take a picture too fast.

Re: Are these software upgrades possible?
« Reply #47 on: 13 / May / 2011, 22:16:02 »
Now that you've given me the ability to log the input and output, I finally caught it crashing for no good reason. (There have been at least 3 instances of it crashing like this today.)

21:55:08 lua press "shoot_full"
21:56:32 lua press "shoot_full"
21:56:32 failed

As you can see, it just flat crashed unprovoked. wtf. What do I need to do to make it stop crashing? It is such a sensitive POS.

Is there some way for the camera to save a log file on the SD card that somehow sheds light on why it crashes when it does?

« Last Edit: 13 / May / 2011, 22:42:28 by John1234 »


*

Offline reyalp

  • ******
  • 13719
Re: Are these software upgrades possible?
« Reply #48 on: 13 / May / 2011, 23:02:34 »
Now that you've given me the ability to log the input and output, I finally caught it crashing for no good reason. (There have been at least 3 instances of it crashing like this today.)

21:55:08 lua press "shoot_full"
21:56:32 lua press "shoot_full"
21:56:32 failed
As a general rule, it's a good idea to make your script button presses act like a human would. Press half shoot, press shoot, release shoot, release half shoot, with appropriate sleep time in between. The shoot() function tries to do this for you (but has problems on some cameras).

You should also know that if you try to run a script while another is still running, Bad Things will happen. If you are using the most recent lua files (revision 50 higher), chdkptp will try to prevent you from doing this.
Quote
As you can see, it just flat crashed unprovoked. wtf. What do I need to do to make it stop crashing? It is such a sensitive POS.
You're using an alpha port of a hack that directly fiddles with the guts of completely undocumented OS on the basis of knowledge gained from experiment, reverse engineering, and the occasional wild guess.

That isn't to say crashes are OK. We try to fix things we can, but you should understand this isn't like a normal piece of software.
Quote
Is there some way for the camera to save a log file on the SD card that somehow sheds light on why it crashes when it does?
Yes http://chdk.wikia.com/wiki/Debugging#Camera_crash_logs_.28romlog.29
Don't forget what the H stands for.

Re: Are these software upgrades possible?
« Reply #49 on: 14 / May / 2011, 00:35:59 »
1. what is a usage example for shoot()? Is it a function that takes no parameters? would the usage example just be .shoot?

2. ok, apparently the script that tells the firmware to save a log of errors is here: CHDK/SCRIPTS/TEST/ROMLOG.LUA and you can also give it a parameter of 0 or 1 to not overwrite or overwrite the log respectively. The question is, how is the ptp command formed that would tell it to run that script? I'm assuming I'll have to tell it to run every time the camera is powered on.

 

Related Topics