Download presentation
Presentation is loading. Please wait.
Published byMelissa Nichols Modified over 9 years ago
1
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
2
CoZy schedules thermostats! “I’ll be away and want to turn my AC down” www.classroomclipart.comwww.classroomclipart.com, home.howstuffworks.com
3
But so do programmable thermostats...
4
Why is CoZy a better solution? - Cost: 26% of the cost of Nest - Freedom! vs
5
Buzzwords ●User Oriented! ●Simple ●Intuitive ●Readable ●Specific every(Sunday): SET_TEMP(27 C)
6
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)
7
Language Features
8
Normal features ●Functions ●Lists ●Type checking ●Lexical scoping ●Arithmetic ●Logic ●Control flow ●print ●log to file Borrrrrrrrrrrring...
9
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!
10
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”
11
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
12
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)
13
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”
14
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)
15
How did this all come together? Lexical Analyzer, Parser, Code Generator Added features Semantic Analyzer
16
How did this all come together? - Communication - Meeting Minutes - Tasks - Deliverables - Version Control - Reporting Bugs
17
Architecture
18
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
19
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
20
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
21
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
22
Dev Environment
23
Development Environment Unfortunately, diversity isn’t always great. + + = :(
24
Development Environment It was difficult, but we made it work.
25
Development Environment,
26
,
27
Other Tools
28
Version Control - Philosophy 1. Thou shalt not dirty the master branch. 2. Thou shalt pull, and pull often.
29
Runtime Environment CoZy srcTarget ProgramPython Raspbian OS python-rpi.gpio CoZy Compiler Python Interpreeter
30
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
31
Compiler Tools PLY (Python Lex-Yacc) Ultimately helped create an AST for us
32
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
33
Testing Plan
34
General Testing Plan Evolution of the Testing Suite
35
General Testing Plan Production Branch Feature Branch... Individual-testing / Pull Request / Peer-testing
36
Testing Suite - Early inline testing in yacc.py and lex.py pro: fast / easy to implement con: difficult to add multiple test cases
37
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
38
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
39
DEMO
40
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
41
Check us out on Github! https://github.com/oceanhuang/CoZy
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.