simulation.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. #include <sys/time.h>
  2. #include <sys/timeb.h>
  3. #include <sys/types.h>
  4. #include <sys/stat.h>
  5. #include <sys/types.h>
  6. #include <sys/ioctl.h>
  7. #include <sys/socket.h>
  8. #include <sys/ipc.h>
  9. #include <sys/shm.h>
  10. #include <sys/shm.h>
  11. #include <sys/mman.h>
  12. #include <linux/wireless.h>
  13. #include <arpa/inet.h>
  14. #include <netinet/in.h>
  15. #include <unistd.h>
  16. #include <stdarg.h>
  17. #include <stdio.h> /*標準輸入輸出定義*/
  18. #include <stdlib.h> /*標準函數庫定義*/
  19. #include <stdint.h>
  20. #include <unistd.h> /*Unix 標準函數定義*/
  21. #include <fcntl.h> /*檔控制定義*/
  22. #include <termios.h> /*PPSIX 終端控制定義*/
  23. #include <errno.h> /*錯誤號定義*/
  24. #include <errno.h>
  25. #include <string.h>
  26. #include <time.h>
  27. #include <ctype.h>
  28. #include <ifaddrs.h>
  29. #include <math.h>
  30. #include <stdbool.h>
  31. #include "./ShareMemory/shmMem.h"
  32. #include "./Define/define.h"
  33. #include "./SelectGun/SelectGun.h"
  34. #include "Config.h"
  35. #include "simulation.h"
  36. static struct SysConfigData *pSysConfig = NULL;
  37. static struct SysInfoData *pSysInfo = NULL;
  38. static struct FaultCodeData *pFaultCode = NULL;
  39. static struct AlarmCodeData *pAlarmCode = NULL;
  40. static struct CHAdeMOData *ShmCHAdeMOData = NULL;
  41. static struct GBTData *ShmGBTData = NULL;
  42. static struct CcsData *ShmCcsData = NULL;
  43. static DcCommonInfo *ShmDcCommonData = NULL;
  44. static SelectGunInfo *ShmSelectGunInfo = NULL;
  45. struct ChargingInfoData *pDcChargingInfo = NULL;
  46. static struct WARNING_CODE_INFO *pSysWarning = NULL;
  47. void SetFaultTest()
  48. {
  49. pAlarmCode->AlarmEvents.bits.CcsLiquidChillerWaterLevelWarning = NO;
  50. pFaultCode->FaultEvents.bits.CcsLiquidChillerWaterLevelFault = NO;
  51. pSysWarning->Level = WARN_LV_NL;
  52. }
  53. void SetSelfTest(bool status)
  54. {
  55. uint8_t index = 0;
  56. struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
  57. struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
  58. struct WARNING_CODE_INFO *pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
  59. struct PsuData *ShmPsuData = (struct PsuData *)GetShmPsuData();
  60. struct CHAdeMOData *ShmCHAdeMOData = (struct CHAdeMOData *)GetShmCHAdeMOData();
  61. struct GBTData *ShmGBTData = (struct GBTData *)GetShmGBTData();
  62. struct CcsData *ShmCcsData = (struct CcsData *)GetShmCcsData();
  63. struct PrimaryMcuData *ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
  64. struct FanModuleData *ShmFanModuleData = (struct FanModuleData *)GetShmFanModuleData();
  65. struct RelayModuleData *ShmRelayModuleData = (struct RelayModuleData *)GetShmRelayModuleData();
  66. ShmRelayModuleData->SelfTest_Comp = status;
  67. if (status) {
  68. strcpy((char*)pSysInfo->RelayModuleFwRev,SIM_VERSION);
  69. strcpy((char*)pSysInfo->FanModuleFwRev,SIM_VERSION);
  70. strcpy((char*)ShmPrimaryMcuData->version,SIM_VERSION);
  71. for (index = 0; index < pSysConfig->TotalConnectorCount; index++) {
  72. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
  73. if (pDcChargingInfo->Type == _Type_Chademo) {
  74. strcpy((char*)ShmCHAdeMOData->evse[pDcChargingInfo->type_index].version,SIM_VERSION);
  75. } else if (pDcChargingInfo->Type == _Type_GB) {
  76. strcpy((char*)ShmGBTData->evse[pDcChargingInfo->type_index].version,SIM_VERSION);
  77. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  78. strcpy((char*)ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].version,SIM_VERSION);
  79. }
  80. ShmDcCommonData->GunRelayWeldingOccur[index] = false;
  81. }
  82. }
  83. }
  84. void main()
  85. {
  86. uint8_t gunIndex = 0;
  87. if (CreateAllCsuShareMemory() == FAIL) {
  88. printf("create share memory error");
  89. return FAIL;
  90. }
  91. MappingGunChargingInfo("Simulation Task");
  92. pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
  93. pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
  94. pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
  95. pFaultCode = (struct FaultCodeData *)GetShmFaultCodeData();
  96. ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
  97. ShmCHAdeMOData = (struct CHAdeMOData *)GetShmCHAdeMOData();
  98. ShmGBTData = (struct GBTData *)GetShmGBTData();
  99. ShmCcsData = (struct CcsData *)GetShmCcsData();
  100. ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
  101. SetSelfTest(SELFTESTRESULT);
  102. while (1) {
  103. for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
  104. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  105. switch (pDcChargingInfo->SystemStatus) {
  106. case S_IDLE:
  107. // Authorizing data
  108. strcpy((char *)&pSysConfig->UserId, USER_ID);
  109. break;
  110. case S_REASSIGN_CHECK:
  111. break;
  112. case S_REASSIGN:
  113. break;
  114. case S_PREPARNING:
  115. break;
  116. case S_PREPARING_FOR_EV:
  117. break;
  118. case S_PREPARING_FOR_EVSE:
  119. break;
  120. case S_CCS_PRECHARGE_ST0:
  121. case S_CCS_PRECHARGE_ST1:
  122. break;
  123. case S_CHARGING:
  124. break;
  125. case S_TERMINATING:
  126. break;
  127. case S_COMPLETE:
  128. break;
  129. case S_ALARM:
  130. break;
  131. case S_FAULT:
  132. SetFaultTest();
  133. break;
  134. case S_RESERVATION:
  135. break;
  136. case S_BOOKING:
  137. break;
  138. case S_MAINTAIN:
  139. break;
  140. case S_DEBUG:
  141. break;
  142. case S_UPDATE:
  143. break;
  144. }
  145. }
  146. usleep(100);
  147. }
  148. return;
  149. }