JPEG compressor

Dependencies:   SDL_lib SX1276Lib mbed

Files at this revision

API Documentation at this revision

Comitter:
miruga27
Date:
Wed Sep 07 18:47:02 2016 +0000
Child:
1:f0c646dfe574
Commit message:
f

Changed in this revision

SDL_lib.lib Show annotated file Show diff for this revision Revisions of this file
SX1276Lib.lib Show annotated file Show diff for this revision Revisions of this file
encoder.cpp Show annotated file Show diff for this revision Revisions of this file
functions.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
main.h 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/SDL_lib.lib	Wed Sep 07 18:47:02 2016 +0000
@@ -0,0 +1,1 @@
+SDL_lib#dda4f4550403
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SX1276Lib.lib	Wed Sep 07 18:47:02 2016 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/teams/Semtech/code/SX1276Lib/#7f3aab69cca9
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/encoder.cpp	Wed Sep 07 18:47:02 2016 +0000
@@ -0,0 +1,169 @@
+//Author: Miguel Ruiz García
+//Company: University of Cantabria. 2016
+//mail: mrg47@alumnos.unican.es
+
+#include "mbed.h"
+#include "stdio.h"
+#include <math.h>
+#include "SDL_lib/SDL.h"
+#include "functions.h"
+
+//#include "MODSERIAL.h"
+//DigitalOut myled(LED1);
+DigitalIn button(PC_13);
+Serial pc(USBTX, USBRX);
+Serial uart(PA_2, PA_3);
+#define BPS 128000
+#define BITS 8
+#define STOP_BITS 1
+ 
+
+
+
+int main2(int argc, char *argv[]) {
+    
+    pc.baud(BPS);
+    pc.format (BITS,SerialBase::None, STOP_BITS) ;
+    
+    myled=1;
+    wait (5);
+    myled=0;
+  //  short int m[8][320][3];
+    int i,j,veces=0;
+    int ci,cj;
+/*for(veces=0;veces<120;veces++){
+    //char *m=(char *)malloc(sizeof(char)*HEIGHT*WIDTH*3);
+    for(ci=0;ci<8;ci++){
+       for(cj=0;cj<320;cj++){
+                
+                while(!pc.readable());
+                //*(m+i*WIDTH+j*3+0)=pc.getc();
+                    m[ci][cj][0]=(unsigned char)pc.getc();
+                    
+                    
+                    myled=0;
+                    
+                
+                while(!pc.readable());   
+                    //*(m+i*WIDTH+j*3+1)=pc.getc();
+                    m[ci][cj][1]=(unsigned char)pc.getc();
+                while(!pc.readable());
+                    //*(m+i*WIDTH+j*3+2)=pc.getc();
+                    m[ci][cj][2]=(unsigned char)pc.getc();
+        
+        }
+    }
+        
+        
+        myled=1;
+
+      //free(m);
+        
+
+    
+  
+    rgb_to_yuv(m);
+    
+    //pc.printf("Imagen trasladada a yuv \n");
+
+    int cont=1;
+    int matrix[8][8][3];
+    for(i=0;i<8;i+=8){
+        for(j=0;j<320;j+=8){
+
+            int k=0,l=0;
+
+            for(k=i;k<i+8;k++){
+                
+                for(l=j;l<j+8;l++){
+                    
+
+                    matrix[k-i][l-j][0]=m[k][l][0];
+                    matrix[k-i][l-j][1]=m[k][l][1];
+                    matrix[k-i][l-j][2]=m[k][l][2];
+                   
+                }
+               
+
+            }
+            //pc.printf("llamo a DCT %d \n",cont);
+            DCT(matrix,m,i,j);// i j índices de los pixeles en x e y del macrobloque
+            cont++;
+
+
+
+        }
+    
+    }
+    //pc.printf("DCT \n");
+
+    
+    cuantizador(m);
+
+    //pc.printf("Cuantizada \n");
+    
+    short int *matriz =(short int *) malloc(sizeof(short int)*HEIGHT*WIDTH*3);
+
+    
+    zig_zag(m,matriz);
+
+
+       
+    RLC(matriz);
+    unsigned char a=64;
+    pc.printf("%c",a);
+   
+}    
+        
+
+     /*   for(i=0;i<8;i++){
+            for(j=0;j<320;j++){//132 WORKS
+                while(!pc.writeable());
+                    //pc.printf("%c",*(m+i*WIDTH+j*3+0));
+                    pc.printf("%c",(char)m[i][j][0]);
+                    
+
+                
+                while(!pc.writeable());
+                    //pc.printf("%c",*(m+i*WIDTH+j*3+1));
+                    pc.printf("%c",(char)m[i][j][1]);
+                    
+                while(!pc.writeable());
+                    //pc.printf("%c",*(m+i*WIDTH+j*3+2));
+                    pc.printf("%c",(char)m[i][j][2]);
+                   
+                    
+            } 
+        }*/
+    
+short int *mw =(short int *) malloc(sizeof(short int)*HEIGHT*WIDTH*3);
+int cont_y=4,cont_u=4,cont_v=4;
+int y=0,u=0,v=0;
+*(mw+y*3+0)=13;
+y++;
+*(mw+y*3+0)=13;
+y++;
+
+*(mw+u*3+1)=13;
+u++;
+*(mw+u*3+1)=13;
+u++;
+
+*(mw+v*3+2)=13;
+v++;
+*(mw+v*3+2)=13;
+v++;
+//lora(mw,&cont_y,&cont_u,&cont_v);
+
+ //http://www.martin-gardner.co.uk/how-to-connect-your-old-sd-card-to-an-arduino/
+    while(1){
+        
+        myled=1;
+        wait(0.2);
+        myled=0;
+        wait(0.2);
+    }
+    
+    
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/functions.h	Wed Sep 07 18:47:02 2016 +0000
@@ -0,0 +1,188 @@
+//Author: Miguel Ruiz García
+//Company: University of Cantabria. 2016
+//mail: mrg47@alumnos.unican.es
+
+
+#define PI 3.1415952
+#define WIDTH 320
+#define HEIGHT 8
+#define DEPTH 24
+#define RAIZ2 1.414214
+#define PI16 0.19635
+
+void DCT(int matrix[8][8][3],short int f[HEIGHT][WIDTH][3],int p_fil,int p_col){
+    int i=0,j=0,u,v;
+    float cu=1.0,cv=1.0;
+    int linea,bpp;
+
+    Uint8 *pixel;
+
+
+    for(u=p_fil;u<8+p_fil;u++){
+
+        if(u==0){
+            cu=RAIZ2/2;
+        }
+        else cu=1.0;
+        for(v=p_col;v<8+p_col;v++){
+            f[u][v][0]=0;
+            f[u][v][1]=0;
+            f[u][v][2]=0;
+            if(v==0){
+                cv=RAIZ2/2;
+
+            }
+            else cv=1.0;
+
+            short int dato=0;
+            short int dato2=0;
+
+
+            for(i=0;i<8;i++){
+
+                for(j=0;j<8;j++){
+
+                    dato=(short int)(cos((float)(((j<<1)+1)*(v-p_col)*PI16)));
+                    dato2=(short int)(cos((float)(((i<<1)+1)*(u-p_fil)*PI16)));
+
+                    f[u][v][0]+=(dato*dato2*(matrix[i][j][0]));//crominancia V
+                    f[u][v][1]+=(dato*dato2*(matrix[i][j][1]));//crominancia U
+                    f[u][v][2]+=(dato*dato2*(matrix[i][j][2]));//luminancia Y
+
+                }
+            }
+                float dato3=(float)((cu*cv)/4);
+                f[u][v][0]*=dato3;
+                f[u][v][1]*=dato3;
+                f[u][v][2]*=dato3;
+
+
+        }
+
+
+    }
+
+ 
+}
+
+void rgb_to_yuv(short int f[HEIGHT][WIDTH][3]){
+    
+
+    Uint8 *pixel;
+    int i=0,j=0;
+    const int linea=1920,bpp=3;
+    float y=0.0,u=0.0,v=0.0;
+    
+    for(i=0;i<HEIGHT;i++){
+        for(j=0;j<WIDTH;j++){
+            short int dato2=f[i][j][2];
+            short int dato1=f[i][j][1];
+            short int dato=f[i][j][0];
+            y=dato2*0.257+dato1*0.504+dato*0.098+16;//y
+        //  y=dato2*0.257+(Uint8)(*(pixel+1)>>1)+*(pixel)/100+16;//y
+            u=dato2*-0.148+dato1*-0.291+dato*0.439+128;//u
+            v=dato2*0.439+dato1*-0.368+dato*-0.071+128;//v
+            if(y>235) y=235;
+            if(u>240) u=240;
+            if(v>240) v=240;
+
+            if(y<16) y=16;
+            if(u<16) u=16;
+            if(v<16) v=16;
+        /*  y=*(pixel+2)*0.183+(*(pixel+1))*0.614+*(pixel)*0.062+16;//y
+            u=*(pixel+2)*-0.101+*(pixel+1)*-0.339+*(pixel)*0.439+128;//u
+            v=*(pixel+2)*0.439+*(pixel+1)*-0.339+*(pixel)*-0.040+128;//v*/
+
+//http://www.equasys.de/colorconversion.html
+
+            f[i][j][2]=(Uint8)y;
+            f[i][j][1]=(Uint8)u;
+            f[i][j][0]=(Uint8)v;
+
+        }
+
+    }
+
+
+}
+
+void zig_zag(short int f[HEIGHT][WIDTH][3],short int *matrix){
+
+    int i=0,p_x=0,p_y=0,j=0;
+    int flag=0;
+
+    for(i=0;i<WIDTH*HEIGHT;i++){
+        
+        *(matrix+j)=f[p_y][p_x][0];
+        *(matrix+j+1)=f[p_y][p_x][1];
+        *(matrix+j+2)=f[p_y][p_x][2];
+
+        j+=3;
+        if(flag==0){
+            p_x++,p_y--;
+            if(p_y<0){
+                p_y=0;
+                flag=1;
+
+            }
+            if(p_x>WIDTH-1){
+                p_x=WIDTH-1;
+                p_y+=2;
+                flag=1;
+
+
+            }
+
+        }
+        else{
+            p_x--,p_y++;
+            if(p_y>HEIGHT-1){
+                p_y=HEIGHT-1;
+                p_x+=2;
+                flag=0;
+
+            }
+            if(p_x<0){
+                p_x=0;
+                flag=0;
+            }
+
+        }
+
+
+    }
+
+
+
+}
+
+void cuantizador(short int mat[HEIGHT][WIDTH][3]){
+    short int luma[8][8]={{16,11,10,16,24,40,51,61},
+                        {12,12,14,19,26,58,60,55},
+                        {14,13,16,24,40,57,69,56},
+                        {14,17,22,29,51,87,80,62},
+                        {18,22,37,56,68,109,103,77},
+                        {24,35,55,64,81,104,113,92},
+                        {49,64,78,87,103,121,120,101},
+                        {72,92,95,98,112,100,103,99}};
+    short int croma[8][8]={{17,18,24,47,99,99,99,99},
+                            {18,21,26,66,99,99,99,99},
+                            {24,26,56,99,99,99,99,99},
+                            {47,66,99,99,99,99,99,99},
+                            {99,99,99,99,99,99,99,99},
+                            {99,99,99,99,99,99,99,99},
+                            {99,99,99,99,99,99,99,99},
+                            {99,99,99,99,99,99,99,99}};
+    int i=0,x_block,y_block,j;
+    for(i=0;i<HEIGHT;i+=8){
+        for(j=0;j<WIDTH;j+=8)
+        for(x_block=i; x_block<i+8 ;x_block++){
+            for(y_block=j; y_block<j+8 ;y_block++){
+                mat[x_block][y_block][2]/=luma[x_block-i][y_block-j];
+                mat[x_block][y_block][1]/=croma[x_block-i][y_block-j];
+                mat[x_block][y_block][0]/=croma[x_block-i][y_block-j];
+            }
+        }
+    }
+
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Sep 07 18:47:02 2016 +0000
@@ -0,0 +1,364 @@
+
+#include "mbed.h"
+#include "main.h"
+#include "sx1276-hal.h"
+#include "debug.h"
+#include "encoder.cpp"
+
+/* Set this flag to '1' to display debug messages on the console */
+#define DEBUG_MESSAGE   0
+
+/* Set this flag to '1' to use the LoRa modulation or to '0' to use FSK modulation */
+#define USE_MODEM_LORA  1
+#define USE_MODEM_FSK   !USE_MODEM_LORA
+
+#define RF_FREQUENCY                                    915000000 // Hz
+#define TX_OUTPUT_POWER                                 14        // 14 dBm
+
+#if USE_MODEM_LORA == 1
+
+    #define LORA_BANDWIDTH                              1         // [0: 125 kHz,
+                                                                  //  1: 250 kHz,
+                                                                  //  2: 500 kHz,
+                                                                  //  3: Reserved]
+    #define LORA_SPREADING_FACTOR                       10         // [SF7..SF12]
+    #define LORA_CODINGRATE                             1         // [1: 4/5,
+                                                                  //  2: 4/6,
+                                                                  //  3: 4/7,
+                                                                  //  4: 4/8]
+    #define LORA_PREAMBLE_LENGTH                        8         // Same for Tx and Rx
+    #define LORA_SYMBOL_TIMEOUT                         5         // Symbols
+    #define LORA_FIX_LENGTH_PAYLOAD_ON                  false
+    #define LORA_FHSS_ENABLED                           true  
+    #define LORA_NB_SYMB_HOP                            4     
+    #define LORA_IQ_INVERSION_ON                        false
+    #define LORA_CRC_ENABLED                            true
+    
+#elif USE_MODEM_FSK == 1
+
+    #define FSK_FDEV                                    25000     // Hz
+    #define FSK_DATARATE                                19200     // bps
+    #define FSK_BANDWIDTH                               50000     // Hz
+    #define FSK_AFC_BANDWIDTH                           83333     // Hz
+    #define FSK_PREAMBLE_LENGTH                         5         // Same for Tx and Rx
+    #define FSK_FIX_LENGTH_PAYLOAD_ON                   false
+    #define FSK_CRC_ENABLED                             true
+    
+#else
+    #error "Please define a modem in the compiler options."
+#endif
+
+#define RX_TIMEOUT_VALUE                                3500000   // in us
+#define BUFFER_SIZE                                     32        // Define the payload size here [min:1 max:255]
+
+#if( defined ( TARGET_KL25Z ) || defined ( TARGET_LPC11U6X ) )
+DigitalOut led(LED2);
+#else
+DigitalOut led(LED1);
+#endif
+
+/*
+ *  Global variables declarations
+ */
+typedef enum
+{
+    LOWPOWER = 0,
+    IDLE,
+    
+    RX,
+    RX_TIMEOUT,
+    RX_ERROR,
+    
+    TX,
+    TX_TIMEOUT,
+    
+    CAD,
+    CAD_DONE
+}AppStates_t;
+
+volatile AppStates_t State = LOWPOWER;
+
+/*!
+ * Radio events function pointer
+ */
+static RadioEvents_t RadioEvents;
+
+/*
+ *  Global variables declarations
+ */
+SX1276MB1xAS Radio( NULL );
+
+const uint8_t PingMsg[] = "PING";
+const uint8_t PongMsg[] = "PONG";
+
+uint16_t BufferSize = BUFFER_SIZE;
+uint8_t Buffer[BUFFER_SIZE];
+
+int16_t RssiValue = 0.0;
+int8_t SnrValue = 0.0;
+
+int main()
+{
+    short int *mw =(short int *) malloc(sizeof(short int)*320*8*3);
+    main2(mw);
+    uint8_t i;
+    bool isMaster = true;
+    
+    debug( "\n\n\r     SX1276 Ping Pong Demo Application \n\n\r" );
+
+    // Initialize Radio driver
+    RadioEvents.TxDone = OnTxDone;
+    RadioEvents.RxDone = OnRxDone;
+    RadioEvents.RxError = OnRxError;
+    RadioEvents.TxTimeout = OnTxTimeout;
+    RadioEvents.RxTimeout = OnRxTimeout;
+    RadioEvents.FhssChangeChannel = OnFhssChangeChannel;
+    Radio.Init( &RadioEvents );
+    
+    // verify the connection with the board
+    while( Radio.Read( REG_VERSION ) == 0x00  )
+    {
+        debug( "Radio could not be detected!\n\r", NULL );
+        wait( 1 );
+    }
+            
+    debug_if( ( DEBUG_MESSAGE & ( Radio.DetectBoardType( ) == SX1276MB1LAS ) ) , "\n\r > Board Type: SX1276MB1LAS < \n\r" );
+    debug_if( ( DEBUG_MESSAGE & ( Radio.DetectBoardType( ) == SX1276MB1MAS ) ) , "\n\r > Board Type: SX1276MB1MAS < \n\r" );
+    
+    Radio.SetChannel( HoppingFrequencies[0] ); 
+
+#if USE_MODEM_LORA == 1
+    
+    debug_if( LORA_FHSS_ENABLED, "\n\n\r             > LORA FHSS Mode < \n\n\r");
+    debug_if( !LORA_FHSS_ENABLED, "\n\n\r             > LORA Mode < \n\n\r");
+
+    Radio.SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH,
+                         LORA_SPREADING_FACTOR, LORA_CODINGRATE,
+                         LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON,
+                         LORA_CRC_ENABLED, LORA_FHSS_ENABLED, LORA_NB_SYMB_HOP, 
+                         LORA_IQ_INVERSION_ON, 4000000 );
+    
+    Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR,
+                         LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH,
+                         LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, 0,
+                         LORA_CRC_ENABLED, LORA_FHSS_ENABLED, LORA_NB_SYMB_HOP, 
+                         LORA_IQ_INVERSION_ON, true );
+                         
+#elif USE_MODEM_FSK == 1
+
+    debug("\n\n\r              > FSK Mode < \n\n\r");
+    Radio.SetTxConfig( MODEM_FSK, TX_OUTPUT_POWER, FSK_FDEV, 0,
+                         FSK_DATARATE, 0,
+                         FSK_PREAMBLE_LENGTH, FSK_FIX_LENGTH_PAYLOAD_ON,
+                         FSK_CRC_ENABLED, 0, 0, 0, 3000000 );
+    
+    Radio.SetRxConfig( MODEM_FSK, FSK_BANDWIDTH, FSK_DATARATE,
+                         0, FSK_AFC_BANDWIDTH, FSK_PREAMBLE_LENGTH,
+                         0, FSK_FIX_LENGTH_PAYLOAD_ON, 0, FSK_CRC_ENABLED,
+                         0, 0, false, true );
+                         
+#else
+
+#error "Please define a modem in the compiler options."
+
+#endif
+     
+    debug_if( DEBUG_MESSAGE, "Starting Ping-Pong loop\r\n" ); 
+        
+    led = 0;
+        
+    Radio.Rx( RX_TIMEOUT_VALUE );
+    
+    while( 1 )
+    {
+        switch( State )
+        {
+        case RX:
+            if( isMaster == true )
+            {
+                if( BufferSize > 0 )
+                {
+                    if( strncmp( ( const char* )Buffer, ( const char* )PongMsg, 4 ) == 0 )
+                    {
+                        led = !led;
+                        debug( "...Pong\r\n" );
+                        // Send the next PING frame            
+                        strcpy( ( char* )Buffer, ( char* )PingMsg );
+                        // We fill the buffer with numbers for the payload 
+                        for( i = 4; i < BufferSize; i++ )
+                        {
+                            Buffer[i] = i - 4;
+                        }
+                        wait_ms( 10 ); 
+                        Radio.Send( Buffer, BufferSize );
+                    }
+                    else if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 )
+                    { // A master already exists then become a slave
+                        debug( "...Ping\r\n" );
+                        led = !led;
+                        isMaster = false;
+                        // Send the next PONG frame            
+                        strcpy( ( char* )Buffer, ( char* )PongMsg );
+                        // We fill the buffer with numbers for the payload 
+                        for( i = 4; i < BufferSize; i++ )
+                        {
+                            Buffer[i] = i - 4;
+                        }
+                        wait_ms( 10 ); 
+                        Radio.Send( Buffer, BufferSize );
+                    }
+                    else // valid reception but neither a PING or a PONG message
+                    {    // Set device as master ans start again
+                        isMaster = true;
+                        Radio.Rx( RX_TIMEOUT_VALUE );
+                        
+                    }    
+                }
+            }
+            else
+            {
+                if( BufferSize > 0 )
+                {
+                    if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 )
+                    {
+                        led = !led;
+                        debug( "...Ping\r\n" );
+                        // Send the reply to the PING string
+                        strcpy( ( char* )Buffer, ( char* )PongMsg );
+                        // We fill the buffer with numbers for the payload 
+                        for( i = 4; i < BufferSize; i++ )
+                        {
+                            Buffer[i] = i - 4;
+                        }
+                        wait_ms( 10 );  
+                        Radio.Send( Buffer, BufferSize );
+                    }
+                    else // valid reception but not a PING as expected
+                    {    // Set device as master and start again
+                        isMaster = true;
+                        Radio.Rx( RX_TIMEOUT_VALUE );
+                    }    
+                }
+            }
+            State = LOWPOWER;
+            break;
+        case TX:    
+            led = !led; 
+            if( isMaster == true )  
+            {
+                debug( "Ping...\r\n" );
+            }
+            else
+            {
+                debug( "Pong...\r\n" );
+            }
+            Radio.Rx( RX_TIMEOUT_VALUE );
+            State = LOWPOWER;
+            break;
+        case RX_TIMEOUT:
+            if( isMaster == true )
+            {
+                // Send the next PING frame
+                strcpy( ( char* )Buffer, ( char* )PingMsg );
+                for( i = 4; i < BufferSize; i++ )
+                {
+                    Buffer[i] = i - 4;
+                }
+                wait_ms( 10 ); 
+                Radio.Send( Buffer, BufferSize );
+            }
+            else
+            {
+                Radio.Rx( RX_TIMEOUT_VALUE );  
+            }             
+            State = LOWPOWER;
+            break;
+        case RX_ERROR:
+            // We have received a Packet with a CRC error, send reply as if packet was correct
+            if( isMaster == true )
+            {
+                // Send the next PING frame
+                strcpy( ( char* )Buffer, ( char* )PingMsg );
+                for( i = 4; i < BufferSize; i++ )
+                {
+                    Buffer[i] = i - 4;
+                }
+                wait_ms( 10 );  
+                Radio.Send( Buffer, BufferSize );
+            }
+            else
+            {
+                // Send the next PONG frame
+                strcpy( ( char* )Buffer, ( char* )PongMsg );
+                for( i = 4; i < BufferSize; i++ )
+                {
+                    Buffer[i] = i - 4;
+                }
+                wait_ms( 10 );  
+                Radio.Send( Buffer, BufferSize );
+            }
+            State = LOWPOWER;
+            break;
+        case TX_TIMEOUT:
+            Radio.Rx( RX_TIMEOUT_VALUE );
+            State = LOWPOWER;
+            break;
+        case LOWPOWER:
+            break;
+        default:
+            State = LOWPOWER;
+            break;
+        }    
+    }
+}
+
+void OnTxDone( void )
+{
+    Radio.SetChannel( HoppingFrequencies[0] );
+    Radio.Sleep( );
+    State = TX;
+    debug_if( DEBUG_MESSAGE, "> OnTxDone\n\r" );
+}
+
+void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr)
+{
+    Radio.SetChannel( HoppingFrequencies[0] );
+    Radio.Sleep( );
+    BufferSize = size;
+    memcpy( Buffer, payload, BufferSize );
+    RssiValue = rssi;
+    SnrValue = snr;
+    State = RX;
+    debug_if( DEBUG_MESSAGE, "> OnRxDone\n\r" );
+}
+
+void OnTxTimeout( void )
+{
+    Radio.SetChannel( HoppingFrequencies[0] );
+    Radio.Sleep( );
+    State = TX_TIMEOUT;
+    debug_if( DEBUG_MESSAGE, "> OnTxTimeout\n\r" );
+}
+
+void OnRxTimeout( void )
+{
+    Radio.SetChannel( HoppingFrequencies[0] );
+    Radio.Sleep( );
+    Buffer[ BufferSize ] = 0;
+    State = RX_TIMEOUT;
+    debug_if( DEBUG_MESSAGE, "> OnRxTimeout\n\r" );
+}
+
+void OnRxError( void )
+{
+    Radio.SetChannel( HoppingFrequencies[0] );
+    Radio.Sleep( );
+    State = RX_ERROR;
+    debug_if( DEBUG_MESSAGE, "> OnRxError\n\r" );
+}
+
+void OnFhssChangeChannel( uint8_t channelIndex )
+{
+    Radio.SetChannel( HoppingFrequencies[channelIndex] );
+    debug_if( DEBUG_MESSAGE, "F%d-", channelIndex);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.h	Wed Sep 07 18:47:02 2016 +0000
@@ -0,0 +1,117 @@
+/*
+ / _____)             _              | |
+( (____  _____ ____ _| |_ _____  ____| |__
+ \____ \| ___ |    (_   _) ___ |/ ___)  _ \
+ _____) ) ____| | | || |_| ____( (___| | | |
+(______/|_____)_|_|_| \__)_____)\____)_| |_|
+    ( C )2014 Semtech
+
+Description: Contains the callbacks for the IRQs and any application related details
+
+License: Revised BSD License, see LICENSE.TXT file include in the project
+
+Maintainer: Miguel Luis and Gregory Cristian
+*/
+#ifndef __MAIN_H__
+#define __MAIN_H__
+
+
+/*!
+ * Frequency hopping frequencies table
+ */
+const uint32_t HoppingFrequencies[] =
+{
+    916500000,
+    923500000,
+    906500000,
+    917500000,
+    917500000,
+    909000000,
+    903000000,
+    916000000,
+    912500000,
+    926000000,
+    925000000,
+    909500000,
+    913000000,
+    918500000,
+    918500000,
+    902500000,
+    911500000,
+    926500000,
+    902500000,
+    922000000,
+    924000000,
+    903500000,
+    913000000,
+    922000000,
+    926000000,
+    910000000,
+    920000000,
+    922500000,
+    911000000,
+    922000000,
+    909500000,
+    926000000,
+    922000000,
+    918000000,
+    925500000,
+    908000000,
+    917500000,
+    926500000,
+    908500000,
+    916000000,
+    905500000,
+    916000000,
+    903000000,
+    905000000,
+    915000000,
+    913000000,
+    907000000,
+    910000000,
+    926500000,
+    925500000,
+    911000000
+};
+
+/*
+ * Callback functions prototypes
+ */
+/*!
+ * @brief Function to be executed on Radio Tx Done event
+ */
+void OnTxDone( void );
+
+/*!
+ * @brief Function to be executed on Radio Rx Done event
+ */
+void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr );
+
+/*!
+ * @brief Function executed on Radio Tx Timeout event
+ */
+void OnTxTimeout( void );
+
+/*!
+ * @brief Function executed on Radio Rx Timeout event
+ */
+void OnRxTimeout( void );
+
+/*!
+ * @brief Function executed on Radio Rx Error event
+ */
+void OnRxError( void );
+
+/*!
+ * @brief Function executed on Radio Fhss Change Channel event
+ */
+void OnFhssChangeChannel( uint8_t channelIndex );
+
+/*!
+ * @brief Function executed on CAD Done event
+ */
+void OnCadDone( void );
+
+#endif // __MAIN_H__
+
+int lora(short int *m,int *cont_y,int *cont_u,int *cont_v)  ;
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Sep 07 18:47:02 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/9296ab0bfc11
\ No newline at end of file