CoZy: A very cool language for temperature control Project Manager: Hannah Keiler Language and Tools Guru: Nate Booth System Architect: Giovanni Ortuno System Integrator: Daron Lin System Tester: Minghai (Ocean) Huang
CoZy schedules thermostats! “I’ll be away and want to turn my AC down” home.howstuffworks.com
But so do programmable thermostats...
Why is CoZy a better solution? - Cost: 26% of the cost of Nest - Freedom! vs
Buzzwords ●User Oriented! ●Simple ●Intuitive ●Readable ●Specific every(Sunday): SET_TEMP(27 C)
Buzzwords ●User Oriented! ●Simple ●Intuitive ●Readable ●Specific ●Statically typed ●Architecture neutral ●Portable - Compiles to Python to run on raspberry pi ●Robust every(Sunday): SET_TEMP(27 C)
Language Features
Normal features ●Functions ●Lists ●Type checking ●Lexical scoping ●Arithmetic ●Logic ●Control flow ●print ●log to file Borrrrrrrrrrrring...
Special features! ●“every” statements ●“once every” statements ●time ranges are primitive types ●temperature is primitive type ●interacts nicely with temperature sensor ●interacts nicely with “heater” Now this is cool!
every statements ●Run consistently every time their date/time condition is met ●If you want it to run at two different sets of times, separate them by semicolon ●If you want it to run when two date/time conditions are both met, separate by “during”
every statement example ●Prints “hello” from 2:45 PM to 6:50 PM and from ___ to ___ every day ●On Mondays, also prints “goodbye” from 2:00 PM to 6:52 PM
every statement example helloText = “hello” goodbyeText = “goodbye” every (2:45 PM to 6:50 PM; 6:53 PM to 11:00 PM): print(helloText) every (2:00 PM to 6:52 PM during Tuesday): print(goodbyeText)
once every statements ●Run once each time their date/time condition is met ●If you want it to run at two different sets of times, separate them by semicolon ●If you want it to run when two date/time conditions are both met, separate by “during”
once every statement example helloText = “hello” goodbyeText = “goodbye” once every (2:45 PM to 6:50 PM; 6:53 PM to 11:00 PM): print(helloText) once every (2:00 PM to 6:52 PM during Tuesday): print(goodbyeText)
How did this all come together? Lexical Analyzer, Parser, Code Generator Added features Semantic Analyzer
How did this all come together? - Communication - Meeting Minutes - Tasks - Deliverables - Version Control - Reporting Bugs
Architecture
Architecture Overview ➔ Cozy File ◆ file.cz ➔ Lexer ◆ cozyLex.py ➔ Parser ◆ cozyYacc.py ➔ Code Gen ◆ codeGenerator.py ➔ Execute Code ◆ runCozy.py Semantic Analyzer + Code Generator Lexical Analyzer Token Stream Syntax Analyzer Syntax Tree CoZy Source Code Python Code
Cozy Code to Token Stream LexToken(DEF,'def',2,1) LexToken(ID,'myFunction',2,5) LexToken(LPAREN,'(',2,15) LexToken(RPAREN,')',2,16) LexToken(COLON,':',2,17) LexToken(NEWLINE,'\n',2,18 ) INDENT LexToken(IF,'if',3,23) LexToken(LPAREN,'(',3,25) LexToken(MONDAY,'Monday',3,26) …….. def myFunction(): if(Monday): print(“It's MONDAY!!”) else: print("It's not Monday YAAY") once every(January): every(10:00 AM to 11:00 PM): myFunction() cozyLex.py
Token Stream to Abstract Syntax Tree LexToken(DEF,'def',2,1) LexToken(ID,'myFunction',2,5) LexToken(LPAREN,'(',2,15) LexToken(RPAREN,')',2,16) LexToken(COLON,':',2,17) LexToken(NEWLINE,'\n',2,18 ) INDENT LexToken(IF,'if',3,23) LexToken(LPAREN,'(',3,25) LexToken(MONDAY,'Monday',3,26) …….. program >program ->external_declaration -->function_definition: 'myFunction' --->statement_list ---->statement ----->selection_statement >or_expression >and_expression >equality_expression …….. cozyYacc.py
AST to Code program >program ->external_declaration -->function_definition: 'myFunction' --->statement_list ---->statement ----->selection_statement >or_expression >and_expression >equality_expression …….. …. if(datetime.datetime.now().weekday() == 0): print "OH NO IT"S MONDAY!!" else: print "It's not monday yaay" …. def condition1(): if ((datetime.datetime.now().weekday() == 1) and (datetime.datetime(100,1,1,10, 0))): return True …... codeGenerator.py
Dev Environment
Development Environment Unfortunately, diversity isn’t always great. + + = :(
Development Environment It was difficult, but we made it work.
Development Environment,
,
Other Tools
Version Control - Philosophy 1. Thou shalt not dirty the master branch. 2. Thou shalt pull, and pull often.
Runtime Environment CoZy srcTarget ProgramPython Raspbian OS python-rpi.gpio CoZy Compiler Python Interpreeter
Runtime Environment CoZy comes with: cozyLex.py cozyYacc.py codeGenerator.py runCozy.py Temperature.py runtimeError.py r_pi/Fake_Thermostat.py r_pi/Thermostat.py r_pi/fake_temp
Compiler Tools PLY (Python Lex-Yacc) Ultimately helped create an AST for us
Running CoZy Download CoZy.tar.gz $ tar xvzf CoZy.tar.gz $ cd CoZy $./setup $ create super awesome CoZy program $./CoZy myAwesomeCoZy.cz OR $./CoZy my AwesomeCoZy.cz -o
Testing Plan
General Testing Plan Evolution of the Testing Suite
General Testing Plan Production Branch Feature Branch... Individual-testing / Pull Request / Peer-testing
Testing Suite - Early inline testing in yacc.py and lex.py pro: fast / easy to implement con: difficult to add multiple test cases
Testing Suite: Intermediate One script to run all test cases pro: easy to add test cases con: lost track of test cases if one test case failed, others don’t execute implemented continuous loop simply append new test case to end
Testing Suite: Final Wrapped the previous python script inside a shell script - one directory, each test case in separate file - pro: easy to keep track of test cases now
DEMO
Take-Aways What we wish we did: ●Became comfortable with git/ Github early ●Developed more tests What we’re glad we did: ●Regular meetings ●Developing base and building features on top
Check us out on Github!