can read and isolate buffered data from raspberry
This commit is contained in:
parent
9c30a011e8
commit
55f4998f78
@ -1,13 +1,25 @@
|
|||||||
package com.example.aped.ui.plots;
|
package com.example.aped.ui.plots;
|
||||||
|
|
||||||
|
import android.net.sip.SipSession;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import com.example.aped.MainActivity;
|
import com.example.aped.MainActivity;
|
||||||
import com.example.aped.R;
|
import com.example.aped.R;
|
||||||
|
import com.example.aped.communication.Communicator;
|
||||||
|
import com.example.aped.utils.IXML;
|
||||||
|
import com.example.aped.utils.XMLHandler;
|
||||||
|
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Dictionary;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import lecho.lib.hellocharts.model.AxisValue;
|
import lecho.lib.hellocharts.model.AxisValue;
|
||||||
import lecho.lib.hellocharts.model.Line;
|
import lecho.lib.hellocharts.model.Line;
|
||||||
@ -19,6 +31,10 @@ public class PlotFragment extends Fragment {
|
|||||||
|
|
||||||
/** Include the MainActivity.*/
|
/** Include the MainActivity.*/
|
||||||
private MainActivity mainActivity;
|
private MainActivity mainActivity;
|
||||||
|
/** List of all the devices with buffers. **/
|
||||||
|
private List<String> bufferedDevices;
|
||||||
|
/** Line Chart View that is displayed **/
|
||||||
|
private LineChartView lineChartView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* paul
|
* paul
|
||||||
@ -32,35 +48,57 @@ public class PlotFragment extends Fragment {
|
|||||||
final ViewGroup container,
|
final ViewGroup container,
|
||||||
final Bundle savedInstanceState) {
|
final Bundle savedInstanceState) {
|
||||||
this.mainActivity = (MainActivity) getActivity();
|
this.mainActivity = (MainActivity) getActivity();
|
||||||
|
this.bufferedDevices = getBufferedDevices(mainActivity.getXml());
|
||||||
|
|
||||||
// Inflate the layout for this fragment
|
// Inflate the layout for this fragment
|
||||||
View view = inflater.inflate(R.layout.fragment_plot, container, false);
|
View view = inflater.inflate(R.layout.fragment_plot, container, false);
|
||||||
LineChartView lineChartView = view.findViewById(R.id.test_plot);
|
this.lineChartView = view.findViewById(R.id.test_plot);
|
||||||
|
|
||||||
String[] xAxisData = {"15:30", "15:31", "15:32"};
|
getBufferedValues(mainActivity.getDelivery(), mainActivity.getXml());
|
||||||
int[] yAxisData = {1, 3, 2};
|
|
||||||
|
|
||||||
List yAxisValues = new ArrayList();
|
|
||||||
List xAxisValues = new ArrayList();
|
|
||||||
|
|
||||||
Line line = new Line(yAxisValues);
|
|
||||||
|
|
||||||
for (int i = 0; i < xAxisData.length; i++) {
|
|
||||||
xAxisValues.add(i, new AxisValue(i).setLabel(xAxisData[i]));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < yAxisData.length; i++) {
|
|
||||||
yAxisValues.add(new PointValue(i, yAxisData[i]));
|
|
||||||
}
|
|
||||||
|
|
||||||
List lines = new ArrayList();
|
|
||||||
|
|
||||||
lines.add(line);
|
|
||||||
|
|
||||||
LineChartData lineChartData = new LineChartData();
|
|
||||||
lineChartData.setLines(lines);
|
|
||||||
|
|
||||||
lineChartView.setLineChartData(lineChartData);
|
|
||||||
mainActivity.getConfigurationHandler().setCurrentView(R.id.nav_plots);
|
mainActivity.getConfigurationHandler().setCurrentView(R.id.nav_plots);
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<String> getBufferedDevices(IXML xml){
|
||||||
|
List<String> returnList = new ArrayList<>();
|
||||||
|
for (String deviceName : xml.getDeviceNames()){
|
||||||
|
if (xml.getBufferSize(deviceName) > 0) {
|
||||||
|
returnList.add(deviceName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return returnList;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void getBufferedValues(Communicator communicator, IXML xml){
|
||||||
|
for (String deviceName : this.bufferedDevices){
|
||||||
|
communicator.readBuffer(deviceName,response -> {
|
||||||
|
try {
|
||||||
|
JSONObject buffer = response.getJSONObject("buffer");
|
||||||
|
for(String pin : (List<String>) (xml.getPort(deviceName)).get("pins")) {
|
||||||
|
String valueString = buffer.getString(pin);
|
||||||
|
valueString = valueString.substring(2,valueString.length()-2);
|
||||||
|
String[] valueStringArray = valueString.split("', '");
|
||||||
|
int[] values = new int[valueString.length()];
|
||||||
|
for (int i = 0; i < valueStringArray.length; i++){
|
||||||
|
values[i] = Integer.parseInt(valueStringArray[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
//display data
|
||||||
|
List yAxisValues = new ArrayList();
|
||||||
|
for (int i = 0; i < values.length; i++){
|
||||||
|
yAxisValues.add(values[i]);
|
||||||
|
}
|
||||||
|
Line line = new Line(yAxisValues);
|
||||||
|
List lines = new ArrayList();
|
||||||
|
lines.add(line);
|
||||||
|
LineChartData lineChartData = new LineChartData();
|
||||||
|
lineChartData.setLines(lines);
|
||||||
|
this.lineChartView.setLineChartData(lineChartData);
|
||||||
|
}
|
||||||
|
} catch (JSONException e) {
|
||||||
|
Log.e("PlotFragment", "error while parsing JSON on READ BUFFER: " + e.getMessage());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user