|
- package de.erich.railcontrol;
-
- import android.widget.Toast;
-
- import java.io.FileWriter;
- import java.io.IOException;
-
- public class zug {
-
- int adresse;
- int direction;
- int speed;
- String name;
- int maxspeed;
-
- boolean initialized;
- boolean firstTime;
-
- int funktion_1;
- int funktion_2;
- int funktion_3;
- int funktion_4;
-
- public zug(int adresse, String name, int maxspeed) {
-
- this.adresse = adresse;
- this.name = name;
- this.maxspeed = maxspeed;
- this.initialized = false;
- firstTime = true;
-
- }
-
- public zug() {
- this.initialized = false;
- firstTime = true;
- }
-
- public boolean initZug() {
- if(btn_listeners.client == null) {
- if(firstTime) {
- Toast.makeText(Lok1.btn_richtung.getContext(), "Noch nicht verbunden!", Toast.LENGTH_SHORT).show();
- firstTime = false;
- }
- return false;
- }
- try {
- btn_listeners.client.sendMessage("INIT 1 GL " + this.adresse + " N 1 " + maxspeed +" 4");
- initialized = true;
- return true;
- } catch (IOException e) {
- e.printStackTrace();
- return false;
- }
- }
-
- public void setSpeed(int speed) {
- if(!(this.initialized)) {
- if(!(this.initZug())) {
- return;
- }
- }
- try {
- btn_listeners.client.sendMessage("SET 1 GL " + this.adresse + " " + this.direction + " " + speed + " " + maxspeed + " " + funktion_1 + " "+ funktion_2 + " "+ funktion_3 + " " + funktion_4);
- this.speed = speed;
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- public void setDirection(int direction) {
- this.direction = direction;
- }
-
- public int changeDirection() {
- if(!(this.initialized)) {
- if(!(this.initZug())) {
- return this.direction;
- }
- }
- if(this.direction == 0) {
- this.direction = 1;
- }
- else if(this.direction == 1) {
- this.direction = 0;
- }
- if(this.speed == 0) {
- try {
- btn_listeners.client.sendMessage("SET 1 GL " + this.adresse + " " + this.direction + " 0 28 " + funktion_1 + " "+ funktion_2 + " "+ funktion_3 + " " + funktion_4);
- } catch (IOException e) {
- e.printStackTrace();
- }
- } else {
- Lok1.speed.setProgress(0);
- }
- return this.direction;
- }
-
- public void setFunction(int function, int status) {
- if(!(this.initialized)) {
- if(!(this.initZug())) {
- return;
- }
- }
- switch(function) {
- case 1:
- funktion_1 = status;
- break;
- case 2:
- funktion_2 = status;
- break;
- case 3:
- funktion_3 = status;
- break;
- case 4:
- funktion_4 = status;
- break;
- }
- try {
- btn_listeners.client.sendMessage("SET 1 GL " + this.adresse + " " + this.direction + " " + this.speed + " " + maxspeed + " " + funktion_1 + " "+ funktion_2 + " "+ funktion_3 + " " + funktion_4);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- public void printConfiguration(FileWriter outStream) throws IOException {
- outStream.write("<Lok\n");
- outStream.write("\tname:\t" + name + "\n\tadresse:\t" + adresse + "\n");
- outStream.write("\tmaxspeed:\t" + maxspeed + "\n");
- outStream.write("/>\n");
- }
-
- public void setProperty(String[] words) {
- if ( words[1].equalsIgnoreCase("name:")) name = words[2];
- else if (words[1].equalsIgnoreCase("adresse:"))
- adresse = Integer.parseInt(words[2]);
- else if (words[1].equalsIgnoreCase("maxspeed:"))
- maxspeed = Integer.parseInt(words[2]);
- }
-
- }
|