simulation.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. pAlarmCode->AlarmEvents.bits.DisconnectedFromDo = NORMAL;
  52. pSysWarning->Level = WARN_LV_NL;
  53. }
  54. void SetSelfTest(bool status)
  55. {
  56. uint8_t index = 0;
  57. struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
  58. struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
  59. struct CHAdeMOData *ShmCHAdeMOData = (struct CHAdeMOData *)GetShmCHAdeMOData();
  60. struct GBTData *ShmGBTData = (struct GBTData *)GetShmGBTData();
  61. struct CcsData *ShmCcsData = (struct CcsData *)GetShmCcsData();
  62. struct RelayModuleData *ShmRelayModuleData = (struct RelayModuleData *)GetShmRelayModuleData();
  63. ShmRelayModuleData->SelfTest_Comp = status;
  64. if (status) {
  65. strcpy((char*)pSysInfo->RelayModuleFwRev,SIM_VERSION);
  66. strcpy((char*)pSysInfo->FanModuleFwRev,SIM_VERSION);
  67. strcpy((char*)pSysInfo->CsuPrimFwRev,SIM_VERSION);
  68. for (index = 0; index < pSysConfig->TotalConnectorCount; index++) {
  69. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
  70. if (pDcChargingInfo->Type == _Type_Chademo) {
  71. strcpy((char*)ShmCHAdeMOData->evse[pDcChargingInfo->type_index].version,SIM_VERSION);
  72. } else if (pDcChargingInfo->Type == _Type_GB) {
  73. strcpy((char*)ShmGBTData->evse[pDcChargingInfo->type_index].version,SIM_VERSION);
  74. } else if (pDcChargingInfo->Type == _Type_CCS_2) {
  75. strcpy((char*)ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].version,SIM_VERSION);
  76. }
  77. ShmDcCommonData->GunRelayWeldingOccur[index] = false;
  78. }
  79. }
  80. }
  81. void main()
  82. {
  83. uint8_t gunIndex = 0;
  84. if (CreateAllCsuShareMemory() == FAIL) {
  85. printf("create share memory error");
  86. return;
  87. }
  88. MappingGunChargingInfo("Simulation Task");
  89. pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
  90. pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
  91. pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
  92. pFaultCode = (struct FaultCodeData *)GetShmFaultCodeData();
  93. ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
  94. ShmCHAdeMOData = (struct CHAdeMOData *)GetShmCHAdeMOData();
  95. ShmGBTData = (struct GBTData *)GetShmGBTData();
  96. ShmCcsData = (struct CcsData *)GetShmCcsData();
  97. ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
  98. SetSelfTest(SELFTESTRESULT);
  99. while (1) {
  100. for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
  101. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  102. switch (pDcChargingInfo->SystemStatus) {
  103. case S_IDLE:
  104. // Authorizing data
  105. strcpy((char *)&pSysConfig->UserId, USER_ID);
  106. break;
  107. case S_REASSIGN_CHECK:
  108. break;
  109. case S_REASSIGN:
  110. break;
  111. case S_PREPARNING:
  112. //ShmPsuData->SystemPresentPsuQuantity = 500;
  113. //ShmPsuData->SystemAvailablePower = 500;
  114. break;
  115. case S_PREPARING_FOR_EV:
  116. pDcChargingInfo->GunLocked = START;
  117. break;
  118. case S_PREPARING_FOR_EVSE:
  119. pDcChargingInfo->GroundFaultStatus = GFD_PASS;
  120. break;
  121. case S_CCS_PRECHARGE_ST0:
  122. case S_CCS_PRECHARGE_ST1:
  123. ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].PresentMsgFlowStatus = 45;
  124. sleep(1);
  125. pDcChargingInfo->RelayK1K2Status = YES;
  126. break;
  127. case S_CHARGING:
  128. break;
  129. case S_TERMINATING:
  130. break;
  131. case S_COMPLETE:
  132. break;
  133. case S_ALARM:
  134. break;
  135. case S_FAULT:
  136. SetFaultTest();
  137. break;
  138. case S_RESERVATION:
  139. break;
  140. case S_BOOKING:
  141. break;
  142. case S_MAINTAIN:
  143. break;
  144. case S_DEBUG:
  145. break;
  146. case S_UPDATE:
  147. break;
  148. }
  149. }
  150. usleep(100);
  151. }
  152. return;
  153. }