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