1 // ********************************************************************* 2 // DPA peer-to-peer transmitter example * 3 // ********************************************************************* 4 // Copyright (c) IQRF Tech s.r.o. 5 // 6 // File: $RCSfile: Peer-to-Peer-Transmitter.c,v $ 7 // Version: $Revision: 1.12 $ 8 // Date: $Date: 2017/08/09 12:24:47 $ 9 // 10 // Revision history: 11 // 2017/03/13 Release for DPA 3.00 12 // 2015/08/05 Release for DPA 2.20 13 // 14 // ********************************************************************* 15 16 // Online DPA documentation http://www.iqrf.org/DpaTechGuide/ 17 18 // Default IQRF include (modify the path according to your setup) 19 #include "IQRF.h" 20 21 // Default DPA header (modify the path according to your setup) 22 #include "DPA.h" 23 24 // This example transmits peer-to-peer packets to CustomDpaHandler-Peer-to-Peer.c example 25 // If the RF channel is set to the secondary channel of the main network, then example shows using peer-to-peer packets without build-in DPA support 26 // !!! It is highly recommended to use additional security techniques (e.g. encryption, rolling code, checksum, CRC) against packet sniffing, spoofing and eavesdropping. 27 // !!! It is also recommended to use listen-before-talk technique to minimize the risk of RF collision that might cause the main network RF traffic to fail. 28 29 // Address of the node to receive the peer-to-peer packet (modify according to your setup) 30 #define RECEIVER_ADDRESS 1 31 32 //############################################################################################ 33 void APPLICATION() 34 //############################################################################################ 35 { 36 // Set RF mode to STD TX, use _TX_LP whet used at LP mode! 37 setRFmode( _TX_STD ); 38 39 // Use the very low RF power 40 setRFpower( 0 ); 41 42 // Infinite loop 43 for ( ;; ) 44 { 45 // Sleep till button is pressed 46 sleepWOC(); 47 if ( buttonPressed ) 48 { 49 // Check if the button is pressed for more than 0.5s 50 uns8 loop = 500 / 10; 51 do 52 { 53 // 10 ms wait 54 waitDelay( 1 ); 55 } while ( --loop != 0 && buttonPressed ); 56 57 // Prepare default PIN 58 PIN = 0; 59 60 // Was just a short (< 0.5s) button press? 61 if ( loop != 0 ) 62 { 63 // Indicate green LED 64 pulseLEDG(); 65 66 // Prepare "DPA" peer-to-peer packet 67 68 // DPA packet fields will be used 69 _DPAF = 1; 70 71 // Fill in PNUM and PCMD 72 _PNUM = PNUM_LEDG; 73 _PCMD = CMD_LED_PULSE; 74 // No DPA Data 75 _DpaDataLength = 0; 76 // DPaParams DPA field will be misused for addressing as the TX and RX field are not available at non-networking packets 77 _DpaParams = RECEIVER_ADDRESS; 78 } 79 else 80 { 81 // Indicate red LED 82 pulseLEDR(); 83 84 // Prepare pure peer-to-peer packet 85 86 // Prepare packet content 87 // Header 88 bufferRF[0] = 'P'; 89 // Address 90 bufferRF[1] = RECEIVER_ADDRESS; 91 // Packet length 92 DLEN = 2; 93 } 94 95 // Transmit the prepared packet 96 RFTXpacket(); 97 98 // Wait to allow LED pulse and to debounce button 99 waitMS( 40 ); 100 // Wait till the button is released 101 while ( buttonPressed ); 102 } 103 } 104 } 105 //############################################################################################ 106