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.
Dependencies: mbed CANBuffer Watchdog MODSERIAL mbed-rtos xbeeRelay IAP
Fork of SystemManagement by
XBee/XBee_Lib.h@0:e516fcccccda, 2014-10-01 (annotated)
- Committer:
- martydd3
- Date:
- Wed Oct 01 12:52:26 2014 +0000
- Revision:
- 0:e516fcccccda
Added LPCDigitalOut, LPCDigitalIn, and CANBuffer Libaries; Comments on code in SysMngmt.cpp involving register and pin access; Note: LPCDigitalOut.h defines a void mode(PinMode) which isn't in LPCDigitalOut.cpp, causes a linking error if used
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| martydd3 | 0:e516fcccccda | 1 | /* |
| martydd3 | 0:e516fcccccda | 2 | Test Code |
| martydd3 | 0:e516fcccccda | 3 | //#include "XBee_Lib.h" |
| martydd3 | 0:e516fcccccda | 4 | #include "mbed.h" |
| martydd3 | 0:e516fcccccda | 5 | #include<sstream> |
| martydd3 | 0:e516fcccccda | 6 | #include <cstring> |
| martydd3 | 0:e516fcccccda | 7 | #include <string> |
| martydd3 | 0:e516fcccccda | 8 | Serial xbee(p28,p27); |
| martydd3 | 0:e516fcccccda | 9 | Serial pc(USBTX,USBRX); |
| martydd3 | 0:e516fcccccda | 10 | DigitalOut led1(LED1); |
| martydd3 | 0:e516fcccccda | 11 | DigitalOut led2(LED2); |
| martydd3 | 0:e516fcccccda | 12 | DigitalOut reset(p5); |
| martydd3 | 0:e516fcccccda | 13 | DigitalIn CTS(p6, PullNone); |
| martydd3 | 0:e516fcccccda | 14 | DigitalIn in(p21, PullDown); |
| martydd3 | 0:e516fcccccda | 15 | |
| martydd3 | 0:e516fcccccda | 16 | int main() |
| martydd3 | 0:e516fcccccda | 17 | { |
| martydd3 | 0:e516fcccccda | 18 | //char a[]="Hello....."; |
| martydd3 | 0:e516fcccccda | 19 | //int i=0; |
| martydd3 | 0:e516fcccccda | 20 | //while(a[i]!='\0') |
| martydd3 | 0:e516fcccccda | 21 | xbee.baud(250000); |
| martydd3 | 0:e516fcccccda | 22 | char a[63]; |
| martydd3 | 0:e516fcccccda | 23 | char b[100]; |
| martydd3 | 0:e516fcccccda | 24 | |
| martydd3 | 0:e516fcccccda | 25 | a[0]='\x31'; |
| martydd3 | 0:e516fcccccda | 26 | for(int j=1; j<=60; j++) |
| martydd3 | 0:e516fcccccda | 27 | { |
| martydd3 | 0:e516fcccccda | 28 | if(a[j-1]=='\x39') |
| martydd3 | 0:e516fcccccda | 29 | { |
| martydd3 | 0:e516fcccccda | 30 | a[j]='\x41'; |
| martydd3 | 0:e516fcccccda | 31 | } |
| martydd3 | 0:e516fcccccda | 32 | else if(a[j-1]=='\x5A') |
| martydd3 | 0:e516fcccccda | 33 | { |
| martydd3 | 0:e516fcccccda | 34 | a[j]='\x61'; |
| martydd3 | 0:e516fcccccda | 35 | } |
| martydd3 | 0:e516fcccccda | 36 | else |
| martydd3 | 0:e516fcccccda | 37 | a[j]=a[j-1]+1; |
| martydd3 | 0:e516fcccccda | 38 | } |
| martydd3 | 0:e516fcccccda | 39 | a[61]='\n'; |
| martydd3 | 0:e516fcccccda | 40 | a[62]='\r'; |
| martydd3 | 0:e516fcccccda | 41 | char data[8]=""; |
| martydd3 | 0:e516fcccccda | 42 | data[0]='a'; |
| martydd3 | 0:e516fcccccda | 43 | data[1]='b'; |
| martydd3 | 0:e516fcccccda | 44 | data[2]='c'; |
| martydd3 | 0:e516fcccccda | 45 | string stri; |
| martydd3 | 0:e516fcccccda | 46 | |
| martydd3 | 0:e516fcccccda | 47 | //pc.printf("%s",a); |
| martydd3 | 0:e516fcccccda | 48 | reset=0; |
| martydd3 | 0:e516fcccccda | 49 | wait_ms(1); |
| martydd3 | 0:e516fcccccda | 50 | reset=1; |
| martydd3 | 0:e516fcccccda | 51 | wait_ms(1); |
| martydd3 | 0:e516fcccccda | 52 | |
| martydd3 | 0:e516fcccccda | 53 | |
| martydd3 | 0:e516fcccccda | 54 | std::ostringstream ostr; |
| martydd3 | 0:e516fcccccda | 55 | ostr<<data; |
| martydd3 | 0:e516fcccccda | 56 | stri=ostr.str(); |
| martydd3 | 0:e516fcccccda | 57 | std::strcpy (b, (ostr.str()).c_str()); |
| martydd3 | 0:e516fcccccda | 58 | pc.printf("%s",b); |
| martydd3 | 0:e516fcccccda | 59 | while(1) |
| martydd3 | 0:e516fcccccda | 60 | { |
| martydd3 | 0:e516fcccccda | 61 | while(in.read()) |
| martydd3 | 0:e516fcccccda | 62 | { |
| martydd3 | 0:e516fcccccda | 63 | pc.printf("Sending Data...\n\r"); |
| martydd3 | 0:e516fcccccda | 64 | xbee.printf("%s",b); |
| martydd3 | 0:e516fcccccda | 65 | |
| martydd3 | 0:e516fcccccda | 66 | if(CTS.read()==1) |
| martydd3 | 0:e516fcccccda | 67 | { |
| martydd3 | 0:e516fcccccda | 68 | pc.printf("DI buffer full\n\r"); |
| martydd3 | 0:e516fcccccda | 69 | led2=1; |
| martydd3 | 0:e516fcccccda | 70 | //break; |
| martydd3 | 0:e516fcccccda | 71 | while(CTS.read()){} |
| martydd3 | 0:e516fcccccda | 72 | pc.printf("DI buffer has place\n\r"); |
| martydd3 | 0:e516fcccccda | 73 | led2=0; |
| martydd3 | 0:e516fcccccda | 74 | //i=0; |
| martydd3 | 0:e516fcccccda | 75 | } |
| martydd3 | 0:e516fcccccda | 76 | |
| martydd3 | 0:e516fcccccda | 77 | //wait_ms(1000); |
| martydd3 | 0:e516fcccccda | 78 | led1=!led1; |
| martydd3 | 0:e516fcccccda | 79 | //++i; |
| martydd3 | 0:e516fcccccda | 80 | } |
| martydd3 | 0:e516fcccccda | 81 | } |
| martydd3 | 0:e516fcccccda | 82 | } |
| martydd3 | 0:e516fcccccda | 83 | */ |
| martydd3 | 0:e516fcccccda | 84 | #ifndef XBEE_LIB_H |
| martydd3 | 0:e516fcccccda | 85 | #define XBEE_LIB_H |
| martydd3 | 0:e516fcccccda | 86 | |
| martydd3 | 0:e516fcccccda | 87 | #include"LPCDigitalOut.h" |
| martydd3 | 0:e516fcccccda | 88 | #include"mbed.h" |
| martydd3 | 0:e516fcccccda | 89 | #include<sstream> |
| martydd3 | 0:e516fcccccda | 90 | |
| martydd3 | 0:e516fcccccda | 91 | Serial Xbee_e1(p9,p10); |
| martydd3 | 0:e516fcccccda | 92 | Serial Xbee_e2(p13,p14); |
| martydd3 | 0:e516fcccccda | 93 | |
| martydd3 | 0:e516fcccccda | 94 | // Used for wireless communications with Xbee |
| martydd3 | 0:e516fcccccda | 95 | |
| martydd3 | 0:e516fcccccda | 96 | //Include the send function only in the main code. |
| martydd3 | 0:e516fcccccda | 97 | class XBee250x |
| martydd3 | 0:e516fcccccda | 98 | { |
| martydd3 | 0:e516fcccccda | 99 | public: |
| martydd3 | 0:e516fcccccda | 100 | XBee250x() |
| martydd3 | 0:e516fcccccda | 101 | { |
| martydd3 | 0:e516fcccccda | 102 | Xbee_e1.baud(250000); |
| martydd3 | 0:e516fcccccda | 103 | Xbee_e2.baud(250000); |
| martydd3 | 0:e516fcccccda | 104 | } |
| martydd3 | 0:e516fcccccda | 105 | |
| martydd3 | 0:e516fcccccda | 106 | void send(CANMessage Rxmsg) |
| martydd3 | 0:e516fcccccda | 107 | { |
| martydd3 | 0:e516fcccccda | 108 | Xbee_e1.printf("%c \t %d \t %s \n\r",Rxmsg.id, Rxmsg.len, Rxmsg.data); |
| martydd3 | 0:e516fcccccda | 109 | Xbee_e2.printf("%c \t %d \t %s \n\r",Rxmsg.id, Rxmsg.len, Rxmsg.data); |
| martydd3 | 0:e516fcccccda | 110 | } |
| martydd3 | 0:e516fcccccda | 111 | }; |
| martydd3 | 0:e516fcccccda | 112 | #endif /*XBEE_LIB_H*/ |
