Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void receive () {
- byte[] buffer = new byte[1024]; // Puffer
- int length; // Anzahl empf. Bytes
- String msg = "";
- try {
- if (stream_in.available() > 0) {
- length = stream_in.read(buffer);
- Log.d(LOG_TAG,
- "amount of received bytes: " + String.valueOf(length));
- // Message zusammensetzen:
- for (int i = 0; i < length; i++)
- {
- msg += (char) buffer[i];
- if(buffer[i+1] ==',') //Dieser Part ist notwendig, dass die Nachricht richtig erkannt wird
- { //Nach dem Komma werden alle anderen Zeichen ignoriert
- String myString = msg;
- value = Double.parseDouble(msg);
- i = length;
- Long tsLong = System.currentTimeMillis()/1000;
- String ts = tsLong.toString();
- timestamp = Double.parseDouble(ts);
- }
- }
- TextView myView = (TextView) getActivity().findViewById(R.id.textView4);
- TextView myV = (TextView) getActivity().findViewById(R.id.textView7);
- myView.setText(Double.toString(value));//Setzt den Text im Feld oben links
- myV.setText(Double.toString(timestamp));
- ConnectionViewModel.dataset a = new ConnectionViewModel.dataset();
- a.value = value;
- a.timestamp = timestamp;
- connectionViewModel.setDatas(a);
- //ConnectionViewModel.datas. v = new ConnectionViewModel;
- /*
- ConnectionViewModel.value = value;
- v.timestamp = timestamp;
- ConnectionViewModel.setValue*/
- }
- } catch (Exception e) {
- Log.e(LOG_TAG, "failure! no receive: " + e.toString());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement