code d'envoie de trame
Dependencies: mbed ConfigFile
Fork of app4-router by
Diff: main.cpp
- Revision:
- 9:9b874294a381
- Parent:
- 8:cfc86293ec94
--- a/main.cpp Tue Feb 25 18:32:33 2014 +0000 +++ b/main.cpp Tue Feb 25 19:20:09 2014 +0000 @@ -1,3 +1,15 @@ +/******************************************************************************************* +* FILE: Router +* File name: main.cpp +* Authors: Pierluc Asselin & Marc-Antoine Dupuis +* Object: S5 Info - APP5 +* Original Date: 22/02/2014 +* Last Modified: 25/02/2014 +********************************************************************************************/ + +/******************* + INCLUDES +*******************/ #include "mbed.h" #include <sstream> #include <stdlib.h> @@ -5,6 +17,9 @@ #include "ConfigFile.h" +/********************************** + DEFINES REGISTRES POUR I2C +***********************************/ #define MMA8452_WRITE_ADDRESS 0x3A #define MMA8452_READ_ADDRESS 0x3B #define WHO_AM_I 0x0D @@ -18,6 +33,9 @@ #define CTRL_REG2 0x2B +/******************* + PINS +*******************/ DigitalOut myled(LED1); DigitalIn pb1(p5); DigitalOut reset(p8); @@ -25,24 +43,36 @@ Serial xbee(p13, p14); I2C i2c(p9, p10); // I2C port (sda, scl) +/******************* + CONFIG FILE +*******************/ LocalFileSystem local("local"); ConfigFile cfg; -//variables globales - +/*********************** + VARIABLES GLOBALES +************************/ int period_ms; //frequence que l'on obtien dans config file string panID; //panID que l'on obtient dans config file - - string convertInt(int number) // Converti un int en string + /******************* + convertInt + Converti un int en string +*******************/ + string convertInt(int number) { stringstream ss;//create a stringstream ss.str(""); ss << number;//add int number to the stream return ss.str();//return a string with the contents of the stream } -void configInit() //fonction de config avec le config file + + /******************* + configInit + fonction de config avec le config file +*******************/ +void configInit() { char *key1 = "PANID"; char *key2 = "FREQ"; @@ -70,7 +100,11 @@ } } -void xbee_init() //fonction de config du module xBee + /******************* + xbee_init + fonction de config du module xBee +*******************/ +void xbee_init() { reset = 0; //initialisation wait_ms(400); @@ -183,13 +217,21 @@ return true; } + + /******************* + getAccelValue + fonction qui lit les registres de données de l'accelerometre +*******************/ unsigned short getAccelValue(char MSB_addr) //fonction qui lit les registres de données de l'accelerometre { return i2c_read_reg(MSB_addr); // Read MSB data from MSB register } -//fonction qui construit la string a envoyer par xbee de l'accelerometre + /******************* + getAccelData + fonction qui construit la string a envoyer par xbee de l'accélérometre +*******************/ string getAccelData() { unsigned short x, y, z; @@ -201,13 +243,22 @@ return "AX" + convertInt(x) + " AY" + convertInt(y) + " AZ" + convertInt(z); } -//fonction qui construit la string a envoyer par xbee du pusb button + + + /******************* + getPushButtonData + fonction qui construit la string a envoyer par xbee du bouton poussoir +*******************/ string getPushButtonData() { return "PB" + convertInt(pb1); } -//fonction d'envoie de trame xbee + + /******************* + xbee_transmit + fonction d'envoie de trame xbee +*******************/ void xbee_transmit(string data_s) { @@ -242,6 +293,12 @@ } + + /******************* + + MAIN + +*******************/ int main() { //appelle des fonctions d'initialisations