Saver nodo

Dependencies:   ds3231 sd-driver-master

Files at this revision

API Documentation at this revision

Comitter:
SolManB
Date:
Fri Jun 15 03:58:21 2018 +0000
Child:
1:dea5f9c332ba
Commit message:
Saver node

Changed in this revision

.gitignore Show annotated file Show diff for this revision Revisions of this file
README.md Show annotated file Show diff for this revision Revisions of this file
ds3231.lib 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-os.lib Show annotated file Show diff for this revision Revisions of this file
sd-driver-master.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.gitignore	Fri Jun 15 03:58:21 2018 +0000
@@ -0,0 +1,4 @@
+.build
+.mbed
+projectfiles
+*.py*
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/README.md	Fri Jun 15 03:58:21 2018 +0000
@@ -0,0 +1,57 @@
+# Getting started with Blinky on mbed OS
+
+This guide reviews the steps required to get Blinky working on an mbed OS platform.
+
+Please install [mbed CLI](https://github.com/ARMmbed/mbed-cli#installing-mbed-cli).
+
+## Import the example application
+
+From the command-line, import the example:
+
+```
+mbed import mbed-os-example-blinky
+cd mbed-os-example-blinky
+```
+
+### Now compile
+
+Invoke `mbed compile`, and specify the name of your platform and your favorite toolchain (`GCC_ARM`, `ARM`, `IAR`). For example, for the ARM Compiler 5:
+
+```
+mbed compile -m K64F -t ARM
+```
+
+Your PC may take a few minutes to compile your code. At the end, you see the following result:
+
+```
+[snip]
++----------------------------+-------+-------+------+
+| Module                     | .text | .data | .bss |
++----------------------------+-------+-------+------+
+| Misc                       | 13939 |    24 | 1372 |
+| core/hal                   | 16993 |    96 |  296 |
+| core/rtos                  |  7384 |    92 | 4204 |
+| features/FEATURE_IPV4      |    80 |     0 |  176 |
+| frameworks/greentea-client |  1830 |    60 |   44 |
+| frameworks/utest           |  2392 |   512 |  292 |
+| Subtotals                  | 42618 |   784 | 6384 |
++----------------------------+-------+-------+------+
+Allocated Heap: unknown
+Allocated Stack: unknown
+Total Static RAM memory (data + bss): 7168 bytes
+Total RAM memory (data + bss + heap + stack): 7168 bytes
+Total Flash memory (text + data + misc): 43402 bytes
+Image: .\.build\K64F\ARM\mbed-os-example-blinky.bin
+```
+
+### Program your board
+
+1. Connect your mbed device to the computer over USB.
+1. Copy the binary file to the mbed device.
+1. Press the reset button to start the program.
+
+The LED on your platform turns on and off.
+
+## Troubleshooting
+
+If you have problems, you can review the [documentation](https://os.mbed.com/docs/latest/tutorials/debugging.html) for suggestions on what could be wrong and how to fix it.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ds3231.lib	Fri Jun 15 03:58:21 2018 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/teams/Maxim-Integrated/code/ds3231/#11630748e2f2
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Jun 15 03:58:21 2018 +0000
@@ -0,0 +1,139 @@
+#include "mbed.h"
+#include "ds3231.h"
+#include "SDBlockDevice.h"
+#include "FATFileSystem.h"
+
+
+AnalogIn x(p20);
+AnalogIn y(p19);
+AnalogIn z(p18);
+AnalogIn bat1(p17);
+AnalogIn bat2(p16);
+Ds3231 rtc(p28,p27);
+Serial pc(USBTX,USBRX);
+DigitalOut led2(LED2);
+SDBlockDevice sd(p5, p6, p7, p8); 
+FATFileSystem fs("fs");
+Serial xbee(p13,p14);
+
+Thread Lectura;
+
+Timer t;
+time_t epoch_time;
+char time1[3],fecha[18],nombre[30],dato1[100],dato[13];
+int seg1, seg2=-1, milis,cel=25, en=0;
+unsigned short ax,ay,az;
+int b1, b2;
+
+
+float temp;
+FILE *fp;
+int i=0;
+
+
+void envio()
+{
+    int r=0;//para el checsum
+    for(int j=0;j<strlen(dato);j++)
+    {
+        r=r+int(dato[j]);
+        
+    }
+    r=r+927;//esto se modifica segun los valores del coordinador
+    if(r>4095) r=r%4096;
+    if(r>255)  r=r%256;
+    int t=255-r;
+    
+    //para el tamano
+    int q=14+strlen(dato);
+    int z=int(q/256);
+    int x=int(q%256);
+
+    xbee.putc(0x7E);
+    xbee.putc(char(z));
+    xbee.putc(char(x));
+    xbee.putc(0x10);
+    xbee.putc(0x00);
+    xbee.putc(0x00);
+    xbee.putc(0x13);
+    xbee.putc(0xA2);
+    xbee.putc(0x00);
+    xbee.putc(0x41);
+    xbee.putc(0x02);
+    xbee.putc(0x01);
+    xbee.putc(0x99);
+    xbee.putc(0xFF);
+    xbee.putc(0xFE);
+    xbee.putc(0x00);
+    xbee.putc(0x00);
+    xbee.putc(dato[0]);
+    xbee.putc(dato[1]);
+    xbee.putc(dato[2]);
+    xbee.putc(dato[3]);
+    xbee.putc(dato[4]);
+    xbee.putc(dato[5]);
+    xbee.putc(dato[6]);
+    xbee.putc(dato[7]);
+    xbee.putc(char(t));
+    
+}
+
+void Lect()
+{
+    while(1)
+    {
+        ax=x.read_u16();
+        ay=y.read_u16();
+        az=z.read_u16();
+        b1 = (int)(bat1.read()*100.0f);
+        b2 = (int)(bat2.read()*100.0f);
+        
+        epoch_time = rtc.get_epoch();
+        strftime(fecha, 19, "%d/%m/%y\t%H:%M:%S", localtime(&epoch_time));
+        strftime(time1,3,"%S", localtime(&epoch_time));
+    
+        seg1=atoi(time1);
+        if(seg1 !=  seg2){seg2=seg1;t.stop(); t.reset();t.start();}
+        milis=t.read_ms();
+
+        //Sensor de temperatura
+        int b=0;
+        if(b1<b2)
+            b=b1/10;
+        else
+            b=b2/10;
+        sprintf(dato1,"%d\t%d\t%d\t%s\t%d\n",ax,ay,az,fecha,milis);   
+        //sprintf(dato,"%c%c%c%c%c%c%c%c",(int)(ax/256),(int)(ax%256),(int)(ay/256),(int)(ay%256),(int)(az/256),(int)(az%256),(b),(char)((int)(milis/10)));
+        //envio();
+        if(i==0)//Archivo de crear la rutina
+    {   
+        strftime(nombre,30,"/fs/%y%m%d_%H%M%S.txt", localtime(&epoch_time));
+        fp= fopen(nombre, "a+");
+        if(fp == NULL) error("Could not open file for write\n");
+    }
+    
+    fprintf(fp,dato1);
+
+    i++;
+    if(i==6000)//Para cerrar el archivo
+    {
+        fclose(fp);
+        i=0;
+        led2=!led2;
+    }
+        Thread::wait(9);
+    }
+}
+
+int main()
+{
+    sd.init();
+    fs.mount(&sd);
+    xbee.baud(115200);
+    pc.baud(921600);
+    Lectura.start(callback(Lect));
+    while(1)
+    {}
+    sd.deinit();
+    fs.unmount();
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Fri Jun 15 03:58:21 2018 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#367dbdf5145f4d6aa3e483c147fe7bda1ce23a36
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sd-driver-master.lib	Fri Jun 15 03:58:21 2018 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/SDesign2018/code/sd-driver-master/#f72b3e7f1ec8