1 // ********************************************************************* 2 // Custom DPA Handler code template * 3 // ********************************************************************* 4 // Copyright (c) MICRORISC s.r.o. 5 // 6 // File: $RCSfile: CustomDpaHandler-Template-Coordinator.c,v $ 7 // Version: $Revision: 1.14 $ 8 // Date: $Date: 2022/02/25 09:41:25 $ 9 // 10 // Revision history: 11 // 2022/02/24 Release for DPA 4.17 12 // 2021/08/20 Release for DPA 4.16 13 // 2020/09/03 Release for DPA 4.15 14 // 2020/02/27 Release for DPA 4.13 15 // 2019/01/10 Release for DPA 4.00 16 // 2017/08/14 Release for DPA 3.01 17 // 2017/03/13 Release for DPA 3.00 18 // 2015/08/05 Release for DPA 2.20 19 // 2014/10/31 Release for DPA 2.10 20 // 2014/04/30 Release for DPA 2.00 21 // 22 // ********************************************************************* 23 24 // Online DPA documentation https://doc.iqrf.org/DpaTechGuide/ 25 26 // Default IQRF include (modify the path according to your setup) 27 #include "IQRF.h" 28 29 // Implement Custom DPA Handler for Coordinator 30 #define COORDINATOR_CUSTOM_HANDLER 31 32 // Default DPA header (modify the path according to your setup) 33 #include "DPA.h" 34 // Default Custom DPA Handler header (modify the path according to your setup) 35 #include "DPAcustomHandler.h" 36 37 // Uncomment the following includes if the respective component is needed 38 // IQRF standards header (modify the path according to your setup) 39 //#include "IQRFstandard.h" 40 //#include "IQRF_HWPID.h" 41 // I2C Master library 42 //#include "NFC.c" 43 44 //############################################################################################ 45 46 // Place for global variables shared among CustomDpaHandler() and other function, otherwise local [static] variables are recommended 47 // example: uns8 globalCounter; 48 49 // Must be the 1st defined function in the source code in order to be placed at the correct FLASH location! 50 //############################################################################################ 51 // https://doc.iqrf.org/DpaTechGuide/pages/custom-dpa-handler.html 52 bit CustomDpaHandler() 53 //############################################################################################ 54 { 55 // Handler presence mark 56 clrwdt(); 57 58 // Place for local static variables used only within CustomDpaHandler() among more events 59 // example: static bit interruptOccured; 60 61 // Detect DPA event to handle (unused event handlers can be commented out or even deleted) 62 switch ( GetDpaEvent() ) 63 { 64 // ------------------------------------------------- 65 case DpaEvent_Idle: 66 // Do a quick background work when RF packet is not received 67 // https://doc.iqrf.org/DpaTechGuide/pages/idle.html 68 break; 69 70 // ------------------------------------------------- 71 case DpaEvent_Reset: 72 // Called after module is reset 73 // https://doc.iqrf.org/DpaTechGuide/pages/ResetEvent.html 74 75 //goto DpaHandleReturnTRUE; // return TRUE only if you handle node bonding/unbonding 76 break; 77 78 // ------------------------------------------------- 79 case DpaEvent_Init: 80 // Do a one time initialization before main loop starts 81 // https://doc.iqrf.org/DpaTechGuide/pages/init.html 82 break; 83 84 // ------------------------------------------------- 85 case DpaEvent_ReceiveDpaRequest: 86 // Called after DPA request was received 87 // https://doc.iqrf.org/DpaTechGuide/pages/receivedparequest.html 88 89 //goto DpaHandleReturnTRUE; // return TRUE to skip default processing 90 break; 91 92 // ------------------------------------------------- 93 case DpaEvent_BeforeSendingDpaResponse: 94 // Called before sending DPA response back to originator of DPA response 95 // https://doc.iqrf.org/DpaTechGuide/pages/beforesendingdparesponse.html 96 break; 97 98 // ------------------------------------------------- 99 case DpaEvent_Notification: 100 // Called after DPA request was processed and after DPA response was sent 101 // https://doc.iqrf.org/DpaTechGuide/pages/notification.html 102 break; 103 104 // ------------------------------------------------- 105 case DpaEvent_AfterRouting: 106 // Called after Notification and after routing of the DPA response was finished 107 // https://doc.iqrf.org/DpaTechGuide/pages/afterrouting.html 108 break; 109 110 // ------------------------------------------------- 111 case DpaEvent_DisableInterrupts: 112 // Called when device needs all hardware interrupts to be disabled (before Reset, Restart, LoadCode, Remove bond and run RFPGM) 113 // https://doc.iqrf.org/DpaTechGuide/pages/eventDisableInterrupts.html 114 break; 115 116 // ------------------------------------------------- 117 case DpaEvent_ReceiveDpaResponse: 118 // Called after DPA response was received at coordinator 119 // https://doc.iqrf.org/DpaTechGuide/pages/receivedparesponse.html 120 121 //goto DpaHandleReturnTRUE; // return TRUE to skip default processing 122 break; 123 124 // ------------------------------------------------- 125 case DpaEvent_IFaceReceive: 126 // Called after DPA request from interface master was received at coordinator 127 // https://doc.iqrf.org/DpaTechGuide/pages/ifacereceive.html 128 129 //goto DpaHandleReturnTRUE; // return TRUE to skip default processing 130 break; 131 132 // ------------------------------------------------- 133 case DpaEvent_PeerToPeer: 134 // Called when peer-to-peer (non-networking) packet is received 135 // https://doc.iqrf.org/DpaTechGuide/pages/peertopeer.html 136 break; 137 138 // ------------------------------------------------- 139 case DpaEvent_UserDpaValue: 140 // Called when DPA is required to return User defined DPA value in the response 141 // https://doc.iqrf.org/DpaTechGuide/pages/userdpavalue.html 142 break; 143 144 // ------------------------------------------------- 145 case DpaEvent_DpaRequest: 146 // Called to interpret DPA request for peripherals 147 // https://doc.iqrf.org/DpaTechGuide/pages/EventDpaRequest.html 148 IfDpaEnumPeripherals_Else_PeripheralInfo_Else_PeripheralRequest() 149 { 150 // ------------------------------------------------- 151 // Peripheral enumeration 152 // https://doc.iqrf.org/DpaTechGuide/pages/enumerate-peripherals.html 153 154 _DpaMessage.EnumPeripheralsAnswer.UserPerNr |= 0; // ? 155 // FlagUserPer( _DpaMessage.EnumPeripheralsAnswer.UserPer, PNUM_USER + 0 ); // ? 156 _DpaMessage.EnumPeripheralsAnswer.HWPID |= 0x000F; // ???? 157 _DpaMessage.EnumPeripheralsAnswer.HWPIDver |= 0; // ???? 158 159 DpaHandleReturnTRUE: 160 return TRUE; 161 } 162 else 163 { 164 // ------------------------------------------------- 165 // Get information about peripheral 166 // https://doc.iqrf.org/DpaTechGuide/pages/get-peripheral-info.html 167 168 if ( _PNUM == PNUM_USER + 0 ) // ? 169 { 170 _DpaMessage.PeripheralInfoAnswer.PerT = 0; // PERIPHERAL_TYPE_? 171 _DpaMessage.PeripheralInfoAnswer.PerTE = 0; // PERIPHERAL_TYPE_EXTENDED_? 172 _DpaMessage.PeripheralInfoAnswer.Par1 = 0; // ? 173 _DpaMessage.PeripheralInfoAnswer.Par2 = 0; // ? 174 goto DpaHandleReturnTRUE; 175 } 176 177 break; 178 } 179 180 // ------------------------------------------------- 181 // Handle peripheral command 182 // https://doc.iqrf.org/DpaTechGuide/pages/handle-peripheral-request.html 183 184 if ( _PNUM == PNUM_USER + 0 ) // ? 185 { 186 if ( _PCMD == 0 ) // ???? 187 { 188 goto DpaHandleReturnTRUE; 189 } 190 } 191 192 break; 193 } 194 195 DpaHandleReturnFALSE: 196 return FALSE; 197 } 198 199 //############################################################################################ 200 // Uncomment the following includes if the respective component is needed 201 //#include "NFC.c" 202 203 // Default Custom DPA Handler header; 2nd include implementing a Code bumper to detect too long code of the Custom DPA Handler (modify the path according to your setup) 204 #include "DPAcustomHandler.h" 205 //############################################################################################