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.
Fork of football_project by
Revision 69:a3295b74209e, committed 2016-02-12
- Comitter:
- AntonLS
- Date:
- Fri Feb 12 21:13:14 2016 +0000
- Parent:
- 68:0c96bb3d73a7
- Child:
- 70:bd4b1e19a0c6
- Commit message:
- Radio-to-Standby prevention edge and corner cases.
Changed in this revision
--- a/Radio.cpp Thu Feb 11 19:28:01 2016 +0000
+++ b/Radio.cpp Fri Feb 12 21:13:14 2016 +0000
@@ -157,13 +157,20 @@
payload[6] = (byte)(em.mac >> 16);
payload[5] = (byte)(em.mac >> 24);
- radio.send( em.m.cone, payload, sizeof(payload), false ); //// NO ACK req.
+ radio_send_raw( em.m.cone, payload, sizeof(payload), false ); //// NO ACK req.
/// radio.send(em.m.cone, payload, sizeof(payload));
if( Dbg ) writeToPhone("SND: %d %d 0x%x\r\n", em.m.cone, node_id, em.mac);
}
}
+void radio_send_raw( uint8_t toAddress, const void* buffer, uint8_t bufferSize, bool requestACK ) ////
+{
+ radio.send( toAddress, buffer, bufferSize, requestACK );
+
+// radio_ensure_rx_mode();
+}
+
void radio_send( Message *m, bool requestACK ) ////
{
static byte payload [6] = {0};
@@ -184,8 +191,7 @@
payload[5] = (byte)++TA::msg_id; //// Msg ID, was: = (byte)'%';
- radio.send( m->cone, payload, sizeof(payload), requestACK ); ////
- radio_receive_complete(); //// Prevent radio from going to sleep.
+ radio_send_raw( m->cone, payload, sizeof(payload), requestACK );
}
void stompage_check()
@@ -204,11 +210,12 @@
bool radio_receive(Message *m)
{
- bool retval = false;
+ bool retval = false;
+ bool ensure_rx_mode = false;
//// For msg id feature...
static prev_message mPrev;
- static long lastMsgAt = millis();
+ static long lastMsgAt = millis();
Message lm;
extended_message em;
@@ -222,21 +229,16 @@
if( radio.TARGETID == datastore_node_id() ) //// Check for stompage...
{
stompage_check();
-
- if( radio.ACK_RECEIVED )
- {
- // We've received an ACK between retries.
- retval = true;
- break;
- }
}
if( !get_crc_ok() ) // CRC error will be rechecked/sent from caller.
{
retval = true;
break;
}
- if( radio.DATALEN < 6 )
+ if( (radio.DATALEN < 6) && !radio.ACK_RECEIVED )
{
+ ensure_rx_mode = true;
+
RA_DEBUG( "Warn: Short packet\r\n" );
RA_DEBUG( "Warn: Data len %d\r\n", radio.DATALEN );
RA_DEBUG( "Warn: Cmd %c, Frm %d\r\n", radio.DATA[0], radio.SENDERID );
@@ -279,27 +281,36 @@
{
memcpy(m, &lm, sizeof(Message));
- //// Check if sender missed an ACK (Got duplicate of last msg, so ignore dup.)
- if( (millis() -lastMsgAt < 100) && //// Only consider as dup if w/in 100ms of prev.
- (mPrev.m.cone == m->cone) &&
- (mPrev.msgid == radio.DATA[5]) )
- { //// ASS-U-ME [for now] last msg is from same cone.
- RA_DEBUG( "Ignored dup cmd\r\n" );
- radio_send_ack();
- break;
+ if( !radio.ACK_RECEIVED )
+ {
+ //// Check if sender missed an ACK (Got duplicate of last msg, so ignore dup.)
+ if( (millis() -lastMsgAt < 100) && //// Only consider as dup if w/in 100ms of prev.
+ (mPrev.m.cone == m->cone) &&
+ (mPrev.msgid == radio.DATA[5]) )
+ { //// ASS-U-ME [for now] last msg is from same cone.
+ RA_DEBUG( "Ignored dup cmd\r\n" );
+ radio_send_ack();
+ ensure_rx_mode = true;
+ break;
+ }
+
+ memcpy( &mPrev.m, m, sizeof( Message ) ); ////
+ mPrev.msgid = radio.DATA[5]; ////
+ lastMsgAt = millis(); ////
+
+ if( Dbg ) writeToPhone("GM: %d %c %d\r\n", radio.SENDERID, m->command, m->value);
}
-
- memcpy( &mPrev.m, m, sizeof( Message ) ); ////
- mPrev.msgid = radio.DATA[5]; ////
- lastMsgAt = millis(); ////
-
- if( Dbg ) writeToPhone("GM: %d %c %d\r\n", radio.SENDERID, m->command, m->value);
retval = true;
}
}
} while( false );
+ if( ensure_rx_mode )
+ {
+ radio_ensure_rx_mode(); // Will stomp/erase payload data.
+ }
+
if( retval )
{
if( get_crc_ok() )
@@ -311,19 +322,35 @@
return retval;
}
+void radio_ensure_rx_mode()
+{
+ if( RF69_MODE_RX != radio._mode )
+ {
+ // Either do this or change the setMode in RFM69.cpp at end of sendFrame() to setMode(RF69_MODE_RX);
+ radio.receiveDone(); //// Prevent radio from going to standby or sleep. (Should never return true here.)
+ }
+}
+
void radio_send_ack() ////
{
radio.sendACK( "K", 1 );
- radio_receive_complete(); //// Prevent radio from going to sleep.
+
+// radio_ensure_rx_mode();
}
bool radio_ack_received( int cone )
{
bool retval = radio.ACKReceived(cone);
- if( retval && (radio.TARGETID == datastore_node_id()) )
+ if( retval )
{
- stompage_check();
+ if( radio.TARGETID == datastore_node_id() )
+ {
+ stompage_check();
+ }
+
+ // Note if we ever want to retrieve data from ACK packet: This stomps the packet data.
+// radio_ensure_rx_mode();
}
return retval;
--- a/Radio.hh Thu Feb 11 19:28:01 2016 +0000 +++ b/Radio.hh Fri Feb 12 21:13:14 2016 +0000 @@ -5,6 +5,8 @@ #define ACK_TIME 20 // max msec for ACK wait - Was 50 +void radio_send_raw( uint8_t toAddress, const void* buffer, uint8_t bufferSize, bool requestACK=true ); //// + void radio_send( Message *m, bool requestACK=true ); //// /// bool radio_send(Message *m); @@ -12,6 +14,8 @@ bool radio_receive(Message *m); +void radio_ensure_rx_mode(); //// + void radio_send_ack(); //// bool radio_ack_received(int cone);
--- a/TA.cpp Thu Feb 11 19:28:01 2016 +0000
+++ b/TA.cpp Fri Feb 12 21:13:14 2016 +0000
@@ -135,7 +135,8 @@
#if 1
// inputs
DigitalIn TA::touch_1( p12,PullDown ); // Test button (p6 [was] RSVD for lower button--p6 is last analog-in though.)
-EdgeDigIn TA::touch_2( p0, PullNone ); // Top touch sensor.
+// EdgeDigIn TA::touch_2( p0, PullNone ); // Top touch sensor.
+DigitalIn TA::touch_2( p0, PullNone ); // Top touch sensor. ////
DigitalIn TA::touch_3( p3, PullNone ); // /Power button (even though not a touch button.)
#endif
@@ -298,7 +299,7 @@
bool TA::sendRaw(uint8_t *message, uint8_t len, uint8_t cone) //// Currently not used.
{
- radio.send(cone, message, len);
+ radio_send_raw(cone, message, len);
return true;
}
@@ -493,7 +494,7 @@
{
if( get_crc_ok() )
{
- if( radio.ACK_RECEIVED ) gotACK = true; ////
+ if( radio.ACK_RECEIVED ) gotACK = true; //// If we got an ACK instead of a command.
else
{
receive_buffer.put( radio.SENDERID );
@@ -541,7 +542,7 @@
//// DEBUG( "Failed to deliver message to cone %d\r\n", dest_cone );
RA_DEBUG( "Fail msg to cone %d\r\n", dest_cone ); ////
- } else
+ } else // success
{
if( send_tries > 1 )
{
@@ -605,22 +606,23 @@
requestACK = true;
//DEBUG( "sending\r\n" );
/// writeToPhone("Sending message to: %d\r\n", dest_cone);
- radio.send( dest_cone, payload, 6, requestACK );
+ radio_send_raw( dest_cone, payload, 6, requestACK );
//DEBUG( "sent\r\n" );
//DEBUG( "Trying to send: %d\r\n", (uint8_t)payload[0] );
//uint16_t temp = (uint16_t)payload[1]<<8;
//temp += (uint8_t)payload[2];
send_tries++;
ack_start = micros();
- if( !radio_receive_complete() /* !radio_ack_received( dest_cone ) */ ) // the 'if' is here to prevent the radio from going to sleep and missing the ACK
+
+ waiting_for_ack = true; //// Check for ack on next spin()
+ //// Note: ensure_rx_mode() at end of spin() accomplishes putting the radio in RX mode.
+ /*
+ if( !radio_receive_complete() ) // the 'if' is here to prevent the radio from going to sleep and missing the ACK
{
waiting_for_ack = true; //// Check for ack on next spin()
- } else // Shouldn't happen...
- {
- if( radio.ACK_RECEIVED ) message_in_queue = false;
- RA_DEBUG( "Rcvd Immed %uus\r\n", micros() -ack_start ); ////
- }
+ } else if( radio.ACK_RECEIVED ) message_in_queue = false; // Shouldn't happen...
+ */
}
} else
@@ -666,6 +668,7 @@
}
}
}
+ radio_ensure_rx_mode(); //// Make sure we don't stay in standby mode.
}
bool TA::activated(void)
--- a/TA.h Thu Feb 11 19:28:01 2016 +0000 +++ b/TA.h Fri Feb 12 21:13:14 2016 +0000 @@ -68,7 +68,8 @@ static DigitalOut buzzPin; static DigitalIn touch_1; -static class EdgeDigIn touch_2; // Reverted to original hw: Light bit 1 is top touch. +// static class EdgeDigIn touch_2; // Reverted to original hw: Light bit 1 is top touch. + static DigitalIn touch_2; // Reverted to original hw: Light bit 1 is top touch. //// // static DigitalIn touch_2; static DigitalIn touch_3;
--- a/types.h Thu Feb 11 19:28:01 2016 +0000
+++ b/types.h Fri Feb 12 21:13:14 2016 +0000
@@ -57,7 +57,7 @@
#ifdef MASTER
const static int NODE_ID = 1;
#else
-const static int NODE_ID = 3; // 99 = Assign ID from Master.
+const static int NODE_ID = 99; // 99 = Assign ID from Master.
#endif
struct Event{
