Also machte ich eine Kommunikation mit Sockel hier (in Client.java, außer Kraft setzen doInBackground, AsyncTask Nutzung)Sensordaten erfrischende
String addr = "******";
try {
socket = new Socket(addr, 10100);
while (socket.isConnected()) {
Thread.sleep(200);
socket.getOutputStream().write(sendData());
socket.getOutputStream().flush();
} and so on..
Und jedoch habe ich einen Konstruktor von Haupttätigkeit zu Client-Informationen die Sie ziehen aus onSensorChanged (die Azimut, Roll- und Pitch), wie
gezeigtpublic Client(Float a, Float b, Float c) {
this.a = a;
this.b = b;
this.c = c;
}
und ich habe mit Server kommuniziert ihnen dynamische Ergebnisse von Orientierungssensor zu senden, und i zum senden hat, die „senddata()“ Funktion zum Puffer sendet, Ich habe früher gemacht. Und alles in allem funktioniert alles gut für meine Verwendung, aber es gibt ein Problem, die Daten außerhalb des Konstruktors werden nicht aktualisiert. Also ich kommuniziere mit dem Server, wenn ich verbinde, aber ich sende das gleiche (zuerst, dass er liest) Azimut, Roll und Pitch immer und immer wieder. Ich habe so viele Dinge ausprobiert und immer noch keine Ahnung, wie ich diese Informationen aus Main Activity -> onSensorChanged to Client herausholen kann, damit die dynamische Ausgabe aktualisiert und gesendet wird. Irgendwelche Tipps oder Hilfe vielleicht? Dank
Edit:
die onSensorChanged
public void onSensorChanged(SensorEvent event) {
Float a = event.values[0];
BigDecimal result1;
result1=round(a,2);
Float b = event.values[2];
if (b <= 5 && b >=-5){
b = (float) 0;
}
b = (float) (b/3.4);
BigDecimal result2;
result2 = round(b,2);
Float c = event.values[1];
if (c <= 5 && c >=-5){
c = (float) 0;
}
c = (float) (c/3.4);
BigDecimal result3;
result3 = round(c,2);
Client myClient = new Client(a, b, c);
myClient.execute();
Und das ist onData()
public byte[] sendData(){
byte[] buff = new byte[68];
byte[] buff1 = intToBytes(1);
byte[] buff2 = intToBytes(20); // ** ROLL
byte[] buff3 = intToBytes(21); // ** PITCH
byte[] buff4 = intToBytes(23); // ** AZIMUT
byte[] buff5 = intToBytes(5);
byte[] buff6 = intToBytes(6);
byte[] buff7 = intToBytes(7);
byte[] buff8 = intToBytes(8);
byte[] buff9 = intToBytes(9);
byte[] buff10 = intToBytes(Math.round(c));
byte[] buff11 = intToBytes(Math.round(b));
byte[] buff12 = intToBytes(Math.round(a));
byte[] buff13 = intToBytes(13);
byte[] buff14 = intToBytes(14);
byte[] buff15 = intToBytes(15);
byte[] buff16 = intToBytes(16);
byte[] buff17 = intToBytes(17);
System.arraycopy(buff1,0,buff,0,buff1.length);
System.arraycopy(buff2,0,buff, 4,buff2.length);
System.arraycopy(buff3,0,buff, 8,buff2.length);
System.arraycopy(buff4,0,buff, 12,buff2.length);
System.arraycopy(buff5,0,buff, 16,buff2.length);
System.arraycopy(buff6,0,buff, 20,buff2.length);
System.arraycopy(buff7,0,buff, 24,buff2.length);
System.arraycopy(buff8,0,buff, 28,buff2.length);
System.arraycopy(buff9,0,buff, 32,buff2.length);
System.arraycopy(buff10,0,buff,36,buff2.length);
System.arraycopy(buff11,0,buff,40,buff2.length);
System.arraycopy(buff12,0,buff,44,buff2.length);
System.arraycopy(buff13,0,buff,48,buff2.length);
System.arraycopy(buff14,0,buff,52,buff2.length);
System.arraycopy(buff15,0,buff,56,buff2.length);
System.arraycopy(buff16,0,buff,60,buff2.length);
System.arraycopy(buff17,0,buff,64,buff2.length);
return buff;}
Zeigt den sendData() - Code an. Und zeigen Sie den vollständigen Client-Klassencode an. Und zeige alle Anrufe von MainActivity. – greenapps
Es gibt noch mehr Code @ greenapps, brauchen mehr? –