Update Readme file
move java file
This commit is contained in:
parent
0ab01b19e6
commit
b7fb7de498
81
README.md
81
README.md
@ -1,27 +1,54 @@
|
|||||||
# Overview
|
# Overview
|
||||||
|
|
||||||
# Deployment
|
# Deployment
|
||||||
|
use the following command to transfer project to raspberry pi:
|
||||||
use the following command to transfer project to raspberry pi:
|
scp -r gpio pi@192.168.1.77:~
|
||||||
|
|
||||||
scp -r gpio pi@192.168.1.77:~
|
# usage
|
||||||
|
## switch relais on
|
||||||
|
```
|
||||||
# Regler
|
javadoc todo
|
||||||
|
```
|
||||||
Pin GPIO Regler
|
## switch relais off
|
||||||
2 5v VCC
|
```
|
||||||
6 GND GND
|
javadoc todo
|
||||||
8 GPIO 14 In1
|
```
|
||||||
10 GPIO 15 In2
|
## read status of relais
|
||||||
12 GPIO 18 In3
|
```
|
||||||
16 GPIO 23 In4
|
javadoc todo
|
||||||
18 GPIO 24 In5
|
```
|
||||||
22 GPIO 25 In6
|
|
||||||
24 GPIO 8 In7
|
## Create Dokumentation
|
||||||
26 GPIO 7 In8
|
```
|
||||||
|
javadoc todo
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
# Requirements
|
||||||
|
## HW
|
||||||
|
* Raspberry PI
|
||||||
|
|
||||||
|
## Software
|
||||||
|
* raspberian url:
|
||||||
|
|
||||||
|
# Verbindung zwischen Raspberry Pi und Relais Box
|
||||||
|
Pin GPIO Relais/Box
|
||||||
|
* 2 5v VCC
|
||||||
|
* 6 GND GND
|
||||||
|
* 8 GPIO 14 In1
|
||||||
|
* 10 GPIO 15 In2
|
||||||
|
* 12 GPIO 18 In3
|
||||||
|
* 16 GPIO 23 In4
|
||||||
|
* 18 GPIO 24 In5
|
||||||
|
* 22 GPIO 25 In6
|
||||||
|
* 24 GPIO 8 In7
|
||||||
|
* 26 GPIO 7 In8
|
||||||
|
|
||||||
|
# ToDo
|
||||||
|
* Status Abfrage implementieren
|
||||||
|
* Javadok Kommentare hinzufügen, Dokumentation generieren und anschauen
|
||||||
|
* Test Durchführen und logfile erzeugen
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,204 +1,205 @@
|
|||||||
//package pdu_jctrl;
|
import java.io.IOException;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.io.IOException;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
// todo: add Dokumentation
|
||||||
public class gpio_java
|
public class gpio_java
|
||||||
{
|
{
|
||||||
public static String rel_map [][] = {
|
public static String rel_map [][] = {
|
||||||
{"rel1","14"},
|
{"rel1","14"},
|
||||||
{"rel2","15"},
|
{"rel2","15"},
|
||||||
{"rel3","18"},
|
{"rel3","18"},
|
||||||
{"rel4","23"},
|
{"rel4","23"},
|
||||||
{"rel5","24"},
|
{"rel5","24"},
|
||||||
{"rel6","25"},
|
{"rel6","25"},
|
||||||
{"rel7","8"},
|
{"rel7","8"},
|
||||||
{"rel8","7"}
|
{"rel8","7"}
|
||||||
};
|
};
|
||||||
public static String [] action = {"on", "off", "status"};
|
public static String [] action = {"on", "off", "status"};
|
||||||
|
|
||||||
public static void main (String [] args)
|
public static void main (String [] args)
|
||||||
{
|
{
|
||||||
// Zum checken der Anzahl der Argumente
|
// Zum checken der Anzahl der Argumente
|
||||||
checkargs(args);
|
checkargs(args);
|
||||||
|
|
||||||
// todo: initialisiere alle acht ports (outputs)
|
// todo: initialisiere alle acht ports (outputs)
|
||||||
init_gpio();
|
init_gpio();
|
||||||
|
|
||||||
// setze gpio (gemaes der parameter)
|
// setze gpio (gemaes der parameter)
|
||||||
gpio_getport(args[0]);
|
gpio_getport(args[0]);
|
||||||
|
|
||||||
|
|
||||||
gpio_cmdhandler(args[0], args[1]);
|
gpio_cmdhandler(args[0], args[1]);
|
||||||
|
|
||||||
/*
|
// todo: remove following not used code
|
||||||
setgpio(true);
|
/*
|
||||||
|
setgpio(true);
|
||||||
try {
|
|
||||||
TimeUnit.SECONDS.sleep(1);
|
try {
|
||||||
}
|
TimeUnit.SECONDS.sleep(1);
|
||||||
catch(InterruptedException e)
|
}
|
||||||
{
|
catch(InterruptedException e)
|
||||||
System.out.println("sleep error InterruptedException ocure");
|
{
|
||||||
}
|
System.out.println("sleep error InterruptedException ocure");
|
||||||
|
}
|
||||||
setgpio(false);
|
|
||||||
*/
|
setgpio(false);
|
||||||
}
|
*/
|
||||||
|
}
|
||||||
public static void checkargs(String[] argumens)
|
|
||||||
{
|
public static void checkargs(String[] argumens)
|
||||||
int laenge = argumens.length;
|
{
|
||||||
String [] h = {"-h"};
|
int laenge = argumens.length;
|
||||||
int idx;
|
String [] h = {"-h"};
|
||||||
boolean parameter1 = false;
|
int idx;
|
||||||
boolean parameter2 = false;
|
boolean parameter1 = false;
|
||||||
|
boolean parameter2 = false;
|
||||||
|
|
||||||
if (laenge == 2)
|
|
||||||
{
|
if (laenge == 2)
|
||||||
//ToDO: Pruefe erstes und zweites Argument
|
{
|
||||||
//Erstes Element(rel)
|
//ToDO: Pruefe erstes und zweites Argument
|
||||||
for (idx = 0; idx<8 ; idx++)
|
//Erstes Element(rel)
|
||||||
{
|
for (idx = 0; idx<8 ; idx++)
|
||||||
if (argumens[0].equals(rel_map[idx][0]))
|
{
|
||||||
{
|
if (argumens[0].equals(rel_map[idx][0]))
|
||||||
parameter1 = true;
|
{
|
||||||
break;
|
parameter1 = true;
|
||||||
}
|
break;
|
||||||
}
|
}
|
||||||
//Zweites Element (action)
|
}
|
||||||
for (idx = 0; idx<3 ; idx++)
|
//Zweites Element (action)
|
||||||
{
|
for (idx = 0; idx<3 ; idx++)
|
||||||
if (argumens[1].equals(action[idx]))
|
{
|
||||||
{
|
if (argumens[1].equals(action[idx]))
|
||||||
parameter2 = true;
|
{
|
||||||
break;
|
parameter2 = true;
|
||||||
}
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
else if (Arrays.equals (argumens, h) == true)
|
}
|
||||||
{
|
else if (Arrays.equals (argumens, h) == true)
|
||||||
|
{
|
||||||
show_usage();
|
|
||||||
|
show_usage();
|
||||||
System.exit(0);
|
|
||||||
}
|
System.exit(0);
|
||||||
else
|
}
|
||||||
{
|
else
|
||||||
System.out.println("Error. If you need help, type the command -h");
|
{
|
||||||
|
System.out.println("Error. If you need help, type the command -h");
|
||||||
System.exit(0);
|
|
||||||
}
|
System.exit(0);
|
||||||
//ToDo: Return
|
}
|
||||||
|
//ToDo: Return
|
||||||
}
|
|
||||||
|
}
|
||||||
public static void init_gpio()
|
|
||||||
{
|
public static void init_gpio()
|
||||||
int idx;
|
{
|
||||||
String port;
|
int idx;
|
||||||
String cmd;
|
String port;
|
||||||
|
String cmd;
|
||||||
for(idx = 0; idx<8 ; idx++)
|
|
||||||
{
|
for(idx = 0; idx<8 ; idx++)
|
||||||
port = rel_map[idx][1];
|
{
|
||||||
cmd = "/usr/bin/gpio -g mode " + port + " out";
|
port = rel_map[idx][1];
|
||||||
launchcmd(cmd);
|
cmd = "/usr/bin/gpio -g mode " + port + " out";
|
||||||
|
launchcmd(cmd);
|
||||||
}
|
|
||||||
return;
|
}
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
public static int gpio_getport(String port)
|
|
||||||
{
|
public static int gpio_getport(String port)
|
||||||
int idx;
|
{
|
||||||
|
int idx;
|
||||||
for(idx = 0; idx<8 ; idx++)
|
|
||||||
{
|
for(idx = 0; idx<8 ; idx++)
|
||||||
if(port.equals(rel_map[idx][0]))
|
{
|
||||||
{
|
if(port.equals(rel_map[idx][0]))
|
||||||
return idx;
|
{
|
||||||
}
|
return idx;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return -1;
|
|
||||||
}
|
return -1;
|
||||||
|
}
|
||||||
public static int gpio_cmdhandler(String port, String cmd)
|
|
||||||
{
|
public static int gpio_cmdhandler(String port, String cmd)
|
||||||
int idx_port;
|
{
|
||||||
|
int idx_port;
|
||||||
idx_port = gpio_getport(port);
|
|
||||||
|
idx_port = gpio_getport(port);
|
||||||
|
|
||||||
if (cmd.equals(action [0]))
|
|
||||||
{
|
if (cmd.equals(action [0]))
|
||||||
//Schalte on
|
{
|
||||||
cmd = "/usr/bin/gpio -g write " + rel_map[idx_port][1] + " 1";
|
//Schalte on
|
||||||
launchcmd(cmd);
|
cmd = "/usr/bin/gpio -g write " + rel_map[idx_port][1] + " 1";
|
||||||
|
launchcmd(cmd);
|
||||||
}
|
|
||||||
if (cmd.equals(action [1]))
|
}
|
||||||
{
|
if (cmd.equals(action [1]))
|
||||||
//Schalte off
|
{
|
||||||
cmd = "/usr/bin/gpio -g write " + rel_map[idx_port][1] + " 0";
|
//Schalte off
|
||||||
launchcmd(cmd);
|
cmd = "/usr/bin/gpio -g write " + rel_map[idx_port][1] + " 0";
|
||||||
}
|
launchcmd(cmd);
|
||||||
/*if (cmd.equals(action [2]))
|
}
|
||||||
{
|
/*if (cmd.equals(action [2]))
|
||||||
//Stats geben
|
{
|
||||||
cmd = "/usr/bin/gpio -g write " + port + status();
|
//Stats geben
|
||||||
launchcmd(cmd);
|
cmd = "/usr/bin/gpio -g write " + port + status();
|
||||||
}*/
|
launchcmd(cmd);
|
||||||
return -1;
|
}*/
|
||||||
}
|
return -1;
|
||||||
|
}
|
||||||
public static void show_usage()
|
|
||||||
{
|
public static void show_usage()
|
||||||
System.out.println("You have to enter exactly 2 arguments.");
|
{
|
||||||
System.out.println("Example: java gpio_java Argument1 Argument2");
|
System.out.println("You have to enter exactly 2 arguments.");
|
||||||
System.out.println("Argument1: rel1, rel2, rel3, ..., rel8");
|
System.out.println("Example: java gpio_java Argument1 Argument2");
|
||||||
System.out.println("Argument2: on,off or status");
|
System.out.println("Argument1: rel1, rel2, rel3, ..., rel8");
|
||||||
}
|
System.out.println("Argument2: on,off or status");
|
||||||
|
}
|
||||||
public static void launchcmd(String cmd)
|
|
||||||
{
|
public static void launchcmd(String cmd)
|
||||||
// Wenn Simulation True ist kann sie auf dem PC ausfuehren
|
{
|
||||||
// wenn die Simulation false is auf dem Raspberry PI
|
// Wenn Simulation True ist kann sie auf dem PC ausfuehren
|
||||||
boolean simulation = false;
|
// wenn die Simulation false is auf dem Raspberry PI
|
||||||
|
boolean simulation = false;
|
||||||
if(simulation==true){
|
|
||||||
System.out.println(cmd);
|
if(simulation==true){
|
||||||
}
|
System.out.println(cmd);
|
||||||
else {
|
}
|
||||||
try{
|
else {
|
||||||
Runtime.getRuntime().exec(cmd);
|
try{
|
||||||
}
|
Runtime.getRuntime().exec(cmd);
|
||||||
catch(IOException e)
|
}
|
||||||
{
|
catch(IOException e)
|
||||||
System.out.println("process error IOException");
|
{
|
||||||
}
|
System.out.println("process error IOException");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void setgpio(boolean status)
|
|
||||||
{
|
public static void setgpio(boolean status)
|
||||||
launchcmd("/usr/bin/gpio -g mode 14 out");
|
{
|
||||||
|
launchcmd("/usr/bin/gpio -g mode 14 out");
|
||||||
if(status == true)
|
|
||||||
{
|
if(status == true)
|
||||||
launchcmd("/usr/bin/gpio -g write 14 1");
|
{
|
||||||
}
|
launchcmd("/usr/bin/gpio -g write 14 1");
|
||||||
else
|
}
|
||||||
{
|
else
|
||||||
launchcmd("/usr/bin/gpio -g write 14 0");
|
{
|
||||||
}
|
launchcmd("/usr/bin/gpio -g write 14 0");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
}
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user