Subversion Repositories HomeAutomation

Rev

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

Rev 1080 Rev 1305
Line 251... Line 251...
251
        $peer_addr = inet_ntoa($ipaddr);
251
        $peer_addr = inet_ntoa($ipaddr);
252
       
252
       
253
        ### check ipaddr to ip in commandlinearg ###
253
        ### check ipaddr to ip in commandlinearg ###
254
        if ($udpip == $peer_addr) {
254
        if ($udpip == $peer_addr) {
255
            #check len of incomming data
255
            #check len of incomming data
256
            if (length($newmsg) > 16 && length($newmsg) < 20) {
256
            if (length($newmsg) > 16 && length($newmsg) < 20)
-
 
257
            {
257
                $retstring = "";
258
                $retstring = "";
258
                &c2sToString($newmsg, $retstring);
259
                &c2sToString($newmsg, $retstring);
259
                if (length($retstring) > 0 && $hwCremote) {
260
                if (length($retstring) > 0 && $hwCremote) {
260
                    print $hwCremote $retstring . "\n";
261
                    print $hwCremote $retstring . "\n";
-
 
262
                }
-
 
263
            }
-
 
264
            elsif (length($newmsg) == 1)
-
 
265
            {
-
 
266
                if (ord(substr($newmsg, 0, 1)) == $C2PINGSTR)
-
 
267
                {
-
 
268
                    print "Got pong from hardware\n";
261
                }
269
                }
262
            }
270
            }
263
        }
271
        }
264
    }
272
    }
265
   
273
   
266
}
274
}
267
 
275
 
268
sub udpServerInit {
276
sub udpServerInit {
269
    print "Starting udpServer\n";
277
    print "Starting udpServer\n";
270
    $udpSsocket = IO::Socket::INET->new(LocalPort => $udpport, Proto => 'udp')
278
    $udpSsocket = IO::Socket::INET->new(LocalPort => $udpport, Proto => 'udp')
271
        or die "socket: $@";
279
        or die "socket: $@";
272
 
280
 
273
    $udpCsocket = IO::Socket::INET->new(PeerPort => $udpport, Proto => 'udp', PeerAddr => $udpip)
281
    $udpCsocket = IO::Socket::INET->new(PeerPort => $udpport, Proto => 'udp', PeerAddr => $udpip)
274
        or die "socket: $@";
282
        or die "socket: $@";
275
   
283
 
276
    #här ska keep-alive/start-paket skickas till ipt enligt commandline-arg
284
    #här ska keep-alive/start-paket skickas till ipt enligt commandline-arg
277
    #just nu skickas bara ett initialiseringspaket
285
    #just nu skickas bara ett initialiseringspaket
278
    my $retstring;
286
#   my $retstring;
279
    &stringToc2s("PKT 00000000 1 0", $retstring);
287
#   &stringToc2s("PKT 00000000 1 0", $retstring);
280
        if ($retstring) {
288
#   if ($retstring) 
-
 
289
#   {
281
        ### Send data ###
290
        ### Send data ###
282
        if (length($hardwareSendFunction) > 0) {
-
 
283
            &{$hardwareSendFunction}($retstring);
291
#       udpServerSend($retstring);
284
        }
292
#   }
-
 
293
#   else
-
 
294
#   {
-
 
295
#       print "Could not create initpacket\n";
285
    }
296
#   }
-
 
297
    print "Testing connection to hardware: ping (hardware should answer with a pong)\n";
-
 
298
    udpServerSend(chr($C2PINGSTR));
286
 
299
 
287
    ### create a connection between the hardware and the tcp-server ###
300
    ### create a connection between the hardware and the tcp-server ###
288
    &hardwareConnInit;
301
    &hardwareConnInit;
289
    $hardwareSendFunction = "udpServerSend";        ### set up callback for a 'send data' function
302
    $hardwareSendFunction = "udpServerSend";        ### set up callback for a 'send data' function
290
    $thr = threads->new(\&hardwareConnThread);
303
    $thr = threads->new(\&hardwareConnThread);