Andriy Makukha
/
football_project_wo_output
football_project_wo_output
Fork of football_project by
Diff: main.cpp
- Revision:
- 97:2894fbc2d4f8
- Parent:
- 95:3cc3ae2e5e7f
- Child:
- 98:9241041ec253
--- a/main.cpp Thu Jun 16 05:06:49 2016 +0000 +++ b/main.cpp Thu Jun 16 06:19:49 2016 +0000 @@ -1,27 +1,12 @@ -#include <RFM69.h> #include <list> #include <DebounceIn.h> -#ifdef BLE_ENABLE - #include "ble/BLE.h" - #include "ble/services/DFUService.h" -#endif +#include "configs.h" using namespace std; Timer tmr; //Output out; -#ifdef BLE_ENABLE -BLEDevice ble; - -// Optional: Device Name, add for human read-ability -//const static char DEVICE_NAME[] = "PassiveCoach"; - -// You have up to 26 bytes of advertising data to use. -//const static uint8_t AdvData[] = {0x01,0x02,0x03,0x04,0x05}; /* Example of hex data */ -//const static uint8_t AdvData[] = {"Keep the Space!"}; /* Example of character data */ -#endif // BLE_ENABLE - /////////////////////////////////// PINS /////////////////////////////////// DebounceIn buttonTeam(BUT_TEAM); @@ -49,15 +34,6 @@ PwmOut speaker(BUZZER); // passive buzzer #endif -/////////////////////////////////// RADIO /////////////////////////////////// -#ifdef ENABLE_PIN -static RFM69 radio(RFM_MOSI, RFM_MISO, RFM_SCK, RFM_SS, RFM_IRQ, RFM_ISM_EN); -#else -static RFM69 radio(RFM_MOSI, RFM_MISO, RFM_SCK, RFM_SS, RFM_IRQ); -#endif - -static bool promiscuousMode = true; // set 'true' to sniff all packets on the same network - /////////////////////////////////// FUNCTIONS /////////////////////////////////// void beep(float period, float time, uint8_t vol) { @@ -120,7 +96,7 @@ // Generate random name on the 62 character alphabet memset(rand_name, 0x00, size); char alph[63] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; - uint32_t seed = ((ain.read_u16()+3)/17)*(radio.readTemperature(-1)+37)*((ain.read_u16()+5)/13); + uint32_t seed = ((ain.read_u16()+3)/17)*((ain.read_u16()+5)/13); srand(seed); for(int i=0;i<size-1;i++) { rand_name[i] = alph[abs(rand()) % 62]; @@ -139,73 +115,6 @@ } } -#ifdef BLE_ENABLE -void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params) -{ - //pc.printf("Disconnected \r\n"); - //pc.printf("Restart advertising \r\n"); - ble.startAdvertising(); -} - -// Optional: Restart advertising when peer disconnects -/* -void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params) -{ - BLE::Instance().gap().startAdvertising(); -} -*/ -// This function is called when the ble initialization process has failed -void onBleInitError(BLE &ble, ble_error_t error) -{ - // Avoid compiler warnings - (void) ble; - (void) error; - - // Initialization error handling should go here -} - -// Callback triggered when the ble initialization process has finished -/* -void bleInitComplete(BLE::InitializationCompleteCallbackContext *params) -{ - BLE& ble = params->ble; - ble_error_t error = params->error; - - if (error != BLE_ERROR_NONE) { - // In case of error, forward the error handling to onBleInitError - onBleInitError(ble, error); - return; - } - - // Ensure that it is the default instance of BLE - if(ble.getInstanceID() != BLE::DEFAULT_INSTANCE) { - return; - } - - // Set device name characteristic data - ble.gap().setDeviceName((const uint8_t *) DEVICE_NAME); - - // Optional: add callback for disconnection - ble.gap().onDisconnection(disconnectionCallback); - - // Sacrifice 3B of 31B to Advertising Flags - ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE ); - ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); - - // Sacrifice 2B of 31B to AdvType overhead, rest goes to AdvData array you define - ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, AdvData, sizeof(AdvData)); - - // Optional: Add name to device - ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME)); - - // Set advertising interval. Longer interval == longer battery life - ble.gap().setAdvertisingInterval(100); // 100ms - - // Start advertising - ble.gap().startAdvertising(); -} -*/ -#endif // BLE_ENABLE /////////////////////////////////// CLASSES /////////////////////////////////// @@ -308,12 +217,6 @@ int main() { -#ifdef BLE_ENABLE - // BLE initialization - ble.init(); - ble.onDisconnection(disconnectionCallback); -#endif // BLE_ENABLE - char tx_buff[100] = {0}; char rx_buff[100] = {0}; char rand_name[NAME_LEN+1] = {0}; @@ -364,50 +267,11 @@ bSpaceOld = 0; bVMOld = 0; bVLOld = 0; - -#ifdef BLE_ENABLE - // setup advertising - ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED); - ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); - ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME, - (const uint8_t *)"KeepTheSpace", sizeof("KeepTheSpace") - 1); - //ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS, - // (const uint8_t *)uart_base_uuid_rev, sizeof(uart_base_uuid)); - - // 100ms; in multiples of 0.625ms. - ble.setAdvertisingInterval(160); - - //ble.addService(uartService); - - DFUService dfu(ble); - - ble.startAdvertising(); - //pc.printf("Advertising Start \r\n"); - - /* - // GAP version - BLE& ble = BLE::Instance(BLE::DEFAULT_INSTANCE); - ble.init(bleInitComplete); // Initialize BLE baselayer - DFUService dfu( ble ); - */ -#endif // BLE_ENABLE - + // Pick node number char this_node = int(ain.read()*255+17)*int(ain.read()*255+11); // random node value //out.printf("Node: %d\r\n", this_node); - // Initialize the radio - radio.initialize(FREQUENCY, this_node, NETWORKID); -#ifdef HIGH_POWER - radio.setHighPower(true); -#endif - radio.encrypt(0); - radio.promiscuous(promiscuousMode); - if(FREQUENCY == RF69_868MHZ) - radio.setFrequency(868000000); - else if(FREQUENCY == RF69_915MHZ) - radio.setFrequency(915000000); - // Pick node name generate_name(rand_name, sizeof(rand_name)); /* @@ -487,59 +351,5 @@ last_shown = current_time; } - // Radios - if (current_time - last_send > SEND_RATE_MS) - { - // Send message - snprintf(tx_buff, sizeof(tx_buff), "N=%s,%d", rand_name, myTeam); - radio.send(EVERY_NODE, tx_buff, strlen(tx_buff)); - last_send = current_time; - //send_wait = min_wait + (rand() % SEND_RATE_MS)*SEND_DESYNC; - - //// Some debugging info I used to display - //out.clear(); - //out.printf("Sent: %s\r\n", tx_buff); - //uint8_t tempC = radio.readTemperature(-1); // -1 = user cal factor, adjust for correct ambient - //uint8_t gain = (radio.readReg(REG_LNA) & 0b111000)>>3; // LNA Current Gain - //uint32_t freq = radio.getFrequency(); - //out.printf("T: %d, G: %d\r\n", tempC, gain); - //if(freq!=868000000) out.printf("Freq: %d\r\n", freq); - - //beep(NOTE_A3, 0.05, volume); - } - - if (radio.receiveDone()) - { - memset(rx_buff, 0x00, sizeof(rx_buff)); - memcpy(rx_buff, (char*)radio.DATA, radio.DATALEN > sizeof(rx_buff)-1 ? sizeof(rx_buff)-1 : radio.DATALEN); - - if(rx_buff[0]=='N' && rx_buff[1]=='=') { - memcpy(other_name, rx_buff+2, NAME_LEN); - other_name[5] = 0x00; - if(sizeof(rx_buff)>8 && rx_buff[7]==',') { - otherTeam = rx_buff[8]-'0'; - } else otherTeam = 1; - players.update(other_name, otherTeam, radio.RSSI, tmr.read_ms()); - - //uint8_t gain = (radio.readReg(REG_LNA) & 0b111000)>>3; // LNA Current Gain - //out.clear(); - //out.printf("Other: %s\r\n", other_name); - //out.printf("RSSI: %d, G: %d\r\n", radio.RSSI, gain); - - //beep(NOTE_A5, 0.5, volume); - } else { // received unknown signal - uint8_t gain = (radio.readReg(REG_LNA) & 0b111000)>>3; // LNA Current Gain - /* - out.clear(); - out.printf("Got: %s\r\n", rx_buff); - out.printf("RSSI: %d, G: %d\r\n", radio.RSSI, gain); - out.sleep(2.0); - */ - } - } - -#ifdef BLE_ENABLE -// ble.waitForEvent(); -#endif // BLE_ENABLE } } \ No newline at end of file