Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of APP4 by
Revision 4:aac38b016952, committed 2014-02-24
- Comitter:
- RufflesAllD
- Date:
- Mon Feb 24 19:06:11 2014 +0000
- Parent:
- 3:350f07072089
- Commit message:
- l
Changed in this revision
--- a/coordinateur.hpp Mon Feb 24 15:40:33 2014 +0000 +++ b/coordinateur.hpp Mon Feb 24 19:06:11 2014 +0000 @@ -12,7 +12,7 @@ // Constructeur Coordinateur(PinName _tx, PinName _rx); - void setPanId(string _pan) { pan = _pan); } + void setPanId(string _pan) { pan = _pan; } private: Trame trame;
--- a/main.cpp Mon Feb 24 15:40:33 2014 +0000 +++ b/main.cpp Mon Feb 24 19:06:11 2014 +0000 @@ -1,12 +1,16 @@ -#include "mbed.h" #include "readfile.hpp" -DigitalOut reset(p8); -Serial pc(USBTX, USBRX); -Serial DATA(p13, p14); LocalFileSystem local("local"); int main() { - while(true); + Routeur *accelRouter = new Routeur(p13, p14); + accelRouter->initAccel(); + + while(true) + { + accelRouter->sendAccelValues(); + accelRouter->sendSwitchValue(); + wait(0.2); + } }
--- a/readfile.cpp Mon Feb 24 15:40:33 2014 +0000 +++ b/readfile.cpp Mon Feb 24 19:06:11 2014 +0000 @@ -11,10 +11,10 @@ { while (getline(myfile,line)) { - if (line[0] != "#") + if (line[0] != '#') { if (line.find("PANID") != string::npos) - ://coord->setPanID(line.substr( + ;//coord->setPanID(line.substr( } }
--- a/readfile.hpp Mon Feb 24 15:40:33 2014 +0000 +++ b/readfile.hpp Mon Feb 24 19:06:11 2014 +0000 @@ -3,9 +3,7 @@ #include <iostream> #include <fstream> -#include <string> -#include "mbed.h" #include "coordinateur.hpp" #include "routeur.hpp"
--- a/routeur.cpp Mon Feb 24 15:40:33 2014 +0000 +++ b/routeur.cpp Mon Feb 24 19:06:11 2014 +0000 @@ -1,6 +1,84 @@ #include "routeur.hpp" +const char COORD_ADRESS[8] = {0x00, 0x13, 0xA2, 0x00, 0x40, 0x0A, 0x2F, 0xB3}; + Routeur::Routeur(PinName _tx, PinName _rx) : - trame(_tx, _rx) + trame(_tx, _rx), accel(p9, p10), piton(p30) +{ + DigitalOut reset(p8); + + reset = 0; + wait(0.4); + reset = 1; + wait(4); +} + +void Routeur::initAccel() +{ + // Mise de l'accéléromètre en standby + writeRegister(CTRL_REG1, 0x10); + + // Set offset de l'accéléromètre + writeRegister(0x31, 0xEE); + + // activate de l'accéléromètre + char c; + readRegister(CTRL_REG1, &c); + writeRegister(CTRL_REG1, c | 0x01); +} + +void Routeur::sendSwitchValue() +{ + switchValue[0] = piton; + + trame.sendTransmitRequest(COORD_ADRESS, switchValue, 1); +} + +void Routeur::sendAccelValues() +{ + int ack = readRegisters(OUT_X_MSB, 6, accelValues); + + trame.sendTransmitRequest(COORD_ADRESS, accelValues, 6); +} + +int Routeur::readRegister(char reg, char* data) { -} \ No newline at end of file + int ack = 0; + accel.start(); + ack = accel.write(DATA_REG_W); + ack = accel.write(reg); + accel.start(); + ack = accel.write(DATA_REG_R); + data[0] = accel.read(0); + accel.stop(); + + return ack; +} + +int Routeur::readRegisters(char reg, int range, char* data) +{ + int ack = 0; + accel.start(); + ack = accel.write(DATA_REG_W); + ack = accel.write(reg); + accel.start(); + ack = accel.write(DATA_REG_R); + for (int i = 0; i < range - 1; i++) + data[i] = accel.read(1); + data[range - 1] = accel.read(0); + accel.stop(); + + return ack; +} + +int Routeur::writeRegister(char reg, char data) +{ + int ack = 0; + accel.start(); + ack = accel.write(DATA_REG_W); + ack = accel.write(reg); + ack = accel.write(data); + accel.stop(); + + return ack; +}
--- a/routeur.hpp Mon Feb 24 15:40:33 2014 +0000 +++ b/routeur.hpp Mon Feb 24 19:06:11 2014 +0000 @@ -4,6 +4,12 @@ #include <string> #include "trame.hpp" +#define CTRL_REG1 0x2A +#define DATA_REG_W 0x3A +#define DATA_REG_R 0x3B + +#define OUT_X_MSB 0x01 + using namespace std; class Routeur @@ -12,8 +18,23 @@ // Constructeur Routeur(PinName _tx, PinName _rx); + void initAccel(); + void sendAccelValues(); + + void sendSwitchValue(); + private: + int readRegister(char reg, char* data); + int readRegisters(char reg, int range, char* dest); + int writeRegister(char reg, char data); + Trame trame; + + I2C accel; + DigitalIn piton; + + char switchValue[1]; + char accelValues[6]; }; #endif
--- a/trame.cpp Mon Feb 24 15:40:33 2014 +0000 +++ b/trame.cpp Mon Feb 24 19:06:11 2014 +0000 @@ -32,8 +32,8 @@ void Trame::sendTransmitRequest(const char* destination, const char* data, int length) { - int tmp = length + 18; - char* trm = new char[tmp]; + int tmp = length + 14; + char* trm = new char[tmp + 4]; trm[0] = 0x7E; // Delimiter trm[1] = static_cast<char>((tmp >> 8) & 0xFF); // MSB de length @@ -42,20 +42,20 @@ trm[4] = 0x01; // API for (int i = 0; i < 8; i++) trm[5 + i] = destination[i]; //Destination - trm[13] = 0x00; // 16 bits address - trm[14] = 0x00; // 16 bits address + trm[13] = 0xFF; // 16 bits address + trm[14] = 0xFE; // 16 bits address trm[15] = 0x00; // Radius trm[16] = 0x00; // Options for (int i = 0; i < length; i++) trm[17 + i] = data[i]; // Data - trm[17 + length] = crc8(trm, tmp - 1); + trm[17 + length] = crc8(trm, tmp+3); Serial xbee(tx, rx); - for (int i = 0; i < tmp; i++) + for (int i = 0; i < tmp+4; i++) xbee.putc(trm[i]); - + wait(0.01); delete trm; } @@ -63,7 +63,7 @@ unsigned char Trame::crc8(const char* data, int length) { unsigned char crc = 0; - for (int i = 1; i < length; i++) + for (int i = 3; i < length; i++) crc += data[i]; return (0xFF - crc);