sampleapplication.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*******************************************************************************
  2. * Copyright (c) 2012, Rockwell Automation, Inc.
  3. * All rights reserved.
  4. *
  5. ******************************************************************************/
  6. #include "opener_api.h"
  7. #include <string.h>
  8. #include <stdlib.h>
  9. #define DEMO_APP_INPUT_ASSEMBLY_NUM 100 //0x064
  10. #define DEMO_APP_OUTPUT_ASSEMBLY_NUM 150 //0x096
  11. #define DEMO_APP_CONFIG_ASSEMBLY_NUM 151 //0x097
  12. #define DEMO_APP_HEARBEAT_INPUT_ONLY_ASSEMBLY_NUM 152 //0x098
  13. #define DEMO_APP_HEARBEAT_LISTEN_ONLY_ASSEMBLY_NUM 153 //0x099
  14. #define DEMO_APP_EXPLICT_ASSEMBLY_NUM 154 //0x09A
  15. /* global variables for demo application (4 assembly data fields) ************/
  16. EIP_UINT8 g_assemblydata064[32]; /* Input */
  17. EIP_UINT8 g_assemblydata096[32]; /* Output */
  18. EIP_UINT8 g_assemblydata097[10]; /* Config */
  19. EIP_UINT8 g_assemblydata09A[32]; /* Explicit */
  20. EIP_STATUS
  21. IApp_Init(void)
  22. {
  23. /* create 3 assembly object instances*/
  24. /*INPUT*/
  25. createAssemblyObject(DEMO_APP_INPUT_ASSEMBLY_NUM, &g_assemblydata064[0],
  26. sizeof(g_assemblydata064));
  27. /*OUTPUT*/
  28. createAssemblyObject(DEMO_APP_OUTPUT_ASSEMBLY_NUM, &g_assemblydata096[0],
  29. sizeof(g_assemblydata096));
  30. /*CONFIG*/
  31. createAssemblyObject(DEMO_APP_CONFIG_ASSEMBLY_NUM, &g_assemblydata097[0],
  32. sizeof(g_assemblydata097));
  33. /*Heart-beat output assembly for Input only connections */
  34. createAssemblyObject(DEMO_APP_HEARBEAT_INPUT_ONLY_ASSEMBLY_NUM, 0, 0);
  35. /*Heart-beat output assembly for Listen only connections */
  36. createAssemblyObject(DEMO_APP_HEARBEAT_LISTEN_ONLY_ASSEMBLY_NUM, 0, 0);
  37. /* assembly for explicit messaging */
  38. createAssemblyObject(DEMO_APP_EXPLICT_ASSEMBLY_NUM, &g_assemblydata09A[0],
  39. sizeof(g_assemblydata09A));
  40. configureExclusiveOwnerConnectionPoint(0, DEMO_APP_OUTPUT_ASSEMBLY_NUM,
  41. DEMO_APP_INPUT_ASSEMBLY_NUM, DEMO_APP_CONFIG_ASSEMBLY_NUM);
  42. configureInputOnlyConnectionPoint(0,
  43. DEMO_APP_HEARBEAT_INPUT_ONLY_ASSEMBLY_NUM, DEMO_APP_INPUT_ASSEMBLY_NUM,
  44. DEMO_APP_CONFIG_ASSEMBLY_NUM);
  45. configureListenOnlyConnectionPoint(0,
  46. DEMO_APP_HEARBEAT_LISTEN_ONLY_ASSEMBLY_NUM, DEMO_APP_INPUT_ASSEMBLY_NUM,
  47. DEMO_APP_CONFIG_ASSEMBLY_NUM);
  48. return EIP_OK;
  49. }
  50. void
  51. IApp_HandleApplication(void)
  52. {
  53. /* check if application needs to trigger an connection */
  54. }
  55. void
  56. IApp_IOConnectionEvent(unsigned int pa_unOutputAssembly,
  57. unsigned int pa_unInputAssembly, EIOConnectionEvent pa_eIOConnectionEvent)
  58. {
  59. /* maintain a correct output state according to the connection state*/
  60. (void) pa_unOutputAssembly; /* suppress compiler warning */
  61. (void) pa_unInputAssembly; /* suppress compiler warning */
  62. (void) pa_eIOConnectionEvent; /* suppress compiler warning */
  63. }
  64. EIP_STATUS
  65. IApp_AfterAssemblyDataReceived(S_CIP_Instance *pa_pstInstance)
  66. {
  67. EIP_STATUS nRetVal = EIP_OK;
  68. /*handle the data received e.g., update outputs of the device */
  69. switch (pa_pstInstance->nInstanceNr)
  70. {
  71. case DEMO_APP_OUTPUT_ASSEMBLY_NUM:
  72. /* Data for the output assembly has been received.
  73. * Mirror it to the inputs */
  74. memcpy(&g_assemblydata064[0], &g_assemblydata096[0],
  75. sizeof(g_assemblydata064));
  76. break;
  77. case DEMO_APP_EXPLICT_ASSEMBLY_NUM:
  78. /* do something interesting with the new data from
  79. * the explicit set-data-attribute message */
  80. break;
  81. case DEMO_APP_CONFIG_ASSEMBLY_NUM:
  82. /* Add here code to handle configuration data and check if it is ok
  83. * The demo application does not handle config data.
  84. * However in order to pass the test we accept any data given.
  85. * EIP_ERROR
  86. */
  87. nRetVal = EIP_OK;
  88. break;
  89. }
  90. return nRetVal;
  91. }
  92. EIP_BOOL8
  93. IApp_BeforeAssemblyDataSend(S_CIP_Instance *pa_pstInstance)
  94. {
  95. /*update data to be sent e.g., read inputs of the device */
  96. /*In this sample app we mirror the data from out to inputs on data receive
  97. * therefore we need nothing to do here. Just return true to inform that
  98. * the data is new.
  99. */
  100. if (pa_pstInstance->nInstanceNr == DEMO_APP_EXPLICT_ASSEMBLY_NUM)
  101. {
  102. /* do something interesting with the existing data
  103. * for the explicit get-data-attribute message */
  104. }
  105. return true;
  106. }
  107. EIP_STATUS
  108. IApp_ResetDevice(void)
  109. {
  110. /* add reset code here*/
  111. return EIP_OK;
  112. }
  113. EIP_STATUS
  114. IApp_ResetDeviceToInitialConfiguration(void)
  115. {
  116. /*rest the parameters */
  117. /*than perform device reset*/
  118. IApp_ResetDevice();
  119. return EIP_OK;
  120. }
  121. void *
  122. IApp_CipCalloc(unsigned pa_nNumberOfElements, unsigned pa_nSizeOfElement)
  123. {
  124. return calloc(pa_nNumberOfElements, pa_nSizeOfElement);
  125. }
  126. void
  127. IApp_CipFree(void *pa_poData)
  128. {
  129. free(pa_poData);
  130. }
  131. void
  132. IApp_RunIdleChanged(EIP_UINT32 pa_nRunIdleValue)
  133. {
  134. (void) pa_nRunIdleValue;
  135. }