fix conflict

This commit is contained in:
misty 2018-06-14 23:33:18 +02:00
parent 222de3533c
commit 852cddc2cb
5 changed files with 243 additions and 52 deletions

View File

@ -9,15 +9,15 @@ import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; import android.os.Bundle;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
public class DisplayMessageActivity extends AppCompatActivity { public class DisplayMessageActivity extends AppCompatActivity {
private Handler handlerCoil; private Handler handlerCoil;
private Handler handlerInputRegister; private Handler handlerInputRegister;
private Handler handlerDiscreteInput;
private GlobalState state; private GlobalState state;
@ -31,15 +31,19 @@ public class DisplayMessageActivity extends AppCompatActivity {
LocalBroadcastManager.getInstance(this).registerReceiver(discreteInputMessageReceiver, new IntentFilter("readOnlyDiscreteInput")); LocalBroadcastManager.getInstance(this).registerReceiver(discreteInputMessageReceiver, new IntentFilter("readOnlyDiscreteInput"));
LocalBroadcastManager.getInstance(this).registerReceiver(inputRegisterMessageReceiver, new IntentFilter("readOnlyInputRegister")); LocalBroadcastManager.getInstance(this).registerReceiver(inputRegisterMessageReceiver, new IntentFilter("readOnlyInputRegister"));
state = (GlobalState) getApplicationContext(); state = (GlobalState) getApplicationContext();
Toast toast = Toast.makeText(getApplicationContext(), "This is my toast !", Toast.LENGTH_LONG);
toast.show();
//handler //handler
handlerCoil = new Handler(); handlerCoil = new Handler();
handlerCoil.post(refreshCoil); handlerCoil.post(refreshCoil);
handlerInputRegister = new Handler(); handlerInputRegister = new Handler();
handlerInputRegister.post(refreshInputRegister); handlerInputRegister.post(refreshInputRegister);
handlerDiscreteInput = new Handler();
handlerDiscreteInput.post(refreshDiscreteInput);
} }
Runnable refreshCoil = new Runnable() { Runnable refreshCoil = new Runnable() {
@ -49,34 +53,44 @@ public class DisplayMessageActivity extends AppCompatActivity {
serviceIntent.setAction("read.coil"); serviceIntent.setAction("read.coil");
serviceIntent.putExtra("extra.ip.address", state.getIpAddress()); serviceIntent.putExtra("extra.ip.address", state.getIpAddress());
serviceIntent.putExtra("extra.ip.port", state.getPort()); serviceIntent.putExtra("extra.ip.port", state.getPort());
serviceIntent.putExtra("extra.ref", state.getCoilRef()); serviceIntent.putExtra("extra.ref", GlobalState.InputConfig.COIL.getStartReference());
serviceIntent.putExtra("extra.count", state.getCoilCount()); serviceIntent.putExtra("extra.count", GlobalState.InputConfig.COIL.getCount());
serviceIntent.putExtra("extra.intent.name", "readOnlyCoil"); serviceIntent.putExtra("extra.intent.name", "readOnlyCoil");
getApplicationContext().startService(serviceIntent); getApplicationContext().startService(serviceIntent);
handlerCoil.postDelayed(this, 10000); handlerCoil.postDelayed(this, 2000);
} }
}; };
Runnable refreshDiscretInput = new Runnable() { Runnable refreshDiscreteInput = new Runnable() {
@Override @Override
public void run() { public void run() {
// TODO Auto-generated method stub Intent serviceIntent = new Intent(getApplicationContext(), MyIntentService.class);
TextView textView = findViewById(R.id.textView1); serviceIntent.setAction("read.discrete.input");
Date currentTime = Calendar.getInstance().getTime(); serviceIntent.putExtra("extra.ip.address", state.getIpAddress());
textView.setText(new Double(Math.random()).toString()); serviceIntent.putExtra("extra.ip.port", state.getPort());
handlerCoil.postDelayed(this, 1000); serviceIntent.putExtra("extra.ref", GlobalState.InputConfig.DISCRETE_INPUT.getStartReference());
serviceIntent.putExtra("extra.count", GlobalState.InputConfig.DISCRETE_INPUT.getCount());
serviceIntent.putExtra("extra.intent.name", "readOnlyDiscreteInput");
getApplicationContext().startService(serviceIntent);
handlerDiscreteInput.postDelayed(this, 5000);
} }
}; };
Runnable refreshInputRegister = new Runnable() { Runnable refreshInputRegister = new Runnable() {
@Override @Override
public void run() { public void run() {
// TODO Auto-generated method stub Intent serviceIntent = new Intent(getApplicationContext(), MyIntentService.class);
TextView textView = findViewById(R.id.textView1); serviceIntent.setAction("read.input.register");
Date currentTime = Calendar.getInstance().getTime(); serviceIntent.putExtra("extra.ip.address", state.getIpAddress());
textView.setText(new Double(Math.random()).toString()); serviceIntent.putExtra("extra.ip.port", state.getPort());
handlerCoil.postDelayed(this, 2000); serviceIntent.putExtra("extra.ref", GlobalState.InputConfig.INPUT_REGISTER.getStartReference());
serviceIntent.putExtra("extra.count", GlobalState.InputConfig.INPUT_REGISTER.getCount());
serviceIntent.putExtra("extra.intent.name", "readOnlyInputRegister");
getApplicationContext().startService(serviceIntent);
handlerInputRegister.postDelayed(this, 1000);
} }
}; };
@ -100,7 +114,7 @@ public class DisplayMessageActivity extends AppCompatActivity {
TextView textView4 = findViewById(R.id.textView4); TextView textView4 = findViewById(R.id.textView4);
textView4.setText(new Boolean(booleanArray[3]).toString()); textView4.setText(new Boolean(booleanArray[3]).toString());
/* TextView textView5 = findViewById(R.id.textView5); TextView textView5 = findViewById(R.id.textView5);
textView5.setText(new Boolean(booleanArray[4]).toString()); textView5.setText(new Boolean(booleanArray[4]).toString());
TextView textView6 = findViewById(R.id.textView6); TextView textView6 = findViewById(R.id.textView6);
@ -110,7 +124,7 @@ public class DisplayMessageActivity extends AppCompatActivity {
textView7.setText(new Boolean(booleanArray[6]).toString()); textView7.setText(new Boolean(booleanArray[6]).toString());
TextView textView8 = findViewById(R.id.textView8); TextView textView8 = findViewById(R.id.textView8);
textView8.setText(new Boolean(booleanArray[7]).toString()); */ textView8.setText(new Boolean(booleanArray[7]).toString());
} }
}; };
@ -119,17 +133,55 @@ public class DisplayMessageActivity extends AppCompatActivity {
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
String action = intent.getAction(); String action = intent.getAction();
Bundle bundle = intent.getExtras(); Bundle bundle = intent.getExtras();
ArrayList<Integer> integers = bundle.getIntegerArrayList("irValues"); ArrayList<Integer> integerArrayList = bundle.getIntegerArrayList("irValues");
TextView textView9 = findViewById(R.id.textView9); TextView textView9 = findViewById(R.id.textView9);
textView9.setText(integers.get(0).toString()); textView9.setText(integerArrayList.get(0).toString());
} }
}; };
private BroadcastReceiver discreteInputMessageReceiver = new BroadcastReceiver() { private BroadcastReceiver discreteInputMessageReceiver = new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Bundle bundle = intent.getExtras();
boolean[] booleanArray = bundle.getBooleanArray("discreteInputValues");
TextView textView10 = findViewById(R.id.textView10);
textView10.setText(new Boolean(booleanArray[0]).toString());
TextView textView11 = findViewById(R.id.textView11);
textView11.setText(new Boolean(booleanArray[1]).toString());
TextView textView12 = findViewById(R.id.textView12);
textView12.setText(new Boolean(booleanArray[2]).toString());
TextView textView13 = findViewById(R.id.textView13);
textView13.setText(new Boolean(booleanArray[3]).toString());
TextView textView14 = findViewById(R.id.textView14);
textView14.setText(new Boolean(booleanArray[4]).toString());
TextView textView15 = findViewById(R.id.textView15);
textView15.setText(new Boolean(booleanArray[5]).toString());
TextView textView16 = findViewById(R.id.textView16);
textView16.setText(new Boolean(booleanArray[6]).toString());
TextView textView17 = findViewById(R.id.textView17);
textView17.setText(new Boolean(booleanArray[7]).toString());
TextView textView18 = findViewById(R.id.textView18);
textView18.setText(new Boolean(booleanArray[8]).toString());
TextView textView19 = findViewById(R.id.textView19);
textView19.setText(new Boolean(booleanArray[9]).toString());
TextView textView20 = findViewById(R.id.textView20);
textView20.setText(new Boolean(booleanArray[10]).toString());
TextView textView21 = findViewById(R.id.textView21);
textView21.setText(new Boolean(booleanArray[11]).toString());
} }
}; };
} }

View File

@ -18,9 +18,13 @@ public class GlobalState extends Application {
// //
public enum InputConfig { public enum InputConfig {
COIL (8192, 80), /* COIL (8192, 8),
INPUT_REGISTER (0, 2), INPUT_REGISTER (1, 1),
DISCRETE_INPUT(0, 12); DISCRETE_INPUT(1, 12);
*/
COIL (1, 8),
INPUT_REGISTER (1, 8),
DISCRETE_INPUT(1, 12);
private int startReference; private int startReference;
private int count; private int count;

View File

@ -19,8 +19,8 @@ public class MainActivity extends AppCompatActivity {
public void sendMessage(View view) { public void sendMessage(View view) {
EditText editText1 = (EditText) findViewById(R.id.ipAddress); EditText editText1 = (EditText) findViewById(R.id.ipAddress);
// String ipAddress = editText1.getText().toString(); // String ipAddress = editText1.getText().toString();
String ipAddress = "10.0.0.60"; String ipAddress = "192.168.157.16";
int port = 502; int port = 503;
EditText editText2 = (EditText) findViewById(R.id.port); EditText editText2 = (EditText) findViewById(R.id.port);
// int port = Integer.parseInt(editText2.getText().toString()); // int port = Integer.parseInt(editText2.getText().toString());
@ -28,8 +28,6 @@ public class MainActivity extends AppCompatActivity {
GlobalState state = (GlobalState) getApplicationContext(); GlobalState state = (GlobalState) getApplicationContext();
state.setIpAddress(ipAddress); state.setIpAddress(ipAddress);
state.setPort(port); state.setPort(port);
// state.setCoilRef(ref);
// state.setCoilCount(count);
Intent coilServiceIntent = new Intent(this, MyIntentService.class); Intent coilServiceIntent = new Intent(this, MyIntentService.class);
coilServiceIntent.setAction("read.coil"); coilServiceIntent.setAction("read.coil");
@ -40,7 +38,7 @@ public class MainActivity extends AppCompatActivity {
coilServiceIntent.putExtra("extra.intent.name", "readOnlyCoil"); coilServiceIntent.putExtra("extra.intent.name", "readOnlyCoil");
this.startService(coilServiceIntent); this.startService(coilServiceIntent);
/* Intent discretInputserviceIntent = new Intent(this, MyIntentService.class); Intent discretInputserviceIntent = new Intent(this, MyIntentService.class);
discretInputserviceIntent.setAction("read.discrete.input"); discretInputserviceIntent.setAction("read.discrete.input");
discretInputserviceIntent.putExtra("extra.ip.address", ipAddress); discretInputserviceIntent.putExtra("extra.ip.address", ipAddress);
discretInputserviceIntent.putExtra("extra.ip.port", port); discretInputserviceIntent.putExtra("extra.ip.port", port);
@ -56,7 +54,7 @@ public class MainActivity extends AppCompatActivity {
inputRegisterServiceIntent.putExtra("extra.ref", GlobalState.InputConfig.INPUT_REGISTER.getStartReference()); inputRegisterServiceIntent.putExtra("extra.ref", GlobalState.InputConfig.INPUT_REGISTER.getStartReference());
inputRegisterServiceIntent.putExtra("extra.count", GlobalState.InputConfig.INPUT_REGISTER.getCount()); inputRegisterServiceIntent.putExtra("extra.count", GlobalState.InputConfig.INPUT_REGISTER.getCount());
inputRegisterServiceIntent.putExtra("extra.intent.name", "readOnlyInputRegister"); inputRegisterServiceIntent.putExtra("extra.intent.name", "readOnlyInputRegister");
this.startService(inputRegisterServiceIntent); */ this.startService(inputRegisterServiceIntent);
Intent nextIntent = new Intent(this, DisplayMessageActivity.class); Intent nextIntent = new Intent(this, DisplayMessageActivity.class);
this.startActivity(nextIntent); this.startActivity(nextIntent);

View File

@ -34,17 +34,14 @@ public class MyIntentService extends IntentService {
private static final String EXTRA_COUNT = "extra.count"; private static final String EXTRA_COUNT = "extra.count";
private static final String EXTRA_INTENT_NAME = "extra.intent.name"; private static final String EXTRA_INTENT_NAME = "extra.intent.name";
// private static final String EXTRA_PARAM2 = "com.example.user.myapp.extra.PARAM2";
public MyIntentService() { public MyIntentService() {
super("MyIntentService"); super("MyIntentService");
} }
private void sendBooleanListToActivity(List<Boolean> booleanList, String intentName) { private void sendBooleanListToActivity(List<Boolean> booleanList, String intentName, String bundleName) {
Intent intent = new Intent(intentName); Intent intent = new Intent(intentName);
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putBooleanArray(bundleName, toPrimitiveArray(booleanList));
bundle.putBooleanArray("coilValues", toPrimitiveArray(booleanList));
intent.putExtras(bundle); intent.putExtras(bundle);
sendLocationBroadcast(intent); sendLocationBroadcast(intent);
} }
@ -70,10 +67,10 @@ public class MyIntentService extends IntentService {
BitVector bv = master.readInputDiscretes(ref, count); BitVector bv = master.readInputDiscretes(ref, count);
List<Boolean> listBooleanBit = new ArrayList<>(); List<Boolean> listBooleanBit = new ArrayList<>();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
System.out.println(i+" discret input "+bv.getBit(i));
listBooleanBit.add(bv.getBit(i)); listBooleanBit.add(bv.getBit(i));
System.out.println("input discrete values : "+i+" - "+bv.getBit(i));
} }
sendBooleanListToActivity(listBooleanBit, intentReceiveName); sendBooleanListToActivity(listBooleanBit, intentReceiveName, "discreteInputValues");
master.disconnect(); master.disconnect();
} catch (Exception e) { } catch (Exception e) {
System.out.println("Exception in reading discrete input " + e); System.out.println("Exception in reading discrete input " + e);
@ -88,10 +85,10 @@ public class MyIntentService extends IntentService {
BitVector bv = master.readCoils(ref,count); BitVector bv = master.readCoils(ref,count);
List<Boolean> listBooleanBit = new ArrayList<>(); List<Boolean> listBooleanBit = new ArrayList<>();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
System.out.println("coil values : "+i+" - "+bv.getBit(i)); System.out.println(i+" coil "+bv.getBit(i));
listBooleanBit.add(bv.getBit(i)); listBooleanBit.add(bv.getBit(i));
} }
sendBooleanListToActivity(listBooleanBit, intentReceiveName); sendBooleanListToActivity(listBooleanBit, intentReceiveName, "coilValues");
master.disconnect(); master.disconnect();
} catch (Exception e) { } catch (Exception e) {
System.out.println("Exception in reading coil " + e); System.out.println("Exception in reading coil " + e);
@ -106,8 +103,8 @@ public class MyIntentService extends IntentService {
InputRegister [] inputRegisters = master.readInputRegisters(ref, count); InputRegister [] inputRegisters = master.readInputRegisters(ref, count);
ArrayList<Integer> listIntegerInputRegister = new ArrayList<>(); ArrayList<Integer> listIntegerInputRegister = new ArrayList<>();
for (InputRegister ir : inputRegisters) { for (InputRegister ir : inputRegisters) {
System.out.println("ir values : "+Math.random()+" - "+ir.getValue());
listIntegerInputRegister.add(ir.getValue()); listIntegerInputRegister.add(ir.getValue());
System.out.println(ir.getValue()+" input register "+Math.random());
} }
sendIntegerListToActivity (listIntegerInputRegister, intentReceiveName); sendIntegerListToActivity (listIntegerInputRegister, intentReceiveName);
master.disconnect(); master.disconnect();
@ -129,10 +126,13 @@ public class MyIntentService extends IntentService {
switch(action) { switch(action) {
case ACTION_READ_DISCRETE_INPUT: case ACTION_READ_DISCRETE_INPUT:
readDiscreteInputAction (ipAddress, port, ref, count, intentName); readDiscreteInputAction (ipAddress, port, ref, count, intentName);
break;
case ACTION_READ_COIL : case ACTION_READ_COIL :
readCoilAction(ipAddress, port, ref, count, intentName); readCoilAction(ipAddress, port, ref, count, intentName);
break;
case ACTION_READ_INPUT_REGISTER : case ACTION_READ_INPUT_REGISTER :
readInputRegisterAction (ipAddress, port,ref, count, intentName); readInputRegisterAction (ipAddress, port,ref, count, intentName);
break;
} }
} }
} }

View File

@ -6,18 +6,6 @@
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".DisplayMessageActivity"> tools:context=".DisplayMessageActivity">
<TextView
android:id="@+id/textView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="TextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView8" />
<TextView <TextView
android:id="@+id/textView1" android:id="@+id/textView1"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -98,4 +86,153 @@
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView7" /> app:layout_constraintTop_toBottomOf="@+id/textView7" />
<TextView
android:id="@+id/textView9"
android:layout_width="68dp"
android:layout_height="22dp"
android:layout_marginStart="36dp"
android:layout_marginTop="324dp"
android:text="TextView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.477" />
<TextView
android:id="@+id/textView11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginStart="16dp"
android:text="TextView"
app:layout_constraintBottom_toTopOf="@+id/textView12"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="@+id/textView12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="1dp"
android:text="TextView"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.741" />
<TextView
android:id="@+id/textView13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="52dp"
android:text="TextView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView12" />
<TextView
android:id="@+id/textView14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:text="TextView"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView13" />
<TextView
android:id="@+id/textView15"
android:layout_width="wrap_content"
android:layout_height="18dp"
android:layout_marginBottom="16dp"
android:layout_marginEnd="72dp"
android:layout_marginStart="8dp"
android:text="TextView"
app:layout_constraintBottom_toTopOf="@+id/textView16"
app:layout_constraintEnd_toStartOf="@+id/textView18"
app:layout_constraintHorizontal_bias="0.705"
app:layout_constraintStart_toEndOf="@+id/textView11" />
<TextView
android:id="@+id/textView16"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="72dp"
android:layout_marginStart="8dp"
android:text="TextView"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/textView19"
app:layout_constraintHorizontal_bias="0.652"
app:layout_constraintStart_toEndOf="@+id/textView12"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.753" />
<TextView
android:id="@+id/textView17"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="68dp"
android:layout_marginTop="8dp"
android:text="TextView"
app:layout_constraintStart_toEndOf="@+id/textView13"
app:layout_constraintTop_toBottomOf="@+id/textView16" />
<TextView
android:id="@+id/textView18"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginTop="336dp"
android:text="TextView"
app:layout_constraintBottom_toTopOf="@+id/textView19"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0"
app:layout_constraintVertical_chainStyle="packed" />
<TextView
android:id="@+id/textView19"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginTop="8dp"
android:text="TextView"
app:layout_constraintBottom_toTopOf="@+id/textView20"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView18" />
<TextView
android:id="@+id/textView20"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginTop="8dp"
android:text="TextView"
app:layout_constraintBottom_toTopOf="@+id/textView21"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView19" />
<TextView
android:id="@+id/textView21"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginTop="36dp"
android:text="TextView"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView20" />
</android.support.constraint.ConstraintLayout> </android.support.constraint.ConstraintLayout>