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