Bläddra i källkod

Update Readme file

move java file
dev-alex
Alex Volkmann 5 år sedan
förälder
incheckning
b7fb7de498
2 ändrade filer med 259 tillägg och 231 borttagningar
  1. +54
    -27
      README.md
  2. +205
    -204
      gpio_java.java

+ 54
- 27
README.md Visa fil

@@ -1,27 +1,54 @@
# Overview

# Deployment

use the following command to transfer project to raspberry pi:

scp -r gpio pi@192.168.1.77:~


# Regler

Pin GPIO Regler
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





# Overview

# Deployment
use the following command to transfer project to raspberry pi:
scp -r gpio pi@192.168.1.77:~

# usage
## switch relais on
```
javadoc todo
```
## switch relais off
```
javadoc todo
```
## read status of relais
```
javadoc todo
```

## Create Dokumentation
```
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





src/pdu_jctrl/gpio_java.java → gpio_java.java Visa fil

@@ -1,204 +1,205 @@
//package pdu_jctrl;

import java.io.IOException;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

public class gpio_java
{
public static String rel_map [][] = {
{"rel1","14"},
{"rel2","15"},
{"rel3","18"},
{"rel4","23"},
{"rel5","24"},
{"rel6","25"},
{"rel7","8"},
{"rel8","7"}
};
public static String [] action = {"on", "off", "status"};

public static void main (String [] args)
{
// Zum checken der Anzahl der Argumente
checkargs(args);
// todo: initialisiere alle acht ports (outputs)
init_gpio();
// setze gpio (gemaes der parameter)
gpio_getport(args[0]);
gpio_cmdhandler(args[0], args[1]);
/*
setgpio(true);
try {
TimeUnit.SECONDS.sleep(1);
}
catch(InterruptedException e)
{
System.out.println("sleep error InterruptedException ocure");
}
setgpio(false);
*/
}
public static void checkargs(String[] argumens)
{
int laenge = argumens.length;
String [] h = {"-h"};
int idx;
boolean parameter1 = false;
boolean parameter2 = false;

if (laenge == 2)
{
//ToDO: Pruefe erstes und zweites Argument
//Erstes Element(rel)
for (idx = 0; idx<8 ; idx++)
{
if (argumens[0].equals(rel_map[idx][0]))
{
parameter1 = true;
break;
}
}
//Zweites Element (action)
for (idx = 0; idx<3 ; idx++)
{
if (argumens[1].equals(action[idx]))
{
parameter2 = true;
break;
}
}
}
else if (Arrays.equals (argumens, h) == true)
{
show_usage();
System.exit(0);
}
else
{
System.out.println("Error. If you need help, type the command -h");
System.exit(0);
}
//ToDo: Return

}
public static void init_gpio()
{
int idx;
String port;
String cmd;
for(idx = 0; idx<8 ; idx++)
{
port = rel_map[idx][1];
cmd = "/usr/bin/gpio -g mode " + port + " out";
launchcmd(cmd);
}
return;
}
public static int gpio_getport(String port)
{
int idx;
for(idx = 0; idx<8 ; idx++)
{
if(port.equals(rel_map[idx][0]))
{
return idx;
}
}
return -1;
}
public static int gpio_cmdhandler(String port, String cmd)
{
int idx_port;
idx_port = gpio_getport(port);

if (cmd.equals(action [0]))
{
//Schalte on
cmd = "/usr/bin/gpio -g write " + rel_map[idx_port][1] + " 1";
launchcmd(cmd);
}
if (cmd.equals(action [1]))
{
//Schalte off
cmd = "/usr/bin/gpio -g write " + rel_map[idx_port][1] + " 0";
launchcmd(cmd);
}
/*if (cmd.equals(action [2]))
{
//Stats geben
cmd = "/usr/bin/gpio -g write " + port + status();
launchcmd(cmd);
}*/
return -1;
}
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("Argument1: rel1, rel2, rel3, ..., rel8");
System.out.println("Argument2: on,off or status");
}
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
boolean simulation = false;
if(simulation==true){
System.out.println(cmd);
}
else {
try{
Runtime.getRuntime().exec(cmd);
}
catch(IOException e)
{
System.out.println("process error IOException");
}
}
}
public static void setgpio(boolean status)
{
launchcmd("/usr/bin/gpio -g mode 14 out");
if(status == true)
{
launchcmd("/usr/bin/gpio -g write 14 1");
}
else
{
launchcmd("/usr/bin/gpio -g write 14 0");
}
}
}
import java.io.IOException;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;


// todo: add Dokumentation
public class gpio_java
{
public static String rel_map [][] = {
{"rel1","14"},
{"rel2","15"},
{"rel3","18"},
{"rel4","23"},
{"rel5","24"},
{"rel6","25"},
{"rel7","8"},
{"rel8","7"}
};
public static String [] action = {"on", "off", "status"};

public static void main (String [] args)
{
// Zum checken der Anzahl der Argumente
checkargs(args);
// todo: initialisiere alle acht ports (outputs)
init_gpio();
// setze gpio (gemaes der parameter)
gpio_getport(args[0]);
gpio_cmdhandler(args[0], args[1]);
// todo: remove following not used code
/*
setgpio(true);
try {
TimeUnit.SECONDS.sleep(1);
}
catch(InterruptedException e)
{
System.out.println("sleep error InterruptedException ocure");
}
setgpio(false);
*/
}
public static void checkargs(String[] argumens)
{
int laenge = argumens.length;
String [] h = {"-h"};
int idx;
boolean parameter1 = false;
boolean parameter2 = false;

if (laenge == 2)
{
//ToDO: Pruefe erstes und zweites Argument
//Erstes Element(rel)
for (idx = 0; idx<8 ; idx++)
{
if (argumens[0].equals(rel_map[idx][0]))
{
parameter1 = true;
break;
}
}
//Zweites Element (action)
for (idx = 0; idx<3 ; idx++)
{
if (argumens[1].equals(action[idx]))
{
parameter2 = true;
break;
}
}
}
else if (Arrays.equals (argumens, h) == true)
{
show_usage();
System.exit(0);
}
else
{
System.out.println("Error. If you need help, type the command -h");
System.exit(0);
}
//ToDo: Return

}
public static void init_gpio()
{
int idx;
String port;
String cmd;
for(idx = 0; idx<8 ; idx++)
{
port = rel_map[idx][1];
cmd = "/usr/bin/gpio -g mode " + port + " out";
launchcmd(cmd);
}
return;
}
public static int gpio_getport(String port)
{
int idx;
for(idx = 0; idx<8 ; idx++)
{
if(port.equals(rel_map[idx][0]))
{
return idx;
}
}
return -1;
}
public static int gpio_cmdhandler(String port, String cmd)
{
int idx_port;
idx_port = gpio_getport(port);

if (cmd.equals(action [0]))
{
//Schalte on
cmd = "/usr/bin/gpio -g write " + rel_map[idx_port][1] + " 1";
launchcmd(cmd);
}
if (cmd.equals(action [1]))
{
//Schalte off
cmd = "/usr/bin/gpio -g write " + rel_map[idx_port][1] + " 0";
launchcmd(cmd);
}
/*if (cmd.equals(action [2]))
{
//Stats geben
cmd = "/usr/bin/gpio -g write " + port + status();
launchcmd(cmd);
}*/
return -1;
}
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("Argument1: rel1, rel2, rel3, ..., rel8");
System.out.println("Argument2: on,off or status");
}
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
boolean simulation = false;
if(simulation==true){
System.out.println(cmd);
}
else {
try{
Runtime.getRuntime().exec(cmd);
}
catch(IOException e)
{
System.out.println("process error IOException");
}
}
}
public static void setgpio(boolean status)
{
launchcmd("/usr/bin/gpio -g mode 14 out");
if(status == true)
{
launchcmd("/usr/bin/gpio -g write 14 1");
}
else
{
launchcmd("/usr/bin/gpio -g write 14 0");
}
}
}

Laddar…
Avbryt
Spara