+<!--
+
+1. Prepare a simple web page (I recommend using sites.google.com or just a plan
+ google doc and publishing it) with the following:
+
+ a. Text that briefly describes your software organization for mbed and the
+ host (e.g. event handlers, threads etc. and what they do in plain text),
+ and the precise protocol and format for data that is exchanged between
+ the host and the mbed.
+
+ b. URLS for: (i) Code for PC as a .zip file (you could put the .zip file on
+ Dropbox or on Github), (ii) Code for mbed on mbed.org (you can publish it
+ there), and (iii) The video.
+
+2. When you have everything ready, fill the form at
+ https://docs.google.com/forms/d/1AaTB7dhT99_khnrwIP3ZzDkjRRhPj7Ql9nE3RqRPwQw/viewform
+
+-->
+
+<h2>Brief Description</h2>
+
+<p>The objective of this homework is to explore organizing embedded software
+ using mbed as the platform in context of a simple system. Sensor data flows
+ in the direction of: mbed → PC → Xively.</p>
+
+<h2>Embedded Target Design</h2>
+
+<p>The mbed code is organized in a single main.cpp file which invokes libraries
+ to read the sensor data. The Accelerometer, Magnetometer, and Touch Sensor
+ libraries were acquired through the mbed website and the Analog Input and
+ Output libraries were included in the mbed SDK.</p>
+
+<p>The software consists of preemptable sensor loop running at a fixed rate, a
+ serial data receive interrupt handler, and a direct-memory access serial
+ transmitter. On each iteration of the sensor loop a time counter is checked
+ to determine which sensor are due for reading. Each sensor function polls
+ data from the sensor, packs the data into an output frame, and then write
+ the frame to the output queue.</p>
+
+<p><i>Note: the sensor reading was originally performed in a timer interrupt
+ routine, however, it moved to a background task to minimize interference
+ with the reception of serial commands.</i></p>
+
+<h2>Data Logger Design</h2>
+
+The data logger is implemented as a Graphical User Interface using Python and
+the GTK+ Toolkit. The source code is organized around the following classes:
+
+<ul>
+ <li>A Main class which performs basic initialization</li>
+ <li>A Config class for storing user preferences</li>
+ <li>A Device class to interfaces with the mbed using PySerial</li>
+ <li>A Logger class to transmit the recorded data to Xively</li>
+ <li>A Visual class to display the user interface</li>
+</ul>
+
+<h2>Data Collection</h2>
+
+<p>The mbed FRDM-KL46Z is responsible for data collection and sending it to the
+ host via Serial-over-USB. Sensors data is collected at a periodic rate and
+ is transmitted to the PC using the DATA_FRAME format shown below. The Serial
+ data transmit is handled by the KL46Z Direct-Memory Access (DMA) controller
+ so that data transmission does not block the CPU. When sensor data is ready,
+ it is packed and appended to a transmit buffer. At the end of the periodic
+ loop the DMA controller is enabled and data transmission begins</p>
+
+<p>Commands are sent to the mbed using the COMMAND_FRAME format and are
+ processed using a serial interrupt handler. The handler parses the incoming
+ messages and performs command processing when a valid COMMAND_FRAME is
+ received.</p>
+
+<h2>Serial Message Formats</h2>
+
+<p>As is mentioned above, the mbed and communicate via UART, thus working based
+ on serial protocol. Since the mbed can be perceived as a slave to the PC, we
+ let the mbed collect and send DATA_FRAME, while PC is responsible for
+ generating COMMAND_FRAME. The frame structure is as follows:</p>
+
+<h3>Data Frame</h3>
+<table cellspacing="0" cellpadding="2" border="1">
+<tr><td>1 Byte</td><td>4 bits </td><td>4 bits </td><td>1 Byte </td><td>(Varied Size)</td><td>1 Byte</td></tr>
+<tr><td>HEADER</td><td>dataType</td><td>snsType</td><td>dataNum</td><td>data </td><td>TAIL </td></tr>
+</table>
+
+<h4>Field Descriptions</h4>
+<table cellspacing="0" cellpadding="2" border="1">
+ <tr><t4>HEADER: </td><td>0x02, constant, indicating the start of a frame</td></tr>
+ <tr><td>dataType:</td><td>Data Type:<table>
+ <tr><td style="padding-left:3em">0- int8</td><td style="padding-left:1em">1 - int16</td><td style="padding-left:1em">2 - int32</td></tr>
+ <tr><td style="padding-left:3em">3- uint8</td><td style="padding-left:1em">4 - uint16</td><td style="padding-left:1em">5 - uint32</td></tr>
+ <tr><td style="padding-left:3em">6- float</td><td style="padding-left:1em">7 - double</td><td style="padding-left:1em"> </td></tr>
+ </table></td></tr>
+ <tr><td>snsType: </td><td>Sensor Type:<ul style="list-style-type: none;">
+ <li>0 - LIGHT_SENSOR</li>
+ <li>1 - ACC_SENSOR</li>
+ <li>2 - MAG_SENSOR</li>
+ <li>3 - TOUCH_SENSOR</li>
+ <li>4 - ADC_SENSOR</li>
+ </ul></td></tr>
+ <tr><td>dataNum: </td><td>Data number. Number of data pack in the frame</td></tr>
+ <tr><td>data: </td><td>Sensor data. How it is packed is based on dataType and dataNum</td></tr>
+ <tr><td>TAIL: </td><td>0x0A, constant, indicating the end of a frame</td></tr>
+</table>
+
+<h3>Command Frame</h3>
+<table cellspacing="0" cellpadding="2" border="1">
+<tr><td>1 Byte</td><td>4 bits </td><td>4 bits </td><td>4 Byte </td><td>1 Byte</td></tr>
+<tr><td>HEADER</td><td>cmdType</td><td>snsType</td><td>Interval</td><td>TAIL </td></tr>
+</table>
+
+<h4>Field Descriptions</h4>
+<table cellspacing="0" cellpadding="2" border="1">
+ <tr><td>HEADER: </td><td>0x02, constant, indicating the start of a frame</td></tr>
+ <tr><td>cmdType: </td><td>Command Type:<ul style="list-style-type: none;">
+ <li>0 - START</li>
+ <li>1 - STOP</li>
+ <li>2 - SET_INT</li>
+ </td></tr>
+ <tr><td>Interval:</td><td>sampling rate. Representing a float of 4 Bytes.</td></tr>
+ <tr><td>TAIL: </td><td>0x0A, constant, indicating the end of a frame</td></tr>
+</table>
+
+<!--
+ a. Text that briefly describes your software organization for mbed and the
+ host (e.g. event handlers, threads etc. and what they do in plain text),
+ and the precise protocol and format for data that is exchanged between
+ the host and the mbed.
+-->
+
+<h2>Sampling Rate</h2>
+
+<p>The following sampling rates were obtained for each sensor, and a combined
+ sampling rate when all sensors are sampling simultaneously. Data collection
+ was performed using a 230400 serial baud rate.</p>
+
+<table>
+ <tr><th>Sensor </th><th style="padding-left: 1em;">Sampling Rate</th></tr>
+ <tr><td>Accelerometer </td><td style="padding-left: 1em;"> 560 Hz </td></tr>
+ <tr><td>Magnetometer </td><td style="padding-left: 1em;"> 530 Hz </td></tr>
+ <tr><td>Touch Sensor </td><td style="padding-left: 1em;">1930 Hz </td></tr>
+ <tr><td>Light Sensor </td><td style="padding-left: 1em;">2414 Hz </td></tr>
+ <tr><td>Analog to Digital</td><td style="padding-left: 1em;"> 820 Hz </td></tr>
+ <tr><td>All Combined </td><td style="padding-left: 1em;"> 150 Hz </td></tr>
+</table>
+
+<h2>Online Submission</h2>
+
+<dl>
+ <dt>Code for mbed</dt>
+ <dd><a href="http://mbed.org/users/andy753421/code/Sensors/">http://mbed.org/users/andy753421/code/Sensors/</a></dd>
+
+ <dt>Code for PC</dt>
+ <dd><a href="https://sites.google.com/a/g.ucla.edu/ibeaconnav/homework1/python.zip">https://sites.google.com/a/g.ucla.edu/ibeaconnav/homework1/python.zip</a></dd>
+
+
+ <dt>Video Link</dt>
+ <dd>(we will do a demo during office hours)</dd>
+</dl>