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.
Diff: main.cpp
- Revision:
- 3:5010d20e681f
- Parent:
- 1:318ad4f36a90
- Child:
- 4:04351e4aad49
--- a/main.cpp Mon Feb 13 17:42:31 2017 +0000
+++ b/main.cpp Mon Feb 13 19:44:54 2017 +0000
@@ -8,28 +8,6 @@
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
@@ -132,6 +110,57 @@
}
}
+void AtCommand(char FirstChar, char SecondChar, char *OptionalParam = NULL, int ParamLen = 0)
+{
+ // Frame Type 0x08
+ // Two char as parameters
+
+ char cmdtosend[10];
+ char sum = 0;
+ int cmdlength = 8;
+ int i = 0;
+
+ cmdtosend[0] = FRAMEDELIMITER;
+ cmdtosend[1] = 0x00;
+ cmdtosend[2] = 0x04 + ParamLen;
+ cmdtosend[3] = 0x08;
+ cmdtosend[4] = 0x52;
+ cmdtosend[5] = FirstChar;
+ cmdtosend[6] = SecondChar;
+
+ // Ajouter les parametres au message
+ if(OptionalParam != NULL)
+ {
+ i = 0;
+ cmdlength += ParamLen;
+
+ while (i < ParamLen)
+ {
+ pc.putc((OptionalParam)[i]);
+ cmdtosend[7 + i] = (OptionalParam)[i];
+ i++;
+ }
+ pc.printf("\r\n");
+ }
+
+ // Calculate checksum
+ i = 3;
+ while (i < (cmdlength - 1))
+ {
+ sum += cmdtosend[i];
+ i++;
+ }
+ cmdtosend[cmdlength - 1] = 0xFF - sum;
+
+ // Envoyer la commande sur UART
+ i = 0;
+ while (i < cmdlength)
+ {
+ xbee.putc(cmdtosend[i]);
+ i++;
+ }
+}
+
void xbee_reader()
{
@@ -161,7 +190,17 @@
wait(3);
+ char Params[2] = {'a', 'b'};
+
ReadSerial();
+ wait(0.5);
+ AtCommand('O', 'I');
+ wait(0.5);
+ AtCommand('I', 'I', &Params[0], 2);
+ wait(0.5);
+ AtCommand('O', 'I');
+ wait(0.5);
+
while(1) {
}