Module_PsuComm.c 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021
  1. #include "Module_PsuComm.h"
  2. #define ARRAY_SIZE(A) (sizeof(A) / sizeof(A[0]))
  3. #define PASS 1
  4. #define FAIL -1
  5. #define YES 1
  6. #define NO 0
  7. #define DERATING_COUNT 30
  8. #define SHARE_CURRENT_GAP 50
  9. #define ELEMENT_NOT_FIND 255
  10. #define PSU_DEFAULT_ADDR 255
  11. #define CHK_VOL_RANGE 50
  12. #define CHK_CUR_RANGE 10
  13. #define DERATING_RANGE 100
  14. #define MIN_1A_CURRENT 10 // 該值須保持最小為 1A
  15. #define MIN_5V_VOLTAGE 50
  16. #define STOP_CURRENT 30
  17. #define PSU_MIN_CUR 1000
  18. #define PSU_MIN_VOL 1500
  19. #define PRE_CHARG_STEP_CUR 30
  20. #define PRE_CHARG_RANGE 50
  21. #define EQUAL 0
  22. #define CMD_DELAY_TIME 25000
  23. #define LOG_VOL_GAP 50
  24. #define LOG_CUR_GAP 5
  25. #define PSU_MIN_OUTPUT_CUR 0.4
  26. #define SHUTDOWN_OUTPUT 0
  27. #define PSU_MODULE_MIN_VOL 50
  28. // 安全在停止充電程序中斷開 Relay 的電流
  29. #define SEFETY_SWITCH_RELAY_CUR 50
  30. #define PSU_GONE_RESET 30
  31. #define PSU_NONE 0
  32. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  33. struct StatusCodeData *ShmStatusCodeData;
  34. struct PsuData *ShmPsuData;
  35. struct DcCommonInformation *ShmDcCommonData;
  36. struct SmartBoxData *ShmSmartBoxData;
  37. bool libInitialize = false;
  38. byte getAvailableCapOffset = 5;
  39. byte deratingKeepCount = 0;
  40. byte step3KeepCount = 0;
  41. byte psuCmdSeq = _PSU_CMD_STATUS;
  42. float chargingOutputLogInfo[2][4];
  43. byte ConnectorUsingSeq[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY][4] =
  44. {{0, 2, 3, 1}, {1, 3, 2, 0}};
  45. void PRINTF_FUNC(char *string, ...);
  46. int StoreLogMsg(const char *fmt, ...);
  47. #define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  48. #define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  49. #define DEBUG_ERROR(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  50. int GetTimeoutValue(struct timespec *startTime);
  51. long int GetTimeoutMValue(struct timespec *startTime)
  52. {
  53. struct timespec endTime;
  54. clock_gettime(CLOCK_MONOTONIC, &endTime);
  55. return 1000 * (endTime.tv_sec - startTime->tv_sec) + (endTime.tv_nsec - startTime->tv_nsec) / 1000000;
  56. }
  57. void GetTimespecMFunc(struct timespec *time)
  58. {
  59. clock_gettime(CLOCK_MONOTONIC, time);
  60. }
  61. int GetTimeoutValue(struct timespec *startTime)
  62. {
  63. struct timespec endTime;
  64. clock_gettime(CLOCK_MONOTONIC_COARSE, &endTime);
  65. return endTime.tv_sec - startTime->tv_sec;
  66. }
  67. void GetTimespecFunc(struct timespec *time)
  68. {
  69. clock_gettime(CLOCK_MONOTONIC_COARSE, time);
  70. }
  71. int StoreLogMsg(const char *fmt, ...)
  72. {
  73. char Buf[4096+256];
  74. char buffer[4096];
  75. va_list args;
  76. struct timeb SeqEndTime;
  77. struct tm *tm;
  78. va_start(args, fmt);
  79. int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
  80. va_end(args);
  81. memset(Buf,0,sizeof(Buf));
  82. ftime(&SeqEndTime);
  83. SeqEndTime.time = time(NULL);
  84. tm=localtime(&SeqEndTime.time);
  85. if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES)
  86. {
  87. sprintf(Buf,"%02d:%02d:%02d:%03d - %s",
  88. tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm, buffer);
  89. printf("%s \n", Buf);
  90. }
  91. else
  92. {
  93. sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog_%s_Log",
  94. tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm,
  95. buffer,
  96. tm->tm_year+1900,tm->tm_mon+1,
  97. ShmSysConfigAndInfo->SysConfig.SerialNumber);
  98. system(Buf);
  99. }
  100. return rc;
  101. }
  102. void PRINTF_FUNC(char *string, ...)
  103. {
  104. va_list args;
  105. char buffer[4096];
  106. va_start(args, string);
  107. vsnprintf(buffer, sizeof(buffer), string, args);
  108. va_end(args);
  109. DEBUG_INFO("%s ", buffer);
  110. }
  111. //=================================
  112. // Common routine
  113. //=================================
  114. void FindTargetGpAndAddr(byte sourceAddr, byte *gp, byte *psuIndex)
  115. {
  116. for (byte _gp = 0; _gp < ShmPsuData->GroupCount; _gp++)
  117. {
  118. for (byte _psu = 0; _psu < ShmPsuData->PsuGroup[_gp].GroupPresentPsuQuantity; _psu++)
  119. {
  120. if (ShmPsuData->PsuGroup[_gp].PsuModule[_psu].Address == sourceAddr)
  121. {
  122. *gp = _gp;
  123. *psuIndex = _psu;
  124. return;
  125. }
  126. }
  127. }
  128. }
  129. //=================================
  130. // Save data to share memory Function
  131. //=================================
  132. bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
  133. {
  134. for (byte index = 0; index < CHAdeMO_QUANTITY; index++)
  135. {
  136. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)
  137. {
  138. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
  139. return true;
  140. }
  141. }
  142. for (byte index = 0; index < CCS_QUANTITY; index++)
  143. {
  144. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)
  145. {
  146. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
  147. return true;
  148. }
  149. }
  150. for (byte index = 0; index < GB_QUANTITY; index++)
  151. {
  152. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)
  153. {
  154. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
  155. return true;
  156. }
  157. }
  158. return false;
  159. }
  160. //=================================
  161. // Alarm code mapping to share memory Function
  162. //=================================
  163. // 檢查 Byte 中某個 Bit 的值
  164. // _byte : 欲改變的 byte
  165. // _bit : 該 byte 的第幾個 bit
  166. int mask_table[] = {
  167. 0x00000001, 0x00000002, 0x00000004, 0x00000008,
  168. 0x00000010, 0x00000020, 0x00000040, 0x00000080,
  169. 0x00000100, 0x00000200, 0x00000400, 0x00000800,
  170. 0x00001000, 0x00002000, 0x00004000, 0x00008000,
  171. 0x00010000, 0x00020000, 0x00040000, 0x00080000,
  172. 0x00100000, 0x00200000, 0x00400000, 0x00800000,
  173. 0x01000000, 0x02000000, 0x04000000, 0x08000000,
  174. 0x10000000, 0x20000000, 0x40000000, 0x80000000
  175. };
  176. // INFY POWER
  177. #define NONE_DEFINE_1 0
  178. #define NONE_DEFINE_2 1
  179. #define FUSE_BURN_OUT 2
  180. #define PFC_DC_COMM_FAIL 3
  181. #define NONE_DEFINE_3 4
  182. #define NONE_DEFINE_4 5
  183. #define UNBALANCE_POSI_NEGA_BUS_VOL 6
  184. #define BUS_OVER_VOL 7
  185. #define BUS_ABNORMAL_VOL 8
  186. #define PHASE_OVP 9
  187. #define ID_REPETITION 10
  188. #define BUS_UVP 11
  189. #define PHASE_LOSE 12
  190. #define NONE_DEFINE_5 13
  191. #define PHASE_UVP 14
  192. #define NONE_DEFINE_6 15
  193. #define CAN_COMM_FAULT 16
  194. #define DC_DC_UNEVEN_CUR_SHARING 17
  195. #define NONE_DEFINE_7 18
  196. #define PFC_POW_OFF 19
  197. #define NONE_DEFINE_8 20
  198. #define FULL_SPEED_OF_FAN 21
  199. #define DC_DC_POW_OFF 22
  200. #define MODULE_UNDER_POW_LIMIT 23
  201. #define TEMP_POW_LIMIT 24
  202. #define AC_POW_LIMIT 25
  203. #define DC_DC_EEPROM_FAULT 26
  204. #define FAN_FAULT 27
  205. #define DC_DC_SHORT_CIRCUIT 28
  206. #define PFC_EEPROM_FAULT 29
  207. #define DC_DC_OTP 30
  208. #define DC_DC_OVP 31
  209. // UU POWER
  210. #define AC_SITE_OVP 0
  211. #define AC_SITE_UVP 1
  212. #define AC_OVP_SHUTDOWN 2
  213. #define PSU_INTERNAL_OVP 3
  214. #define PFC_INTERNAL_UVP 4
  215. #define PFC_INTERNAL_UNBALANCE 5
  216. #define DC_OUTPUT_OVP 6
  217. #define DC_OVP_SHUTDOWN 7
  218. #define DC_OUTPUT_UVP 8
  219. #define FAN_DONT_WORK 9
  220. #define UU_NONE_DEFINE_1 10
  221. #define UU_FAN_FAULT 11
  222. #define ENV_OTP 12
  223. #define ENV_UTP 13
  224. #define PFC_OTP 14
  225. #define OUTPUT_RELAY_BROKEN 15
  226. #define DC_OTP 16
  227. #define UU_NONE_DEFINE_2 17
  228. #define UU_PFC_DC_COMM_FAIL 18
  229. #define UU_NONE_DEFINE_3 19
  230. #define PFC_BROKEN 20
  231. #define DC_TO_DC_BROKEN 21
  232. #define UU_NONE_DEFINE_4 22
  233. #define UU_NONE_DEFINE_5 23
  234. #define UU_NONE_DEFINE_6 24
  235. #define DC_TO_DC_DONT_WORK 25
  236. #define UU_NONE_DEFINE_7 26
  237. #define UU_NONE_DEFINE_8 27
  238. #define DC_OUTPUT_VOLTAGE_UNBALANCE 28
  239. #define UU_ID_REPETITION 29
  240. #define NONE_DEFINE_9 30
  241. #define ABNORMAL_DISCHARGE_CIRCUIT 31
  242. unsigned char DetectBitValue(int _value, unsigned char _bit)
  243. {
  244. return ( _value & mask_table[_bit] ) != 0x00;
  245. }
  246. bool AbnormalStopAnalysis(byte gun_index, int errCode)
  247. {
  248. bool isErr = false;
  249. for(byte count = 0; count < sizeof(mask_table)/sizeof(mask_table[0]); count++)
  250. {
  251. byte value = DetectBitValue(errCode, count);
  252. if (value == 1)
  253. {
  254. switch(count)
  255. {
  256. case NONE_DEFINE_1 : {} break;
  257. case NONE_DEFINE_2 : {} break;
  258. case FUSE_BURN_OUT :
  259. {
  260. isErr = true;
  261. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFuseBurnOut == NO)
  262. {
  263. PRINTF_FUNC("PSU AbnormalStop : FUSE_BURN_OUT \n");
  264. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFuseBurnOut = YES;
  265. }
  266. } break;
  267. case PFC_DC_COMM_FAIL :
  268. {
  269. isErr = true;
  270. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuPfcAndDcdcCommFault == NO)
  271. {
  272. PRINTF_FUNC ( "PSU AbnormalStop : PFC_DC_COMM_FAIL \n" );
  273. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuPfcAndDcdcCommFault = YES;
  274. }
  275. } break;
  276. case NONE_DEFINE_3 : {} break;
  277. case NONE_DEFINE_4 : {} break;
  278. case UNBALANCE_POSI_NEGA_BUS_VOL :
  279. {
  280. isErr = true;
  281. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuBusVoltageUnbalance == NO)
  282. {
  283. PRINTF_FUNC ( "PSU AbnormalStop : UNBALANCE_POSI_NEGA_BUS_VOL \n" );
  284. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuBusVoltageUnbalance = YES;
  285. }
  286. } break;
  287. case BUS_OVER_VOL :
  288. {
  289. isErr = true;
  290. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuBusOverVoltage == NO)
  291. {
  292. PRINTF_FUNC ( "PSU AbnormalStop : BUS_OVER_VOL \n" );
  293. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuBusOverVoltage = YES;
  294. }
  295. } break;
  296. case BUS_ABNORMAL_VOL :
  297. {
  298. isErr = true;
  299. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuBusVoltageAbnormal == NO)
  300. {
  301. PRINTF_FUNC ( "PSU AbnormalStop : BUS_ABNORMAL_VOL \n" );
  302. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuBusVoltageAbnormal = YES;
  303. }
  304. } break;
  305. case PHASE_OVP :
  306. {
  307. isErr = true;
  308. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuPhaseOvp == NO)
  309. {
  310. PRINTF_FUNC ( "PSU AbnormalStop : PHASE_OVP \n" );
  311. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuPhaseOvp = YES;
  312. }
  313. } break;
  314. case ID_REPETITION :
  315. {
  316. isErr = true;
  317. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuIdRepeat == NO)
  318. {
  319. PRINTF_FUNC ( "PSU AbnormalStop : ID_REPETITION \n" );
  320. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuIdRepeat = YES;
  321. }
  322. } break;
  323. case BUS_UVP :
  324. {
  325. isErr = true;
  326. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuBusUnderVoltage == NO)
  327. {
  328. PRINTF_FUNC ( "PSU AbnormalStop : BUS_UVP \n" );
  329. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuBusUnderVoltage = YES;
  330. }
  331. } break;
  332. case PHASE_LOSE :
  333. {
  334. isErr = true;
  335. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuInputPhaseLoss == NO)
  336. {
  337. PRINTF_FUNC ( "PSU AbnormalStop : PHASE_LOSE \n" );
  338. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuInputPhaseLoss = YES;
  339. }
  340. } break;
  341. case NONE_DEFINE_5 : {} break;
  342. case PHASE_UVP :
  343. {
  344. isErr = true;
  345. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DcInputUVP == NO)
  346. {
  347. PRINTF_FUNC ( "PSU AbnormalStop : PHASE_UVP \n" );
  348. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DcInputUVP = YES;
  349. }
  350. } break;
  351. case NONE_DEFINE_6 : {} break;
  352. case CAN_COMM_FAULT :
  353. {
  354. isErr = true;
  355. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuCanCommFault == NO)
  356. {
  357. PRINTF_FUNC ( "PSU AbnormalStop : CAN_COMM_FAULT \n" );
  358. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuCanCommFault = YES;
  359. }
  360. } break;
  361. case DC_DC_UNEVEN_CUR_SHARING :
  362. {
  363. isErr = true;
  364. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuSevereUnevenCurrent == NO)
  365. {
  366. PRINTF_FUNC ( "PSU AbnormalStop : DC_DC_UNEVEN_CUR_SHARING \n" );
  367. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuSevereUnevenCurrent = YES;
  368. }
  369. } break;
  370. case NONE_DEFINE_7 : {} break;
  371. case PFC_POW_OFF :
  372. {
  373. //if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuPfcPowOff == NO)
  374. {
  375. //PRINTF_FUNC ( "PSU AbnormalStop : PFC_POW_OFF \n" );
  376. //ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuPfcPowOff = YES;
  377. }
  378. } break;
  379. case NONE_DEFINE_8 : {} break;
  380. case FULL_SPEED_OF_FAN :
  381. {
  382. isErr = true;
  383. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFanFullSpeed == NO)
  384. {
  385. PRINTF_FUNC ( "PSU AbnormalStop : FULL_SPEED_OF_FAN \n" );
  386. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFanFullSpeed = YES;
  387. }
  388. } break;
  389. case DC_DC_POW_OFF :
  390. {
  391. //if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcDcPowOff == NO)
  392. {
  393. //PRINTF_FUNC ( "PSU AbnormalStop : DC_DC_POW_OFF \n" );
  394. //ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcDcPowOff = YES;
  395. }
  396. } break;
  397. case MODULE_UNDER_POW_LIMIT :
  398. {
  399. isErr = true;
  400. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuPowerLimitedState == NO)
  401. {
  402. PRINTF_FUNC("PSU AbnormalStop : MODULE_UNDER_POW_LIMIT \n");
  403. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuPowerLimitedState = YES;
  404. }
  405. } break;
  406. case TEMP_POW_LIMIT :
  407. {
  408. isErr = true;
  409. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuTemperaturePowerLimit == NO)
  410. {
  411. PRINTF_FUNC ( "PSU AbnormalStop : TEMP_POW_LIMIT \n" );
  412. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuTemperaturePowerLimit = YES;
  413. }
  414. } break;
  415. case AC_POW_LIMIT :
  416. {
  417. isErr = true;
  418. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuAcPowerLimit == NO)
  419. {
  420. PRINTF_FUNC ( "PSU AbnormalStop : AC_POW_LIMIT \n" );
  421. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuAcPowerLimit = YES;
  422. }
  423. } break;
  424. case DC_DC_EEPROM_FAULT :
  425. {
  426. isErr = true;
  427. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcdcEepromFault == NO)
  428. {
  429. PRINTF_FUNC ( "PSU AbnormalStop : DC_DC_EEPROM_FAULT \n" );
  430. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcdcEepromFault = YES;
  431. }
  432. } break;
  433. case FAN_FAULT :
  434. {
  435. isErr = true;
  436. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFanFailureAlarm == NO)
  437. {
  438. PRINTF_FUNC ( "PSU AbnormalStop : FAN_FAULT \n" );
  439. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFanFailureAlarm = YES;
  440. }
  441. } break;
  442. case DC_DC_SHORT_CIRCUIT :
  443. {
  444. isErr = true;
  445. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuOutputShortCircuit == NO)
  446. {
  447. PRINTF_FUNC ( "PSU AbnormalStop : DC_DC_SHORT_CIRCUIT \n" );
  448. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuOutputShortCircuit = YES;
  449. }
  450. } break;
  451. case PFC_EEPROM_FAULT :
  452. {
  453. isErr = true;
  454. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuPfcEepromFault == NO)
  455. {
  456. PRINTF_FUNC ( "PSU AbnormalStop : PFC_EEPROM_FAULT \n" );
  457. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuPfcEepromFault = YES;
  458. }
  459. } break;
  460. case DC_DC_OTP :
  461. {
  462. isErr = true;
  463. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcDcOtp == NO)
  464. {
  465. PRINTF_FUNC ( "PSU AbnormalStop : DC_DC_OTP \n" );
  466. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcDcOtp = YES;
  467. }
  468. } break;
  469. case DC_DC_OVP :
  470. {
  471. isErr = true;
  472. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcDcOvp == NO)
  473. {
  474. PRINTF_FUNC ( "PSU AbnormalStop : DC_DC_OVP \n" );
  475. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcDcOvp = YES;
  476. }
  477. } break;
  478. }
  479. }
  480. }
  481. return isErr;
  482. }
  483. bool AbnormalStopAnalysis_UU(byte gun_index, int errCode)
  484. {
  485. bool isErr = false;
  486. for(byte count = 0; count < sizeof(mask_table)/sizeof(mask_table[0]); count++)
  487. {
  488. byte value = DetectBitValue(errCode, count);
  489. if (value == 1)
  490. {
  491. switch(count)
  492. {
  493. case AC_SITE_OVP :
  494. {
  495. // if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuBusOverVoltage == NO)
  496. // {
  497. // PRINTF_FUNC ( "PSU AbnormalStop : AC_SITE_OVP \n" );
  498. // ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuBusOverVoltage = YES;
  499. // }
  500. }
  501. break;
  502. case AC_SITE_UVP :
  503. {
  504. // if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuBusVoltageAbnormal == NO)
  505. // {
  506. // PRINTF_FUNC ( "PSU AbnormalStop : AC_SITE_UVP \n" );
  507. // ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuBusVoltageAbnormal = YES;
  508. // }
  509. }
  510. break;
  511. case AC_OVP_SHUTDOWN :
  512. {
  513. isErr = true;
  514. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuAcPowerLimit == NO)
  515. {
  516. PRINTF_FUNC ( "PSU AbnormalStop : AC_OVP_SHUTDOWN \n" );
  517. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuAcPowerLimit = YES;
  518. }
  519. }
  520. break;
  521. case PSU_INTERNAL_OVP :
  522. {
  523. isErr = true;
  524. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFuseBurnOut == NO)
  525. {
  526. PRINTF_FUNC("PSU AbnormalStop : PSU_INTERNAL_OVP \n");
  527. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFuseBurnOut = YES;
  528. }
  529. }
  530. break;
  531. case PFC_INTERNAL_UVP :
  532. {
  533. isErr = true;
  534. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuBusUnderVoltage == NO)
  535. {
  536. PRINTF_FUNC ( "PSU AbnormalStop : PFC_INTERNAL_UVP \n" );
  537. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuBusUnderVoltage = YES;
  538. }
  539. }
  540. break;
  541. case PFC_INTERNAL_UNBALANCE :
  542. {
  543. isErr = true;
  544. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuSevereUnevenCurrent == NO)
  545. {
  546. PRINTF_FUNC ( "PSU AbnormalStop : PFC_INTERNAL_UNBALANCE \n" );
  547. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuSevereUnevenCurrent = YES;
  548. }
  549. }
  550. break;
  551. case DC_OUTPUT_OVP :
  552. {
  553. isErr = true;
  554. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcDcOvp == NO)
  555. {
  556. PRINTF_FUNC ( "PSU AbnormalStop : DC_OUTPUT_OVP \n" );
  557. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcDcOvp = YES;
  558. }
  559. }
  560. break;
  561. case DC_OVP_SHUTDOWN :
  562. {
  563. isErr = true;
  564. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuPowerLimitedState == NO)
  565. {
  566. PRINTF_FUNC("PSU AbnormalStop : DC_OVP_SHUTDOWN \n");
  567. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuPowerLimitedState = YES;
  568. }
  569. }
  570. break;
  571. case DC_OUTPUT_UVP :
  572. {
  573. isErr = true;
  574. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuPhaseOvp == NO)
  575. {
  576. PRINTF_FUNC ( "PSU AbnormalStop : DC_OUTPUT_UVP \n" );
  577. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuPhaseOvp = YES;
  578. }
  579. }
  580. break;
  581. case FAN_DONT_WORK :
  582. {
  583. isErr = true;
  584. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFanFullSpeed == NO)
  585. {
  586. PRINTF_FUNC ( "PSU AbnormalStop : FAN_DONT_WORK \n" );
  587. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFanFullSpeed = YES;
  588. }
  589. }
  590. break;
  591. case UU_NONE_DEFINE_1 : {} break;
  592. case UU_FAN_FAULT :
  593. {
  594. // if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFanFailureAlarm == NO)
  595. // {
  596. // PRINTF_FUNC ( "PSU AbnormalStop : UU_FAN_FAULT \n" );
  597. // ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFanFailureAlarm = YES;
  598. // }
  599. }
  600. break;
  601. case ENV_OTP :
  602. {
  603. isErr = true;
  604. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuTemperaturePowerLimit == NO)
  605. {
  606. PRINTF_FUNC ( "PSU AbnormalStop : ENV_OTP \n" );
  607. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuTemperaturePowerLimit = YES;
  608. }
  609. }
  610. break;
  611. case ENV_UTP :
  612. {
  613. isErr = true;
  614. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcDcOtp == NO)
  615. {
  616. PRINTF_FUNC ( "PSU AbnormalStop : ENV_UTP \n" );
  617. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcDcOtp = YES;
  618. }
  619. }
  620. break;
  621. case PFC_OTP :
  622. {
  623. isErr = true;
  624. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuTemperaturePowerLimit == NO)
  625. {
  626. PRINTF_FUNC ( "PSU AbnormalStop : ENV_OTP \n" );
  627. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuTemperaturePowerLimit = YES;
  628. }
  629. }
  630. break;
  631. case OUTPUT_RELAY_BROKEN :
  632. {
  633. isErr = true;
  634. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuTemperaturePowerLimit == NO)
  635. {
  636. PRINTF_FUNC ( "PSU AbnormalStop : OUTPUT_RELAY_BROKEN \n" );
  637. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuTemperaturePowerLimit = YES;
  638. }
  639. }
  640. break;
  641. case DC_OTP :
  642. {
  643. isErr = true;
  644. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuTemperaturePowerLimit == NO)
  645. {
  646. PRINTF_FUNC ( "PSU AbnormalStop : DC_OTP \n" );
  647. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuTemperaturePowerLimit = YES;
  648. }
  649. }
  650. break;
  651. case UU_NONE_DEFINE_2 : {} break;
  652. case UU_PFC_DC_COMM_FAIL :
  653. {
  654. isErr = true;
  655. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuPfcAndDcdcCommFault == NO)
  656. {
  657. PRINTF_FUNC ( "PSU AbnormalStop : UU_PFC_DC_COMM_FAIL \n" );
  658. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuPfcAndDcdcCommFault = YES;
  659. }
  660. }
  661. break;
  662. case UU_NONE_DEFINE_3 : {} break;
  663. case PFC_BROKEN :
  664. {
  665. isErr = true;
  666. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuPfcEepromFault == NO)
  667. {
  668. PRINTF_FUNC ( "PSU AbnormalStop : PFC_BROKEN \n" );
  669. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuPfcEepromFault = YES;
  670. }
  671. }
  672. break;
  673. case DC_TO_DC_BROKEN :
  674. {
  675. isErr = true;
  676. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcdcEepromFault == NO)
  677. {
  678. PRINTF_FUNC ( "PSU AbnormalStop : DC_DC_EEPROM_FAULT \n" );
  679. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcdcEepromFault = YES;
  680. }
  681. }
  682. break;
  683. case UU_NONE_DEFINE_4 : {} break;
  684. case UU_NONE_DEFINE_5 : {} break;
  685. case UU_NONE_DEFINE_6 : {} break;
  686. case DC_TO_DC_DONT_WORK :
  687. {
  688. isErr = true;
  689. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuInputPhaseLoss == NO)
  690. {
  691. PRINTF_FUNC ( "PSU AbnormalStop : DC_TO_DC_DONT_WORK \n" );
  692. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuInputPhaseLoss = YES;
  693. }
  694. }
  695. break;
  696. case UU_NONE_DEFINE_7 : {} break;
  697. case UU_NONE_DEFINE_8 : {} break;
  698. case DC_OUTPUT_VOLTAGE_UNBALANCE :
  699. {
  700. isErr = true;
  701. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuBusVoltageUnbalance == NO)
  702. {
  703. PRINTF_FUNC ( "PSU AbnormalStop : DC_OUTPUT_VOLTAGE_UNBALANCE \n" );
  704. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuBusVoltageUnbalance = YES;
  705. }
  706. }
  707. break;
  708. case UU_ID_REPETITION :
  709. {
  710. isErr = true;
  711. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuIdRepeat == NO)
  712. {
  713. PRINTF_FUNC ( "PSU AbnormalStop : UU_ID_REPETITION \n" );
  714. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuIdRepeat = YES;
  715. }
  716. }
  717. break;
  718. case NONE_DEFINE_9 : {} break;
  719. case ABNORMAL_DISCHARGE_CIRCUIT :
  720. {
  721. isErr = true;
  722. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuOutputShortCircuit == NO)
  723. {
  724. PRINTF_FUNC ( "PSU AbnormalStop : ABNORMAL_DISCHARGE_CIRCUIT \n" );
  725. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuOutputShortCircuit = YES;
  726. }
  727. }
  728. break;
  729. }
  730. }
  731. }
  732. return isErr;
  733. }
  734. bool IsVoltageStable(byte _index)
  735. {
  736. bool result = true;
  737. float sample = ShmDcCommonData->_outputVoltageSapmle[_index][0];
  738. if (ShmPsuData->PsuGroup[_index].GroupPresentOutputVoltage >= 1500)
  739. {
  740. for(byte i = 1; i < VOLTAGE_SAMPLE_COUNT; i++)
  741. {
  742. if (sample <= ShmDcCommonData->_outputVoltageSapmle[_index][i] - 300 ||
  743. sample >= ShmDcCommonData->_outputVoltageSapmle[_index][i] + 300)
  744. {
  745. result = false;
  746. }
  747. }
  748. //if (result)
  749. {
  750. // printf("V[0] => %f \n", ShmDcCommonData->_outputVoltageSapmle[_index][0]);
  751. // printf("V[1] => %f \n", ShmDcCommonData->_outputVoltageSapmle[_index][1]);
  752. // printf("V[2] => %f \n", ShmDcCommonData->_outputVoltageSapmle[_index][2]);
  753. // printf("V[3] => %f \n", ShmDcCommonData->_outputVoltageSapmle[_index][3]);
  754. // printf("V[4] => %f \n", ShmDcCommonData->_outputVoltageSapmle[_index][4]);
  755. }
  756. }
  757. else
  758. result = false;
  759. return result;
  760. }
  761. //=================================
  762. // Callback Function
  763. //=================================
  764. void ChkUuPwrErrOccur(unsigned address, unsigned char err1, unsigned char err2, unsigned char err3, unsigned char err4)
  765. {
  766. if (ShmPsuData->Work_Step < GET_SYS_CAP)
  767. return;
  768. byte group, psuIndex;
  769. FindTargetGpAndAddr(address, &group, &psuIndex);
  770. int alarm = err1 | (err2 << 8) | (err3 << 16) | (err4 << 24);
  771. if (AbnormalStopAnalysis_UU (group, alarm))
  772. {
  773. ShmPsuData->PsuGroup[group].PsuModule[psuIndex].AlarmCode = YES;
  774. // if (!ShmPsuData->PsuGroup [group].GroupErrorFlag.bits.PsuFailure)
  775. // {
  776. // ShmPsuData->PsuGroup [group].GroupErrorFlag.bits.PsuFailure = YES;
  777. // ShmPsuData->PsuStopChargeFlag = YES;
  778. // ShmDcCommonData->_isPsuErrorOccur = YES;
  779. // PRINTF_FUNC ( "Group_%d - Index_%d, PSU Error Occurred. \n", group, psuIndex );
  780. // }
  781. }
  782. else
  783. ShmPsuData->PsuGroup[group].PsuModule[psuIndex].AlarmCode = NO;
  784. }
  785. void GetStatusCallback(byte group, byte SN, byte temp, int alarm, byte type,
  786. unsigned char err1, unsigned char err2, unsigned char err3, unsigned char err4)
  787. {
  788. if (ShmDcCommonData->_psuProtocol != type)
  789. ShmDcCommonData->_psuProtocol = type;
  790. if (type == _PSU_PROTOCOL_UU)
  791. {
  792. ShmDcCommonData->psuKeepCommunication = ShmDcCommonData->acContactSwitch;
  793. int _timebuf = GetTimeoutValue ( & ShmDcCommonData->_psuComm_time );
  794. if (_timebuf > 1 || _timebuf < 0)
  795. {
  796. GetTimespecFunc ( & ShmDcCommonData->_psuComm_time );
  797. }
  798. if (ShmPsuData->Work_Step == _WORK_CHARGING)
  799. {
  800. ChkUuPwrErrOccur(SN, err1, err2, err3, err4);
  801. }
  802. }
  803. bool isFind = false;
  804. bool isComp = false;
  805. byte totalPsuQuantity = 0;
  806. if (group >= 4)
  807. return;
  808. for (byte _group = 0; _group < ShmPsuData->GroupCount; _group++)
  809. {
  810. totalPsuQuantity += ShmPsuData->PsuGroup[_group].GroupPresentPsuQuantity;
  811. }
  812. // if (type == _PSU_PROTOCOL_UU)
  813. // {
  814. // for (byte psuIndex = 0; psuIndex < ShmPsuData->PsuGroup [group].GroupPresentPsuQuantity; psuIndex ++)
  815. // {
  816. // if (ShmPsuData->PsuGroup [group].PsuModule [psuIndex].Address == PSU_DEFAULT_ADDR)
  817. // {
  818. // ShmPsuData->PsuGroup [group].PsuModule [psuIndex].Address = SN;
  819. // return;
  820. // }
  821. // }
  822. //
  823. // if (totalPsuQuantity == ShmPsuData->SystemPresentPsuQuantity &&
  824. // ShmPsuData->Work_Step < GET_SYS_CAP)
  825. // isComp = true;
  826. // }
  827. // else if (totalPsuQuantity != ShmPsuData->SystemPresentPsuQuantity &&
  828. // ShmPsuData->SystemPresentPsuQuantity > 0)
  829. if (totalPsuQuantity != ShmPsuData->SystemPresentPsuQuantity &&
  830. ShmPsuData->SystemPresentPsuQuantity > 0)
  831. {
  832. for (byte psuIndex = 0; psuIndex < ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity; psuIndex++)
  833. {
  834. if (ShmPsuData->PsuGroup[group].PsuModule[psuIndex].Address == SN)
  835. {
  836. isFind = true;
  837. break;
  838. }
  839. }
  840. if(!isFind)
  841. {
  842. PRINTF_FUNC("ADD Group = %d, GroupPresentPsuQuantity = %d Psu Count = %d \n",
  843. group, ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity, SN);
  844. ShmPsuData->PsuGroup[group].PsuModule[ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity].Address = SN;
  845. ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity++;
  846. }
  847. totalPsuQuantity = 0;
  848. for (byte _group = 0; _group < ShmPsuData->GroupCount; _group++)
  849. {
  850. totalPsuQuantity += ShmPsuData->PsuGroup[_group].GroupPresentPsuQuantity;
  851. }
  852. PRINTF_FUNC("totalPsuQuantity = %d \n",
  853. totalPsuQuantity);
  854. if (totalPsuQuantity == ShmPsuData->SystemPresentPsuQuantity)
  855. isComp = true;
  856. }
  857. if (isComp)
  858. {
  859. PRINTF_FUNC ("**************************************************************************** \n" );
  860. for (int _count = 0; _count < ShmPsuData->GroupCount; _count ++)
  861. {
  862. PRINTF_FUNC ( "Group = %d, Psu Count = %d \n", _count, ShmPsuData->PsuGroup [_count].GroupPresentPsuQuantity);
  863. for (int _Pcount = 0; _Pcount < ShmPsuData->PsuGroup [_count].GroupPresentPsuQuantity; _Pcount++)
  864. {
  865. PRINTF_FUNC ( "Address = %d \n", ShmPsuData->PsuGroup[_count].PsuModule[_Pcount].Address);
  866. }
  867. }
  868. PRINTF_FUNC ("**************************************************************************** \n" );
  869. }
  870. }
  871. void GetModuleCountCallback(byte group, byte count)
  872. {
  873. if (group == SYSTEM_CMD)
  874. {
  875. ShmPsuData->SystemPresentPsuQuantity = count;
  876. }
  877. else
  878. {
  879. // if (ShmDcCommonData->_psuProtocol == _PSU_PROTOCOL_UU)
  880. // ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity = count;
  881. }
  882. }
  883. void GetAvailableCapCallback(byte address, short maxVol, short minVol, short maxCur, short totalPow)
  884. {
  885. if (ShmPsuData->Work_Step < GET_SYS_CAP)
  886. return;
  887. byte group, psuIndex;
  888. FindTargetGpAndAddr(address, &group, &psuIndex);
  889. ShmPsuData->PsuGroup[group].PsuModule[psuIndex].AvailablePower = totalPow;
  890. ShmPsuData->PsuGroup[group].PsuModule[psuIndex].AvailableCurrent = maxCur;
  891. ShmPsuData->PsuGroup[group].PsuModule[psuIndex].PresentMaxOutputVoltage = maxVol;
  892. }
  893. void GetFwCallback(byte address, short dcSwVer, short pfcSwVer, short hwVer, byte type)
  894. {
  895. if (ShmPsuData->Work_Step < GET_SYS_CAP)
  896. return;
  897. byte group, psuIndex;
  898. FindTargetGpAndAddr(address, &group, &psuIndex);
  899. sprintf((char *)ShmPsuData->PsuVersion[address].FwPrimaryVersion, "DC %d.%02d", (dcSwVer & 0xFF00) >> 8, dcSwVer & 0xFF);
  900. sprintf((char *)ShmPsuData->PsuVersion[address].FwSecondVersion, "PFC %d.%02d", (pfcSwVer & 0xFF00) >> 8, pfcSwVer & 0xFF);
  901. sprintf((char *)ShmPsuData->PsuGroup[group].PsuModule[psuIndex].FwVersion, "DC %d.%02d : PFC %d.%02d",
  902. (dcSwVer & 0xFF00) >> 8, dcSwVer & 0xFF,
  903. (pfcSwVer & 0xFF00) >> 8, pfcSwVer & 0xFF);
  904. }
  905. void GetInputVoltageCallback(byte address, unsigned short vol1, unsigned short vol2, unsigned short vol3)
  906. {
  907. if (ShmPsuData->Work_Step < GET_SYS_CAP)
  908. return;
  909. byte group, psuIndex;
  910. FindTargetGpAndAddr(address, &group, &psuIndex);
  911. ShmPsuData->PsuGroup[group].PsuModule[psuIndex].InputVoltageL1 = vol1;
  912. ShmPsuData->PsuGroup[group].PsuModule[psuIndex].InputVoltageL2 = vol2;
  913. ShmPsuData->PsuGroup[group].PsuModule[psuIndex].InputVoltageL3 = vol3;
  914. // PRINTF_FUNC("***Input*** address = %d, R = %d, S = %d, T = %d, gp = %d \n",
  915. // address, vol1, vol2, vol3, group);
  916. }
  917. void GetPresentOutputCallback(byte group, unsigned short outVol, unsigned short outCur)
  918. {
  919. }
  920. void GetMisCallback(byte address, unsigned int value, byte type)
  921. {
  922. if (ShmPsuData->Work_Step < GET_SYS_CAP)
  923. return;
  924. byte group, psuIndex;
  925. FindTargetGpAndAddr(address, &group, &psuIndex);
  926. if (type == 1)
  927. {
  928. ShmPsuData->PsuGroup[group].PsuModule[psuIndex].FanSpeed_1 = value;
  929. ShmPsuData->PsuGroup[group].PsuModule[psuIndex].FanSpeed_2 = value;
  930. ShmPsuData->PsuGroup[group].PsuModule[psuIndex].FanSpeed_3 = value;
  931. ShmPsuData->PsuGroup[group].PsuModule[psuIndex].FanSpeed_4 = value;
  932. }
  933. else if (type == 2)
  934. {
  935. //printf("DC - group = %d, index = %d, value = %d \n", group, address, value);
  936. // ShmPsuData->PsuGroup[group].PsuModule[psuIndex].CriticalTemp1 = value;
  937. // ShmPsuData->PsuGroup[group].PsuModule[psuIndex].CriticalTemp2 = value;
  938. // ShmPsuData->PsuGroup[group].PsuModule[psuIndex].CriticalTemp3 = value;
  939. ShmPsuData->PsuGroup[group].PsuModule[psuIndex].ExletTemp = value;
  940. }
  941. else if (type == 3)
  942. {
  943. printf("PFC - group = %d, index = %d, value = %d \n", group, address, value);
  944. }
  945. }
  946. void GetIavailableCallback(byte address, unsigned short Iavail, unsigned short Vext)
  947. {
  948. if (ShmPsuData->Work_Step < GET_SYS_CAP || Iavail > 1000)
  949. return;
  950. byte group, psuIndex;
  951. FindTargetGpAndAddr(address, &group, &psuIndex);
  952. // if (group == 2)
  953. // {
  954. // printf("V1 = %f \n", ShmDcCommonData->_outputVoltageSapmle[group][0]);
  955. // printf("V2 = %f \n", ShmDcCommonData->_outputVoltageSapmle[group][1]);
  956. // printf("V3 = %f \n", ShmDcCommonData->_outputVoltageSapmle[group][2]);
  957. // printf("V4 = %f \n", ShmDcCommonData->_outputVoltageSapmle[group][3]);
  958. // printf("V5 = %f \n", ShmDcCommonData->_outputVoltageSapmle[group][4]);
  959. // }
  960. if (IsVoltageStable(group))
  961. {
  962. ShmPsuData->PsuGroup[group].PsuModule[psuIndex].IAvailableCurrent = Iavail;
  963. ShmPsuData->PsuGroup[group].PsuModule[psuIndex].KwAvailablePower =
  964. ShmPsuData->PsuGroup[group].PsuModule[psuIndex].PresentOutputVoltage *
  965. ShmPsuData->PsuGroup[group].PsuModule[psuIndex].IAvailableCurrent / 100 / 1000;
  966. }
  967. }
  968. void GetPresentOutputFCallback(byte group, float outVol, float outCur, byte type)
  969. {
  970. if (ShmPsuData->Work_Step < GET_SYS_CAP || type == _PSU_PROTOCOL_INFY)
  971. return;
  972. for(byte count = 0; count < ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity; count++)
  973. {
  974. ShmPsuData->PsuGroup[group].PsuModule[count].PresentOutputVoltage = (unsigned short)(outVol);
  975. ShmPsuData->PsuGroup[group].PsuModule[count].PresentOutputCurrent = (unsigned short)(outCur / ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity);
  976. }
  977. }
  978. //==========================================
  979. // 特規用指令
  980. //==========================================
  981. void GetOutputAndTempCallback(byte address, unsigned short outputVol_s,
  982. unsigned short outputCur_s, unsigned short outputPower, unsigned char Temperature, byte type)
  983. {
  984. if (ShmPsuData->Work_Step != _WORK_CHARGING)
  985. return;
  986. byte group = 0, psuIndex = 0;
  987. FindTargetGpAndAddr(address, &group, &psuIndex);
  988. //PRINTF_FUNC("GetOutputAndTempCallback = *address = %d, group = %d, psuIndex = %d \n", address, group, psuIndex);
  989. //printf("group = %d, addr = %d \n", group, addr);
  990. ShmPsuData->PsuGroup[group].PsuModule[psuIndex].CriticalTemp1 = Temperature;
  991. ShmPsuData->PsuGroup[group].PsuModule[psuIndex].CriticalTemp2 = Temperature;
  992. ShmPsuData->PsuGroup[group].PsuModule[psuIndex].CriticalTemp3 = Temperature;
  993. // ShmPsuData->PsuGroup[group].PsuModule[psuIndex].ExletTemp = Temperature;
  994. if (type == _PSU_PROTOCOL_UU)
  995. return;
  996. // isinf : -1 = 負無窮,1 = 正無窮,0 = 其他
  997. ShmPsuData->PsuGroup[group].PsuModule[psuIndex].PresentOutputVoltage = (unsigned short)(outputVol_s);
  998. ShmPsuData->PsuGroup[group].PsuModule[psuIndex].PresentOutputCurrent = (unsigned short)(outputCur_s);
  999. }
  1000. void GetModuleStatusCallback(byte address, unsigned char isErr, unsigned char status,
  1001. unsigned char err1, unsigned char err2, unsigned char err3, unsigned char err4)
  1002. {
  1003. ShmDcCommonData->psuKeepCommunication = ShmDcCommonData->acContactSwitch;
  1004. int _timebuf = GetTimeoutValue(&ShmDcCommonData->_psuComm_time);
  1005. if (_timebuf > 1 || _timebuf < 0)
  1006. {
  1007. GetTimespecFunc(&ShmDcCommonData->_psuComm_time);
  1008. }
  1009. if (ShmPsuData->Work_Step != _WORK_CHARGING)
  1010. return;
  1011. byte group = 0, psuIndex = 0;
  1012. FindTargetGpAndAddr(address, &group, &psuIndex);
  1013. //PRINTF_FUNC("GetModuleStatusCallback = *address = %d, group = %d, psuIndex = %d \n", address, group, psuIndex);
  1014. int alarm = err1 | (err2 << 8) | (err3 << 16) | (err4 << 24);
  1015. if(AbnormalStopAnalysis(group, alarm))
  1016. {
  1017. ShmPsuData->PsuGroup[group].PsuModule[psuIndex].AlarmCode = YES;
  1018. // if (!ShmPsuData->PsuGroup[group].GroupErrorFlag.bits.PsuFailure)
  1019. // {
  1020. // ShmPsuData->PsuGroup[group].GroupErrorFlag.bits.PsuFailure = YES;
  1021. // ShmPsuData->PsuStopChargeFlag = YES;
  1022. // ShmDcCommonData->_isPsuErrorOccur = YES;
  1023. // PRINTF_FUNC("Group_%d - Index_%d, PSU Error Occurred. \n", group, psuIndex);
  1024. // }
  1025. }
  1026. else
  1027. ShmPsuData->PsuGroup[group].PsuModule[psuIndex].AlarmCode = NO;
  1028. }
  1029. void GetModuleInputCallback(byte address, unsigned short inputR,
  1030. unsigned short inputS, unsigned short inputT)
  1031. {
  1032. if (ShmPsuData->Work_Step != _WORK_CHARGING)
  1033. return;
  1034. byte group = 0, psuIndex = 0;
  1035. FindTargetGpAndAddr(address, &group, &psuIndex);
  1036. //PRINTF_FUNC("*address = %d, group = %d, psuIndex = %d \n", address, group, psuIndex);
  1037. ShmPsuData->PsuGroup[group].PsuModule[psuIndex].InputVoltageL1 = inputR;
  1038. ShmPsuData->PsuGroup[group].PsuModule[psuIndex].InputVoltageL2 = inputS;
  1039. ShmPsuData->PsuGroup[group].PsuModule[psuIndex].InputVoltageL3 = inputT;
  1040. //PRINTF_FUNC("***Input*** address = %d, R = %d, S = %d, T = %d \n",
  1041. // address, inputR, inputS, inputT);
  1042. }
  1043. //==========================================
  1044. // Init all share memory
  1045. //==========================================
  1046. int InitShareMemory()
  1047. {
  1048. int result = PASS;
  1049. int MeterSMId;
  1050. //creat ShmSysConfigAndInfo
  1051. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  1052. {
  1053. #ifdef SystemLogMessage
  1054. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG %d \n");
  1055. #endif
  1056. result = FAIL;
  1057. }
  1058. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1059. {
  1060. #ifdef SystemLogMessage
  1061. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG \n");
  1062. #endif
  1063. result = FAIL;
  1064. }
  1065. //creat ShmStatusCodeData
  1066. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  1067. {
  1068. #ifdef SystemLogMessage
  1069. DEBUG_ERROR("shmget ShmStatusCodeData NG \n");
  1070. #endif
  1071. result = FAIL;
  1072. }
  1073. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1074. {
  1075. #ifdef SystemLogMessage
  1076. DEBUG_ERROR("shmat ShmStatusCodeData NG \n");
  1077. #endif
  1078. result = FAIL;
  1079. }
  1080. //creat ShmPsuData
  1081. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  1082. {
  1083. #ifdef SystemLogMessage
  1084. DEBUG_ERROR("shmget ShmPsuData NG \n");
  1085. #endif
  1086. result = FAIL;
  1087. }
  1088. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1089. {
  1090. #ifdef SystemLogMessage
  1091. DEBUG_ERROR("shmat ShmPsuData NG \n");
  1092. #endif
  1093. result = FAIL;
  1094. }
  1095. if ((MeterSMId = shmget ( ShmSmartBoxKey, sizeof(struct SmartBoxData), IPC_CREAT | 0777 )) < 0)
  1096. {
  1097. #ifdef SystemLogMessage
  1098. DEBUG_ERROR("shmat ShmSmartBoxKey NG \n");
  1099. #endif
  1100. return FAIL;
  1101. }
  1102. else if ((ShmSmartBoxData = shmat ( MeterSMId, NULL, 0 )) == (void *) - 1)
  1103. {
  1104. #ifdef SystemLogMessage
  1105. DEBUG_ERROR("shmat ShmSmartBoxData NG \n");
  1106. #endif
  1107. return FAIL;
  1108. }
  1109. if ((MeterSMId = shmget(ShmCommonKey, sizeof(struct DcCommonInformation), IPC_CREAT | 0777)) < 0)
  1110. {
  1111. #ifdef SystemLogMessage
  1112. DEBUG_ERROR("shmget ShmCommonKey NG \n");
  1113. #endif
  1114. result = FAIL;
  1115. }
  1116. else if ((ShmDcCommonData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1117. {
  1118. #ifdef SystemLogMessage
  1119. DEBUG_ERROR("shmat ShmCommonKey NG \n");
  1120. #endif
  1121. result = FAIL;
  1122. }
  1123. return result;
  1124. }
  1125. //================================================
  1126. // Log function
  1127. //================================================
  1128. void OutputChargingLogFuncion(byte groupIndex)
  1129. {
  1130. // 列印時機 : 需求改變時
  1131. if (chargingOutputLogInfo[groupIndex][_CHARGING_LOG_NEED_VOL] != chargingInfo[groupIndex]->EvBatterytargetVoltage * 10)
  1132. {
  1133. chargingOutputLogInfo[groupIndex][_CHARGING_LOG_NEED_VOL] = chargingInfo[groupIndex]->EvBatterytargetVoltage * 10;
  1134. chargingOutputLogInfo[groupIndex][_CHARGING_LOG_OUTPUT_VOL] = chargingInfo[groupIndex]->FireChargingVoltage;
  1135. PRINTF_FUNC("Conn %d, EV Req Voltage : %.1f (V), EVSE Output Voltage = %.1f (V) \n", groupIndex,
  1136. chargingOutputLogInfo[groupIndex][_CHARGING_LOG_NEED_VOL] / 10,
  1137. chargingOutputLogInfo[groupIndex][_CHARGING_LOG_OUTPUT_VOL] / 10);
  1138. }
  1139. if (chargingOutputLogInfo[groupIndex][_CHARGING_LOG_NEED_CUR] != chargingInfo[groupIndex]->EvBatterytargetCurrent * 10)
  1140. {
  1141. chargingOutputLogInfo[groupIndex][_CHARGING_LOG_NEED_CUR] = chargingInfo[groupIndex]->EvBatterytargetCurrent * 10;
  1142. chargingOutputLogInfo[groupIndex][_CHARGING_LOG_OUTPUT_CUR] = chargingInfo[groupIndex]->PresentChargingCurrent;
  1143. PRINTF_FUNC("Conn %d, EV Req Current : %.1f (A), EVSE Output Current = %.1f (A) \n", groupIndex,
  1144. chargingOutputLogInfo[groupIndex][_CHARGING_LOG_NEED_CUR] / 10,
  1145. chargingOutputLogInfo[groupIndex][_CHARGING_LOG_OUTPUT_CUR]);
  1146. }
  1147. }
  1148. //================================================
  1149. // Main process
  1150. //================================================
  1151. void ClearPsuAlarmCode()
  1152. {
  1153. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFuseBurnOut = NO;
  1154. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuPfcAndDcdcCommFault = NO;
  1155. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuBusVoltageUnbalance = NO;
  1156. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuBusOverVoltage = NO;
  1157. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuBusVoltageAbnormal = NO;
  1158. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuPhaseOvp = NO;
  1159. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuIdRepeat = NO;
  1160. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuBusUnderVoltage = NO;
  1161. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuInputPhaseLoss = NO;
  1162. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DcInputUVP = NO;
  1163. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuCanCommFault = NO;
  1164. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuSevereUnevenCurrent = NO;
  1165. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFfcSideShutDown = NO;
  1166. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFanFullSpeed = NO;
  1167. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcSideShutDown = NO;
  1168. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuPowerLimitedState = NO;
  1169. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuTemperaturePowerLimit = NO;
  1170. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuAcPowerLimit = NO;
  1171. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcdcEepromFault = NO;
  1172. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFanFailureAlarm = NO;
  1173. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuOutputShortCircuit = NO;
  1174. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuPfcEepromFault = NO;
  1175. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcDcOtp = NO;
  1176. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcDcOvp = NO;
  1177. }
  1178. void Check2ClearPsuError()
  1179. {
  1180. for (byte group = 0; group < ShmPsuData->GroupCount; group++)
  1181. {
  1182. for (byte psuIndex = 0; psuIndex < ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity; psuIndex++)
  1183. {
  1184. if (ShmPsuData->PsuGroup[group].PsuModule[psuIndex].AlarmCode != 0)
  1185. {
  1186. return;
  1187. }
  1188. }
  1189. }
  1190. ClearPsuAlarmCode();
  1191. }
  1192. void FindGunInfo()
  1193. {
  1194. bool isPass = false;
  1195. while ( ! isPass)
  1196. {
  1197. isPass = true;
  1198. for (byte _index = 0; _index < _gunCountRecord; _index ++)
  1199. {
  1200. if ( ! FindChargingInfoData ( _index, & chargingInfo [0] ))
  1201. {
  1202. DEBUG_ERROR( "Module_PsuComm : FindChargingInfoData false \n" );
  1203. isPass = false;
  1204. break;
  1205. }
  1206. }
  1207. sleep ( 1 );
  1208. }
  1209. }
  1210. void InitialPsuData()
  1211. {
  1212. if (ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == YES)
  1213. ShmPsuData->GroupCount = 1;
  1214. else
  1215. ShmPsuData->GroupCount = ARRAY_SIZE(ShmPsuData->PsuGroup);
  1216. ShmPsuData->SystemAvailableCurrent = 0;
  1217. ShmPsuData->SystemAvailablePower = 0;
  1218. ShmPsuData->SystemPresentPsuQuantity = 0;
  1219. for (byte _groupCount = 0; _groupCount < ShmPsuData->GroupCount; _groupCount++)
  1220. {
  1221. ShmPsuData->PsuGroup[_groupCount].GroupAvailablePower = 0;
  1222. ShmPsuData->PsuGroup[_groupCount].GroupAvailableCurrent = 0;
  1223. ShmPsuData->PsuGroup[_groupCount].GroupRealOutputPower = 0;
  1224. ShmPsuData->PsuGroup[_groupCount].GroupErrorFlag.bits.PsuFailure = NO;
  1225. ShmPsuData->PsuGroup[_groupCount].UsingTarget = GUN_CHECK;
  1226. for (byte _psuCount = 0; _psuCount < MAX_PSU_QUANTITY; _psuCount++)
  1227. ShmPsuData->PsuGroup[_groupCount].PsuModule[_psuCount].Address = PSU_DEFAULT_ADDR;
  1228. }
  1229. for(byte _gunCount = 0; _gunCount < _gunCountRecord; _gunCount++)
  1230. {
  1231. chargingInfo[_gunCount]->PresentChargingVoltage = 0;
  1232. chargingInfo[_gunCount]->PresentChargingCurrent = 0;
  1233. }
  1234. ShmPsuData->PsuStopChargeFlag = NO;
  1235. ShmDcCommonData->_isPsuErrorOccur = NO;
  1236. _delayToGetCap = 0;
  1237. }
  1238. void Await()
  1239. {
  1240. usleep(CMD_DELAY_TIME);
  1241. }
  1242. bool ClosePsuPower(byte targetConn, int target)
  1243. {
  1244. bool isStop = true;
  1245. if (target == SYSTEM_CMD)
  1246. {
  1247. for (byte groupIndex = 0; groupIndex < _gunCountRecord; groupIndex++)
  1248. {
  1249. if((chargingInfo[groupIndex]->PresentChargingCurrent * 10) > SEFETY_SWITCH_RELAY_CUR)
  1250. {
  1251. isStop = false;
  1252. }
  1253. }
  1254. if (isStop)
  1255. {
  1256. SwitchPower(SYSTEM_CMD, PSU_POWER_OFF);
  1257. }
  1258. else
  1259. {
  1260. PresentOutputVol(SYSTEM_CMD, 0, 0, ShmPsuData->SystemPresentPsuQuantity);
  1261. }
  1262. }
  1263. else if(ShmPsuData->PsuGroup[target].GroupPresentOutputCurrent > SEFETY_SWITCH_RELAY_CUR)
  1264. {
  1265. //PRINTF_FUNC ("target = %d, %d \n", target, ShmPsuData->PsuGroup[target].GroupPresentOutputCurrent);
  1266. isStop = false;
  1267. PresentOutputVol(target, 0, 0, ShmPsuData->PsuGroup[target].GroupPresentPsuQuantity); Await();
  1268. }
  1269. else
  1270. {
  1271. //PRINTF_FUNC ("close = %d \n", target);
  1272. SwitchPower(target, PSU_POWER_OFF);
  1273. FlashLed(target, PSU_FLASH_NORMAL);
  1274. }
  1275. return isStop;
  1276. }
  1277. void SwitchOffPowerCheck(byte groupIndex)
  1278. {
  1279. _maxChargingStatus = _CHARGING_GUN_STATUS_STOP;
  1280. for (byte index = 0; index < _gunCountRecord; index++)
  1281. {
  1282. // 判斷另一把槍的狀態
  1283. if (index != groupIndex)
  1284. {
  1285. if ((chargingInfo[index]->SystemStatus >= SYS_MODE_PREPARE_FOR_EV && chargingInfo[index]->SystemStatus <= SYS_MODE_CHARGING) ||
  1286. (chargingInfo[index]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && chargingInfo[index]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
  1287. _maxChargingStatus = _CHARGING_GUN_STATUS_CHARGING;
  1288. else
  1289. _maxChargingStatus = _CHARGING_GUN_STATUS_STOP;
  1290. }
  1291. }
  1292. }
  1293. byte GetPollingCmd()
  1294. {
  1295. if (psuCmdSeq == _PSU_CMD_CAP)
  1296. {
  1297. psuCmdSeq = _PSU_CMD_IAVAILABLE;
  1298. }
  1299. else if (psuCmdSeq == _PSU_CMD_IAVAILABLE)
  1300. {
  1301. psuCmdSeq = _PSU_CMD_OUTPUT_V;
  1302. }
  1303. else if (psuCmdSeq == _PSU_CMD_OUTPUT_V)
  1304. {
  1305. psuCmdSeq = _PSU_CMD_STATUS;
  1306. }
  1307. else if (psuCmdSeq == _PSU_CMD_STATUS)
  1308. {
  1309. if (_delay2GetPsuTemp <= 0)
  1310. psuCmdSeq = _PSU_CMD_TEMP;
  1311. else
  1312. psuCmdSeq = _PSU_CMD_CAP;
  1313. }
  1314. else
  1315. psuCmdSeq = _PSU_CMD_CAP;
  1316. return psuCmdSeq;
  1317. }
  1318. void PsuPowerON(byte targetPsuGroup)
  1319. {
  1320. // 電流 : 除上使用的模塊總數得到每一個模塊應該輸出的電流值再乘上該輸出群的模塊數量
  1321. PresentOutputVol(targetPsuGroup,
  1322. ShmPsuData->PsuGroup[targetPsuGroup].GroupTargetOutputVoltage,
  1323. ShmPsuData->PsuGroup[targetPsuGroup].GroupTargetOutputCurrent,
  1324. ShmPsuData->PsuGroup[targetPsuGroup].GroupPresentPsuQuantity);
  1325. if (ShmPsuData->PsuGroup[targetPsuGroup].PwSwitchStatus == _PSU_POWER_STATUS_OFF)
  1326. {
  1327. ShmPsuData->PsuGroup[targetPsuGroup].PwSwitchStatus = _PSU_POWER_STATUS_ON;
  1328. SwitchPower(targetPsuGroup, PSU_POWER_ON);
  1329. FlashLed(targetPsuGroup, PSU_FLASH_ON);
  1330. }
  1331. }
  1332. byte PsuPowerOFF(byte targetConn, byte targetPsuGroup)
  1333. {
  1334. if (ShmPsuData->PsuGroup[targetPsuGroup].PwSwitchStatus == _PSU_POWER_STATUS_ON)
  1335. {
  1336. // 判斷輸出是否還在
  1337. if (ClosePsuPower(targetConn, targetPsuGroup))
  1338. ShmPsuData->PsuGroup[targetPsuGroup].PwSwitchStatus = _PSU_POWER_STATUS_OFF;
  1339. }
  1340. return ShmPsuData->PsuGroup[targetPsuGroup].PwSwitchStatus;
  1341. }
  1342. void PsuOutputCurrentLimtit(byte targetGroup, unsigned short *cur)
  1343. {
  1344. //LWADD_MIN_POWER
  1345. unsigned short Psu_Min_OutputCur =
  1346. (ShmPsuData->PsuGroup[targetGroup].GroupPresentPsuQuantity * PSU_MIN_OUTPUT_CUR) * 10;
  1347. if (*cur < Psu_Min_OutputCur)
  1348. *cur = Psu_Min_OutputCur;
  1349. }
  1350. int main(void)
  1351. {
  1352. if(InitShareMemory() == FAIL)
  1353. {
  1354. #ifdef SystemLogMessage
  1355. DEBUG_ERROR("InitShareMemory NG\n");
  1356. #endif
  1357. if(ShmStatusCodeData != NULL)
  1358. {
  1359. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
  1360. }
  1361. sleep(5);
  1362. return 0;
  1363. }
  1364. PRINTF_FUNC("InitShareMemory OK\n");
  1365. // register callback function
  1366. RefreshStatus(&GetStatusCallback);
  1367. RefreshModuleCount(&GetModuleCountCallback);
  1368. RefreshAvailableCap(&GetAvailableCapCallback);
  1369. RefreshFwVersion(&GetFwCallback);
  1370. RefreshInputVol(&GetInputVoltageCallback);
  1371. RefreshGetOutput(&GetPresentOutputCallback);
  1372. RefreshMisInfo(&GetMisCallback);
  1373. RefreshIavailable(&GetIavailableCallback);
  1374. RefreshGetOutputF(&GetPresentOutputFCallback);
  1375. // GetPresentOutputCallback & GetStatusCallback
  1376. AutoMode_RefreshOutputAndTemp(&GetOutputAndTempCallback);
  1377. // GetStatusCallback
  1378. AutoMode_RefreshModuleStatus(&GetModuleStatusCallback);
  1379. // GetInputVoltageCallback
  1380. AutoMode_RefreshModuleInput(&GetModuleInputCallback);
  1381. sleep(2);
  1382. _gunCountRecord = ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
  1383. // initial object
  1384. FindGunInfo();
  1385. InitialPsuData();
  1386. GetTimespecFunc(&ShmDcCommonData->_psuComm_time);
  1387. libInitialize = InitialCommunication();
  1388. byte isInitialComp = NO;
  1389. if (ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == YES)
  1390. {
  1391. PRINTF_FUNC("Alter native mode. \n");
  1392. }
  1393. //main loop
  1394. while (libInitialize)
  1395. {
  1396. // 斷電狀態
  1397. if (ShmSysConfigAndInfo->SysInfo.AcContactorStatus == NO)
  1398. {
  1399. //一但 AC Off PSU 斷電全部的 PSU Group ID 會全部清 0
  1400. if (!isInitialComp)
  1401. {
  1402. ShmPsuData->Work_Step = INITIAL_START;
  1403. psuCmdSeq = _PSU_CMD_STATUS;
  1404. sleep(2);
  1405. InitialPsuData();
  1406. isInitialComp = YES;
  1407. }
  1408. ShmDcCommonData->psuKeepCommunication = ShmDcCommonData->acContactSwitch;
  1409. sleep(1);
  1410. continue;
  1411. }
  1412. else
  1413. {
  1414. if (isInitialComp)
  1415. GetTimespecFunc(&ShmDcCommonData->_psuComm_time);
  1416. isInitialComp = NO;
  1417. }
  1418. // 自檢失敗
  1419. if (ShmPsuData->Work_Step == _NO_WORKING)
  1420. {
  1421. PRINTF_FUNC("== PSU == self test fail. \n");
  1422. sleep(5);
  1423. }
  1424. else if (ShmDcCommonData->rebootCount < 1)
  1425. {
  1426. int _time = GetTimeoutValue(&ShmDcCommonData->_psuComm_time);
  1427. if (_time < 0)
  1428. GetTimespecFunc(&ShmDcCommonData->_psuComm_time);
  1429. if (_time > PSU_GONE_RESET)
  1430. {
  1431. if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuComminicationErrWithCSU == NO)
  1432. {
  1433. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuComminicationErrWithCSU = YES;
  1434. ShmDcCommonData->rebootCount = 1;
  1435. PRINTF_FUNC("Psu is gone, reset one time. \n");
  1436. }
  1437. }
  1438. }
  1439. switch(ShmPsuData->Work_Step)
  1440. {
  1441. case INITIAL_START:
  1442. {
  1443. PRINTF_FUNC("== PSU == INITIAL_START \n");
  1444. GetTimespecMFunc(&_cmdSubPsuPriority_time);
  1445. sleep(5);
  1446. ClosePsuPower(PSU_NONE, SYSTEM_CMD);
  1447. SetWalkInConfig(SYSTEM_CMD, NO, 0);
  1448. FlashLed(SYSTEM_CMD, PSU_FLASH_NORMAL);
  1449. for (byte index = 0; index < ShmPsuData->GroupCount; index++)
  1450. {
  1451. ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity = 0;
  1452. isStartOutputSwitch[index] = false;
  1453. }
  1454. ShmPsuData->Work_Step = GET_PSU_COUNT;
  1455. }
  1456. break;
  1457. case GET_PSU_COUNT:
  1458. {
  1459. int time = GetTimeoutMValue(&_cmdSubPsuPriority_time);
  1460. byte moduleCount = 0;
  1461. if (time < 0)
  1462. GetTimespecMFunc(&_cmdSubPsuPriority_time);
  1463. // 發送取得目前全部模組數量
  1464. GetModuleCount(SYSTEM_CMD);
  1465. if (time > 500)
  1466. {
  1467. if (psuCmdSeq == _PSU_CMD_STATUS)
  1468. {
  1469. // 取得狀態 : 支援模塊不須按照順序功能
  1470. for (byte index = 0; index < ShmPsuData->GroupCount; index++)
  1471. {
  1472. GetStatus(index, LIB_IN_USE);
  1473. }
  1474. Await();
  1475. }
  1476. else if (psuCmdSeq == _PSU_CMD_GETCOUNT)
  1477. {
  1478. // 分別取各群模組數量
  1479. for (byte index = 0; index < ShmPsuData->GroupCount; index++)
  1480. {
  1481. // 總和各群模組數量
  1482. moduleCount += ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity;
  1483. // 取各群模組數量
  1484. GetModuleCount(index);
  1485. }
  1486. if(_delayToGetCap == 0 &&
  1487. moduleCount == ShmPsuData->SystemPresentPsuQuantity && moduleCount > 0)
  1488. {
  1489. PRINTF_FUNC("== PSU == Connector Count = %d, moduleCount = %d, sysCount = %d\n",
  1490. _gunCountRecord, moduleCount, ShmPsuData->SystemPresentPsuQuantity);
  1491. }
  1492. // 判斷系統數量與各群數量一致
  1493. if(moduleCount == ShmPsuData->SystemPresentPsuQuantity && moduleCount > 0)
  1494. {
  1495. // 電樁在 Booting 的狀態 - 自檢
  1496. PRINTF_FUNC ( "== PSU == GET_SYS_CAP \n" );
  1497. ShmPsuData->Work_Step = GET_SYS_CAP;
  1498. }
  1499. }
  1500. if (psuCmdSeq == _PSU_CMD_STATUS)
  1501. psuCmdSeq = _PSU_CMD_GETCOUNT;
  1502. else
  1503. psuCmdSeq = _PSU_CMD_STATUS;
  1504. GetTimespecMFunc(&_cmdSubPsuPriority_time);
  1505. }
  1506. }
  1507. break;
  1508. case GET_SYS_CAP:
  1509. {
  1510. int time = GetTimeoutMValue(&_cmdSubPsuPriority_time);
  1511. if (time < 0)
  1512. GetTimespecMFunc(&_cmdSubPsuPriority_time);
  1513. if (time > 200)
  1514. {
  1515. bool isFinish = true;
  1516. for(byte group = 0; group < ShmPsuData->GroupCount; group++)
  1517. {
  1518. if (isFinish)
  1519. {
  1520. for (byte psuCount = 0; psuCount < ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity; psuCount++)
  1521. {
  1522. if (strcmp((char *)ShmPsuData->PsuGroup[group].PsuModule[psuCount].FwVersion, "") == EQUAL ||
  1523. ShmPsuData->SystemAvailablePower <= 0 || ShmPsuData->SystemAvailableCurrent <= 0)
  1524. {
  1525. isFinish = false;
  1526. break;
  1527. }
  1528. }
  1529. }
  1530. }
  1531. if (!isFinish)
  1532. {
  1533. for (byte index = 0; index < ShmPsuData->GroupCount; index++)
  1534. {
  1535. if (psuCmdSeq == _PSU_CMD_STATUS)
  1536. {
  1537. // 取得狀態 : 支援模塊不須按照順序功能
  1538. GetStatus(index, LIB_IN_USE);
  1539. }
  1540. else if (psuCmdSeq == _PSU_CMD_CAP)
  1541. {
  1542. // 取系統總輸出能力
  1543. GetModuleCap(index);
  1544. }
  1545. else if (psuCmdSeq == _PSU_CMD_VERSION)
  1546. {
  1547. // 取版號
  1548. GetModuleVer(index);
  1549. }
  1550. }
  1551. Await();
  1552. if (psuCmdSeq == _PSU_CMD_STATUS)
  1553. psuCmdSeq = _PSU_CMD_CAP;
  1554. else if (psuCmdSeq == _PSU_CMD_CAP)
  1555. psuCmdSeq = _PSU_CMD_VERSION;
  1556. else
  1557. psuCmdSeq = _PSU_CMD_STATUS;
  1558. }
  1559. else
  1560. {
  1561. // 判斷系統輸出額定功率與電流
  1562. PRINTF_FUNC("SystemAvailableCurrent = %d (A), SystemAvailablePower = %d (KW) \n",
  1563. ShmPsuData->SystemAvailableCurrent / 10, ShmPsuData->SystemAvailablePower / 10);
  1564. if (ShmSysConfigAndInfo->SysInfo.BootingStatus == BOOTTING)
  1565. {
  1566. PRINTF_FUNC ( "== PSU == BOOTING_COMPLETE \n" );
  1567. ShmPsuData->Work_Step = BOOTING_COMPLETE;
  1568. }
  1569. else
  1570. {
  1571. PRINTF_FUNC ( "== PSU == _WORK_CHARGING \n" );
  1572. ShmPsuData->Work_Step = _WORK_CHARGING;
  1573. }
  1574. }
  1575. GetTimespecMFunc(&_cmdSubPsuPriority_time);
  1576. GetTimespecMFunc(&_log_time);
  1577. }
  1578. }
  1579. break;
  1580. case BOOTING_COMPLETE:
  1581. {
  1582. bool isSelfTestPass = true;
  1583. for (byte groupIndex = 0; groupIndex < _gunCountRecord; groupIndex++)
  1584. {
  1585. if (chargingInfo[groupIndex]->SystemStatus == SYS_MODE_BOOTING)
  1586. {
  1587. isSelfTestPass = false;
  1588. }
  1589. }
  1590. if (isSelfTestPass)
  1591. ShmPsuData->Work_Step = _WORK_CHARGING;
  1592. sleep(1);
  1593. }
  1594. break;
  1595. case _WORK_CHARGING:
  1596. {
  1597. int time = GetTimeoutMValue(&_cmdSubPsuPriority_time);
  1598. int logTime = GetTimeoutMValue(&_log_time);
  1599. //int _timebuf = 0;
  1600. if (time < 0)
  1601. GetTimespecMFunc(&_cmdSubPsuPriority_time);
  1602. // 低 Priority 的指令
  1603. if (time > 1500)
  1604. {
  1605. GetTimespecMFunc(&_cmdSubPsuPriority_time);
  1606. Check2ClearPsuError();
  1607. if (_delay2GetPsuTemp > 0)
  1608. _delay2GetPsuTemp--;
  1609. }
  1610. for (byte groupIndex = 0; groupIndex < ShmPsuData->GroupCount; groupIndex++)
  1611. {
  1612. if (psuCmdSeq == _PSU_CMD_STATUS)
  1613. {
  1614. // 取得狀態
  1615. GetStatus(groupIndex, LIB_IN_USE);
  1616. }
  1617. else if (psuCmdSeq == _PSU_CMD_CAP)
  1618. {
  1619. // 取系統總輸出能力
  1620. GetModuleCap(groupIndex);
  1621. }
  1622. else if (psuCmdSeq == _PSU_CMD_IAVAILABLE)
  1623. {
  1624. GetModuleIavailable ( groupIndex );
  1625. }
  1626. else if (psuCmdSeq == _PSU_CMD_OUTPUT_V)
  1627. {
  1628. // 取各群輸出電壓電流 (UU)
  1629. GetModuleOutputF(groupIndex);
  1630. }
  1631. else if (psuCmdSeq == _PSU_CMD_TEMP)
  1632. {
  1633. // 取得模塊溫度
  1634. GetDcTemperature(groupIndex);
  1635. _delay2GetPsuTemp = 10; // 15s
  1636. }
  1637. }
  1638. Await();
  1639. psuCmdSeq = GetPollingCmd();
  1640. for (byte gunIndex = 0; gunIndex < _gunCountRecord; gunIndex++)
  1641. {
  1642. // 針對各槍當前狀態,傳送需要回傳的資料指令
  1643. if (((chargingInfo[gunIndex]->SystemStatus >= SYS_MODE_PREPARE_FOR_EVSE && chargingInfo[gunIndex]->SystemStatus <= SYS_MODE_CHARGING) && chargingInfo[gunIndex]->RelayK1K2Status) ||
  1644. (chargingInfo[gunIndex]->SystemStatus >= SYS_MODE_PREPARE_FOR_EVSE && chargingInfo[gunIndex]->SystemStatus <= SYS_MODE_CHARGING && chargingInfo[gunIndex]->Type == _Type_GB) ||
  1645. (chargingInfo[gunIndex]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && chargingInfo[gunIndex]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
  1646. {
  1647. OutputChargingLogFuncion(gunIndex);
  1648. // 該槍該群是否為使用中
  1649. if (ShmPsuData->PsuGroup[gunIndex].PwSwitchStatus == _PSU_POWER_STATUS_OFF &&
  1650. ShmSmartBoxData->ConnectorStatus[gunIndex].ConnectorStaus != _CONNECTOR_STATUS_USING)
  1651. {
  1652. // 切出該模塊
  1653. }
  1654. else
  1655. {
  1656. unsigned short _shareOutputCur_buf = 0;
  1657. // Fetch Group
  1658. if (ShmSmartBoxData->Dynamic4Fetch[gunIndex].ShareGroup < ShmPsuData->GroupCount)
  1659. {
  1660. byte _shareGroup = ShmSmartBoxData->Dynamic4Fetch[gunIndex].ShareGroup;
  1661. byte totalPsuCount = chargingInfo[gunIndex]->_TotalPsuCount;
  1662. if (ShmSmartBoxData->Dynamic4Fetch[gunIndex].FetchLoopStep >= _PSU_DYNAMIC_FETCH_STEP_TG_VOL &&
  1663. ShmSmartBoxData->Dynamic4Fetch[gunIndex].FetchLoopStep <= _PSU_DYNAMIC_FETCH_STEP_WATI_FINISH)
  1664. {
  1665. // 升壓
  1666. ShmPsuData->PsuGroup[_shareGroup].GroupTargetOutputVoltage = chargingInfo[gunIndex]->EvBatterytargetVoltage * 10;
  1667. if (ShmSmartBoxData->Dynamic4Fetch[gunIndex].FetchLoopStep >= _PSU_DYNAMIC_FETCH_STEP_CUR_SHARE)
  1668. {
  1669. // 均流
  1670. totalPsuCount += ShmPsuData->PsuGroup[_shareGroup].GroupPresentPsuQuantity;
  1671. // 目標電流
  1672. ShmSmartBoxData->Dynamic4Fetch[gunIndex].ShareTargetCurrent = (chargingInfo[gunIndex]->PresentChargingCurrent /
  1673. totalPsuCount * ShmPsuData->PsuGroup[_shareGroup].GroupPresentPsuQuantity) * 10;
  1674. if (ShmPsuData->PsuGroup [_shareGroup].GroupPresentOutputCurrent + SHARE_CURRENT_GAP <=
  1675. ShmSmartBoxData->Dynamic4Fetch[gunIndex].ShareTargetCurrent)
  1676. _shareOutputCur_buf = ShmPsuData->PsuGroup[_shareGroup].GroupPresentOutputCurrent + SHARE_CURRENT_GAP;
  1677. else
  1678. _shareOutputCur_buf = ShmSmartBoxData->Dynamic4Fetch[gunIndex].ShareTargetCurrent;
  1679. }
  1680. PsuOutputCurrentLimtit(_shareGroup, &_shareOutputCur_buf);
  1681. ShmPsuData->PsuGroup [_shareGroup].GroupTargetOutputCurrent = _shareOutputCur_buf;
  1682. // if (logTime >= 1000)
  1683. // {
  1684. // PRINTF_FUNC("_shareGroup = %d, ShareTargetCurrent = %d, GroupPresentOutputCurrent = %d, GroupTargetOutputCurrent = %d \n",
  1685. // _shareGroup,
  1686. // ShmSmartBoxData->Dynamic4Fetch[gunIndex].ShareTargetCurrent,
  1687. // ShmPsuData->PsuGroup[_shareGroup].GroupPresentOutputCurrent,
  1688. // ShmPsuData->PsuGroup [_shareGroup].GroupTargetOutputCurrent);
  1689. // }
  1690. if (ShmPsuData->PsuGroup [_shareGroup].GroupTargetOutputVoltage <= PSU_MIN_VOL)
  1691. {
  1692. PsuPowerOFF ( gunIndex, _shareGroup );
  1693. }
  1694. else
  1695. {
  1696. PsuPowerON ( _shareGroup );
  1697. }
  1698. }
  1699. }
  1700. // Release Group
  1701. unsigned short _releasePsuCount_buf = 0;
  1702. unsigned short _releaseTargetCur = 0;
  1703. if (ShmSmartBoxData->Dynamic4Release[gunIndex].ReleaseGroup < ShmPsuData->GroupCount)
  1704. {
  1705. byte _releaseGroup = ShmSmartBoxData->Dynamic4Release[gunIndex].ReleaseGroup;
  1706. if (ShmSmartBoxData->Dynamic4Release[gunIndex].ReleaseLoopStep >= _PSU_DYNAMIC_RELEASE_STEP_PWROFF &&
  1707. ShmSmartBoxData->Dynamic4Release[gunIndex].ReleaseLoopStep <= _PSU_DYNAMIC_RELEASE_STEP_WAIT_FINISH)
  1708. {
  1709. unsigned short _releaseTargetVol = chargingInfo[gunIndex]->EvBatterytargetVoltage * 10;
  1710. _releasePsuCount_buf = ShmPsuData->PsuGroup[_releaseGroup].GroupPresentPsuQuantity;
  1711. // 扣掉預計要輸出的電流, 餘下的才是該模塊輸出的電流
  1712. // if (logTime >= 1000)
  1713. // {
  1714. // PRINTF_FUNC ("Req = %.1f, LimitCur = %.1f, _releasePsuCount_buf = %d \n",
  1715. // chargingInfo[gunIndex]->EvBatterytargetCurrent * 10,
  1716. // ShmSmartBoxData->Dynamic4Release[gunIndex].LimitCur,
  1717. // _releasePsuCount_buf);
  1718. // }
  1719. if ((chargingInfo[gunIndex]->EvBatterytargetCurrent * 10) - ShmSmartBoxData->Dynamic4Release[gunIndex].LimitCur - PSU_CUR_GAP < PSU_MIN_OUTPUT_CUR)
  1720. _releaseTargetCur = PSU_MIN_OUTPUT_CUR;
  1721. else
  1722. _releaseTargetCur = (chargingInfo[gunIndex]->EvBatterytargetCurrent * 10) - ShmSmartBoxData->Dynamic4Release[gunIndex].LimitCur - PSU_CUR_GAP;
  1723. if (ShmSmartBoxData->Dynamic4Release[gunIndex].ReleaseLoopStep == _PSU_DYNAMIC_RELEASE_STEP_PWROFF)
  1724. {
  1725. ShmPsuData->PsuGroup[_releaseGroup].GroupTargetOutputVoltage = _releaseTargetVol;
  1726. PsuOutputCurrentLimtit(_releaseGroup, &_releaseTargetCur);
  1727. ShmPsuData->PsuGroup[_releaseGroup].GroupTargetOutputCurrent = _releaseTargetCur;
  1728. PsuPowerON(_releaseGroup);
  1729. }
  1730. else if (ShmSmartBoxData->Dynamic4Release[gunIndex].ReleaseLoopStep == _PSU_DYNAMIC_RELEASE_STEP_WAIT_FINISH)
  1731. {
  1732. PsuPowerOFF(gunIndex, _releaseGroup);
  1733. }
  1734. }
  1735. }
  1736. // 對群下發輸出指令
  1737. float sumCurrent = 0;
  1738. for (int _psuGpIndex = ShmSmartBoxData->ConnectorUsingGroupCount[gunIndex] - 1; _psuGpIndex >= 0; _psuGpIndex--)
  1739. {
  1740. byte _targetGroup = ConnectorUsingSeq[gunIndex][_psuGpIndex];
  1741. byte psuTotalCount = chargingInfo[gunIndex]->_TotalPsuCount - _releasePsuCount_buf;
  1742. unsigned short _targetOutputVol_buf = chargingInfo[gunIndex]->EvBatterytargetVoltage * 10;
  1743. float _evTargetCur = chargingInfo[gunIndex]->EvBatterytargetCurrent;
  1744. if (_evTargetCur - (_shareOutputCur_buf / 10) <= 0)
  1745. _evTargetCur = 0;
  1746. else
  1747. _evTargetCur -= (_shareOutputCur_buf / 10);
  1748. if (_releasePsuCount_buf != 0)
  1749. {
  1750. if (ShmSmartBoxData->Dynamic4Release[gunIndex].ReleaseGroup == _targetGroup)
  1751. continue;
  1752. else
  1753. _evTargetCur = ShmSmartBoxData->Dynamic4Release[gunIndex].LimitCur / 10;
  1754. }
  1755. unsigned short _targetOutputCur_buf = 0;
  1756. // 最後一群輸出為總輸出 - 已經輸出的電流
  1757. if (_psuGpIndex == 0)
  1758. {
  1759. if (_evTargetCur - sumCurrent > 0)
  1760. _targetOutputCur_buf = (_evTargetCur - sumCurrent) * 10;
  1761. else
  1762. {
  1763. // 輸出電流邏輯 : 該群需要分攤輸出的電流 = 總需求電流 / 總模塊個數 * 該群模塊個數
  1764. _targetOutputCur_buf = (_evTargetCur /
  1765. psuTotalCount * ShmPsuData->PsuGroup[_targetGroup].GroupPresentPsuQuantity) * 10;
  1766. }
  1767. }
  1768. else
  1769. {
  1770. // 輸出電流邏輯 : 該群需要分攤輸出的電流 = 總需求電流 / 總模塊個數 * 該群模塊個數
  1771. _targetOutputCur_buf = (_evTargetCur /
  1772. psuTotalCount * ShmPsuData->PsuGroup[_targetGroup].GroupPresentPsuQuantity) * 10;
  1773. sumCurrent += _targetOutputCur_buf;
  1774. }
  1775. // 經度 0.1
  1776. // if (logTime >= LOG_TIME)
  1777. // {
  1778. // PRINTF_FUNC("psuTotalCount = %d, _evTargetCur = %.1f, sumCurrent = %.1f \n",
  1779. // psuTotalCount,
  1780. // _evTargetCur,
  1781. // sumCurrent);
  1782. //
  1783. // PRINTF_FUNC("_targetGroup = %d, _targetOutputVol_buf = %d (0.1), _targetOutputCur_buf = %d (0.1)\n",
  1784. // _targetGroup,
  1785. // _targetOutputVol_buf,
  1786. // _targetOutputCur_buf);
  1787. // }
  1788. ShmPsuData->PsuGroup[_targetGroup].GroupTargetOutputVoltage = _targetOutputVol_buf;
  1789. PsuOutputCurrentLimtit(_targetGroup, &_targetOutputCur_buf);
  1790. ShmPsuData->PsuGroup[_targetGroup].GroupTargetOutputCurrent = _targetOutputCur_buf;
  1791. if (ShmPsuData->PsuGroup[_targetGroup].GroupTargetOutputVoltage <= PSU_MIN_VOL)
  1792. PsuPowerOFF(gunIndex, _targetGroup);
  1793. else
  1794. PsuPowerON(_targetGroup);
  1795. }
  1796. }
  1797. }
  1798. else if (chargingInfo[gunIndex]->SystemStatus >= SYS_MODE_TERMINATING &&
  1799. chargingInfo[gunIndex]->SystemStatus <= SYS_MODE_ALARM)
  1800. {
  1801. // 對群下發輸出指令
  1802. bool isAllStop = true;
  1803. for (byte _psuGpIndex = 0; _psuGpIndex < ShmSmartBoxData->ConnectorUsingGroupCount[gunIndex]; _psuGpIndex++)
  1804. {
  1805. if (PsuPowerOFF(gunIndex, ConnectorUsingSeq[gunIndex][_psuGpIndex]) == _PSU_POWER_STATUS_ON)
  1806. {
  1807. if (isAllStop)
  1808. isAllStop = false;
  1809. }
  1810. }
  1811. if (ShmSmartBoxData->Dynamic4Fetch[gunIndex].ShareGroup < ShmPsuData->GroupCount)
  1812. {
  1813. PsuPowerOFF(gunIndex, ShmSmartBoxData->Dynamic4Fetch[gunIndex].ShareGroup);
  1814. }
  1815. if (isAllStop)
  1816. ShmSmartBoxData->ConnectorStatus[gunIndex].ConnectorStaus = _CONNECTOR_STATUS_NONE;
  1817. }
  1818. }
  1819. if (logTime > LOG_TIME)
  1820. GetTimespecMFunc(&_log_time);
  1821. }
  1822. break;
  1823. }
  1824. usleep(20000);
  1825. }
  1826. return FAIL;
  1827. }