High Altitude Recovery Payload

HARP: High Altitude Recovery Payload

Version 0.1: RC design

/media/uploads/tylerjw/_scaled_2012-07-23_mbed_xbee_breadboard.jpg

By connecting the second xbee to a computer using a terminal command and supplying the characters L, R, C, F the light patterns change on the mbed.

Committer:
tylerjw
Date:
Thu Jul 26 22:49:36 2012 +0000
Revision:
5:49ccc75efb93
Parent:
2:d1b64b3c9d26
Child:
6:2bd373ba18ae
put the right library, mbed-rtos vs  rtos

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tylerjw 1:21a6da67311c 1 /* Copyright (c) 2012 Tyler Weaver, MIT License
tylerjw 1:21a6da67311c 2 *
tylerjw 1:21a6da67311c 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
tylerjw 1:21a6da67311c 4 * and associated documentation files (the "Software"), to deal in the Software without restriction,
tylerjw 1:21a6da67311c 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
tylerjw 1:21a6da67311c 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
tylerjw 1:21a6da67311c 7 * furnished to do so, subject to the following conditions:
tylerjw 1:21a6da67311c 8 *
tylerjw 1:21a6da67311c 9 * The above copyright notice and this permission notice shall be included in all copies or
tylerjw 1:21a6da67311c 10 * substantial portions of the Software.
tylerjw 1:21a6da67311c 11 *
tylerjw 1:21a6da67311c 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
tylerjw 1:21a6da67311c 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
tylerjw 1:21a6da67311c 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
tylerjw 1:21a6da67311c 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
tylerjw 1:21a6da67311c 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
tylerjw 1:21a6da67311c 17 */
tylerjw 2:d1b64b3c9d26 18
tylerjw 2:d1b64b3c9d26 19
tylerjw 0:043ed5bb10f2 20 #include "mbed.h"
tylerjw 0:043ed5bb10f2 21 #include "rtos.h"
tylerjw 0:043ed5bb10f2 22 #include "watchdog.h"
tylerjw 0:043ed5bb10f2 23
tylerjw 0:043ed5bb10f2 24 // Setup the watchdog timer
tylerjw 0:043ed5bb10f2 25 Watchdog wdt;
tylerjw 0:043ed5bb10f2 26
tylerjw 0:043ed5bb10f2 27 // xbee serial connection
tylerjw 0:043ed5bb10f2 28 Serial xbee(p13,p14);
tylerjw 0:043ed5bb10f2 29
tylerjw 0:043ed5bb10f2 30 // status leds
tylerjw 0:043ed5bb10f2 31 BusOut status_led(LED4, LED3, LED2, LED1);
tylerjw 0:043ed5bb10f2 32
tylerjw 0:043ed5bb10f2 33 typedef struct {
tylerjw 0:043ed5bb10f2 34 char msg; // the direction to turn in
tylerjw 0:043ed5bb10f2 35 } message_p;
tylerjw 0:043ed5bb10f2 36
tylerjw 0:043ed5bb10f2 37 MemoryPool<message_p, 16> mpool_p;
tylerjw 0:043ed5bb10f2 38 Queue<message_p, 16> queue_p;
tylerjw 0:043ed5bb10f2 39
tylerjw 0:043ed5bb10f2 40 void xbee_thread(void const *argument) {
tylerjw 0:043ed5bb10f2 41 while (true) {
tylerjw 0:043ed5bb10f2 42 if (xbee.readable()) {
tylerjw 0:043ed5bb10f2 43 message_p *message = mpool_p.alloc();
tylerjw 0:043ed5bb10f2 44 message->msg = xbee.getc();
tylerjw 0:043ed5bb10f2 45
tylerjw 0:043ed5bb10f2 46 queue_p.put(message);
tylerjw 0:043ed5bb10f2 47 }
tylerjw 0:043ed5bb10f2 48 Thread::wait(100);
tylerjw 0:043ed5bb10f2 49 }
tylerjw 0:043ed5bb10f2 50 }
tylerjw 0:043ed5bb10f2 51
tylerjw 0:043ed5bb10f2 52 int main (void) {
tylerjw 0:043ed5bb10f2 53 status_led = 0x9;
tylerjw 0:043ed5bb10f2 54 // setup watchdog
tylerjw 0:043ed5bb10f2 55 wdt.kick(2.0); // 2 second watchdog
tylerjw 0:043ed5bb10f2 56 // setup xbee serial
tylerjw 0:043ed5bb10f2 57 xbee.baud(9600);
tylerjw 0:043ed5bb10f2 58
tylerjw 0:043ed5bb10f2 59 Thread thread1(xbee_thread);
tylerjw 0:043ed5bb10f2 60
tylerjw 0:043ed5bb10f2 61 while (true) {
tylerjw 0:043ed5bb10f2 62
tylerjw 0:043ed5bb10f2 63 osEvent evt_p = queue_p.get(1000); // wait for 1 second
tylerjw 0:043ed5bb10f2 64
tylerjw 0:043ed5bb10f2 65 if (evt_p.status == osEventMessage) {
tylerjw 0:043ed5bb10f2 66 message_p *message = (message_p*)evt_p.value.p;
tylerjw 0:043ed5bb10f2 67 printf("\nMessage from xbee: %c\n\r", message->msg);
tylerjw 0:043ed5bb10f2 68 switch (message->msg) {
tylerjw 0:043ed5bb10f2 69 case 'L': // turn left
tylerjw 0:043ed5bb10f2 70 status_led = 0x3;
tylerjw 0:043ed5bb10f2 71 break;
tylerjw 0:043ed5bb10f2 72 case 'C': // center
tylerjw 0:043ed5bb10f2 73 status_led = 0x6;
tylerjw 0:043ed5bb10f2 74 break;
tylerjw 0:043ed5bb10f2 75 case 'R': // turn right
tylerjw 0:043ed5bb10f2 76 status_led = 0xC;
tylerjw 0:043ed5bb10f2 77 break;
tylerjw 0:043ed5bb10f2 78 case 'F': // flare
tylerjw 0:043ed5bb10f2 79 status_led = 0xF;
tylerjw 0:043ed5bb10f2 80 break;
tylerjw 0:043ed5bb10f2 81 }
tylerjw 0:043ed5bb10f2 82
tylerjw 0:043ed5bb10f2 83 mpool_p.free(message);
tylerjw 0:043ed5bb10f2 84 }
tylerjw 0:043ed5bb10f2 85 wdt.kick();
tylerjw 0:043ed5bb10f2 86 }
tylerjw 0:043ed5bb10f2 87 }