simple data logger

Dependencies:   Buffer MMA8451Q mbed-rtos mbed

Files at this revision

API Documentation at this revision

Comitter:
jhestolano
Date:
Tue Jun 04 01:42:20 2013 +0000
Commit message:
Simple data logger.

Changed in this revision

Buffer.lib Show annotated file Show diff for this revision Revisions of this file
MMA8451Q.lib Show annotated file Show diff for this revision Revisions of this file
logger.cpp Show annotated file Show diff for this revision Revisions of this file
logger.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Buffer.lib	Tue Jun 04 01:42:20 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/jhestolano/code/Buffer/#f45f33d1febb
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MMA8451Q.lib	Tue Jun 04 01:42:20 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/JoKer/code/MMA8451Q/#2d14600116fc
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/logger.cpp	Tue Jun 04 01:42:20 2013 +0000
@@ -0,0 +1,71 @@
+#include "logger.h"
+
+Logger::Logger(PinName tx, PinName rx) :
+    port(tx, rx),
+    redLed(LED_RED),
+    blueLed(LED_BLUE),
+    greenLed(LED_GREEN),
+    acc(PTE25, PTE24, MMA8451Q_I2C_ADDRESS),
+//tx_th(tx_thread, (void*)this),
+    data_th(this->data_thread, (void*)this),
+    led_th(this->led_thread, (void*)&blueLed),
+    acc_x(BUF_SIZE)  
+      
+{
+    redLed = 1; blueLed = 1; greenLed = 1;
+    msg = 0;
+    newMsg = false;
+    port.baud(BAUD_115200);
+    port.attach(this, &Logger::rcv_isr, Serial::RxIrq);
+}
+
+/* Rutina de interrupción para recibir datos del servidor */
+/* Funciona! */
+void Logger::rcv_isr()
+{
+    msg = UART0->D; // Leer UART0 para desactivar bandera de interrupción.
+    while(UART0->S1 & UART_S1_RDRF_MASK); // Esperar a UART0 listo.
+    newMsg = true;
+    //redLed = !redLed;
+}
+
+/* Thread para adquisicion de datos de los sensores */
+/* Funciona */
+void Logger::data_thread(const void* args)
+{
+    Logger* log = (Logger*)args;
+    float temp[3];
+    //Buffer<float> buf_x(BUF_SIZE); Buffer<float> buf_y(BUF_SIZE); Buffer<float> buf_z(BUF_SIZE);
+    while(true)
+    {
+        log->led_th.signal_set(LED_SIGNAL);
+        log->acc.getAccAllAxis(temp);
+        log->acc_x.put(temp[0]);
+        //buf_x.put(temp[0]); buf_y.put(temp[1]); buf_z.put(temp[2]);
+        //log->port.printf("a[x]: %f, a[y]: %f, a[z]: %f\n\r", temp[0], temp[1], temp[2]);
+        log->port.printf("a[x}: %f\n\r", log->acc_x.get());
+        Thread::wait(SAMPLE_RATE);
+    }
+    
+}
+
+void Logger::led_thread(const void* args) 
+{
+    DigitalOut* led = (DigitalOut*)args;
+    while(true)
+    {
+        Thread::signal_wait(LED_SIGNAL);
+        *led = !(*led);
+    }
+}
+
+/* Thread para el envio de datos al servidor */
+//void Logger::tx_thread(const void* args) {}
+
+
+
+/* Destructor */
+Logger::~Logger() 
+{
+
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/logger.h	Tue Jun 04 01:42:20 2013 +0000
@@ -0,0 +1,51 @@
+#ifndef LOGGER_H
+#define LOGGER_H
+
+#include "mbed.h"
+#include "rtos.h"
+#include "MMA8451Q.h"
+#include "buffer.h"
+
+const int BAUD_115200           = 115200;
+const int BUF_SIZE              = 128;
+const int MMA8451Q_I2C_ADDRESS  = (0x1D << 1);
+
+const int SEND_DATA_SIGNAL      = 0x01;
+const int GET_DATA_SIGNAL       = 0x02;
+const int LED_SIGNAL            = 0x03;
+
+const int SAMPLE_RATE           = 1000; //Milisegundos.
+const int TRANSMIT_RATE         = 60000; //Milisegundos.
+
+class Logger
+{
+private:
+    Serial port;    
+    DigitalOut redLed;
+    DigitalOut blueLed;
+    DigitalOut greenLed;
+    MMA8451Q acc;
+    //Thread tx_th;
+    Thread data_th;
+    Thread led_th;
+    int msg;
+    bool newMsg;
+    Buffer<float> acc_x;
+    
+    static void led_thread(void const* args);
+    static void data_thread(void const* args);
+    void rcv_isr();
+    
+
+public:
+    Logger(PinName tx, PinName rx);
+    float* getData();
+    //static void tx_thread(void const* args);
+    
+    
+    ~Logger();
+};
+
+
+
+#endif //LOGGER_H
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Jun 04 01:42:20 2013 +0000
@@ -0,0 +1,7 @@
+#include "logger.h"
+
+int main()
+{
+    Logger myLog(USBTX, USBRX);
+    while(true);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Tue Jun 04 01:42:20 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed-rtos/#58b30ac3f00e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Jun 04 01:42:20 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/b3110cd2dd17
\ No newline at end of file