Andriy Makukha / Mbed 2 deprecated football_project_wo_output

Dependencies:   mbed

Fork of football_project by MZJ

Committer:
AntonLS
Date:
Thu Feb 11 19:28:01 2016 +0000
Revision:
68:0c96bb3d73a7
Parent:
67:5650f461722a
Child:
69:a3295b74209e
Reduce radio-to-sleep possibility.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
elmbed 18:affef3a7db2a 1 #include <RFM69.h>
elmbed 18:affef3a7db2a 2 #include <SPI.h>
elmbed 23:26f27c462976 3 #include "types.h"
elmbed 23:26f27c462976 4 #include "TA.h"
elmbed 62:9b34dc1b265d 5 #include "DataStore.hh"
AntonLS 67:5650f461722a 6 #include "Radio.hh"
elmbed 18:affef3a7db2a 7
elmbed 44:4ad6133987ed 8 #define RADIO_STARTUP_ID 99
elmbed 18:affef3a7db2a 9 #define NETWORKID 101 //the same on all nodes that talk to each other
elmbed 18:affef3a7db2a 10
elmbed 18:affef3a7db2a 11 #define FREQUENCY RF69_915MHZ
elmbed 18:affef3a7db2a 12
elmbed 18:affef3a7db2a 13 //#define IS_RFM69HW //NOTE: uncomment this ONLY for RFM69HW or RFM69HCW
elmbed 18:affef3a7db2a 14 #define ENCRYPT_KEY "EncryptKey123456" // use same 16byte encryption key for all devices on net
elmbed 18:affef3a7db2a 15 #define LED 9 // Anardino miniWireless has LEDs on D9
elmbed 18:affef3a7db2a 16 #define SERIAL_BAUD 115200
elmbed 18:affef3a7db2a 17 #define VERSION "1.0"
elmbed 18:affef3a7db2a 18
elmbed 18:affef3a7db2a 19 #define MSGBUFSIZE 64 // message buffersize, but for this demo we only use:
elmbed 18:affef3a7db2a 20 // 1-byte NODEID + 4-bytes for time + 1-byte for temp in C + 2-bytes for vcc(mV)
elmbed 18:affef3a7db2a 21
elmbed 18:affef3a7db2a 22 //RFM69::RFM69(PinName PinName mosi, PinName miso, PinName sclk,slaveSelectPin, PinName int)
elmbed 23:26f27c462976 23 RFM69 radio(P0_24,P0_23,P0_25,P0_28,P0_7);
elmbed 18:affef3a7db2a 24
elmbed 23:26f27c462976 25 static bool promiscuousMode = true; // set 'true' to sniff all packets on the same network
elmbed 44:4ad6133987ed 26 extern unsigned long millis();
elmbed 44:4ad6133987ed 27
elmbed 62:9b34dc1b265d 28 extern bool is_master;
elmbed 18:affef3a7db2a 29
elmbed 44:4ad6133987ed 30 struct node_id_mapping
elmbed 44:4ad6133987ed 31 {
elmbed 44:4ad6133987ed 32 int mac;
elmbed 44:4ad6133987ed 33 int node_id;
elmbed 44:4ad6133987ed 34 };
elmbed 18:affef3a7db2a 35
elmbed 44:4ad6133987ed 36 struct extended_message
elmbed 44:4ad6133987ed 37 {
elmbed 44:4ad6133987ed 38 Message m;
elmbed 44:4ad6133987ed 39 int mac;
elmbed 44:4ad6133987ed 40 };
elmbed 23:26f27c462976 41
AntonLS 67:5650f461722a 42 struct prev_message // maybe TODO we could have an array of NUM_CONES of these.
AntonLS 67:5650f461722a 43 {
AntonLS 67:5650f461722a 44 Message m;
AntonLS 67:5650f461722a 45 uint8_t msgid;
AntonLS 67:5650f461722a 46 };
AntonLS 67:5650f461722a 47
AntonLS 65:7addf8506bdb 48 /*
elmbed 56:dccf9b22d594 49 int get_node_id()
elmbed 56:dccf9b22d594 50 {
elmbed 56:dccf9b22d594 51 return my_node_id == RADIO_STARTUP_ID ? 0 : my_node_id;
elmbed 56:dccf9b22d594 52 }
AntonLS 65:7addf8506bdb 53 */
elmbed 56:dccf9b22d594 54
AntonLS 67:5650f461722a 55 static node_id_mapping nodes[NUM_CONES] = {0};
elmbed 44:4ad6133987ed 56 static int node_idx = 0;
elmbed 44:4ad6133987ed 57 static int my_mac = 0;
elmbed 18:affef3a7db2a 58
elmbed 18:affef3a7db2a 59 void radio_init()
elmbed 18:affef3a7db2a 60 {
elmbed 62:9b34dc1b265d 61 radio.initialize(FREQUENCY, datastore_node_id(), NETWORKID);
elmbed 23:26f27c462976 62 radio.encrypt(0);
elmbed 23:26f27c462976 63 radio.promiscuous(promiscuousMode);
elmbed 23:26f27c462976 64 }
elmbed 23:26f27c462976 65
elmbed 56:dccf9b22d594 66 /* Gets the node ID which is associated with the
elmbed 56:dccf9b22d594 67 * given mac. If no ID has been given then zero
elmbed 56:dccf9b22d594 68 * is returned.
elmbed 56:dccf9b22d594 69 *
elmbed 56:dccf9b22d594 70 * @param mac - the mac address if the cone
elmbed 56:dccf9b22d594 71 * @returns ID if found else zero
elmbed 56:dccf9b22d594 72 */
elmbed 44:4ad6133987ed 73 static int get_node_id(int mac)
elmbed 44:4ad6133987ed 74 {
elmbed 44:4ad6133987ed 75 for (int i = 0; i < node_idx; ++i)
elmbed 44:4ad6133987ed 76 {
elmbed 44:4ad6133987ed 77 if (nodes[i].mac == mac)
elmbed 44:4ad6133987ed 78 {
elmbed 44:4ad6133987ed 79 return nodes[i].node_id;
elmbed 44:4ad6133987ed 80 }
elmbed 44:4ad6133987ed 81 }
elmbed 44:4ad6133987ed 82
elmbed 44:4ad6133987ed 83 return 0;
elmbed 44:4ad6133987ed 84 }
elmbed 28:8e74ddc4f70f 85
elmbed 56:dccf9b22d594 86 /* Process a radio startup message from the master.
elmbed 56:dccf9b22d594 87 *
elmbed 56:dccf9b22d594 88 * @param em - the message from the master
elmbed 56:dccf9b22d594 89 */
elmbed 44:4ad6133987ed 90 static void slave_process(extended_message *em)
elmbed 44:4ad6133987ed 91 {
elmbed 44:4ad6133987ed 92 if (em->m.command == 'R')
elmbed 44:4ad6133987ed 93 {
elmbed 44:4ad6133987ed 94 // We have been given a node id
elmbed 62:9b34dc1b265d 95 datastore_set_node_id(em->m.value);
elmbed 44:4ad6133987ed 96
elmbed 62:9b34dc1b265d 97 if( Dbg ) writeToPhone("NID: %d\r\n", datastore_node_id());
elmbed 44:4ad6133987ed 98
elmbed 44:4ad6133987ed 99 // Now reset the radio :)
AntonLS 67:5650f461722a 100 /// promiscuousMode = false;
elmbed 44:4ad6133987ed 101 radio_init();
elmbed 44:4ad6133987ed 102 }
elmbed 44:4ad6133987ed 103 }
elmbed 44:4ad6133987ed 104
elmbed 56:dccf9b22d594 105 /* Process a radio startup message from a slave.
elmbed 56:dccf9b22d594 106 *
elmbed 56:dccf9b22d594 107 * @param m - the message from the slave
elmbed 56:dccf9b22d594 108 */
elmbed 44:4ad6133987ed 109 static void master_process(Message *m)
elmbed 44:4ad6133987ed 110 {
elmbed 44:4ad6133987ed 111 byte payload[10] = {0};
elmbed 44:4ad6133987ed 112 int node_id = 0;
elmbed 44:4ad6133987ed 113
elmbed 44:4ad6133987ed 114 if (m->command == 'S')
elmbed 44:4ad6133987ed 115 {
elmbed 44:4ad6133987ed 116 // Message from a cone requesting an ID.
elmbed 44:4ad6133987ed 117 // The payload should be part of the MAC address
elmbed 44:4ad6133987ed 118 node_id = 0;
elmbed 44:4ad6133987ed 119
elmbed 44:4ad6133987ed 120 if (node_idx == 0)
elmbed 44:4ad6133987ed 121 {
elmbed 44:4ad6133987ed 122 node_id = 2;
elmbed 44:4ad6133987ed 123 }
elmbed 44:4ad6133987ed 124 else
elmbed 44:4ad6133987ed 125 {
elmbed 44:4ad6133987ed 126 node_id = nodes[node_idx-1].node_id + 1;
elmbed 44:4ad6133987ed 127 }
elmbed 44:4ad6133987ed 128
elmbed 44:4ad6133987ed 129 int node_found = get_node_id(m->value);
elmbed 44:4ad6133987ed 130
elmbed 44:4ad6133987ed 131 if (node_found == 0)
elmbed 44:4ad6133987ed 132 {
elmbed 44:4ad6133987ed 133 nodes[node_idx].node_id = node_id;
elmbed 44:4ad6133987ed 134 nodes[node_idx++].mac = m->value;
elmbed 44:4ad6133987ed 135 }
elmbed 44:4ad6133987ed 136 else
elmbed 44:4ad6133987ed 137 {
elmbed 44:4ad6133987ed 138 node_id = node_found;
elmbed 44:4ad6133987ed 139 }
elmbed 44:4ad6133987ed 140
AntonLS 67:5650f461722a 141 // Send the cone its ID
elmbed 44:4ad6133987ed 142 extended_message em;
elmbed 44:4ad6133987ed 143 em.m.cone = 99;
elmbed 44:4ad6133987ed 144 em.m.command = 'R';
elmbed 44:4ad6133987ed 145 em.m.value = node_id;
elmbed 44:4ad6133987ed 146 em.mac = m->value;
elmbed 44:4ad6133987ed 147
elmbed 44:4ad6133987ed 148 payload[0] = (byte)em.m.command;
elmbed 44:4ad6133987ed 149
elmbed 44:4ad6133987ed 150 payload[4] = (byte)em.m.value & 255;
elmbed 44:4ad6133987ed 151 payload[3] = (byte)(em.m.value >> 8);
elmbed 44:4ad6133987ed 152 payload[2] = (byte)(em.m.value >> 16);
elmbed 44:4ad6133987ed 153 payload[1] = (byte)(em.m.value >> 24);
elmbed 44:4ad6133987ed 154
elmbed 44:4ad6133987ed 155 payload[8] = (byte)em.mac & 255;
elmbed 44:4ad6133987ed 156 payload[7] = (byte)(em.mac >> 8);
elmbed 44:4ad6133987ed 157 payload[6] = (byte)(em.mac >> 16);
elmbed 44:4ad6133987ed 158 payload[5] = (byte)(em.mac >> 24);
AntonLS 67:5650f461722a 159
AntonLS 67:5650f461722a 160 radio.send( em.m.cone, payload, sizeof(payload), false ); //// NO ACK req.
AntonLS 67:5650f461722a 161 /// radio.send(em.m.cone, payload, sizeof(payload));
elmbed 44:4ad6133987ed 162
AntonLS 52:060fdec99780 163 if( Dbg ) writeToPhone("SND: %d %d 0x%x\r\n", em.m.cone, node_id, em.mac);
elmbed 44:4ad6133987ed 164 }
elmbed 44:4ad6133987ed 165 }
elmbed 28:8e74ddc4f70f 166
AntonLS 67:5650f461722a 167 void radio_send( Message *m, bool requestACK ) ////
elmbed 23:26f27c462976 168 {
elmbed 23:26f27c462976 169 static byte payload [6] = {0};
elmbed 23:26f27c462976 170
elmbed 23:26f27c462976 171 if (m == NULL)
elmbed 23:26f27c462976 172 {
elmbed 23:26f27c462976 173 return;
elmbed 23:26f27c462976 174 }
AntonLS 67:5650f461722a 175
AntonLS 52:060fdec99780 176 //if( Dbg ) writeToPhone("SM: %c to: %d frm: %d (%d)\r\n", m->command, m->cone, NODE_ID, m->value);
AntonLS 52:060fdec99780 177
elmbed 23:26f27c462976 178 payload[0] = (byte)m->command;
elmbed 44:4ad6133987ed 179
elmbed 23:26f27c462976 180 payload[4] = (byte)m->value & 255;
elmbed 23:26f27c462976 181 payload[3] = (byte)(m->value >> 8);
elmbed 23:26f27c462976 182 payload[2] = (byte)(m->value >> 16);
elmbed 23:26f27c462976 183 payload[1] = (byte)(m->value >> 24);
AntonLS 67:5650f461722a 184
AntonLS 67:5650f461722a 185 payload[5] = (byte)++TA::msg_id; //// Msg ID, was: = (byte)'%';
AntonLS 67:5650f461722a 186
AntonLS 67:5650f461722a 187 radio.send( m->cone, payload, sizeof(payload), requestACK ); ////
AntonLS 68:0c96bb3d73a7 188 radio_receive_complete(); //// Prevent radio from going to sleep.
AntonLS 67:5650f461722a 189 }
AntonLS 67:5650f461722a 190
AntonLS 67:5650f461722a 191 void stompage_check()
AntonLS 67:5650f461722a 192 {
AntonLS 67:5650f461722a 193 if( --radio.INCNT != 0 )
AntonLS 67:5650f461722a 194 {
AntonLS 67:5650f461722a 195 writeToPhone( "LOST MSGS: %d\r\n", radio.INCNT );
AntonLS 67:5650f461722a 196 radio.INCNT = 0;
AntonLS 67:5650f461722a 197 }
elmbed 18:affef3a7db2a 198 }
elmbed 18:affef3a7db2a 199
elmbed 23:26f27c462976 200 bool radio_receive_complete()
elmbed 23:26f27c462976 201 {
elmbed 23:26f27c462976 202 return radio.receiveDone();
elmbed 23:26f27c462976 203 }
elmbed 23:26f27c462976 204
elmbed 23:26f27c462976 205 bool radio_receive(Message *m)
elmbed 23:26f27c462976 206 {
AntonLS 67:5650f461722a 207 bool retval = false;
AntonLS 67:5650f461722a 208
AntonLS 67:5650f461722a 209 //// For msg id feature...
AntonLS 67:5650f461722a 210 static prev_message mPrev;
AntonLS 67:5650f461722a 211 static long lastMsgAt = millis();
AntonLS 67:5650f461722a 212
elmbed 44:4ad6133987ed 213 Message lm;
elmbed 44:4ad6133987ed 214 extended_message em;
AntonLS 67:5650f461722a 215
AntonLS 67:5650f461722a 216 do
elmbed 23:26f27c462976 217 {
AntonLS 67:5650f461722a 218 if( m == NULL ) break;
AntonLS 67:5650f461722a 219
AntonLS 67:5650f461722a 220 if (radio.receiveDone())
AntonLS 67:5650f461722a 221 {
AntonLS 67:5650f461722a 222 if( radio.TARGETID == datastore_node_id() ) //// Check for stompage...
AntonLS 67:5650f461722a 223 {
AntonLS 67:5650f461722a 224 stompage_check();
AntonLS 67:5650f461722a 225
AntonLS 67:5650f461722a 226 if( radio.ACK_RECEIVED )
AntonLS 67:5650f461722a 227 {
AntonLS 67:5650f461722a 228 // We've received an ACK between retries.
AntonLS 67:5650f461722a 229 retval = true;
AntonLS 67:5650f461722a 230 break;
AntonLS 67:5650f461722a 231 }
AntonLS 67:5650f461722a 232 }
AntonLS 67:5650f461722a 233 if( !get_crc_ok() ) // CRC error will be rechecked/sent from caller.
AntonLS 67:5650f461722a 234 {
AntonLS 67:5650f461722a 235 retval = true;
AntonLS 67:5650f461722a 236 break;
AntonLS 67:5650f461722a 237 }
AntonLS 67:5650f461722a 238 if( radio.DATALEN < 6 )
AntonLS 67:5650f461722a 239 {
AntonLS 67:5650f461722a 240 RA_DEBUG( "Warn: Short packet\r\n" );
AntonLS 67:5650f461722a 241 RA_DEBUG( "Warn: Data len %d\r\n", radio.DATALEN );
AntonLS 67:5650f461722a 242 RA_DEBUG( "Warn: Cmd %c, Frm %d\r\n", radio.DATA[0], radio.SENDERID );
AntonLS 67:5650f461722a 243 break;
AntonLS 67:5650f461722a 244 }
AntonLS 67:5650f461722a 245
AntonLS 67:5650f461722a 246 lm.cone = radio.SENDERID;
AntonLS 67:5650f461722a 247 lm.command = radio.DATA[0];
AntonLS 67:5650f461722a 248
AntonLS 67:5650f461722a 249 lm.value = ((int)radio.DATA[1] << 24);
AntonLS 67:5650f461722a 250 lm.value |= ((int)radio.DATA[2] << 16);
AntonLS 67:5650f461722a 251 lm.value |= (((int)radio.DATA[3]) << 8);
AntonLS 67:5650f461722a 252 lm.value |= (radio.DATA[4]);
AntonLS 67:5650f461722a 253
AntonLS 67:5650f461722a 254 if (is_master && lm.command == 'S')
AntonLS 67:5650f461722a 255 {
AntonLS 67:5650f461722a 256 // Don't pass on radio startup messages
AntonLS 67:5650f461722a 257 master_process(&lm);
AntonLS 67:5650f461722a 258 break;
AntonLS 67:5650f461722a 259 }
AntonLS 67:5650f461722a 260 else if (!is_master && (NODE_ID == 99) && radio.TARGETID == RADIO_STARTUP_ID) //// NODE_ID check allows not using auto node IDs
AntonLS 67:5650f461722a 261 {
AntonLS 67:5650f461722a 262 em.mac = (int)radio.DATA[8] & 0xff;
AntonLS 67:5650f461722a 263 em.mac |= (int)radio.DATA[7] << 8;
AntonLS 67:5650f461722a 264 em.mac |= (int)radio.DATA[6] << 16;
AntonLS 67:5650f461722a 265 em.mac |= (int)radio.DATA[5] << 24;
elmbed 44:4ad6133987ed 266
AntonLS 67:5650f461722a 267 if( Dbg ) writeToPhone("RP: 0x%x\r\n", em.mac);
elmbed 44:4ad6133987ed 268
AntonLS 67:5650f461722a 269 if (em.mac != my_mac)
AntonLS 67:5650f461722a 270 {
AntonLS 67:5650f461722a 271 if( Dbg ) writeToPhone("DM 0x%x\r\n", em.mac);
AntonLS 67:5650f461722a 272 break; // This message was meant for someone else
AntonLS 67:5650f461722a 273 }
elmbed 44:4ad6133987ed 274
AntonLS 67:5650f461722a 275 memcpy(&em.m, &lm, sizeof(Message));
AntonLS 67:5650f461722a 276 slave_process(&em);
AntonLS 67:5650f461722a 277 }
AntonLS 67:5650f461722a 278 else if (radio.TARGETID == datastore_node_id())
AntonLS 67:5650f461722a 279 {
AntonLS 67:5650f461722a 280 memcpy(m, &lm, sizeof(Message));
AntonLS 67:5650f461722a 281
AntonLS 67:5650f461722a 282 //// Check if sender missed an ACK (Got duplicate of last msg, so ignore dup.)
AntonLS 67:5650f461722a 283 if( (millis() -lastMsgAt < 100) && //// Only consider as dup if w/in 100ms of prev.
AntonLS 67:5650f461722a 284 (mPrev.m.cone == m->cone) &&
AntonLS 67:5650f461722a 285 (mPrev.msgid == radio.DATA[5]) )
AntonLS 67:5650f461722a 286 { //// ASS-U-ME [for now] last msg is from same cone.
AntonLS 67:5650f461722a 287 RA_DEBUG( "Ignored dup cmd\r\n" );
AntonLS 67:5650f461722a 288 radio_send_ack();
AntonLS 67:5650f461722a 289 break;
AntonLS 67:5650f461722a 290 }
AntonLS 32:64e5d7340d82 291
AntonLS 67:5650f461722a 292 memcpy( &mPrev.m, m, sizeof( Message ) ); ////
AntonLS 67:5650f461722a 293 mPrev.msgid = radio.DATA[5]; ////
AntonLS 67:5650f461722a 294 lastMsgAt = millis(); ////
AntonLS 67:5650f461722a 295
AntonLS 67:5650f461722a 296 if( Dbg ) writeToPhone("GM: %d %c %d\r\n", radio.SENDERID, m->command, m->value);
AntonLS 67:5650f461722a 297 retval = true;
AntonLS 67:5650f461722a 298 }
AntonLS 67:5650f461722a 299 }
AntonLS 67:5650f461722a 300
AntonLS 67:5650f461722a 301 } while( false );
AntonLS 67:5650f461722a 302
AntonLS 67:5650f461722a 303 if( retval )
AntonLS 67:5650f461722a 304 {
AntonLS 67:5650f461722a 305 if( get_crc_ok() )
AntonLS 67:5650f461722a 306 RA_DEBUG( "M: %c %d r:%d\r\n", m->command, m->value, get_rssi() );
AntonLS 67:5650f461722a 307 if( get_fifo_ov() )
AntonLS 67:5650f461722a 308 RA_DEBUG( "Radio FIFO Overflow\r\n" );
elmbed 23:26f27c462976 309 }
AntonLS 67:5650f461722a 310
AntonLS 67:5650f461722a 311 return retval;
elmbed 23:26f27c462976 312 }
elmbed 23:26f27c462976 313
AntonLS 67:5650f461722a 314 void radio_send_ack() ////
AntonLS 67:5650f461722a 315 {
AntonLS 67:5650f461722a 316 radio.sendACK( "K", 1 );
AntonLS 68:0c96bb3d73a7 317 radio_receive_complete(); //// Prevent radio from going to sleep.
AntonLS 67:5650f461722a 318 }
AntonLS 67:5650f461722a 319
AntonLS 67:5650f461722a 320 bool radio_ack_received( int cone )
elmbed 23:26f27c462976 321 {
AntonLS 67:5650f461722a 322 bool retval = radio.ACKReceived(cone);
AntonLS 67:5650f461722a 323
AntonLS 67:5650f461722a 324 if( retval && (radio.TARGETID == datastore_node_id()) )
AntonLS 67:5650f461722a 325 {
AntonLS 67:5650f461722a 326 stompage_check();
AntonLS 67:5650f461722a 327 }
AntonLS 67:5650f461722a 328
AntonLS 67:5650f461722a 329 return retval;
elmbed 23:26f27c462976 330 }
elmbed 23:26f27c462976 331
elmbed 56:dccf9b22d594 332 /* This is only needed for the slave cones, the master
elmbed 56:dccf9b22d594 333 * cone will just return.
elmbed 56:dccf9b22d594 334 *
elmbed 56:dccf9b22d594 335 * If the slave cone doesn't have a valid node ID send out
elmbed 56:dccf9b22d594 336 * the node ID request message to the master cone.
elmbed 56:dccf9b22d594 337 *
elmbed 56:dccf9b22d594 338 * @param mac - the mac address for this cone (currently the first two bytes)
elmbed 56:dccf9b22d594 339 */
elmbed 44:4ad6133987ed 340 void radio_loop(int mac)
elmbed 18:affef3a7db2a 341 {
elmbed 44:4ad6133987ed 342 static unsigned long last_send = 0L;
elmbed 44:4ad6133987ed 343 unsigned long current = millis();
elmbed 44:4ad6133987ed 344 Message m;
elmbed 44:4ad6133987ed 345
elmbed 44:4ad6133987ed 346 if (my_mac == 0)
elmbed 44:4ad6133987ed 347 {
AntonLS 67:5650f461722a 348 my_mac = mac;
elmbed 44:4ad6133987ed 349 }
elmbed 44:4ad6133987ed 350
elmbed 44:4ad6133987ed 351 if (is_master)
elmbed 44:4ad6133987ed 352 {
elmbed 44:4ad6133987ed 353 return; // Only needed for slave cones
elmbed 44:4ad6133987ed 354 }
AntonLS 67:5650f461722a 355
elmbed 62:9b34dc1b265d 356 if (datastore_node_id() != RADIO_STARTUP_ID && current - last_send > 1000L)
elmbed 44:4ad6133987ed 357 {
elmbed 62:9b34dc1b265d 358 if( Dbg ) writeToPhone("NID: %d\r\n", datastore_node_id());
elmbed 44:4ad6133987ed 359 last_send = current;
elmbed 44:4ad6133987ed 360 }
elmbed 44:4ad6133987ed 361
elmbed 44:4ad6133987ed 362 // Send out an i'm here message
elmbed 62:9b34dc1b265d 363 if (datastore_node_id() != RADIO_STARTUP_ID || current - last_send < 1000L)
elmbed 44:4ad6133987ed 364 {
elmbed 44:4ad6133987ed 365 return;
elmbed 44:4ad6133987ed 366 }
elmbed 44:4ad6133987ed 367
elmbed 44:4ad6133987ed 368 m.command = 'S';
elmbed 44:4ad6133987ed 369 m.cone = 1;
elmbed 44:4ad6133987ed 370 m.value = my_mac;
elmbed 44:4ad6133987ed 371
AntonLS 52:060fdec99780 372 if( Dbg ) writeToPhone("SNM\r\n");
elmbed 44:4ad6133987ed 373
elmbed 44:4ad6133987ed 374 last_send = current;
elmbed 44:4ad6133987ed 375
AntonLS 67:5650f461722a 376 radio_send( &m, false ); ////
AntonLS 67:5650f461722a 377 /// radio_send(&m);
AntonLS 67:5650f461722a 378 }
AntonLS 67:5650f461722a 379
AntonLS 67:5650f461722a 380
AntonLS 67:5650f461722a 381
AntonLS 67:5650f461722a 382 int16_t get_rssi()
AntonLS 67:5650f461722a 383 {
AntonLS 67:5650f461722a 384 return radio.RSSI;
elmbed 18:affef3a7db2a 385 }
elmbed 23:26f27c462976 386
AntonLS 67:5650f461722a 387 bool get_crc_ok()
AntonLS 67:5650f461722a 388 {
AntonLS 67:5650f461722a 389 return radio.CRCOK;
AntonLS 67:5650f461722a 390 }
AntonLS 67:5650f461722a 391
AntonLS 67:5650f461722a 392 bool get_fifo_ov()
AntonLS 67:5650f461722a 393 {
AntonLS 67:5650f461722a 394 return radio.FIFOV;
AntonLS 67:5650f461722a 395 }
AntonLS 67:5650f461722a 396
AntonLS 67:5650f461722a 397 // for debugging
AntonLS 67:5650f461722a 398 void read_all_regs()
AntonLS 67:5650f461722a 399 {
AntonLS 67:5650f461722a 400 radio.readAllRegs();
AntonLS 67:5650f461722a 401 }
AntonLS 67:5650f461722a 402