University of Waterloo Midterm Examination Term: Winter Year: 2013 Student Name UW Student ID Number Course Abbreviation and Number ECE 155 Course Title Engineering Design with Embed- ded Systems Section(s) 001 Sections Combined Course(s) Section Numbers of Combined Course(s) Instructor(s) Patrick Lam Date of Exam Friday, March 1, 2013 Time Period Start Time: 1:00 p.m. End Time: 2:20 p.m. Duration of Exam 80 minutes Number of Exam Pages 14 (including this cover sheet) Exam Type Closed Book Additional Materials Allowed NO ADDITIONAL MATERIALS ALLOWED Marking Scheme (For Examiner Use Only): Question Mark Weight Question Mark Weight 1 16 3a 5 3b 5 2 10 3c 4 2a 2 3d 5 2b 3 3e 5 2c 5 4a 5 5 5 4b 10 Total 80 Copyright c 2013 by P. Lam. Duplicate at will. 1 of 14
14
Embed
University of Waterloo Midterm Examination - Patrick Lam · ECE 155, Winter 2013 Midterm Exam Name: Question 2. Terminology [20 marks total] In this course, you have learned a number
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
University of WaterlooMidterm Examination
Term: Winter Year: 2013
Student Name
UW Student ID Number
Course Abbreviation and Number ECE 155
Course Title Engineering Design with Embed-ded Systems
Section(s) 001
Sections Combined Course(s)
Section Numbers of Combined Course(s)
Instructor(s) Patrick Lam
Date of Exam Friday, March 1, 2013
Time Period Start Time: 1:00 p.m.End Time: 2:20 p.m.
Duration of Exam 80 minutes
Number of Exam Pages 14(including this cover sheet)
Exam Type Closed Book
Additional Materials Allowed NO ADDITIONAL MATERIALSALLOWED
1. No aids permitted. No calculators of any type permitted.
2. Turn off all communication devices.
3. There are 5 questions and some of them have multiple parts.
4. The exam period lasts 80 minutes and there are 80 marks.
5. If you feel like you need to ask a question, know that the most likely answer is“Read the Question”. If you find that a question requires clarification, proceed byclearly stating any reasonable assumptions necessary to complete the question. Ifyour assumptions are reasonable, they will be taken into account during grading.
6. After reading and understanding the instructions, sign your name in the spaceprovided below for your signature.
(a) Convert a discrete-time digital signal into a continuous-time analog signal.
(b) Convert a continuous-time analog signal into a discrete-time digital signal.
(c) Convert a discrete-time digital signal into a regular signal.
(d) Convert a discrete-time digital signal into an analog-time analog signal.
ANSWER:
xiv. Which of the following is a typical combination of the key components found in anIDE?
(a) Compiler, Graphics Editor, Code Editor
(b) Android SDK, Emulators, Code Editor
(c) SVN, Compiler, Code Editor
(d) Compiler, Code Editor, Debugger
ANSWER:
xv. What will generally happen when a watchdog timer is fired?
(a) The timer resets its interval to 0.
(b) The program initiates a break point at the line of code where watchdog timerwas fired.
(c) The system asks the user if she or he wants to terminate the offending process.
(d) The program executes a watchdog handler, which usually terminates a long-running task.
ANSWER:
xvi. If an embedded system with large number of activities must respond rapidly to anexternal event E, which one of the following synchronization mechanisms should beused to notify the program of an occurrence of E?
In this course, you have learned a number of terms related to embedded systems, softwaresystems, and engineering design. Complete each row of Table 1 shown below by writingthe term that best corresponds with the definition provided.
Table 1: Terminology
Term Definition
A device that converts input from the externalenvironment into a form suitable for a computersystem.A mechanism by which a device informs a processorthat something has occurred.A low-level test which verifies the functionality of asingle class at a time.Gets notified of changes to the state of your system.An independent evaluation of a design alternative.A system in which the time to respond to an externalevent must be bounded by a known, finite amountof time.Successful solutions to a design problem should (butaren’t required to) satisfy these.
Removes high-frequency noise from its input (usedin your labs).First step in software bricolage (where you puttogether a system based on others’ work).A method executed in response to the generation ofan Android event.
Part A) Version Control [2 marks]
Alice and Bob both check out a working copy of file MainActivity.java from theirversion control repository. Alice commits a change to line 42 of the file. Bob also makesa change to the file at line 42. Now, what does Bob need to do before he can commit achange to MainActivity.java?
(1 point) List two reasons to use a simulation of a system instead of working on the realthing.
(2 points) Which would you expect to be more accurate near-term weather-forecastingsimulation: a stochastic simulation with 32 bits of accuracy, run 10000 times; or adeterministic simulation with 80 bits of accuracy, run once? Why?
Part C) Inheritance and Subclassing [5 marks]
Consider the following code:
class A {void foo() { Log.d(”W”, ”hi”); }}
class B extends A {void foo() { Log.d(”W”, ”iPhone”); }
void bar() { Log.d(”W”, ”Android”); }}
class Main {public static void main(String[] argv) {
A a = new A(); // (1)B b = new B(); // (2)A c = new B(); // (3)B d = new A(); // (4)
Question 3. Android Programming: Timers and XML[24 marks total]
Part A) Problems with Java Timers [5 marks]
This code implements a Timer that runs for 10 seconds. The payload is to set the textof an EditText to a certain value. However, the code will throw an exception when it isrun.
(4 points) Without using a Handler, fix the code so that it works properly. (If you can’tremember the syntax but can describe, in precise words, what you need to do, you mayget 1.5/4 for this part. If you provide code that uses the wrong names but is otherwisecorrect, you can get full marks, as long as I can tell what names you meant.)
You may assume that the EditText was previously defined in the layout.
(4 points) Now implement the above code using a Handler instead of a Java timer.
(1 point) Which of the two implementations would you expect to fire closer to exactly 10seconds after it was scheduled?
Part C) Event-Driven Programming [4 marks]
Recall this diagram from lecture.
Android
onCreate()
click listener
Write down (in text) the relevant actions that need to occur to handle a button click. I’mlooking for the actions that your program takes, along with what Android does at certaintimes. (Say who is doing what.)
Part E) Launching Activities and Getting Responses [5 marks]
(3 points) List (in text) the steps that you need to take to get Android to launch anotherActivity. How does Android know which activity to launch? (2 points) Describe how toget a response back from an Activity that you’ve launched, including anything specialthat you may have to do while launching the activity.
public class FSMTest {@Testpublic void reachesFinalState() {
FSM f = new FSM();f.transition(1);f.transition(3);f.transition(7);assertTrue(f.isAccepting());}
@Testpublic void initialIsNotFinal() {
FSM f = new FSM();assertFalse(f.isAccepting());}}
Test case reachesFinalState() currently fails. Assume that both test cases are sup-posed to pass. Show a set of changes to the FSM class which makes both cases pass.
(5 points) Write a new unit test method which verifies that the sequence of inputs“1 3 3 4” does not put the finite state machine into an accepting state.
(5 points) Write another new unit test method which verifies that the sequence of inputs“1 3 3 7” is accepted by the initial FSM class and that no prefix of “1 3 3 7” is acceptedby that class (e.g. “1”; “1 3”; “1 3 3”).
public class UsesInner {protected void onCreate(){// ... removed ...Timer t = new Timer();EditText textBox = (EditText)findViewById(R.id.textBox);
t.schedule(new TimerTask {public void run() {
textBox.setText(”This is a midterm question!”);}
}, 10000);}}
This code uses an inner class to define the TimerTask object. Rewrite it without usingan inner class; that is, create a class MyTimerTask and an instance of that class whichyou pass to t.schedule(). Your code should behave just like the original code.