Skip to content

fix doubles instead ints in gson java #297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions java-package/brainflow/src/main/java/brainflow/BoardDescr.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package brainflow;

import java.util.List;

public class BoardDescr
{
public Integer sampling_rate;
public List<Integer> eeg_channels;
public List<Integer> eog_channels;
public List<Integer> exg_channels;
public List<Integer> emg_channels;
public List<Integer> ppg_channels;
public List<Integer> eda_channels;
public List<Integer> accel_channels;
public List<Integer> gyro_channels;
public List<Integer> temperature_channels;
public List<Integer> resistance_channels;
public List<Integer> other_channels;
public Integer package_num_channel;
public Integer batter_channel;
public Integer timestamp_channel;
public Integer marker_channel;
public Integer num_rows;
public String name;
public String eeg_names;

public BoardDescr ()
{
sampling_rate = null;
eeg_channels = null;
eog_channels = null;
exg_channels = null;
emg_channels = null;
ppg_channels = null;
eda_channels = null;
accel_channels = null;
gyro_channels = null;
temperature_channels = null;
resistance_channels = null;
other_channels = null;
package_num_channel = null;
timestamp_channel = null;
num_rows = null;
name = null;
eeg_names = null;
}
}
10 changes: 5 additions & 5 deletions java-package/brainflow/src/main/java/brainflow/BoardShim.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.SystemUtils;
Expand Down Expand Up @@ -328,8 +330,7 @@ public static String[] get_eeg_names (int board_id) throws BrainFlowError
/**
* Get board description
*/
@SuppressWarnings ("unchecked")
public static Map<String, Object> get_board_descr (int board_id) throws BrainFlowError
public static <T> T get_board_descr (Class<T> type, int board_id) throws BrainFlowError
{
int[] len = new int[1];
byte[] str = new byte[16000];
Expand All @@ -340,9 +341,8 @@ public static Map<String, Object> get_board_descr (int board_id) throws BrainFlo
}
String descr_string = new String (str, 0, len[0]);
Gson gson = new Gson ();
Map<String, Object> map = new HashMap<String, Object> ();
map = (Map<String, Object>) gson.fromJson (descr_string, map.getClass ());
return map;
T res = (T) gson.fromJson (descr_string, type);
return res;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import brainflow.DetrendOperations;
import brainflow.LogLevels;
import brainflow.WindowFunctions;
import brainflow.BoardDescr;

public class BandPower
{
Expand All @@ -25,8 +26,8 @@ public static void main (String[] args) throws Exception
BrainFlowInputParams params = new BrainFlowInputParams ();
int board_id = BoardIds.SYNTHETIC_BOARD.get_code ();
BoardShim board_shim = new BoardShim (board_id, params);
Map<String, Object> board_descr = BoardShim.get_board_descr (board_id);
int sampling_rate = ((Double) board_descr.get ("sampling_rate")).intValue ();
BoardDescr board_descr = BoardShim.get_board_descr (BoardDescr.class, board_id);
int sampling_rate = board_descr.sampling_rate;
int nfft = DataFilter.get_nearest_power_of_two (sampling_rate);

board_shim.prepare_session ();
Expand All @@ -37,8 +38,7 @@ public static void main (String[] args) throws Exception
double[][] data = board_shim.get_board_data ();
board_shim.release_session ();

@SuppressWarnings ("unchecked")
List<Double> eeg_channels = (List<Double>) board_descr.get ("eeg_channels");
List<Integer> eeg_channels = board_descr.eeg_channels;
// seconds channel of synthetic board has big 'alpha' use it for test
int eeg_channel = eeg_channels.get (1).intValue ();
// optional: detrend before psd
Expand Down