Skip to content

Commit

Permalink
Merge develop into master
Browse files Browse the repository at this point in the history
  • Loading branch information
mntns committed Dec 23, 2020
2 parents ca45062 + db40f71 commit b74782f
Show file tree
Hide file tree
Showing 15 changed files with 414 additions and 318 deletions.
116 changes: 95 additions & 21 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,107 @@
# This is a basic workflow to help you get started with Actions
name: ci

name: CI

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
push:
branches: [ master ]
branches: [ master, develop ]
pull_request:
branches: [ master ]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
build-aarch64:
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- uses: actions/setup-ruby@v1
with:
ruby-version: '2.6'
- run: gem install fpm -v 1.10.2
- uses: actions/setup-node@v2-beta
with:
node-version: '12'
- uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
daemon/target
key: ${{ runner.os }}-cargo-aarch64-${{ hashFiles('**/Cargo.lock') }}
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v2
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: aarch64-unknown-linux-gnu
override: true
- uses: marcopolo/cargo@master
with:
use-cross: true
command: build
args: --target aarch64-unknown-linux-gnu --features raspberry --release
working-directory: daemon
- run: cp -r daemon/target/aarch64-unknown-linux-gnu/release daemon/target
- run: yarn install
- run: yarn run build
- run: yarn run dist-arm64
- uses: actions/upload-artifact@v2
with:
name: pi-tool-deb-aarch64
path: dist/*.deb
build-armv7:
runs-on: ubuntu-latest

# Runs a single command using the runners shell
- name: Run a one-line script
run: echo Hello, world!

# Runs a set of commands using the runners shell
- name: Run a multi-line script
run: |
echo Add other actions to build,
echo test, and deploy your project.
steps:
- uses: actions/checkout@v2
- uses: actions/setup-ruby@v1
with:
ruby-version: '2.6'
- run: gem install fpm -v 1.10.2
- uses: actions/setup-node@v2-beta
with:
node-version: '12'
- uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
daemon/target
key: ${{ runner.os }}-cargo-armv7-${{ hashFiles('**/Cargo.lock') }}
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v2
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: armv7-unknown-linux-gnueabihf
override: true
- uses: marcopolo/cargo@master
with:
use-cross: true
command: build
args: --target armv7-unknown-linux-gnueabihf --features raspberry --release
working-directory: daemon
- run: cp -r daemon/target/armv7-unknown-linux-gnueabihf/release daemon/target
- run: yarn install
- run: yarn run build
- run: yarn run dist-armv7l
- uses: actions/upload-artifact@v2
with:
name: pi-tool-deb-armv7
path: dist/*.deb


10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM arm32v7/debian:latest
FROM ubuntu:latest

RUN apt-get update
RUN apt-get -y install curl ruby
RUN curl -sL https://nodejs.org/dist/v12.18.4/node-v12.18.4-linux-armv7l.tar.xz -o node.tar.xz
RUN tar -xzf node.tar.gz
RUN cd node
RUN cp -R * /usr/local/
RUN curl -sL https://deb.nodesource.com/setup_12.x | bash -
RUN apt-get install -y nodejs
RUN npm install -g yarn


11 changes: 11 additions & 0 deletions daemon/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions daemon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ crossbeam = "0.7.3"
lazy_static = "1.4.0"
sysfs_gpio = "0.5.4"
sysinfo = "0.15.1"
openssl = { version = "0.10", features = ["vendored"] }

[features]
raspberry = []
21 changes: 12 additions & 9 deletions daemon/src/actions.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
use log::*;
use std::process::Command;
use std::result::Result;
use log::*;

/// Shuts down the system
pub fn shutdown() -> Result<(), String> {
info!("Shutting down system");

if cfg!(feature="raspberry") {
if let Err(_e) = Command::new("sudo").args(&["shutdown", "-h", "now"]).spawn() {
warn!("Failed to shut down system");
}
if cfg!(feature = "raspberry") {
if let Err(_e) = Command::new("sudo")
.args(&["shutdown", "-h", "now"])
.spawn()
{
warn!("Failed to shut down system");
}
}

Ok(())
Expand All @@ -19,10 +22,10 @@ pub fn shutdown() -> Result<(), String> {
pub fn reboot() -> Result<(), String> {
info!("Rebooting system");

if cfg!(feature="raspberry") {
if let Err(_e) = Command::new("sudo").args(&["reboot"]).spawn() {
warn!("Failed to reboot system");
}
if cfg!(feature = "raspberry") {
if let Err(_e) = Command::new("sudo").args(&["reboot"]).spawn() {
warn!("Failed to reboot system");
}
}

Ok(())
Expand Down
57 changes: 31 additions & 26 deletions daemon/src/command_handler.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
use serde_derive::{Serialize, Deserialize};
use crossbeam::crossbeam_channel::Receiver;
use std::collections::HashMap;
use crate::metrics::{Measurement, MetricIdentifier, Collector};
use crate::mapping::ButtonListener;
use crate::overclock::{OverclockParameters, overclock};
use crate::actions::reboot;
use crate::mapping::ButtonListener;
use crate::metrics::{Collector, Measurement, MetricIdentifier};
use crate::overclock::{overclock, OverclockParameters};
use crate::util::MappingRepr;
use crossbeam::crossbeam_channel::Receiver;
use serde_derive::{Deserialize, Serialize};
use std::collections::HashMap;

/// Defines commands that can be sent to the daemon
#[derive(Debug, Serialize, Deserialize)]
#[serde(tag = "command")]
pub enum Command {
Overclock { params: OverclockParameters },
Overclock {
params: OverclockParameters,
},
Reboot,
SubscribeMetric { metric: MetricIdentifier },
UnsubscribeMetric { metric: MetricIdentifier },
SyncMappings { mappings: HashMap<String, MappingRepr> },
SubscribeMetric {
metric: MetricIdentifier,
},
UnsubscribeMetric {
metric: MetricIdentifier,
},
SyncMappings {
mappings: HashMap<String, MappingRepr>,
},
}


/// Defines all events that can be emitted by the daemon
#[derive(Serialize, Deserialize, Debug)]
#[serde(tag = "event")]
Expand All @@ -30,31 +37,27 @@ pub enum Event {
/// Starts the command handler
pub fn start_handler(peer_map: crate::PeerMap, ws_rx: Receiver<Command>) {
std::thread::spawn(move || {
// Starts metric collector
// Starts metric collector
let mut collector = Collector::new();
collector.start(peer_map.clone());

// Starts button press listener
let mut btn_listener = ButtonListener::new();
btn_listener.start(peer_map.clone());
let mut btn_listener = ButtonListener::new();
btn_listener.start(peer_map.clone());

for cmd in ws_rx {
match cmd {
Command::Overclock { params: p } => {
overclock(p)
},
Command::Reboot => {
reboot().unwrap()
},
Command::Overclock { params: p } => overclock(p),
Command::Reboot => reboot().unwrap(),
Command::SubscribeMetric { metric: m } => {
collector.subscribe(m);
},
}
Command::UnsubscribeMetric { metric: m } => {
collector.unsubscribe(m);
},
}
Command::SyncMappings { mappings: m_repr } => {
let mappings = m_repr.iter().map(|(id, m)| m.to_mapping(id)).collect();
btn_listener.sync(mappings);
let mappings = m_repr.iter().map(|(id, m)| m.to_mapping(id)).collect();
btn_listener.sync(mappings);
}
}
}
Expand All @@ -67,7 +70,9 @@ pub fn broadcast(peer_map: &crate::PeerMap, event: Event) {
let mut peers = peer_map.lock().unwrap();

for peer_tx in peers.values_mut() {
let event_json_c= event_json.clone();
peer_tx.unbounded_send(tungstenite::Message::Text(event_json_c)).unwrap();
let event_json_c = event_json.clone();
peer_tx
.unbounded_send(tungstenite::Message::Text(event_json_c))
.unwrap();
}
}
Loading

0 comments on commit b74782f

Please sign in to comment.