comms not ready
Dependencies: NRF2401P mbed-rtos mbed
Revision 1:51a5cfbfd25c, committed 2015-06-12
- Comitter:
- newc4420
- Date:
- Fri Jun 12 13:46:53 2015 +0000
- Parent:
- 0:05989ea2d008
- Commit message:
- V4
;
Changed in this revision
NRF2401P.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/NRF2401P.lib Fri Jun 12 13:46:53 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/epgmdm/code/NRF2401P/#7e253c677a1f
--- a/main.cpp Fri Jun 12 08:57:26 2015 +0000 +++ b/main.cpp Fri Jun 12 13:46:53 2015 +0000 @@ -1,5 +1,8 @@ #include "mbed.h" #include "rtos.h" +#include "NRF2401P.h" + +Serial pc(USBTX, USBRX); // tx, rx /*Program to open locker when a signal level (lock) is sent in from an external controller. System is split into threads so main loop can run even when waiting in door unlock function. @@ -11,6 +14,8 @@ /*function definitions*/ void unlock (void const *args); //function statement to unlock door, +void battcomms (void const *args); //function statement to communicate with battery + /*set pins*/ DigitalOut latch(D0); //signal out to open door DigitalIn lock(D1); //signal in from interface to unlock door @@ -37,7 +42,7 @@ latch = 1; //solenoid initially locked Thread Tunlock(unlock); //set up unlock function as a thread, thread should not run while unlockflag ==0 - + Thread Tbattcomms(battcomms); //set up battcomms as a thread //main loop that runs forever, checking for external flags and if door open/closed and to fire off alarm(status thread) while(true) @@ -71,6 +76,8 @@ } } + + /*function to unlock door to be called in thread. Note time limit on solenoid open to prevent overheating (should put spring to force door open once unlocked) unlock protocol thread*/ void unlock (void const *args) @@ -109,3 +116,36 @@ } } } + +/*battery communication function to be called in thread*/ +void battcomms (void const *args) +{ + + long long addr1=0xAB12CD; // setup address - any 5 byte number - same as TX + int channel =52; // [0-126] setup channel, must be same as TX + bool txOK; + char msg[32]; + char ackData[32]; + char len; + + // Setup + NRF2401P nrf1(PTD2,PTD3, PTD1,PTA13, PTD0); //pins on mosi, miso, sclk, csn, ce) + + nrf1.quickRxSetup(channel, addr1); // sets nrf24l01+ as receiver, using pipe 1 + while(true) + { + + // receive + pc.printf("Waiting for Data ...\r\n"); + while (! nrf1.isRxData()); // note this blocks until RX data + len= nrf1.getRxData(msg); // gets the message, len is length of msg + msg[len] = '\0'; + pc.printf("Received %d bytes: %s\r\n",len, msg); + // set ack data + sprintf(ackData,"HELLO"); + nrf1.acknowledgeData(ackData, strlen(ackData),1); // ack for pipe 1 + pc.printf("Sent HELLO\r\n"); + + wait(0.1); + } +} \ No newline at end of file