summaryrefslogtreecommitdiff
path: root/2.3-1/macros/Hardware/RasberryPi/raspi.sci
blob: 4da09ca4fb44bb3dda89cec7412731ce64f17c64 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright (C) 2017 - IIT Bombay - FOSSEE
//
// This file must be used under the terms of the CeCILL.
// This source file is licensed as described in the file COPYING, which
// you should have received as part of this distribution.  The terms
// are also available at
// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
// Organization: FOSSEE, IIT Bombay
// Email: toolbox@scilab.in

global RPI_piAdress;

if getos()=="Linux" then
    RPI_MacrosPath=get_absolute_file_path("raspi.sci");
    RPI_MacrosPath=part(RPI_MacrosPath,1:(length(RPI_MacrosPath)-7));
    RPI_MacrosPath=RPI_MacrosPath+'src/python/';
//    disp("Linux");
    function raspi(adress,local,username)
    // Function to initiate the connection to the raspberry pi
    //
    // Calling Sequence
    //  raspi(adress,local,username)
    //
    // Parameters
    //  address : Network address of the raspberry pi. Eg:10.42.0.82
    //  local   : username of the local computer.
    //  username: username on the raspberry pi.
    //
    // Description
    //  This program initiates the connection to the raspberry pi at the given address by running the python server script on port 9077 on the pi.
    //
    // Examples
    //  raspi('10.42.0.82','panda','pi')
    // See also
    //  raspi_close
    //
    // Authors
    //  Jorawar Singh
    
        global RPI_piAdress;
        RPI_piAdress=adress;
        
        disp("Step 1/6")
        TCL_EvalStr("if {[file exists /home/"+local+"/.ssh/id_rsa]} {} else {exec ssh-keygen -N """" -f /home/"+local+"/.ssh/id_rsa -q}");
        disp("Step 2/6")
        TCL_EvalStr("exec ssh-add >logs.txt 2>&1");
        disp("Step 3/6")
        TCL_EvalStr("exec ssh-copy-id -i /home/"+local+"/.ssh/id_rsa.pub "+username+"@"+adress+" > logs.txt 2>&1");
        disp("Step 4/6")
        TCL_EvalStr("exec rsync -avz "+RPI_MacrosPath+"serverWP.py "+username+"@"+adress+":.scilab/ >logs.txt");
        disp("Step 5/6")
        TCL_EvalStr("exec ssh "+username+"@"+adress+" sudo python /home/"+username+"/.scilab/serverWP.py &");
        disp("Step 6/6")
        TCL_EvalStr(["file delete logs.txt";"file delete &1"]);
    endfunction
elseif getos()=='Windows' then
    tempPath=get_absolute_file_path("raspi.sci");
    RPI_MacrosPath=strsubst(tempPath,'\','/');
    RPI_MacrosPath=part(RPI_MacrosPath,1:(length(RPI_MacrosPath)-7));
    RPI_MacrosPath=RPI_MacrosPath+'src/python/';
    function raspi(adress,username)
    // Function to initiate the connection to the raspberry pi
    //
    // Calling Sequence
    //  raspi(adress,username)
    //
    // Parameters
    //  address : Network address of the raspberry pi. Eg:10.42.0.82
    //  username: username on the raspberry pi.
    //
    // Description
    //  This program initiates the connection to the raspberry pi at the given address by running the python server script on port 9077 on the pi.
    //
    // Examples
    //  raspi('169.254.191.116','pi')
    // See also
    //  raspi_close
    //
    // Authors
    //  Jorawar Singh
        
        global RPI_piAdress;
        RPI_piAdress=adress;
        
        disp("Step 1/3")
        TCL_EvalStr("exec mintty ssh "+username+"@"+adress+" mkdir .scilab");
        disp("Step 2/3")
        TCL_EvalStr("exec mintty scp "+RPI_MacrosPath+"serverWP.py "+username+"@"+adress+":/home/"+username+"/.scilab/");
        disp("Step 3/3 (Wait ~15 seconds)")
        TCL_EvalStr("exec mintty ssh "+username+"@"+adress+" sudo python /home/"+username+"/.scilab/serverWP.py &");
        sleep(15000)
        TCL_EvalStr("exec taskkill /IM mintty.exe");
    endfunction
end