Alex Millane / Mbed 2 deprecated IFARanging

Dependencies:   mbed

Committer:
millanea
Date:
Tue Jul 07 09:36:12 2015 +0000
Revision:
0:99928431bb44
First commit. Committing the entire project such that it can be published.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
millanea 0:99928431bb44 1 #include "Observer.h"
millanea 0:99928431bb44 2
millanea 0:99928431bb44 3 Observer::Observer( MM2WayRanging& newRanging, DW1000& newDw, Serial& output, Serial& mavlinkIn ) : Node( newRanging, newDw ), bufferedOutput( output ), mavlinkPassthrough( mavlinkIn, bufferedOutput )
millanea 0:99928431bb44 4 {
millanea 0:99928431bb44 5 debugprintf("Observer Initialized\r\n") ;
millanea 0:99928431bb44 6 // Registering the callback for observer functionality
millanea 0:99928431bb44 7 dw.setCallbacks(this, &Observer::observerCallbackRX, &Observer::observerCallbackTX);
millanea 0:99928431bb44 8 //dw.setCallbacks(this, &Observer::observerCallbackRX, NULL);
millanea 0:99928431bb44 9 }
millanea 0:99928431bb44 10
millanea 0:99928431bb44 11 void Observer::execute()
millanea 0:99928431bb44 12 {
millanea 0:99928431bb44 13 // Executing the passthrough background task
millanea 0:99928431bb44 14 mavlinkPassthrough.executeBackgroundTask() ;
millanea 0:99928431bb44 15 // Executing the frames output background task
millanea 0:99928431bb44 16 bufferedOutput.executeBackgroundTask() ;
millanea 0:99928431bb44 17 }
millanea 0:99928431bb44 18
millanea 0:99928431bb44 19 void Observer::observerCallbackRX()
millanea 0:99928431bb44 20 {
millanea 0:99928431bb44 21 // Creating a distance frame to hold received message
millanea 0:99928431bb44 22 DistancesFrame distFrame ;
millanea 0:99928431bb44 23 // Reading received message into distance frame
millanea 0:99928431bb44 24 dw.readRegister(DW1000_RX_BUFFER, 0, (uint8_t*)&distFrame, dw.getFramelength()) ;
millanea 0:99928431bb44 25
millanea 0:99928431bb44 26 // If message directed at this node
millanea 0:99928431bb44 27 if ( distFrame.destination == ranging.address )
millanea 0:99928431bb44 28 {
millanea 0:99928431bb44 29 // Disabling while accessing shared output buffer
millanea 0:99928431bb44 30 __disable_irq() ;
millanea 0:99928431bb44 31
millanea 0:99928431bb44 32 // A float for debug
millanea 0:99928431bb44 33 //volatile float debugFloat = 0.00 ;
millanea 0:99928431bb44 34
millanea 0:99928431bb44 35 // Printing the heading code
millanea 0:99928431bb44 36 bufferedOutput.addChar( HEADERCODE ) ;
millanea 0:99928431bb44 37 // Printing the message length
millanea 0:99928431bb44 38 bufferedOutput.addChar( 4*sizeof(float) ) ;
millanea 0:99928431bb44 39 // Looping through and printing received distance
millanea 0:99928431bb44 40 for( int nodeIndex=1; nodeIndex<=4; nodeIndex++ )
millanea 0:99928431bb44 41 {
millanea 0:99928431bb44 42 // Retreving address of distance as char address
millanea 0:99928431bb44 43 char *pdist = (char *) &distFrame.dist[nodeIndex-1] ;
millanea 0:99928431bb44 44 //debugFloat ++ ;
millanea 0:99928431bb44 45 //char *pdist = (char *) &debugFloat ;
millanea 0:99928431bb44 46 // Looping over the bytes in the float and sending
millanea 0:99928431bb44 47 for( char index = 0 ; index < sizeof(float) ; index++ )
millanea 0:99928431bb44 48 {
millanea 0:99928431bb44 49 bufferedOutput.addChar( pdist[ index ] ) ;
millanea 0:99928431bb44 50 }
millanea 0:99928431bb44 51 }
millanea 0:99928431bb44 52
millanea 0:99928431bb44 53 // Re-enabling interrupts
millanea 0:99928431bb44 54 __enable_irq() ;
millanea 0:99928431bb44 55 }
millanea 0:99928431bb44 56 // Starting receive again
millanea 0:99928431bb44 57 dw.startRX();
millanea 0:99928431bb44 58 }
millanea 0:99928431bb44 59
millanea 0:99928431bb44 60 void Observer::observerCallbackTX()
millanea 0:99928431bb44 61 {
millanea 0:99928431bb44 62 // Debug output
millanea 0:99928431bb44 63 //debugprintf("Message sent\r\n") ;
millanea 0:99928431bb44 64 }