![]() |
OpenSlug.EventsOnMediaCardInsertion HistoryHide minor edits - Show changes to markup March 07, 2006, at 11:29 AM
by -- overlong line formatting corrected
Changed lines 188-189 from:
to:
Changed lines 202-204 from:
to:
March 05, 2006, at 06:11 PM
by --
Changed lines 9-10 from:
sdparm http://sg.torque.net/sg/sdparm.html is a tool that is meant to do for scsi discs what hdparm does for ide ones. (You may like to try most likely in vain to set the idle time of your usb enclosure using it). We can use sdparm to test for the presence of a valid scsi device on USB reader's installed devices. You will need to build or install sdparm (in Debian, to:
sdparm http://sg.torque.net/sg/sdparm.html is a tool that is meant to do for scsi discs what hdparm does for ide ones. (You may like to try most likely in vain to set the idle time of your usb enclosure using it). We can use sdparm to test for the presence of a valid scsi device on USB reader's installed devices. You will need to build or install sdparm (in Debian, Changed line 201 from:
to:
March 05, 2006, at 06:06 PM
by --
Changed lines 9-10 from:
sdparm http://sg.torque.net/sg/sdparm.html is a tool that is meant to do for scsi discs what hdparm does for ide ones. (You may like to try most likely in vain to set the idle time of your usb enclosure using it). We can use sdparm to test for the presence of a valid scsi device on USB reader's installed devices. You will need to build or install sdparm (in Debian, to:
sdparm http://sg.torque.net/sg/sdparm.html is a tool that is meant to do for scsi discs what hdparm does for ide ones. (You may like to try most likely in vain to set the idle time of your usb enclosure using it). We can use sdparm to test for the presence of a valid scsi device on USB reader's installed devices. You will need to build or install sdparm (in Debian, February 05, 2006, at 03:28 PM
by -- tweaked for (Open)DebianSlug
Changed lines 5-6 from:
The problem is that linux and the USB media card reader do not have a mechanism to announce that the scsi devices that the device driver models the media cards as have been hotplugged. A solution is to poll the presence of the media card. to:
The problem is that linux and the USB media card reader do not have a mechanism to announce that the media card scsi devices (which is how the device driver models the media cards to the system) have been hotplugged. A solution is to poll the presence of the media card. Changed lines 9-10 from:
sdparm http://sg.torque.net/sg/sdparm.html is a tool that is meant to do for scsi discs what hdparm does for ide ones. (You may like to try most likely in vain to set the idle time of your usb enclosure using it). We can use sdparm to test for the presence of a valid scsi device on USB reader's installed devices. You will need to build or install sdparm. to:
sdparm http://sg.torque.net/sg/sdparm.html is a tool that is meant to do for scsi discs what hdparm does for ide ones. (You may like to try most likely in vain to set the idle time of your usb enclosure using it). We can use sdparm to test for the presence of a valid scsi device on USB reader's installed devices. You will need to build or install sdparm (in Debian, Changed line 29 from:
* % sudo cf-monitor "sdparm /dev/sdc1 2> /dev/null > /dev/null" "buzzer 1" 1000 & to:
* % sudo cf-monitor "sdparm /dev/sdc1 2> /dev/null > /dev/null" "beep" 1000 & Changed lines 88-90 from:
cfmonitor=/usr/bin/cf-monitor cfcardscript=/usr/bin/cf-card-script sdparm=/usr/local/bin/sdparm to:
cfmonitor=/usr/local/bin/cf-monitor cfcardscript=/usr/local/bin/cf-card-script sdparm=/usr/bin/sdparm Changed lines 132-138 from:
You will then need to set up symbolic links to this script in In use I use the following script to copy from a Canon 20D's CF card to a network shared drive (as well as merging the irritating 100 photo directories into one -- after 10000 photos you will need to rename and restart with an empty directory, it will not overwrite existing files). The script mounts, copies then unmounts the card. It uses the 'buzzer' package to notify when the card is inserted, a file is transfered and the card can be removed. to:
You will then need to set up symbolic links to this script in Added lines 134-143:
% update-rc.d cfmonitor defaults @] In use I use the following script to copy from a Canon 20D's CF card to a network shared drive (as well as merging the irritating 100 photo directories into one -- after 10000 photos you will need to rename and restart with an empty directory, it will not overwrite existing files). The script mounts, copies then unmounts the card. It uses the 'beep' package to notify when the card is inserted, a file is transfered and the card can be removed. Added lines 150-151:
Changed lines 162-163 from:
buzzer 1 -250 7 to:
beep -f 392.0 -n -f 493.9 Changed line 172 from:
buzzer 21 to:
beep -f 450 -l 10 Changed lines 180-181 from:
buzzer 7 -250 1 -250 to:
beep -f 493.9 -n -f 392.0 December 20, 2005, at 09:15 AM
by -- note about using syslog-ng rather than syslogd (I suggest everyone moves over since mem(syslogd+klogd) > mem(syslog-ng))
Changed lines 176-195 from:
@] to:
@] Syslogd I found that a kernel entry of "Device not ready. Make sure there is a disc in the drive." was made each time sdparm failed in polling the device. This may annoy. I uninstalled syslogd (put an 'exit 0' at the top of the file in /etc/init.d/syslog) installed the syslog-ng package and in the configfile /etc/syslog-ng/syslog-ng.conf changed the source line to include kernel messages (this should be the default install really)
and added the line to create a filter for the message
and changed the output line to
You may well want to comment out all the output lines at the bottom of the file except messages, console and console_all and add the change the option line at the top of the file to
December 19, 2005, at 07:02 AM
by --
Changed lines 5-6 from:
The problem is that the linux and the USB media card reader do not have a mechanism to announce that the scsi devices that the device driver models the media cards as have been hotplugged. A solution is to poll the presence of the media card. to:
The problem is that linux and the USB media card reader do not have a mechanism to announce that the scsi devices that the device driver models the media cards as have been hotplugged. A solution is to poll the presence of the media card. December 19, 2005, at 07:00 AM
by --
Changed line 162 from:
target="$target_dir"`expr "$file" : '.*\([Ii][Mm][Gg].*\)'` to:
target="$target_dir"`expr "$file" : '.*\([i_]mg.*\)'` December 17, 2005, at 02:59 AM
by --
Changed lines 3-4 from:
When a media card is inserted into a USB media card reader (that is already plugged in) then no events are generated by this hardware change. (If an unplugged reader is plugged in then Hotplug can be used to respond to the circumstance.) to:
When a media card (e.g. a cf card) is inserted into a USB media card reader (that is already plugged in) then no events are generated by this hardware change. (If an unplugged reader is plugged in then Hotplug can be used to respond to the circumstance.) Changed lines 93-95 from:
parms='"$sdparm $dev 2> /dev/null > /dev/null" $cfcardscript 1000' test -x "$cfmonitor" || exit 0 to:
test -x "$cfmonitor" || exit 0 Changed lines 96-97 from:
test -x "$sdparm" || exit 0 to:
test -x "$sdparm" || exit 0 Changed lines 101-102 from:
start-stop-daemon --start --quiet -b --exec $cfmonitor -- $parms to:
start-stop-daemon --start --quiet -b --exec $cfmonitor -- "$sdparm $dev 2> /dev/null > /dev/null" $cfcardscript 1000 Changed lines 111-112 from:
start-stop-daemon --stop --quiet --signal 1 --exec $cf-monitor -- $parms to:
start-stop-daemon --stop --quiet --signal 1 --exec $cf-monitor -- "$sdparm $dev 2> /dev/null > /dev/null" $cfcardscript 1000 Changed lines 120-121 from:
start-stop-daemon --start --quiet -b --exec $cfmonitor -- $parms to:
start-stop-daemon --start --quiet -b --exec $cfmonitor -- "$sdparm $dev 2> /dev/null > /dev/null" $cfcardscript 1000 December 16, 2005, at 02:20 PM
by --
Changed line 134 from:
I use the following script to copy from a Canon 20D's CF card to a network shared drive (as well as merging the irritating 100 photo directories into one -- after 10000 photos you will need to rename and restart with an empty directory, it will not overwrite existing files). The script mounts, copies then unmounts the card. It uses the 'buzzer' package to notify when the card is inserted, a file is transfered and the card be removed. \\ to:
I use the following script to copy from a Canon 20D's CF card to a network shared drive (as well as merging the irritating 100 photo directories into one -- after 10000 photos you will need to rename and restart with an empty directory, it will not overwrite existing files). The script mounts, copies then unmounts the card. It uses the 'buzzer' package to notify when the card is inserted, a file is transfered and the card can be removed. \\ December 16, 2005, at 02:17 PM
by --
Changed lines 3-4 from:
When a media card is inserted into a USB media card reader (that is already plugged in) then no events are generated by this hardware change. (If an unplugged reader is plugged in then Hotplug can be used to respond to the circumstance). to:
When a media card is inserted into a USB media card reader (that is already plugged in) then no events are generated by this hardware change. (If an unplugged reader is plugged in then Hotplug can be used to respond to the circumstance.) December 16, 2005, at 02:17 PM
by --
Changed lines 3-4 from:
When a media card is inserted into a USB media card reader (that is already plugged in) then no events are generated by this hardware change. (If an unplugged reader is plugged in then HotPlug? can be used to respond to the circumstance). to:
When a media card is inserted into a USB media card reader (that is already plugged in) then no events are generated by this hardware change. (If an unplugged reader is plugged in then Hotplug can be used to respond to the circumstance). December 16, 2005, at 02:14 PM
by --
Deleted lines 61-65:
/*
printf("Executing '0.2f times per second and executing '%s' on success transition. ",
*(argv+1), (float)poll/1000.0f, *(argv+2));
*/
Changed line 102 from:
start-stop-daemon --start --quiet -b --exec $cfmonitor -- "$sdparm $dev 2> /dev/null > /dev/null" $cfcardscript 1000 to:
start-stop-daemon --start --quiet -b --exec $cfmonitor -- $parms Changed line 134 from:
I use the following script to copy from a Canon 20D's CF card to the network shared drive as well (as merging the 100 photo directories into one -- after 10000 files you will need to rename and restart with an empty directory). The script mounts, copies then unmounts the card. It uses the 'buzzer' package to notify when the card is inserted, a file is transfered and the card be removed. \\ to:
I use the following script to copy from a Canon 20D's CF card to a network shared drive (as well as merging the irritating 100 photo directories into one -- after 10000 photos you will need to rename and restart with an empty directory, it will not overwrite existing files). The script mounts, copies then unmounts the card. It uses the 'buzzer' package to notify when the card is inserted, a file is transfered and the card be removed. \\ December 16, 2005, at 02:04 PM
by --
Changed lines 13-15 from:
The following C program will poll the success of a specified command and if there is a change in the success of the command from fail to success (i.e. sdparm was not recognising a valid scsi device and now it does) then the program will run another command (your event). @@ to:
The following C program will poll the success of a specified command and if there is a change in the success of the command from fail to success (i.e. sdparm was not recognising a valid scsi device and now it does) then the program will run another command (your event). Changed lines 81-82 from:
@@ to:
@] Changed lines 87-89 from:
The variables let you set up cf-monitor to call a script cfcardscript which polls the device dev using sdparm. You will need to specify your paths of course. @@ to:
The variables let you set up cf-monitor to call a script cfcardscript which polls the device dev using sdparm. You will need to specify your paths of course. Changed lines 133-135 from:
@@ You will then need to set up symbolic links to this script in /etc/rc2-5.d, I called the link S66cfmonitor in each directory. to:
@] You will then need to set up symbolic links to this script in In use I use the following script to copy from a Canon 20D's CF card to the network shared drive as well (as merging the 100 photo directories into one -- after 10000 files you will need to rename and restart with an empty directory). The script mounts, copies then unmounts the card. It uses the 'buzzer' package to notify when the card is inserted, a file is transfered and the card be removed.
#!/bin/sh
#
# To be run by cf-monitor using e.g.
#
# sudo cf-monitor "sdparm /dev/sdc1 2> /dev/null > /dev/null" cf-card-script 1000 &
#
########################################################
source_dev="/dev/sdc1"
source_dir="/media/cf"
target_dir="/media/hdd/public/CF-CARD/"
########################################################
mount $source_dev $source_dir
buzzer 1 -250 7
if [ -e "$source_dir/dcim" ] # Check if file exists.
then
for file in `ls $source_dir/dcim/*canon/*`
do
target="$target_dir"`expr "$file" : '.*\([Ii][Mm][Gg].*\)'`
if [ ! -e "$target" ]
then
cp "$file" "$target"
buzzer 21
fi
done
fi
chown -R guest "$target_dir"
umount /dev/sdc1
buzzer 7 -250 1 -250
December 16, 2005, at 01:23 PM
by -- How to enable automatic response to media card insertion into an already installed USB card reader.
Added lines 1-133:
How to generate events when a media card is inserted into an USB readerWhen a media card is inserted into a USB media card reader (that is already plugged in) then no events are generated by this hardware change. (If an unplugged reader is plugged in then HotPlug? can be used to respond to the circumstance). The problem is that the linux and the USB media card reader do not have a mechanism to announce that the scsi devices that the device driver models the media cards as have been hotplugged. A solution is to poll the presence of the media card. sdparm sdparm http://sg.torque.net/sg/sdparm.html is a tool that is meant to do for scsi discs what hdparm does for ide ones. (You may like to try most likely in vain to set the idle time of your usb enclosure using it). We can use sdparm to test for the presence of a valid scsi device on USB reader's installed devices. You will need to build or install sdparm. Polling The following C program will poll the success of a specified command and if there is a change in the success of the command from fail to success (i.e. sdparm was not recognising a valid scsi device and now it does) then the program will run another command (your event). @@ /* cf-monitor.c * * Code licensed with GPL * * cf-monitor TEST CMD [POLL millisecs] * * This command executes the command TEST every POLL millisecs (default 2000) and * if a transition from the command TEST failing to the command TEST succeeding occurs * then the command CMD is executed. * * Usage example: * * % sudo cf-monitor "sdparm /dev/sdc1 2> /dev/null > /dev/null" "buzzer 1" 1000 & * * Which polls device /dev/sdc1 every second and beeps if the device becomes available * to mount (while writing all output from sdparm to /dev/null). * * The sdparm command can be found at http://sg.torque.net/sg/sdparm.html * */
void wait(int milli_secs) { struct timespec t; t.tv_sec = milli_secs/1000; t.tv_nsec = 1000000 *(milli_secs%1000); nanosleep(&t,0); } int main(int argc, char **argv) { char *cmd;
int flag = 0, fail, poll = DEFAULT_POLL;
if (argc < 3) { printf("Usage: %s TEST CMD [POLL millisecs]\n", *argv); return 256; }
if (argc > 3) { poll = atoi(*(argv+3)); }
if (poll < 100) poll = 100; // sensible max poll rate of 10/s
/*
printf("Executing '0.2f times per second and executing '%s' on success transition. ",
*(argv+1), (float)poll/1000.0f, *(argv+2));
*/
fail = system(*(argv+1));
if (!fail) {flag = 1;}
while (1)
{
fail = system(*(argv+1));
if (!fail && flag == 0) { system(*(argv+2)); flag = 1; }
if (fail) flag = 0;
wait(poll);
}
return 0;
} @@ Starting on boot Here's a boot script to be inserted as root in The variables let you set up cf-monitor to call a script cfcardscript which polls the device dev using sdparm. You will need to specify your paths of course. @@
cfmonitor=/usr/bin/cf-monitor cfcardscript=/usr/bin/cf-card-script sdparm=/usr/local/bin/sdparm dev=/dev/sdc1 parms='"$sdparm $dev 2> /dev/null > /dev/null" $cfcardscript 1000' test -x "$cfmonitor" || exit 0 test -x "$cfcardscript" || exit 0 test -x "$sdparm" || exit 0 case "$1" in start)
echo -n "Starting cf-monitor"
start-stop-daemon --start --quiet -b --exec $cfmonitor -- "$sdparm $dev 2> /dev/null > /dev/null" $cfcardscript 1000
echo "."
;;
stop)
echo -n "Stopping cf-monitor"
start-stop-daemon --stop --quiet -x $cfmonitor
echo "."
;;
reload|force-reload)
start-stop-daemon --stop --quiet --signal 1 --exec $cf-monitor -- $parms
;;
restart)
echo -n "Stopping cf-monitor"
start-stop-daemon --stop --quiet -x $cfmonitor
echo "."
sleep 1
echo -n "Starting cf-monitor"
start-stop-daemon --start --quiet -b --exec $cfmonitor -- $parms
echo "."
;;
*)
echo "Usage: /etc/init.d/cf-monitor {start|stop|reload|restart|force-reload}"
exit 1
esac exit 0 @@ You will then need to set up symbolic links to this script in /etc/rc2-5.d, I called the link S66cfmonitor in each directory. |