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