-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added setup files and xdf utils to code
- Loading branch information
1 parent
0333746
commit e31864a
Showing
8 changed files
with
183 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[Unit] | ||
Description=Create The Access Point for the coral | ||
Before=hostapd.service dnsmasq.service | ||
After=network-online.target | ||
Wants=network-online.target | ||
|
||
[Service] | ||
Type=simple | ||
ExecStart=/usr/local/bin/create_ap0.sh | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/bin/bash | ||
|
||
# Get the name of the interface on phy1 | ||
phy1_interface=$(sudo iw dev | awk '/phy#1/ {getline; print $2}') | ||
|
||
# Check if the interface name is p2p0 | ||
if [[ $phy1_interface == "ap0" ]]; then | ||
echo "ap0 already set up, not running script..." | ||
else | ||
echo $phy1_interface | ||
# Delete the existing p2p0 interface | ||
/sbin/iw dev $phy1_interface del | ||
|
||
# Reload the Network Manager utility | ||
systemctl restart NetworkManager | ||
|
||
# Create a new ap0 interface in AP mode | ||
/sbin/iw phy phy1 interface add ap0 type __ap | ||
|
||
# Disable power management for the ap0 interface | ||
/sbin/iw dev ap0 set power_save off | ||
|
||
# Reload the Network Manager utility again | ||
systemctl restart NetworkManager | ||
|
||
# Get an IPV4 address for the server | ||
ifconfig ap0 192.168.4.1 up | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Configuration for Access Point | ||
interface=ap0 | ||
dhcp-range=192.168.4.2,192.168.4.20,255.255.255.0,24h | ||
dhcp-option=3,192.168.4.1 | ||
dhcp-option=6,192.168.4.1 | ||
server=8.8.8.8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
interface=ap0 | ||
driver=nl80211 | ||
ssid=YOUR-SSID-HERE | ||
hw_mode=g | ||
channel=6 | ||
wpa=2 | ||
wpa_passphrase=YOUR-PASSWORD-HERE | ||
wpa_key_mgmt=WPA-PSK | ||
wpa_pairwise=TKIP CCMP | ||
rsn_pairwise=CCMP | ||
auth_algs=1 | ||
macaddr_acl=0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[Unit] | ||
Description=Jupyter Notebook Server | ||
After=create_ap.service | ||
After=hostapd.service | ||
After=dnsmasq.service | ||
|
||
[Service] | ||
Type=exec | ||
ExecStart=/bin/bash -c "XDG_RUNTIME_DIR=/run/user/`id -u` /usr/bin/jupyter notebook --no-browser --ip 192.168.4.1 --port 8080 --notebook-dir=/home/mendel" | ||
User=mendel | ||
Group=mendel | ||
Restart=on-failure | ||
RestartSec=60s | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[Unit] | ||
Description=Setup tables service | ||
After=create_ap.service | ||
Wants=network-online.target | ||
After=network-online.target | ||
|
||
[Service] | ||
Type=simple | ||
ExecStart=/usr/local/bin/setup_tables.sh | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/bin/bash | ||
|
||
echo "Telling kernel to turn on ipv4 ip_forwarding" | ||
echo 1 > /proc/sys/net/ipv4/ip_forward | ||
echo "Done. Setting up iptables rules to allow FORWARDING" | ||
|
||
DOWNSTREAM=ap0 # ap0 is client network (running hostapd) | ||
UPSTREAM=wlan0 # upstream network (internet) | ||
|
||
# Allow IP Masquerading (NAT) of packets from clients (downstream) to upstream network (internet) | ||
iptables -t nat -A POSTROUTING -o $UPSTREAM -j MASQUERADE | ||
|
||
# Forward packets from downstream clients to the upstream internet | ||
iptables -A FORWARD -i $DOWNSTREAM -o $UPSTREAM -j ACCEPT | ||
|
||
# Forward packers from the internet to clients IF THE CONNECTION IS ALREADY OPEN! | ||
iptables -A FORWARD -i $UPSTREAM -o $DOWNSTREAM -m state --state RELATED,ESTABLISHED -j ACCEPT | ||
|
||
# Setup the external DNS server | ||
iptables -t nat -A PREROUTING -i $DOWNSTREAM -p udp --dport 53 -j DNAT --to-destination 8.8.8.8:53 | ||
|
||
echo "Done setting up iptables rules. Forwarding enabled" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
|
||
import numpy as np | ||
import pyxdf | ||
import os | ||
import matplotlib.pyplot as plt | ||
import pandas as pd | ||
|
||
STREAM_NAMES = { | ||
'filtered_data': 'Portiloop Filtered', | ||
'raw_data': 'Portiloop Raw Data', | ||
'stimuli': 'Portiloop_stimuli' | ||
} | ||
|
||
|
||
def read_xdf_file(xdf_file, channel): | ||
""" | ||
Read a single xdf file and return the data of the given channel as a dataframe. | ||
""" | ||
xdf_data, _ = pyxdf.load_xdf(xdf_file) | ||
|
||
# Load all streams given their names | ||
filtered_stream, raw_stream, markers = None, None, None | ||
for stream in xdf_data: | ||
# print(stream['info']['name']) | ||
if stream['info']['name'][0] == STREAM_NAMES['filtered_data']: | ||
filtered_stream = stream | ||
elif stream['info']['name'][0] == STREAM_NAMES['raw_data']: | ||
raw_stream = stream | ||
elif stream['info']['name'][0] == STREAM_NAMES['stimuli']: | ||
markers = stream | ||
|
||
if filtered_stream is None or raw_stream is None: | ||
raise ValueError("One of the necessary streams could not be found. Make sure that at least one signal stream is present in XDF recording") | ||
|
||
# Add all samples from raw and filtered signals | ||
points = [] | ||
diffs = [] | ||
shortest_stream = min(int(filtered_stream['footer']['info']['sample_count'][0]), | ||
int(raw_stream['footer']['info']['sample_count'][0])) | ||
for i in range(shortest_stream): | ||
if markers is not None: | ||
datapoint = [filtered_stream['time_stamps'][i], | ||
float(filtered_stream['time_series'][i, channel-1]), | ||
raw_stream['time_series'][i, channel-1], | ||
0] | ||
else: | ||
datapoint = [filtered_stream['time_stamps'][i], | ||
float(filtered_stream['time_series'][i, channel-1]), | ||
raw_stream['time_series'][i, channel-1]] | ||
diffs.append(abs(filtered_stream['time_stamps'][i] - raw_stream['time_stamps'][i])) | ||
points.append(datapoint) | ||
|
||
# Add markers | ||
columns = ["Time Stamps", "Filtered Signal", "Raw Signal"] | ||
if markers is not None: | ||
columns.append("Stimuli") | ||
for time_stamp in markers['time_stamps']: | ||
new_index = np.abs(filtered_stream['time_stamps'] - time_stamp).argmin() | ||
points[new_index][3] = 1 | ||
|
||
# Create dataframe | ||
array = np.array(points) | ||
|
||
return array, columns | ||
|
||
|
||
def read_edf_file(edf_file): | ||
""" | ||
Read a single edf file and return the data as a dictionary. | ||
""" | ||
pass | ||
|
||
|
||
if __name__ == "__main__": | ||
pass |