Subversion Repositories HomeAutomation

Rev

Rev 889 | Rev 935 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 889 Rev 907
Line 15... Line 15...
15
require 5.002;
15
require 5.002;
16
use IO::Socket;
16
use IO::Socket;
17
use IO::Select;
17
use IO::Select;
18
use threads;
18
use threads;
19
use Getopt::Long;
19
use Getopt::Long;
-
 
20
 
-
 
21
use POSIX qw(setsid);
20
 
22
 
21
$binaryname = "canDaemon.pl";
23
$binaryname = "canDaemon.pl";
22
if ( @ARGV > 0 ) {
24
if ( @ARGV > 0 ) {
23
    GetOptions( "baudrate=i"    => \$baudarg,   #
25
    GetOptions( "baudrate=i"    => \$baudarg,           #
24
            "server=s"  => \$serverarg,         #
26
            "server=s"  => \$serverarg,         #
25
            "port=i"    => \$portarg,           #
27
            "port=i"    => \$portarg,           #
26
            "tcpport=i" => \$tcpportarg,        #
28
            "tcpport=i" => \$tcpportarg,        #
27
            "device=s"  => \$devicearg,         #
29
            "device=s"  => \$devicearg,         #
28
            "help"      => \$help,              #
30
            "help"      => \$help,          #
-
 
31
            "xDaemon"   => \$daemon,            #
29
                        );
32
                        );
30
} else {
33
} else {
31
    $help = 1;
34
    $help = 1;
32
}
35
}
33
 
36
 
34
if ($help) {
37
if ($help) {
35
    print "Usage ./$binaryname [options]\n";
38
    print "Usage ./$binaryname [options]\n";
36
    print "Options:\n";
39
    print "Options:\n";
-
 
40
    print "  -x                         Make canDaemon detach as a UNIX daemon\n";
37
    print "  -d <device> (udp or /dev/ttyXYZ)       Choose hardware for communication\n";
41
    print "  -d <device> (udp or /dev/ttyXYZ)       Choose hardware for communication\n";
38
    print "  -b <baudrate>              Baudrate, for serial devices\n";
42
    print "  -b <baudrate>                  Baudrate, for serial devices\n";
39
    print "  -s <server>                    Server, for udp devices\n";
43
    print "  -s <server>                    Server, for udp devices\n";
40
    print "  -p <port>                  Port, for udp devices\n";
44
    print "  -p <port>                  Port, for udp devices\n";
41
    print "  -t <tcpport>                   Port, for tcp server (default 1200)\n";
45
    print "  -t <tcpport>                   Port, for tcp server (default 1200)\n";
42
    print "  -h <help>                  Shows this usage\n";
46
    print "  -h                         Shows this usage\n";
43
    print "\n";
47
    print "\n";
44
    print "example: ./$binaryname -d /dev/ttyUSB0 -b 38400\n";
48
    print "example: ./$binaryname -d /dev/ttyUSB0 -b 38400\n";
45
    print "example: ./$binaryname -d udp -s 192.168.0.10 -p 1100\n";
49
    print "example: ./$binaryname -d udp -s 192.168.0.10 -p 1100\n";
46
 
50
 
47
    exit 0;
51
    exit 0;
Line 53... Line 57...
53
if ($portarg) {
57
if ($portarg) {
54
    $udpport = $portarg;
58
    $udpport = $portarg;
55
}
59
}
56
if ($tcpportarg) {
60
if ($tcpportarg) {
57
    $hubport = $tcpportarg;
61
    $hubport = $tcpportarg;
-
 
62
}
-
 
63
 
-
 
64
if ($daemon) {
-
 
65
    chdir '/'                 or die "Can't chdir to /: $!";
-
 
66
    umask 0;
-
 
67
    open STDIN, '/dev/null'   or die "Can't read /dev/null: $!";
-
 
68
    open STDOUT, '>/dev/null' or die "Can't write to /dev/null: $!";
-
 
69
    #open STDERR, '>/dev/null' or die "Can't write to /dev/null: $!";
-
 
70
    defined(my $pid = fork)   or die "Can't fork: $!";
-
 
71
    exit if $pid;
-
 
72
    setsid                    or die "Can't start a new session: $!";
58
}
73
}
59
 
74
 
60
$C2SSTARTSTR = 253;
75
$C2SSTARTSTR = 253;
61
$C2SENDSTR = 250;
76
$C2SENDSTR = 250;
62
$C2PINGSTR = 251;
77
$C2PINGSTR = 251;
Line 92... Line 107...
92
            } else {
107
            } else {
93
                $usingWin32Serial = 1;
108
                $usingWin32Serial = 1;
94
            }
109
            }
95
        } else {
110
        } else {
96
            $usingDeviceSerial = 1;
111
            $usingDeviceSerial = 1;
97
        }
112
        }
98
       
113
       
99
        &serialConnInit;
114
        &serialConnInit;
100
        $thr = threads->new(\&serialConnThread);
115
        $thr = threads->new(\&serialConnThread);
101
        $thr->detach;      
116
        $thr->detach;      
102
    }
117
    }
103
#   } else {
118
#   } else {
104
#       print "Argument $devicearg is not correct\n";
119
#       print "Argument $devicearg is not correct\n";
105
#       exit 0;
120
#       exit 0;
106
#   }
121
#   }
107
}
122
}
-
 
123
 
108
 
124
 
109
### loop here until user aborts with ctrl+c ###
125
### loop here until user aborts with ctrl+c ###
110
while (1) { sleep 1; }
126
while (1) { sleep 1; }
111
 
127
 
112
 
128