Andriy Makukha / Mbed 2 deprecated football_project_wo_output

Dependencies:   mbed

Fork of football_project by MZJ

Committer:
AntonLS
Date:
Tue Jan 05 13:05:48 2016 +0000
Revision:
31:a6110950f385
Parent:
30:c60b0d52b067
Child:
32:64e5d7340d82
Touch sensor rising edge ISR for better response.; Overcharge alarm more conserv.  Slave touch pwr toggle. ; Shows 101%/102% batt on plug/unplug, later gives real batt level.; Incl mbed-src to change startup code to use 32k RAM when set to BLE Nano.;

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 18:affef3a7db2a 5
elmbed 18:affef3a7db2a 6 #define NETWORKID 101 //the same on all nodes that talk to each other
elmbed 18:affef3a7db2a 7
elmbed 18:affef3a7db2a 8 #define FREQUENCY RF69_915MHZ
elmbed 18:affef3a7db2a 9
elmbed 18:affef3a7db2a 10 //#define IS_RFM69HW //NOTE: uncomment this ONLY for RFM69HW or RFM69HCW
elmbed 18:affef3a7db2a 11 #define ENCRYPT_KEY "EncryptKey123456" // use same 16byte encryption key for all devices on net
elmbed 18:affef3a7db2a 12 #define ACK_TIME 50 // max msec for ACK wait
elmbed 18:affef3a7db2a 13 #define LED 9 // Anardino miniWireless has LEDs on D9
elmbed 18:affef3a7db2a 14 #define SERIAL_BAUD 115200
elmbed 18:affef3a7db2a 15 #define VERSION "1.0"
elmbed 18:affef3a7db2a 16
elmbed 18:affef3a7db2a 17 #define MSGBUFSIZE 64 // message buffersize, but for this demo we only use:
elmbed 18:affef3a7db2a 18 // 1-byte NODEID + 4-bytes for time + 1-byte for temp in C + 2-bytes for vcc(mV)
elmbed 18:affef3a7db2a 19
elmbed 18:affef3a7db2a 20 //RFM69::RFM69(PinName PinName mosi, PinName miso, PinName sclk,slaveSelectPin, PinName int)
elmbed 23:26f27c462976 21 RFM69 radio(P0_24,P0_23,P0_25,P0_28,P0_7);
elmbed 18:affef3a7db2a 22
elmbed 23:26f27c462976 23 static bool promiscuousMode = true; // set 'true' to sniff all packets on the same network
elmbed 18:affef3a7db2a 24 static bool requestACK = false;
elmbed 18:affef3a7db2a 25
elmbed 23:26f27c462976 26 static char phone_buffer[50] = {0};
elmbed 23:26f27c462976 27 static char radio_buffer[50] = {0};
elmbed 18:affef3a7db2a 28
elmbed 23:26f27c462976 29 extern "C" void writeToPhone(char *format, ...);
elmbed 23:26f27c462976 30
elmbed 18:affef3a7db2a 31
elmbed 18:affef3a7db2a 32 void radio_init()
elmbed 18:affef3a7db2a 33 {
elmbed 23:26f27c462976 34 radio.initialize(FREQUENCY, NODE_ID, NETWORKID);
elmbed 23:26f27c462976 35 radio.encrypt(0);
elmbed 23:26f27c462976 36 radio.promiscuous(promiscuousMode);
elmbed 23:26f27c462976 37 }
elmbed 23:26f27c462976 38
elmbed 28:8e74ddc4f70f 39
elmbed 28:8e74ddc4f70f 40
elmbed 23:26f27c462976 41 void radio_send(Message *m)
elmbed 23:26f27c462976 42 {
elmbed 23:26f27c462976 43 static byte payload [6] = {0};
elmbed 23:26f27c462976 44
elmbed 23:26f27c462976 45 if (m == NULL)
elmbed 23:26f27c462976 46 {
elmbed 23:26f27c462976 47 return;
elmbed 23:26f27c462976 48 }
elmbed 23:26f27c462976 49
AntonLS 31:a6110950f385 50 writeToPhone("Sending message: %c to: %d from: %d\r\n", m->command, m->cone, NODE_ID); /// DEBUG-only message
elmbed 23:26f27c462976 51
elmbed 23:26f27c462976 52 payload[0] = (byte)m->command;
elmbed 23:26f27c462976 53 payload[4] = (byte)m->value & 255;
elmbed 23:26f27c462976 54 payload[3] = (byte)(m->value >> 8);
elmbed 23:26f27c462976 55 payload[2] = (byte)(m->value >> 16);
elmbed 23:26f27c462976 56 payload[1] = (byte)(m->value >> 24);
elmbed 23:26f27c462976 57 payload[5] = (byte)'%';
elmbed 28:8e74ddc4f70f 58
elmbed 28:8e74ddc4f70f 59 radio.send(m->cone, payload, sizeof(payload));
elmbed 18:affef3a7db2a 60 }
elmbed 18:affef3a7db2a 61
elmbed 23:26f27c462976 62 bool radio_receive_complete()
elmbed 23:26f27c462976 63 {
elmbed 23:26f27c462976 64 return radio.receiveDone();
elmbed 23:26f27c462976 65 }
elmbed 23:26f27c462976 66
elmbed 23:26f27c462976 67 bool radio_receive(Message *m)
elmbed 23:26f27c462976 68 {
elmbed 23:26f27c462976 69 if (m == NULL)
elmbed 23:26f27c462976 70 {
elmbed 23:26f27c462976 71 return false;
elmbed 23:26f27c462976 72 }
elmbed 23:26f27c462976 73
elmbed 23:26f27c462976 74 if (radio.receiveDone())
elmbed 23:26f27c462976 75 {
AntonLS 31:a6110950f385 76 writeToPhone("Received: %d bytes", radio.DATALEN); /// DEBUG-only message
elmbed 23:26f27c462976 77 if (radio.DATALEN < 6)
elmbed 23:26f27c462976 78 {
elmbed 23:26f27c462976 79 return false;
elmbed 23:26f27c462976 80 }
elmbed 23:26f27c462976 81
AntonLS 31:a6110950f385 82 writeToPhone("Got message from: %d\r\n", radio.SENDERID); /// DEBUG-only message
elmbed 23:26f27c462976 83
elmbed 23:26f27c462976 84 m->cone = radio.SENDERID;
elmbed 23:26f27c462976 85 m->command = radio.DATA[0];
elmbed 23:26f27c462976 86 m->value = radio.DATA[1];
elmbed 23:26f27c462976 87
elmbed 23:26f27c462976 88 return true;
elmbed 23:26f27c462976 89 }
elmbed 23:26f27c462976 90
elmbed 23:26f27c462976 91 return false;
elmbed 23:26f27c462976 92 }
elmbed 23:26f27c462976 93
elmbed 23:26f27c462976 94 bool radio_ack_received(int cone)
elmbed 23:26f27c462976 95 {
elmbed 23:26f27c462976 96 return radio.ACKReceived(cone);
elmbed 23:26f27c462976 97 }
elmbed 23:26f27c462976 98
elmbed 18:affef3a7db2a 99 void radio_loop()
elmbed 18:affef3a7db2a 100 {
elmbed 18:affef3a7db2a 101 static int counter = 0;
elmbed 18:affef3a7db2a 102
elmbed 18:affef3a7db2a 103 if (radio.receiveDone())
elmbed 18:affef3a7db2a 104 {
elmbed 23:26f27c462976 105 snprintf(phone_buffer, sizeof(phone_buffer), "%d.\r\n[%s]\r\n", radio.SENDERID, radio.DATA);
elmbed 18:affef3a7db2a 106 writeToPhone(phone_buffer);
elmbed 18:affef3a7db2a 107
elmbed 18:affef3a7db2a 108 if (radio.ACKRequested())
elmbed 18:affef3a7db2a 109 {
elmbed 18:affef3a7db2a 110 radio.sendACK();
elmbed 18:affef3a7db2a 111 }
elmbed 18:affef3a7db2a 112 }
elmbed 18:affef3a7db2a 113 }
elmbed 23:26f27c462976 114