Los Putacos / Mbed OS WearableDevice_Nucleo_New

Dependencies:   MPU9250_SPI

Fork of WearableDevice_Nucleo by Los Putacos

Committer:
Muglug
Date:
Wed Oct 25 13:24:05 2017 +0000
Revision:
23:aad5fd1b3ef9
Parent:
20:197c69b38adf
Child:
24:eed68c95160c
SD Card Working.;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gusteibolt 1:a6dc717fb060 1 /*
gusteibolt 1:a6dc717fb060 2 * Los Putacos
gusteibolt 1:a6dc717fb060 3 * Copyright (C) 2017, All rights reserved.
Muglug 18:7f9c2b8541e1 4 * ________________________________________
gusteibolt 1:a6dc717fb060 5 *
gusteibolt 1:a6dc717fb060 6 * Created by: Gustavo Campana, Michael Schmidt, Miguel Lopez
gusteibolt 1:a6dc717fb060 7 * Date: 11-Oct-2017
gusteibolt 1:a6dc717fb060 8 * Version: V0.1
gusteibolt 1:a6dc717fb060 9 */
Muglug 23:aad5fd1b3ef9 10 //-----------------------------------------------------------------
gusteibolt 1:a6dc717fb060 11
gusteibolt 1:a6dc717fb060 12 //-----------------------------------------------------------------
gusteibolt 1:a6dc717fb060 13 // Board: NUCLEO - F401RE
gusteibolt 1:a6dc717fb060 14 // Version: MR1136 rev C
gusteibolt 1:a6dc717fb060 15 //-----------------------------------------------------------------
gusteibolt 1:a6dc717fb060 16
gusteibolt 1:a6dc717fb060 17 //-----------------------------------------------------------------
gusteibolt 1:a6dc717fb060 18 // Includes
gusteibolt 0:73cd0cb02330 19 #include "mbed.h"
Muglug 23:aad5fd1b3ef9 20 #include "configuration.h"
Muglug 23:aad5fd1b3ef9 21 #include "pin.h"
gusteibolt 3:26aeff25f610 22
Muglug 23:aad5fd1b3ef9 23 // #include "rtos.h"
gusteibolt 10:577e1fc4453e 24 #include "event.h"
Muglug 23:aad5fd1b3ef9 25 // #include "mbed_events.h"
Muglug 17:f98597cd2efc 26
Muglug 17:f98597cd2efc 27 #include "XBeeLib.h"
Muglug 19:0a3ae902722e 28 #include "SDFileSystem.h"
gusteibolt 1:a6dc717fb060 29 //-----------------------------------------------------------------
gusteibolt 0:73cd0cb02330 30
gusteibolt 1:a6dc717fb060 31 //-----------------------------------------------------------------
gusteibolt 1:a6dc717fb060 32 // Declarations
Muglug 23:aad5fd1b3ef9 33 // Timer time_stamp; //Timer µS time-stamp
Muglug 18:7f9c2b8541e1 34 EventQueue queue(32 * EVENTS_EVENT_SIZE); //Event
Muglug 23:aad5fd1b3ef9 35 const char DeviceNr[6] = "DEV01";
Muglug 23:aad5fd1b3ef9 36 char Data_Buffer[] = "";
gusteibolt 3:26aeff25f610 37
Muglug 23:aad5fd1b3ef9 38 // PC Serial (Debug)
Muglug 23:aad5fd1b3ef9 39 Serial PC(USBTX, USBRX);
Muglug 23:aad5fd1b3ef9 40 XBeeLib::XBeeZB XBee = XBeeLib::XBeeZB(RADIO_TX, RADIO_RX, RADIO_RESET, NC, NC, 115200);
Muglug 23:aad5fd1b3ef9 41 int task1_id = queue.call_every(200, CheckInputBuffer);
gusteibolt 3:26aeff25f610 42
Muglug 23:aad5fd1b3ef9 43 // Create an SDFileSystem object
Muglug 23:aad5fd1b3ef9 44 SDFileSystem sd(PC_12, PC_11, PC_10, PD_2, "sd");
Muglug 23:aad5fd1b3ef9 45
gusteibolt 1:a6dc717fb060 46 //-----------------------------------------------------------------
gusteibolt 1:a6dc717fb060 47
gusteibolt 1:a6dc717fb060 48 //-----------------------------------------------------------------
Muglug 23:aad5fd1b3ef9 49 /* Callback function, invoked at packet reception */
Muglug 23:aad5fd1b3ef9 50 static void receive_cb(const XBeeLib::RemoteXBeeZB& remote, bool broadcast, const uint8_t *const data, uint16_t len)
Muglug 23:aad5fd1b3ef9 51 {
Muglug 23:aad5fd1b3ef9 52 PC.printf("Package Length: %i \r\n", len);
Muglug 23:aad5fd1b3ef9 53 for (int i = 0; i < len; i++) {
Muglug 23:aad5fd1b3ef9 54 Data_Buffer[i] = char(data[i]);
Muglug 23:aad5fd1b3ef9 55 PC.printf("%c", Data_Buffer[i]);
Muglug 23:aad5fd1b3ef9 56 }
Muglug 23:aad5fd1b3ef9 57
Muglug 23:aad5fd1b3ef9 58 if (len == 9)
Muglug 23:aad5fd1b3ef9 59 {
Muglug 23:aad5fd1b3ef9 60 if ((char(Data_Buffer[0]) == '#') && (char(Data_Buffer[6]) == ','))
Muglug 23:aad5fd1b3ef9 61 {
Muglug 23:aad5fd1b3ef9 62 PC.printf(" - Command Detected!\r\n");
Muglug 23:aad5fd1b3ef9 63
Muglug 23:aad5fd1b3ef9 64 if (strstr(Data_Buffer, DeviceNr) != NULL)
Muglug 23:aad5fd1b3ef9 65 PC.printf("Correct Package ID!\r\n");
Muglug 23:aad5fd1b3ef9 66 else
Muglug 23:aad5fd1b3ef9 67 PC.printf("Wrong Package ID!\r\n");
Muglug 23:aad5fd1b3ef9 68 }
Muglug 23:aad5fd1b3ef9 69 else
Muglug 23:aad5fd1b3ef9 70 PC.printf(" - Non-valid Command Delimiter!\r\n");
Muglug 23:aad5fd1b3ef9 71 }
Muglug 23:aad5fd1b3ef9 72 else
Muglug 23:aad5fd1b3ef9 73 PC.printf(" - Non-valid Package Length!\r\n");
Muglug 23:aad5fd1b3ef9 74
Muglug 23:aad5fd1b3ef9 75 extern int task1_id;
Muglug 23:aad5fd1b3ef9 76 queue.cancel(task1_id);
gusteibolt 8:ba93a973f967 77 }
gusteibolt 8:ba93a973f967 78 //-----------------------------------------------------------------
gusteibolt 8:ba93a973f967 79
gusteibolt 8:ba93a973f967 80 //-----------------------------------------------------------------
Muglug 18:7f9c2b8541e1 81 void Setup()
Muglug 18:7f9c2b8541e1 82 {
Muglug 18:7f9c2b8541e1 83 PC.baud(9600);
Muglug 23:aad5fd1b3ef9 84 PC.printf("\r\n-------------------------------------\r\n");
Muglug 23:aad5fd1b3ef9 85 PC.printf("CPU SystemCoreClock is %d Hz", SystemCoreClock);
Muglug 18:7f9c2b8541e1 86
Muglug 23:aad5fd1b3ef9 87 XBee.init();
Muglug 23:aad5fd1b3ef9 88 XBee.register_receive_cb(&receive_cb); // Register Callbacks
Muglug 23:aad5fd1b3ef9 89 // time_stamp.start(); // Start Timer
Muglug 18:7f9c2b8541e1 90
gusteibolt 3:26aeff25f610 91 // Task queue
Muglug 23:aad5fd1b3ef9 92 // int task1_id = queue.call_every(200, CheckInputBuffer);
Muglug 23:aad5fd1b3ef9 93 // int task2_id = queue.call_every(50, ReadIMUData);
Muglug 18:7f9c2b8541e1 94 // int task3_id = queue.call_every(3000, &print_event, (void *)"called every 3 seconds\n", (int) time_stamp.read());
Muglug 18:7f9c2b8541e1 95 // int task4_id = queue.call_every(50, blink_event, led1);
Muglug 18:7f9c2b8541e1 96 // int task5_id = queue.call_every(500, println_event);
Muglug 18:7f9c2b8541e1 97 // int task6_id = queue.call_every(500, readIMU);
Muglug 18:7f9c2b8541e1 98 // int task7_id = queue.call_every(500, gayEvent);
gusteibolt 0:73cd0cb02330 99 }
Mister_Lopez 4:56e903769e94 100
Muglug 23:aad5fd1b3ef9 101 void SDTest()
Muglug 19:0a3ae902722e 102 {
Muglug 23:aad5fd1b3ef9 103 mkdir("/sd/Log", 0777);
Muglug 23:aad5fd1b3ef9 104
Muglug 23:aad5fd1b3ef9 105 FILE *fp = fopen("/sd/Log/Data_Log.txt", "w");
Muglug 23:aad5fd1b3ef9 106 if(fp == NULL) {
Muglug 23:aad5fd1b3ef9 107 error("File Writing Failed!\n");
Muglug 23:aad5fd1b3ef9 108 }
Muglug 23:aad5fd1b3ef9 109 fprintf(fp, "Data Dummy...");
Muglug 23:aad5fd1b3ef9 110 fclose(fp);
Muglug 23:aad5fd1b3ef9 111
Muglug 23:aad5fd1b3ef9 112 printf("SD Test Successful!\n");
Muglug 23:aad5fd1b3ef9 113 }
Muglug 19:0a3ae902722e 114
Muglug 23:aad5fd1b3ef9 115 const uint8_t data[] = "Hello Master!";
Muglug 23:aad5fd1b3ef9 116 const uint16_t data_len = sizeof data / sizeof data[0] - 1;
Muglug 23:aad5fd1b3ef9 117
Muglug 23:aad5fd1b3ef9 118 void Test()
Muglug 23:aad5fd1b3ef9 119 {
Muglug 23:aad5fd1b3ef9 120 XBeeLib::TxStatus txStatus = XBee.send_data_to_coordinator(data, data_len);
Muglug 23:aad5fd1b3ef9 121 if (txStatus != XBeeLib::TxStatusSuccess)
Muglug 23:aad5fd1b3ef9 122 PC.printf("send_data_broadcast() failed with error %d\n", (int)txStatus);
Muglug 23:aad5fd1b3ef9 123 }
Muglug 23:aad5fd1b3ef9 124 //-----------------------------------------------------------------
Muglug 18:7f9c2b8541e1 125
Mister_Lopez 4:56e903769e94 126 //-----------------------------------------------------------------
gusteibolt 0:73cd0cb02330 127 int main()
gusteibolt 0:73cd0cb02330 128 {
Muglug 18:7f9c2b8541e1 129 Setup(); // Initial Setups
Muglug 18:7f9c2b8541e1 130
Muglug 18:7f9c2b8541e1 131 // Reading the analog input (Microphone)
Muglug 18:7f9c2b8541e1 132 // array = micro.read_u16();
Muglug 18:7f9c2b8541e1 133
Muglug 23:aad5fd1b3ef9 134 led1 = 1;
Muglug 23:aad5fd1b3ef9 135 PC.printf(" - Ready!\r\n\r\n");
Muglug 23:aad5fd1b3ef9 136
Muglug 23:aad5fd1b3ef9 137 SDTest();
Muglug 23:aad5fd1b3ef9 138 // queue.dispatch();
Muglug 23:aad5fd1b3ef9 139 while (true) {
Muglug 23:aad5fd1b3ef9 140 // PC.printf("In the while");
Muglug 19:0a3ae902722e 141 }
gusteibolt 0:73cd0cb02330 142 }
Muglug 18:7f9c2b8541e1 143 //-----------------------------------------------------------------