22
mruby The programming language for IoT Kyushu Institute of Technology Kazuaki TANAKA Ruby Association mruby Forum

mruby The programming language for IoTossforum.jp/jossfiles/4-7 mruby The programming language for IoT.pdf · Why Ruby? Easy to read ... Implement mruby application 2. Test on PC

  • Upload
    others

  • View
    25

  • Download
    0

Embed Size (px)

Citation preview

Page 1: mruby The programming language for IoTossforum.jp/jossfiles/4-7 mruby The programming language for IoT.pdf · Why Ruby? Easy to read ... Implement mruby application 2. Test on PC

mruby

The programming language for IoT

Kyushu Institute of TechnologyKazuaki TANAKA

Ruby Associationmruby Forum

Page 2: mruby The programming language for IoTossforum.jp/jossfiles/4-7 mruby The programming language for IoT.pdf · Why Ruby? Easy to read ... Implement mruby application 2. Test on PC

EmbeddedSoftware

Development

Page 3: mruby The programming language for IoTossforum.jp/jossfiles/4-7 mruby The programming language for IoT.pdf · Why Ruby? Easy to read ... Implement mruby application 2. Test on PC

Hardware+

Software

Page 4: mruby The programming language for IoTossforum.jp/jossfiles/4-7 mruby The programming language for IoT.pdf · Why Ruby? Easy to read ... Implement mruby application 2. Test on PC

Limited Resources

* Memory* Processing power* Time (Real-time processing)

Page 5: mruby The programming language for IoTossforum.jp/jossfiles/4-7 mruby The programming language for IoT.pdf · Why Ruby? Easy to read ... Implement mruby application 2. Test on PC

Realtime?

*NOT* processing speed!

Time constraints in response from events.

i.e. “Deadline estimation”

Page 6: mruby The programming language for IoTossforum.jp/jossfiles/4-7 mruby The programming language for IoT.pdf · Why Ruby? Easy to read ... Implement mruby application 2. Test on PC

Rubyfor

Embedded Software Development

mruby

Page 7: mruby The programming language for IoTossforum.jp/jossfiles/4-7 mruby The programming language for IoT.pdf · Why Ruby? Easy to read ... Implement mruby application 2. Test on PC

Why Ruby?● Easy to read, easy to implement

● ISO/IEC 30170, JIS X 3017

● Open source software

Page 8: mruby The programming language for IoTossforum.jp/jossfiles/4-7 mruby The programming language for IoT.pdf · Why Ruby? Easy to read ... Implement mruby application 2. Test on PC

mruby provides,,,● Lightweight C interface

– C-func. and Ruby-method mapping● Less resources in execution

– mruby compiler and VM– Small VM < 250KB

● Realtime– Incremental GC

Page 9: mruby The programming language for IoTossforum.jp/jossfiles/4-7 mruby The programming language for IoT.pdf · Why Ruby? Easy to read ... Implement mruby application 2. Test on PC

Compiler and VM

mrubycode

Code analyze

Bytecode

Executionin target device

Device independentformat

Compiler

VM

Page 10: mruby The programming language for IoTossforum.jp/jossfiles/4-7 mruby The programming language for IoT.pdf · Why Ruby? Easy to read ... Implement mruby application 2. Test on PC

Ruby and mruby

● Ruby– Widely used in Web application development– Rapid software development

● mruby– Reduce resources in execution– Compiler and VM, like Java environment

Page 11: mruby The programming language for IoTossforum.jp/jossfiles/4-7 mruby The programming language for IoT.pdf · Why Ruby? Easy to read ... Implement mruby application 2. Test on PC

Software developmentusing mruby

* Build VM for target device

* Implement mruby application* Test* Deploy

Page 12: mruby The programming language for IoTossforum.jp/jossfiles/4-7 mruby The programming language for IoT.pdf · Why Ruby? Easy to read ... Implement mruby application 2. Test on PC

Test in early phase

* VM for PCTest application on PCwith emulated driver

Page 13: mruby The programming language for IoTossforum.jp/jossfiles/4-7 mruby The programming language for IoT.pdf · Why Ruby? Easy to read ... Implement mruby application 2. Test on PC

1. Implement C application

2. Download to target device

3. Test on target deviceIf errors, back to 1

Using C

Page 14: mruby The programming language for IoTossforum.jp/jossfiles/4-7 mruby The programming language for IoT.pdf · Why Ruby? Easy to read ... Implement mruby application 2. Test on PC

0. Build VM for PC and for target device

1. Implement mruby application

2. Test on PC (with VM for PC)If errors, back to 1

3. Download to target device

4. Test on target device (with VM for device)If errors, back to 1

Using mruby

Page 15: mruby The programming language for IoTossforum.jp/jossfiles/4-7 mruby The programming language for IoT.pdf · Why Ruby? Easy to read ... Implement mruby application 2. Test on PC

More advantages

* Develop mruby application without target device

* Separate hardware layer code and abstracted layer code* Hide source code

Page 16: mruby The programming language for IoTossforum.jp/jossfiles/4-7 mruby The programming language for IoT.pdf · Why Ruby? Easy to read ... Implement mruby application 2. Test on PC

https://github.com/mruby/mruby

http://forum.mruby.org/

Get mrubyLatest

Versioned mruby(with Tested libraries)

Page 17: mruby The programming language for IoTossforum.jp/jossfiles/4-7 mruby The programming language for IoT.pdf · Why Ruby? Easy to read ... Implement mruby application 2. Test on PC
Page 18: mruby The programming language for IoTossforum.jp/jossfiles/4-7 mruby The programming language for IoT.pdf · Why Ruby? Easy to read ... Implement mruby application 2. Test on PC

DEMO

Page 19: mruby The programming language for IoTossforum.jp/jossfiles/4-7 mruby The programming language for IoT.pdf · Why Ruby? Easy to read ... Implement mruby application 2. Test on PC

Sample Program

a = 15p a * 2

a = 1.2p a * 2

a = "abc"p a * 2

a = [1,2]p a * 2

Page 20: mruby The programming language for IoTossforum.jp/jossfiles/4-7 mruby The programming language for IoT.pdf · Why Ruby? Easy to read ... Implement mruby application 2. Test on PC

Dynamic Execution

def func(n) return n+1end

if rand(2)==1 then def func(n) return n*2 endend

p func(5)

Page 21: mruby The programming language for IoTossforum.jp/jossfiles/4-7 mruby The programming language for IoT.pdf · Why Ruby? Easy to read ... Implement mruby application 2. Test on PC

Research Topic

Page 22: mruby The programming language for IoTossforum.jp/jossfiles/4-7 mruby The programming language for IoT.pdf · Why Ruby? Easy to read ... Implement mruby application 2. Test on PC

mruby

i = 209while i>=200 do puts i i = i - 1end

i = 100while i<110 do puts i i = i + 1end