Tessel Rust

The Tessel2's RUSTY ENDOSKELETON

NodeConf Europe 2015
István Szmozsánszky "Flaki"
@slsoftworks

@slsoftworks 

JavaScript Developer

Mozilla Contributor
&
Community TechSpeaker

Tessel Project
Team Member

Frontend Trainer at
DPC Consulting

the Rust Hungary community
rust-lang.hu

the Tessel 2

the Tessel 2
tessel.io

  • Prototype in any language
    (JS in node.js, Rust or Python)
  • Refactor in Rust if needed
  • Order with modules integrated
  • Profit! $$$

OSS + OS-HW + OG

@slsoftworks 

why so RUSTY?!

@slsoftworks 
@slsoftworks 

it's Not about the WHY - iT's all about
holy sh*t JavaScript is hUGE
JavaScript World Domination?

...but is it really  JAVASCRIPT?

@slsoftworks 

YES

...and also...
no

←  mandatory cat photo

the original tessel

A lUA VM Disguised as JavaScript
Colony

@slsoftworks 

MAKE IT?

NODE MCU Didn't even try - maybe JERRYScript will triumph
What's the deal with iot.js and JerryScript?

@slsoftworks 

OR BREAK IT?

well, more like fix it, but still...

NODE MCU Didn't even try - maybe JERRYScript will triumph
Colony

@slsoftworks 

What rust then?

@slsoftworks 

...like ever... - Death To C

Don't DO THIS

A Programming Language is a tool

@slsoftworks 

What is rust?

  • A new programming language
  • Predictable high performance
  • Memory & thread safety
  • Compile-time error checking
  • Powerful multi-paradigm syntax
  • Minimal runtime, no garbage-collector
  • Multiplatform (Unix/Windows/OSX)
  • Modules+package manager (Cargo)
@slsoftworks 

But HOW?

@slsoftworks 

When's rust the right tool?

  • Speeeeeed
  • Power consciousness

node-ffi

just HELP US build the thing!
github.com/tessel/tessel-rust

native-compiled rust binaries

check out the ExaMPLe
on GitHub

Service in Rust

use std::thread;
use unix_socket::{UnixStream, UnixListener};

// access to the tessel and accelerometer crate
extern crate rust_tessel;
extern crate rust_accel_mma84;


fn handle_client(stream: UnixStream) {

    // initialize the accelerometer
    let port = rust_tessel::TesselPort::new("a").unwrap();
    let mut accel = rust_accel_mma84::Accelerometer::new(port);
    accel.mode_active();

    // stream accelerometer data
    let mut vals = [0;3];
    loop {
        accel.get_acceleration(&mut vals);

        stream.write(vals[0]);
        stream.write(vals[1]);
        stream.write(vals[2]);

        thread::sleep_ms(100)
    }
}

let listener = UnixListener::bind("/tmp/rs2js-bridge-sock-000").unwrap();

// accept connections and process them, spawning a new thread for each one
for stream in listener.incoming() {
    match stream {
        Ok(stream) => {
            /* connection succeeded */
            thread::spawn(|| handle_client(stream));
        }
        Err(err) => {
            /* connection failed */
            break;
        }
    }
}

check out the ExaMPLe
on GitHub

nODE.JS SIDE

var spawn = require('child_process').spawn;
var child = spawn('accel_rs', [], {});

// Use standard out...
child.stdout.on('data', function(data) {
    console.log(data.toString());
});

// ... OR use a domain socket
var net = require('net');
var client = net.connect({path: '/tmp/rs2js-bridge-sock-000'});


function() { //'connect' listener
    console.log('Rust bridge opened!');
    client.write('world!\r\n');
});

client.on('data', function(data) {
  console.log(data.toString());
  client.end();
});

Thank you!

GET IN TOUCH!
 

Tessel ♥ Rust - Tessel2's Rusty Endoskeleton

By Szmozsánszky István

Tessel ♥ Rust - Tessel2's Rusty Endoskeleton

What is Rust — and why should I care about it? Introducing the Rust programming language, and its new home on the mighty Tessel 2.

  • 6,152