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.
main.cpp
- Committer:
- ShaolinPoutine
- Date:
- 2017-02-09
- Revision:
- 0:25f9d14d01bd
- Child:
- 1:318ad4f36a90
File content as of revision 0:25f9d14d01bd:
#include "mbed.h"
#define FRAMEDELIMITER 0x7E
DigitalOut resetswitch(p8);
Serial xbee(p13, p14);
Serial pc(USBTX, USBRX);
DigitalOut myled(LED1);
int StartAPIMode ()
{
char reponse[4] = {42,42,42,'\0'};
wait(1);
xbee.putc('+');
xbee.putc('+');
xbee.putc('+');
wait(0.5);
int i = 0;
while (i < 4)
{
reponse[i] = xbee.getc();
pc.putc(reponse[i]);
i++;
}
return reponse[1];
}
int CalculateChecksum()
{
// Does not include frame delimiter and lenght
return 1;
}
int CalculateLenght()
{
// Calculate the number of bytes in the frame data
return 1;
}
void printhexa(char c)
{
char msb = c >> 4;
char lsb = c & 0xF;
if (msb < 10)
msb += 0x30;
else
msb += 0x37;
if (lsb < 10)
lsb += 0x30;
else
lsb += 0x37;
pc.putc('0');
pc.putc('x');
pc.putc(msb);
pc.putc(lsb);
pc.putc(' ');
}
void GetATResponse()
{
char start = xbee.getc(); // = FRAMEDELIMITER
//assert
char len_msb = xbee.getc();
char len_lsb = xbee.getc();
int len = ((int) len_msb << 4) + (int) len_lsb;
char frame_data[len];
int i = 0;
pc.printf("%d : ", len);
while (i < len)
{
wait(0.2);
if (xbee.readable())
{
frame_data[i] = xbee.getc();
printhexa(frame_data[i]);
}
i++;
}
char checksum = xbee.getc();
// Verify checksum
pc.printf("\r\n");
}
void ReadSerial()
{
// 00 13 A2 00
// 40 3E 09 63
char cmdtosend[8];
int i = 0;
cmdtosend[0] = FRAMEDELIMITER;
cmdtosend[1] = 0x00;
cmdtosend[2] = 0x04;
cmdtosend[3] = 0x08;
cmdtosend[4] = 0x52;
cmdtosend[5] = 'S'; // 0x53
cmdtosend[6] = 'H'; // 0x48
cmdtosend[7] = 0xFF - (cmdtosend[3]+cmdtosend[4]+cmdtosend[5]+cmdtosend[6]);
while (i < 8)
{
xbee.putc(cmdtosend[i]);
i++;
}
GetATResponse();
pc.printf("Sending second\r\n");
cmdtosend[0] = FRAMEDELIMITER;
cmdtosend[1] = 0x00;
cmdtosend[2] = 0x04;
cmdtosend[3] = 0x08;
cmdtosend[4] = 0x52;
cmdtosend[5] = 'S'; // 0x53
cmdtosend[6] = 'H'; // 0x4C
cmdtosend[7] = 0xFF - (cmdtosend[3]+cmdtosend[4]+cmdtosend[5]+cmdtosend[6]);
while (i < 8)
{
xbee.putc(cmdtosend[i]);
i++;
}
pc.printf("Sent\r\n");
GetATResponse();
}
int main() {
pc.printf("\r\n");
myled = 0;
resetswitch = 0;
wait(0.4);
resetswitch = 1;
//StartAPIMode();
wait(1);
GetATResponse();
GetATResponse();
ReadSerial();
myled = 1;
while(1) {
// Attend une réception de signal
GetATResponse();
myled = !myled;
}
}