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 Repo_Noeud_Mobile by
Diff: Communication/Xbee.cpp
- Revision:
- 50:48e8da5fc1ae
- Parent:
- 44:0862bc49ffa7
- Child:
- 51:299408ceee3a
--- a/Communication/Xbee.cpp Wed Apr 08 20:29:22 2015 +0000 +++ b/Communication/Xbee.cpp Sat Apr 11 19:20:22 2015 +0000 @@ -14,6 +14,7 @@ this->XbeePin = new Serial(pinTx, pinRx); PanId = panId; SetPanId(PanId); + frameID=0; } Xbee::~Xbee() @@ -46,7 +47,7 @@ command[1] = length1; //length first char command[2] = length2; //length second char command[3] = 0x10; //frame type - Send Request - command[4] = 0x01; //frame ID + command[4] = frameID; //frame ID sum += 0x10; sum += 0x01; @@ -70,13 +71,13 @@ } command[size-1] = 0xFF - sum; //checksum - Envoyer(command, size); //send frame array to XBee +frameID++; } void Xbee::EnvoyerStructure(Mobile_Vers_Fixe mvf) { - char data[8] = {}; + char data[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; data[0] = mvf.gants; data[1] = mvf.accelData.x >> 8; @@ -85,7 +86,7 @@ data[4] = mvf.accelData.y & 0x00FF; data[5] = mvf.accelData.z >> 8; data[6] = mvf.accelData.z & 0x00FF; - + x_pc.printf("\r\nAccel x: %d", mvf.accelData.x); mvf.flexSensor.index == 1 ? data[7] = 0x04 : data[7] = 0; mvf.flexSensor.majeur == 1 ? data[7] += 0x02 : data[7] += 0; mvf.flexSensor.annulaire == 1 ? data[7] += 0x01 : data[7] += 0; @@ -95,8 +96,8 @@ void Xbee::EnvoyerStructure(Mobile_Vers_Fixe* mvf) { - char data[8] = {}; - + char data[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + //x_pc.printf(" \r\n Gants id %c", mvf->gants); data[0] = mvf->gants; data[1] = mvf->accelData.x >> 8; data[2] = mvf->accelData.x & 0x00FF; @@ -104,7 +105,7 @@ data[4] = mvf->accelData.y & 0x00FF; data[5] = mvf->accelData.z >> 8; data[6] = mvf->accelData.z & 0x00FF; - + x_pc.printf("\r\nAccel x: %d", mvf->accelData.x); mvf->flexSensor.index == 1 ? data[7] = 0x04 : data[7] = 0; mvf->flexSensor.majeur == 1 ? data[7] += 0x02 : data[7] += 0; mvf->flexSensor.annulaire == 1 ? data[7] += 0x01 : data[7] += 0; @@ -118,23 +119,26 @@ { char buffer[3]; int index = 0; + x_pc.printf("\r\n Start recevoir thread x"); while(true) { if (XbeePin->readable()) { + //x_pc.printf("Data recu: %x",XbeePin->getc()); //Start byte if (XbeePin->getc() == 0x7E) { index = 0; - + //x_pc.printf("\r\n Start Byte x"); //Get length and frame type while (index < 3) { buffer[index] = XbeePin->getc(); index++; } + //x_pc.printf("\n\r Type de trame: %x", buffer[2]); index = 0; //If frame is a receive packet if (buffer[2] == 0x90) { - + //x_pc.printf("\r\n Bonne trame"); //Ici va falloir compter le nombre de bytes de niaiseries - //qui se passent avant les datas, 11 je crois + //qui se passent avant les donnees, 11 je crois do { char c = XbeePin->getc(); index++; @@ -142,14 +146,15 @@ index = 0; //GameID - int gameMode = XbeePin->getc() - 60; + + int gameMode = XbeePin->getc(); index++; - + x_pc.printf("\r\n gameMode %x", gameMode); //ChkSum buffer[0] = XbeePin->getc(); - + Fixe_Vers_Mobile *emile = mailbox_TypeDeJeu.alloc(); - + // Verifier si mail pointe pas vers 0 [boite pleine] while (emile == 0) { wait_ms(25);