Module_PsuComm.c 86 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748
  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 DERATING_GAP 30
  9. #define ELEMENT_NOT_FIND 255
  10. #define CHK_VOL_RANGE 50
  11. #define CHK_CUR_RANGE 10
  12. #define DERATING_RANGE 100
  13. #define MIN_1A_CURRENT 10 // 該值須保持最小為 1A
  14. #define MIN_5V_VOLTAGE 50
  15. #define STOP_CURRENT 30
  16. #define PSU_MIN_CUR 1000
  17. #define PSU_MIN_VOL 1500
  18. #define PRE_CHARG_STEP_CUR 30
  19. #define PRE_CHARG_RANGE 50
  20. #define EQUAL 0
  21. #define CMD_DELAY_TIME 25000
  22. #define LOG_VOL_GAP 50
  23. #define LOG_CUR_GAP 5
  24. #define PSU_MIN_OUTPUT_CUR 1
  25. #define SHUTDOWN_OUTPUT 0
  26. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  27. struct StatusCodeData *ShmStatusCodeData;
  28. struct PsuData *ShmPsuData;
  29. struct DcCommonInformation *ShmDcCommonData;
  30. bool libInitialize = false;
  31. byte getAvailableCapOffset = 5;
  32. byte deratingKeepCount = 0;
  33. byte step3KeepCount = 0;
  34. byte psuCmdSeq = _PSU_CMD_CAP;
  35. byte startModuleFlag = false;
  36. float chargingOutputLogInfo[2][4];
  37. void PRINTF_FUNC(char *string, ...);
  38. int StoreLogMsg(const char *fmt, ...);
  39. #define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  40. #define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  41. #define DEBUG_ERROR(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  42. int GetTimeoutValue(struct timespec *startTime);
  43. long int GetTimeoutMValue(struct timespec *startTime)
  44. {
  45. struct timespec endTime;
  46. clock_gettime(CLOCK_MONOTONIC, &endTime);
  47. return 1000 * (endTime.tv_sec - startTime->tv_sec) + (endTime.tv_nsec - startTime->tv_nsec) / 1000000;
  48. }
  49. void GetTimespecMFunc(struct timespec *time)
  50. {
  51. clock_gettime(CLOCK_MONOTONIC, time);
  52. }
  53. int GetTimeoutValue(struct timespec *startTime)
  54. {
  55. struct timespec endTime;
  56. clock_gettime(CLOCK_MONOTONIC_COARSE, &endTime);
  57. return endTime.tv_sec - startTime->tv_sec;
  58. }
  59. void GetTimespecFunc(struct timespec *time)
  60. {
  61. clock_gettime(CLOCK_MONOTONIC_COARSE, time);
  62. }
  63. int StoreLogMsg(const char *fmt, ...)
  64. {
  65. char Buf[4096+256];
  66. char buffer[4096];
  67. va_list args;
  68. struct timeb SeqEndTime;
  69. struct tm *tm;
  70. va_start(args, fmt);
  71. int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
  72. va_end(args);
  73. memset(Buf,0,sizeof(Buf));
  74. ftime(&SeqEndTime);
  75. SeqEndTime.time = time(NULL);
  76. tm=localtime(&SeqEndTime.time);
  77. if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES)
  78. {
  79. sprintf(Buf,"%02d:%02d:%02d:%03d - %s",
  80. tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm, buffer);
  81. printf("%s \n", Buf);
  82. }
  83. else
  84. {
  85. sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog_%s",
  86. tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm,
  87. buffer,
  88. tm->tm_year+1900,tm->tm_mon+1,
  89. ShmSysConfigAndInfo->SysConfig.SerialNumber);
  90. system(Buf);
  91. }
  92. return rc;
  93. }
  94. void PRINTF_FUNC(char *string, ...)
  95. {
  96. va_list args;
  97. char buffer[4096];
  98. va_start(args, string);
  99. vsnprintf(buffer, sizeof(buffer), string, args);
  100. va_end(args);
  101. DEBUG_INFO("%s ", buffer);
  102. }
  103. //=================================
  104. // Common routine
  105. //=================================
  106. size_t FindIndex(const int a[], size_t size, int value, byte group)
  107. {
  108. size_t index = 0;
  109. while ( index < size && a[index] != value ) ++index;
  110. return (index == size ? ELEMENT_NOT_FIND : group);
  111. }
  112. byte FindTargetGroup(byte address)
  113. {
  114. byte _group = ELEMENT_NOT_FIND;
  115. if (ShmPsuData->GroupCount == 1)
  116. _group = 0;
  117. else
  118. {
  119. _group = FindIndex(ShmDcCommonData->connector[0], ShmPsuData->PsuGroup[0].GroupPresentPsuQuantity, address, 0);
  120. if (_group == ELEMENT_NOT_FIND)
  121. _group = FindIndex(ShmDcCommonData->connector[1], ShmPsuData->PsuGroup[1].GroupPresentPsuQuantity, address, 1);
  122. }
  123. return _group;
  124. }
  125. byte FindRealAddr(byte group, byte address)
  126. {
  127. byte _addr = 0;
  128. byte index = 0;
  129. if (group == 0)
  130. {
  131. while (index < ShmDcCommonData->conn_1_count)
  132. {
  133. if (ShmDcCommonData->connector[group][index] == address)
  134. {
  135. _addr = index;
  136. break;
  137. }
  138. ++index;
  139. }
  140. }
  141. else if (group == 1)
  142. {
  143. while (index < ShmDcCommonData->conn_2_count)
  144. {
  145. if (ShmDcCommonData->connector [group][index] == address)
  146. {
  147. _addr = index;
  148. break;
  149. }
  150. ++ index;
  151. }
  152. }
  153. return _addr;
  154. }
  155. bool IsOverModuleCount(byte count)
  156. {
  157. bool result = false;
  158. if (count >= ShmPsuData->SystemPresentPsuQuantity)
  159. result = true;
  160. return result;
  161. }
  162. //=================================
  163. // Save data to share memory Function
  164. //=================================
  165. bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
  166. {
  167. for (byte index = 0; index < CHAdeMO_QUANTITY; index++)
  168. {
  169. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)
  170. {
  171. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
  172. return true;
  173. }
  174. }
  175. for (byte index = 0; index < CCS_QUANTITY; index++)
  176. {
  177. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)
  178. {
  179. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
  180. return true;
  181. }
  182. }
  183. for (byte index = 0; index < GB_QUANTITY; index++)
  184. {
  185. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)
  186. {
  187. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
  188. return true;
  189. }
  190. }
  191. return false;
  192. }
  193. //=================================
  194. // Alarm code mapping to share memory Function
  195. //=================================
  196. // 檢查 Byte 中某個 Bit 的值
  197. // _byte : 欲改變的 byte
  198. // _bit : 該 byte 的第幾個 bit
  199. int mask_table[] = {
  200. 0x00000001, 0x00000002, 0x00000004, 0x00000008,
  201. 0x00000010, 0x00000020, 0x00000040, 0x00000080,
  202. 0x00000100, 0x00000200, 0x00000400, 0x00000800,
  203. 0x00001000, 0x00002000, 0x00004000, 0x00008000,
  204. 0x00010000, 0x00020000, 0x00040000, 0x00080000,
  205. 0x00100000, 0x00200000, 0x00400000, 0x00800000,
  206. 0x01000000, 0x02000000, 0x04000000, 0x08000000,
  207. 0x10000000, 0x20000000, 0x40000000, 0x80000000
  208. };
  209. #define NONE_DEFINE_1 0
  210. #define NONE_DEFINE_2 1
  211. #define FUSE_BURN_OUT 2
  212. #define PFC_DC_COMM_FAIL 3
  213. #define NONE_DEFINE_3 4
  214. #define NONE_DEFINE_4 5
  215. #define UNBALANCE_POSI_NEGA_BUS_VOL 6
  216. #define BUS_OVER_VOL 7
  217. #define BUS_ABNORMAL_VOL 8
  218. #define PHASE_OVP 9
  219. #define ID_REPETITION 10
  220. #define BUS_UVP 11
  221. #define PHASE_LOSE 12
  222. #define NONE_DEFINE_5 13
  223. #define PHASE_UVP 14
  224. #define NONE_DEFINE_6 15
  225. #define CAN_COMM_FAULT 16
  226. #define DC_DC_UNEVEN_CUR_SHARING 17
  227. #define NONE_DEFINE_7 18
  228. #define PFC_POW_OFF 19
  229. #define NONE_DEFINE_8 20
  230. #define FULL_SPEED_OF_FAN 21
  231. #define DC_DC_POW_OFF 22
  232. #define MODULE_UNDER_POW_LIMIT 23
  233. #define TEMP_POW_LIMIT 24
  234. #define AC_POW_LIMIT 25
  235. #define DC_DC_EEPROM_FAULT 26
  236. #define FAN_FAULT 27
  237. #define DC_DC_SHORT_CIRCUIT 28
  238. #define PFC_EEPROM_FAULT 29
  239. #define DC_DC_OTP 30
  240. #define DC_DC_OVP 31
  241. unsigned char DetectBitValue(int _value, unsigned char _bit)
  242. {
  243. return ( _value & mask_table[_bit] ) != 0x00;
  244. }
  245. bool AbnormalStopAnalysis(byte gun_index, int errCode)
  246. {
  247. bool isErr = false;
  248. for(byte count = 0; count < sizeof(mask_table)/sizeof(mask_table[0]); count++)
  249. {
  250. byte value = DetectBitValue(errCode, count);
  251. if (value == 1)
  252. {
  253. switch(count)
  254. {
  255. case NONE_DEFINE_1 : {} break;
  256. case NONE_DEFINE_2 : {} break;
  257. case FUSE_BURN_OUT :
  258. {
  259. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFuseBurnOut == NO)
  260. {
  261. PRINTF_FUNC("PSU AbnormalStop : FUSE_BURN_OUT \n");
  262. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFuseBurnOut = YES;
  263. }
  264. } break;
  265. case PFC_DC_COMM_FAIL :
  266. {
  267. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuPfcAndDcdcCommFault == NO)
  268. {
  269. PRINTF_FUNC ( "PSU AbnormalStop : PFC_DC_COMM_FAIL \n" );
  270. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuPfcAndDcdcCommFault = YES;
  271. }
  272. } break;
  273. case NONE_DEFINE_3 : {} break;
  274. case NONE_DEFINE_4 : {} break;
  275. case UNBALANCE_POSI_NEGA_BUS_VOL :
  276. {
  277. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuBusVoltageUnbalance == NO)
  278. {
  279. PRINTF_FUNC ( "PSU AbnormalStop : UNBALANCE_POSI_NEGA_BUS_VOL \n" );
  280. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuBusVoltageUnbalance = YES;
  281. }
  282. } break;
  283. case BUS_OVER_VOL :
  284. {
  285. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuBusOverVoltage == NO)
  286. {
  287. PRINTF_FUNC ( "PSU AbnormalStop : BUS_OVER_VOL \n" );
  288. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuBusOverVoltage = YES;
  289. }
  290. } break;
  291. case BUS_ABNORMAL_VOL :
  292. {
  293. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuBusVoltageAbnormal == NO)
  294. {
  295. PRINTF_FUNC ( "PSU AbnormalStop : BUS_ABNORMAL_VOL \n" );
  296. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuBusVoltageAbnormal = YES;
  297. }
  298. } break;
  299. case PHASE_OVP :
  300. {
  301. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DcInputOVP == NO)
  302. {
  303. PRINTF_FUNC ( "PSU AbnormalStop : PHASE_OVP \n" );
  304. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DcInputOVP = YES;
  305. }
  306. } break;
  307. case ID_REPETITION :
  308. {
  309. isErr = true;
  310. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuIdRepeat == NO)
  311. {
  312. PRINTF_FUNC ( "PSU AbnormalStop : ID_REPETITION \n" );
  313. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuIdRepeat = YES;
  314. }
  315. } break;
  316. case BUS_UVP :
  317. {
  318. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuBusUnderVoltage == NO)
  319. {
  320. PRINTF_FUNC ( "PSU AbnormalStop : BUS_UVP \n" );
  321. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuBusUnderVoltage = YES;
  322. }
  323. } break;
  324. case PHASE_LOSE :
  325. {
  326. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuInputPhaseLoss == NO)
  327. {
  328. PRINTF_FUNC ( "PSU AbnormalStop : PHASE_LOSE \n" );
  329. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuInputPhaseLoss = YES;
  330. }
  331. } break;
  332. case NONE_DEFINE_5 : {} break;
  333. case PHASE_UVP :
  334. {
  335. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DcInputUVP == NO)
  336. {
  337. PRINTF_FUNC ( "PSU AbnormalStop : PHASE_UVP \n" );
  338. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DcInputUVP = YES;
  339. }
  340. } break;
  341. case NONE_DEFINE_6 : {} break;
  342. case CAN_COMM_FAULT :
  343. {
  344. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuCanCommFault == NO)
  345. {
  346. PRINTF_FUNC ( "PSU AbnormalStop : CAN_COMM_FAULT \n" );
  347. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuCanCommFault = YES;
  348. }
  349. } break;
  350. case DC_DC_UNEVEN_CUR_SHARING :
  351. {
  352. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuSevereUnevenCurrent == NO)
  353. {
  354. PRINTF_FUNC ( "PSU AbnormalStop : DC_DC_UNEVEN_CUR_SHARING \n" );
  355. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuSevereUnevenCurrent = YES;
  356. }
  357. } break;
  358. case NONE_DEFINE_7 : {} break;
  359. case PFC_POW_OFF :
  360. {
  361. //if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuPfcPowOff == NO)
  362. {
  363. //PRINTF_FUNC ( "PSU AbnormalStop : PFC_POW_OFF \n" );
  364. //ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuPfcPowOff = YES;
  365. }
  366. } break;
  367. case NONE_DEFINE_8 : {} break;
  368. case FULL_SPEED_OF_FAN :
  369. {
  370. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFanFullSpeed == NO)
  371. {
  372. PRINTF_FUNC ( "PSU AbnormalStop : FULL_SPEED_OF_FAN \n" );
  373. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFanFullSpeed = YES;
  374. }
  375. } break;
  376. case DC_DC_POW_OFF :
  377. {
  378. //if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcDcPowOff == NO)
  379. {
  380. //PRINTF_FUNC ( "PSU AbnormalStop : DC_DC_POW_OFF \n" );
  381. //ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcDcPowOff = YES;
  382. }
  383. } break;
  384. case MODULE_UNDER_POW_LIMIT :
  385. {
  386. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuPowerLimitedState == NO)
  387. {
  388. PRINTF_FUNC("PSU AbnormalStop : MODULE_UNDER_POW_LIMIT \n");
  389. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuPowerLimitedState = YES;
  390. }
  391. } break;
  392. case TEMP_POW_LIMIT :
  393. {
  394. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuTemperaturePowerLimit == NO)
  395. {
  396. PRINTF_FUNC ( "PSU AbnormalStop : TEMP_POW_LIMIT \n" );
  397. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuTemperaturePowerLimit = YES;
  398. }
  399. } break;
  400. case AC_POW_LIMIT :
  401. {
  402. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuAcPowerLimit == NO)
  403. {
  404. PRINTF_FUNC ( "PSU AbnormalStop : AC_POW_LIMIT \n" );
  405. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuAcPowerLimit = YES;
  406. }
  407. } break;
  408. case DC_DC_EEPROM_FAULT :
  409. {
  410. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcdcEepromFault == NO)
  411. {
  412. PRINTF_FUNC ( "PSU AbnormalStop : DC_DC_EEPROM_FAULT \n" );
  413. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcdcEepromFault = YES;
  414. }
  415. } break;
  416. case FAN_FAULT :
  417. {
  418. isErr = true;
  419. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFanFailureAlarm == NO)
  420. {
  421. PRINTF_FUNC ( "PSU AbnormalStop : FAN_FAULT \n" );
  422. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFanFailureAlarm = YES;
  423. }
  424. } break;
  425. case DC_DC_SHORT_CIRCUIT :
  426. {
  427. isErr = true;
  428. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuOutputShortCircuit == NO)
  429. {
  430. PRINTF_FUNC ( "PSU AbnormalStop : DC_DC_SHORT_CIRCUIT \n" );
  431. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuOutputShortCircuit = YES;
  432. }
  433. } break;
  434. case PFC_EEPROM_FAULT :
  435. {
  436. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuPfcEepromFault == NO)
  437. {
  438. PRINTF_FUNC ( "PSU AbnormalStop : PFC_EEPROM_FAULT \n" );
  439. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuPfcEepromFault = YES;
  440. }
  441. } break;
  442. case DC_DC_OTP :
  443. {
  444. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcDcOtp == NO)
  445. {
  446. PRINTF_FUNC ( "PSU AbnormalStop : DC_DC_OTP \n" );
  447. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcDcOtp = YES;
  448. }
  449. } break;
  450. case DC_DC_OVP :
  451. {
  452. isErr = true;
  453. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcDcOvp == NO)
  454. {
  455. PRINTF_FUNC ( "PSU AbnormalStop : DC_DC_OVP \n" );
  456. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcDcOvp = YES;
  457. }
  458. } break;
  459. }
  460. }
  461. else if (value == 0)
  462. {
  463. switch(count)
  464. {
  465. case NONE_DEFINE_1 : {} break;
  466. case NONE_DEFINE_2 : {} break;
  467. case FUSE_BURN_OUT :
  468. {
  469. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFuseBurnOut == YES)
  470. {
  471. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFuseBurnOut = NO;
  472. }
  473. } break;
  474. case PFC_DC_COMM_FAIL :
  475. {
  476. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuPfcAndDcdcCommFault == YES)
  477. {
  478. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuPfcAndDcdcCommFault = NO;
  479. }
  480. } break;
  481. case NONE_DEFINE_3 : {} break;
  482. case NONE_DEFINE_4 : {} break;
  483. case UNBALANCE_POSI_NEGA_BUS_VOL :
  484. {
  485. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuBusVoltageUnbalance == YES)
  486. {
  487. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuBusVoltageUnbalance = NO;
  488. }
  489. } break;
  490. case BUS_OVER_VOL :
  491. {
  492. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuBusOverVoltage == YES)
  493. {
  494. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuBusOverVoltage = NO;
  495. }
  496. } break;
  497. case BUS_ABNORMAL_VOL :
  498. {
  499. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuBusVoltageAbnormal == YES)
  500. {
  501. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuBusVoltageAbnormal = NO;
  502. }
  503. } break;
  504. case PHASE_OVP :
  505. {
  506. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DcInputOVP == YES)
  507. {
  508. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DcInputOVP = NO;
  509. }
  510. } break;
  511. case ID_REPETITION :
  512. {
  513. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuIdRepeat == YES)
  514. {
  515. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuIdRepeat = NO;
  516. }
  517. } break;
  518. case BUS_UVP :
  519. {
  520. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuBusUnderVoltage == YES)
  521. {
  522. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuBusUnderVoltage = NO;
  523. }
  524. } break;
  525. case PHASE_LOSE :
  526. {
  527. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuInputPhaseLoss == YES)
  528. {
  529. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuInputPhaseLoss = NO;
  530. }
  531. } break;
  532. case NONE_DEFINE_5 : {} break;
  533. case PHASE_UVP :
  534. {
  535. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DcInputUVP == YES)
  536. {
  537. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DcInputUVP = NO;
  538. }
  539. } break;
  540. case NONE_DEFINE_6 : {} break;
  541. case CAN_COMM_FAULT :
  542. {
  543. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuCanCommFault == YES)
  544. {
  545. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuCanCommFault = NO;
  546. }
  547. } break;
  548. case DC_DC_UNEVEN_CUR_SHARING :
  549. {
  550. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuSevereUnevenCurrent == YES)
  551. {
  552. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuSevereUnevenCurrent = NO;
  553. }
  554. } break;
  555. case NONE_DEFINE_7 : {} break;
  556. case PFC_POW_OFF :
  557. {
  558. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFfcSideShutDown == YES)
  559. {
  560. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFfcSideShutDown = NO;
  561. }
  562. } break;
  563. case NONE_DEFINE_8 : {} break;
  564. case FULL_SPEED_OF_FAN :
  565. {
  566. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFanFullSpeed == YES)
  567. {
  568. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFanFullSpeed = NO;
  569. }
  570. } break;
  571. case DC_DC_POW_OFF :
  572. {
  573. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcSideShutDown == YES)
  574. {
  575. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcSideShutDown = NO;
  576. }
  577. } break;
  578. case MODULE_UNDER_POW_LIMIT :
  579. {
  580. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuPowerLimitedState == YES)
  581. {
  582. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuPowerLimitedState = NO;
  583. }
  584. } break;
  585. case TEMP_POW_LIMIT :
  586. {
  587. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuTemperaturePowerLimit == YES)
  588. {
  589. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuTemperaturePowerLimit = NO;
  590. }
  591. } break;
  592. case AC_POW_LIMIT :
  593. {
  594. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuAcPowerLimit == YES)
  595. {
  596. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuAcPowerLimit = NO;
  597. }
  598. } break;
  599. case DC_DC_EEPROM_FAULT :
  600. {
  601. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcdcEepromFault == YES)
  602. {
  603. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcdcEepromFault = NO;
  604. }
  605. } break;
  606. case FAN_FAULT :
  607. {
  608. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFanFailureAlarm == YES)
  609. {
  610. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFanFailureAlarm = NO;
  611. }
  612. } break;
  613. case DC_DC_SHORT_CIRCUIT :
  614. {
  615. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuOutputShortCircuit == YES)
  616. {
  617. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuOutputShortCircuit = NO;
  618. }
  619. } break;
  620. case PFC_EEPROM_FAULT :
  621. {
  622. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuPfcEepromFault == YES)
  623. {
  624. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuPfcEepromFault = NO;
  625. }
  626. } break;
  627. case DC_DC_OTP :
  628. {
  629. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcDcOtp == YES)
  630. {
  631. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcDcOtp = NO;
  632. }
  633. } break;
  634. case DC_DC_OVP :
  635. {
  636. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcDcOvp == YES)
  637. {
  638. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcDcOvp = NO;
  639. }
  640. } break;
  641. }
  642. }
  643. }
  644. return isErr;
  645. }
  646. //=================================
  647. // Callback Function
  648. //=================================
  649. // no using -- GetOutputAndTempCallback
  650. void GetStatusCallback(byte group, byte SN, byte temp, int alarm)
  651. {
  652. bool isFind = false;
  653. bool isComp = false;
  654. if ((ShmDcCommonData->conn_1_count + ShmDcCommonData->conn_2_count) != ShmPsuData->SystemPresentPsuQuantity)
  655. {
  656. if (group == 0)
  657. {
  658. for(byte psuIndex = 0; psuIndex < ShmDcCommonData->conn_1_count; psuIndex++)
  659. {
  660. if (ShmDcCommonData->connector[0][psuIndex] == SN)
  661. {
  662. isFind = true;
  663. break;
  664. }
  665. }
  666. if(!isFind)
  667. {
  668. ShmDcCommonData->connector[0][ShmDcCommonData->conn_1_count] = SN;
  669. ShmDcCommonData->conn_1_count++;
  670. }
  671. }
  672. else if (group == 1)
  673. {
  674. for(byte psuIndex = 0; psuIndex < ShmDcCommonData->conn_2_count; psuIndex++)
  675. {
  676. if (ShmDcCommonData->connector[1][psuIndex] == SN)
  677. {
  678. isFind = true;
  679. break;
  680. }
  681. }
  682. if(!isFind)
  683. {
  684. ShmDcCommonData->connector[1][ShmDcCommonData->conn_2_count] = SN;
  685. ShmDcCommonData->conn_2_count++;
  686. }
  687. }
  688. }
  689. else
  690. {
  691. isComp = true;
  692. }
  693. if ((ShmDcCommonData->conn_1_count + ShmDcCommonData->conn_2_count) == ShmPsuData->SystemPresentPsuQuantity)
  694. {
  695. // Arrangment
  696. // for(byte psuIndex = 0; psuIndex < ShmDcCommonData->conn_1_count; psuIndex++)
  697. // {
  698. // ShmDcCommonData->connector[0][psuIndex] = psuIndex;
  699. // }
  700. //
  701. // for(byte psuIndex = 0; psuIndex < ShmDcCommonData->conn_2_count; psuIndex++)
  702. // {
  703. // ShmDcCommonData->connector[1][psuIndex] = ShmDcCommonData->conn_1_count + psuIndex;
  704. // }
  705. if (!isComp)
  706. {
  707. for(byte psuIndex = 0; psuIndex < ShmDcCommonData->conn_1_count; psuIndex++)
  708. PRINTF_FUNC("DC Left Gun - PSU Number = %d \n", ShmDcCommonData->connector[0][psuIndex]);
  709. for(byte psuIndex = 0; psuIndex < ShmDcCommonData->conn_2_count; psuIndex++)
  710. PRINTF_FUNC("DC Right Gun - PSU Number = %d \n", ShmDcCommonData->connector[1][psuIndex]);
  711. }
  712. if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 1 &&
  713. ShmDcCommonData->chargerType == CHARGER_TYPE_STANDARD)
  714. {
  715. // 雙槍才需要考慮是否模塊 switch 撥錯了
  716. char EvsePower[2];
  717. byte maxCount = 0;
  718. int power = 0;
  719. EvsePower[2] = '\0';
  720. if (strlen((char *) ShmSysConfigAndInfo->SysConfig.ModelName) >= 6)
  721. {
  722. strncpy(EvsePower, (char *)(ShmSysConfigAndInfo->SysConfig.ModelName + 4), 2);
  723. power = atoi(EvsePower);
  724. }
  725. // 超過 90 KW 或 360 KW
  726. if (power < 30 || power == 36)
  727. power *= 10;
  728. maxCount = ((power / 30) + 1) / 2;
  729. if (ShmDcCommonData->conn_1_count > maxCount ||
  730. ShmDcCommonData->conn_2_count > maxCount)
  731. {
  732. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDipSwitchStestFail = YES;
  733. }
  734. }
  735. }
  736. }
  737. // no using -- GetOutputAndTempCallback End
  738. void GetModuleCountCallback(byte group, byte count)
  739. {
  740. if (group == SYSTEM_CMD)
  741. ShmPsuData->SystemPresentPsuQuantity = count;
  742. else
  743. {
  744. if (group >= ShmSysConfigAndInfo->SysConfig.TotalConnectorCount)
  745. return;
  746. ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity = count;
  747. }
  748. }
  749. void GetMaxPowerAndCur(unsigned char mode, int ratingCur, int *pow, int *cur)
  750. {
  751. if (ShmPsuData->Work_Step < GET_SYS_CAP)
  752. return;
  753. unsigned short maxCurrent = ShmPsuData->SystemAvailableCurrent;
  754. unsigned short maxPower = ShmPsuData->SystemAvailablePower;
  755. if (ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent * 10 != 0 &&
  756. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent * 10 < maxCurrent)
  757. maxCurrent = ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent * 10;
  758. if (ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 10 != 0 &&
  759. ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 10 < maxPower)
  760. maxPower = ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 10;
  761. if (mode == _MAIN_CHARGING_MODE_AVER)
  762. {
  763. maxCurrent /= 2;
  764. maxPower /= 2;
  765. }
  766. if (ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower >= 0 &&
  767. maxPower > ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower)
  768. maxPower = ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower;
  769. if (maxPower != 0 && maxPower <= *pow)
  770. *pow = maxPower;
  771. if (maxCurrent != 0 && maxCurrent <= *cur)
  772. *cur = maxCurrent;
  773. if (ratingCur != 0 && ratingCur <= *cur)
  774. *cur = ratingCur;
  775. }
  776. void GetAvailableCapCallback(byte address, short maxVol, short minVol, short maxCur, short totalPow)
  777. {
  778. if (ShmPsuData->Work_Step < GET_SYS_CAP)
  779. return;
  780. int _groupPower = 0, _groupCurrent = 0;
  781. byte group = FindTargetGroup(address);
  782. byte addr = FindRealAddr(group, address);
  783. float _chargingVol = 0, _targetVol = 0;
  784. // if (group == 1)
  785. // address -= ShmPsuData->PsuGroup[group - 1].GroupPresentPsuQuantity;
  786. if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_MAX)
  787. {
  788. for (byte groupIndex = 0; groupIndex < _gunCount; groupIndex++)
  789. {
  790. if (chargingInfo[groupIndex]->EvBatteryMaxVoltage > 0)
  791. {
  792. _chargingVol = chargingInfo[groupIndex]->EvBatteryMaxVoltage;
  793. _targetVol = chargingInfo[groupIndex]->EvBatterytargetVoltage;
  794. break;
  795. }
  796. }
  797. }
  798. if (chargingInfo[group]->DeratingChargingCurrent == 0)
  799. {
  800. // 在還沒取得真正可輸出的電流前,依照 GFD 階段得到的真正 POWER / 模塊個數 / 車子電池最大電壓
  801. if (ShmPsuData->PsuGroup[group].GroupRealOutputPower > 0 && _chargingVol > 0)
  802. {
  803. ShmPsuData->PsuGroup[group].PsuModule[addr].AvailableCurrent =
  804. ((ShmPsuData->PsuGroup[group].GroupRealOutputPower / ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity) * 1000 / (int)_chargingVol) * 10;
  805. }
  806. else
  807. {
  808. // 注一 : 獲取模塊最大輸出能力 (忽視 Derating 狀態),所以這邊需要限制實際可輸出的電流
  809. if (ShmPsuData->PsuGroup[group].PsuModule[addr].AvailableCurrent <= 0)
  810. ShmPsuData->PsuGroup[group].PsuModule[addr].AvailableCurrent = PSU_MIN_CUR;
  811. }
  812. }
  813. else
  814. {
  815. ShmPsuData->PsuGroup[group].PsuModule[addr].AvailableCurrent = maxCur;
  816. }
  817. ShmPsuData->PsuGroup[group].PsuModule[addr].AvailablePower = totalPow;
  818. // 總和該 Group 的可輸出電流
  819. for (byte index = 0; index < ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity; index++)
  820. {
  821. _groupCurrent += ShmPsuData->PsuGroup[group].PsuModule[index].AvailableCurrent;
  822. _groupPower += ShmPsuData->PsuGroup[group].PsuModule[index].AvailablePower;
  823. }
  824. // 各群得到最大輸出能力 (電流、Power)
  825. ShmPsuData->PsuGroup[group].GroupAvailableCurrent = _groupCurrent;
  826. ShmPsuData->PsuGroup[group].GroupAvailablePower = _groupPower;
  827. if (chargingInfo[group]->MaximumChargingVoltage != maxVol)
  828. {
  829. PRINTF_FUNC("G_%d -> Max Vol = %d \n", group, maxVol / 10);
  830. chargingInfo[group]->MaximumChargingVoltage = maxVol;
  831. }
  832. int _power = 0, _current = 0, _ratingcurrent = 0, _sysRealPower = 0;
  833. bool isGetAllDeratingCurrent = true;
  834. for (byte index = 0; index < ShmPsuData->GroupCount; index++)
  835. {
  836. _power += ShmPsuData->PsuGroup[index].GroupAvailablePower;
  837. _current += ShmPsuData->PsuGroup[index].GroupAvailableCurrent;
  838. _ratingcurrent += chargingInfo[index]->DeratingChargingCurrent;
  839. _sysRealPower += ShmPsuData->PsuGroup[index].GroupRealOutputPower;
  840. if (ShmPsuData->PsuGroup[index].GroupPresentOutputVoltage >= PSU_MIN_VOL &&
  841. chargingInfo[index]->DeratingChargingCurrent == 0)
  842. isGetAllDeratingCurrent = false;
  843. }
  844. // 如果不是所有群都得到 Derating current,則先不採樣該次的 ratingCurrent
  845. if (!isGetAllDeratingCurrent) _ratingcurrent = 0;
  846. // 因應注一,為避免一值改變通知車子電樁最大可輸出電流所做的限制
  847. // 而因為 rating value 一般都會小於模塊的最大可輸出電流
  848. // 所以如果該值大於在注一所限制的輸出電流,則以此值為主
  849. if (_ratingcurrent != 0) _current = _ratingcurrent;
  850. if (ShmSysConfigAndInfo->SysInfo.BootingStatus == BOOTTING)
  851. {
  852. ShmPsuData->SystemAvailableCurrent = _current;
  853. ShmPsuData->SystemAvailablePower = _power;
  854. }
  855. if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER ||
  856. (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag >= _REASSIGNED_GET_NEW_CAP &&
  857. ShmSysConfigAndInfo->SysInfo.ReAssignedFlag <= _REASSIGNED_RELAY_M_TO_A))
  858. {
  859. int halfPow = ShmPsuData->PsuGroup[group].GroupAvailablePower;
  860. int halfCur = ShmPsuData->PsuGroup[group].GroupAvailableCurrent;
  861. int ratingCur = chargingInfo[group]->DeratingChargingCurrent;
  862. int gpRealPow = ShmPsuData->PsuGroup[group].GroupRealOutputPower;
  863. if ((ShmSysConfigAndInfo->SysInfo.ReAssignedFlag >= _REASSIGNED_GET_NEW_CAP &&
  864. ShmSysConfigAndInfo->SysInfo.ReAssignedFlag <= _REASSIGNED_RELAY_M_TO_A))
  865. {
  866. if (chargingInfo[group]->DividChargingCurrent == 0)
  867. return;
  868. else
  869. {
  870. halfCur = chargingInfo[group]->DividChargingCurrent;
  871. ratingCur = 0;
  872. }
  873. }
  874. GetMaxPowerAndCur(_MAIN_CHARGING_MODE_AVER, ratingCur, &halfPow, &halfCur);
  875. {
  876. // 以下狀況 -> 槍資訊中的最大輸出能力,為該群的輸出能力
  877. // 1. 如不是最大充
  878. // 2. 智能切換成均充過程
  879. chargingInfo[group]->AvailableChargingCurrent = halfCur;
  880. chargingInfo[group]->AvailableChargingPower = halfPow;
  881. chargingInfo[group]->RealRatingPower = gpRealPow;
  882. if(chargingInfo[group]->DeratingChargingCurrent > 0)
  883. {
  884. unsigned short _powBuf = 0;
  885. _powBuf = ((chargingInfo[group]->DeratingChargingCurrent / 10) * ShmPsuData->PsuGroup[group].GroupPresentOutputVoltage / 10) / 1000; // 單位是 KW
  886. if (_powBuf > ShmPsuData->PsuGroup[group].GroupRealOutputPower ||
  887. chargingInfo[group]->EvBatterytargetVoltage > 0)
  888. {
  889. ShmPsuData->PsuGroup[group].GroupRealOutputPower = _powBuf;
  890. }
  891. }
  892. }
  893. }
  894. else if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_MAX)
  895. {
  896. GetMaxPowerAndCur(_MAIN_CHARGING_MODE_MAX, _ratingcurrent, &_power, &_current);
  897. if (ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == YES)
  898. {
  899. for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; count++)
  900. {
  901. chargingInfo[count]->MaximumChargingVoltage = maxVol;
  902. chargingInfo[count]->AvailableChargingCurrent = _current;
  903. chargingInfo[count]->AvailableChargingPower = _power;
  904. chargingInfo[count]->RealRatingPower = _sysRealPower;
  905. }
  906. }
  907. else
  908. {
  909. // 如果是最大充,該槍資訊中的輸出能力為各群輸出能力的和
  910. chargingInfo[group]->AvailableChargingCurrent = _current;
  911. chargingInfo[group]->AvailableChargingPower = _power;
  912. chargingInfo[group]->RealRatingPower = _sysRealPower;
  913. }
  914. if(chargingInfo[group]->DeratingChargingCurrent > 0)
  915. {
  916. unsigned short _powBuf = 0;
  917. _powBuf = ((chargingInfo[group]->DeratingChargingCurrent / 10) * ShmPsuData->PsuGroup[group].GroupPresentOutputVoltage / 10) / 1000; // 單位是 KW
  918. if (_powBuf > ShmPsuData->PsuGroup[group].GroupRealOutputPower ||
  919. chargingInfo[group]->EvBatterytargetVoltage > 0 ||
  920. _targetVol > 0)
  921. {
  922. ShmPsuData->PsuGroup[group].GroupRealOutputPower = _powBuf;
  923. }
  924. }
  925. }
  926. }
  927. void GetFwCallback(byte address, short dcSwVer, short pfcSwVer, short hwVer)
  928. {
  929. if (ShmPsuData->Work_Step < GET_SYS_CAP)
  930. return;
  931. if (IsOverModuleCount(address))
  932. return;
  933. byte group = FindTargetGroup(address);
  934. byte addr = FindRealAddr(group, address);
  935. sprintf((char *)ShmPsuData->PsuVersion[address].FwPrimaryVersion, "DC %d.%02d", (dcSwVer & 0xFF00) >> 8, dcSwVer & 0xFF);
  936. sprintf((char *)ShmPsuData->PsuVersion[address].FwSecondVersion, "PFC %d.%02d", (pfcSwVer & 0xFF00) >> 8, pfcSwVer & 0xFF);
  937. // if (group == 1)
  938. // address -= ShmPsuData->PsuGroup[group - 1].GroupPresentPsuQuantity;
  939. sprintf((char *)ShmPsuData->PsuGroup[group].PsuModule[addr].FwVersion, "DC %d.%02d", (dcSwVer & 0xFF00) >> 8, dcSwVer & 0xFF);
  940. //DEBUG_INFO("fw Ver. = %s \n", ShmPsuData->PsuGroup[group].PsuModule[address].FwVersion);
  941. }
  942. // no using -- GetInputVoltageCallback
  943. void GetInputVoltageCallback(byte address, unsigned short vol1, unsigned short vol2, unsigned short vol3)
  944. {
  945. // if (ShmPsuData->Work_Step < GET_SYS_CAP)
  946. // return;
  947. //
  948. // if (IsOverModuleCount(address))
  949. // return;
  950. //
  951. // byte group = FindTargetGroup(address);
  952. //
  953. // if (group == 1)
  954. // address -= ShmPsuData->PsuGroup[group - 1].GroupPresentPsuQuantity;
  955. //
  956. // ShmPsuData->PsuGroup[group].PsuModule[address].InputVoltageL1 = vol1;
  957. // ShmPsuData->PsuGroup[group].PsuModule[address].InputVoltageL2 = vol2;
  958. // ShmPsuData->PsuGroup[group].PsuModule[address].InputVoltageL3 = vol3;
  959. //
  960. // PRINTF_FUNC("***Input*** address = %d, R = %d, S = %d, T = %d, gp = %d \n",
  961. // address, vol1, vol2, vol3, group);
  962. }
  963. // no using -- GetInputVoltageCallback End
  964. // no using -- GetOutputAndTempCallback
  965. void GetPresentOutputCallback(byte group, unsigned short outVol, unsigned short outCur)
  966. {
  967. // if (ShmPsuData->Work_Step < GET_SYS_CAP)
  968. // return;
  969. //if (outCur != ShmPsuData->PsuGroup[group].GroupPresentOutputCurrent)
  970. //{
  971. // PRINTF_FUNC("Gp_%d, gp output cur = %d \n", group, outCur);
  972. //}
  973. // // PSU Group - 電壓
  974. // ShmPsuData->PsuGroup[group].GroupPresentOutputVoltage = outVol;
  975. // // PSU Group - 電流
  976. // ShmPsuData->PsuGroup[group].GroupPresentOutputCurrent = outCur;
  977. //
  978. // if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_MAX ||
  979. // (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER &&
  980. // (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag >= _REASSIGNED_WAITING &&
  981. // ShmSysConfigAndInfo->SysInfo.ReAssignedFlag <= _REASSIGNED_COMP))
  982. // )
  983. // {
  984. // unsigned short outputVol = 0;
  985. // unsigned short outputCur = 0;
  986. //
  987. // for (byte index = 0; index < ShmPsuData->GroupCount; index++)
  988. // {
  989. // bool needtoAdd = true;
  990. //
  991. // if (ShmPsuData->PsuGroup[index].GroupPresentOutputVoltage > outputVol)
  992. // outputVol = ShmPsuData->PsuGroup[index].GroupPresentOutputVoltage;
  993. //
  994. // if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag >= _REASSIGNED_ADJUST_M_TO_A &&
  995. // ShmSysConfigAndInfo->SysInfo.ReAssignedFlag <= _REASSIGNED_RELAY_M_TO_A)
  996. // {
  997. //// PRINTF_FUNC("Gp_%d, DividChargingCurrent = %d \n", index,
  998. //// chargingInfo[index]->DividChargingCurrent);
  999. // if (chargingInfo[index]->DividChargingCurrent == 0)
  1000. // needtoAdd = false;
  1001. // }
  1002. //
  1003. // if (needtoAdd)
  1004. // outputCur += ShmPsuData->PsuGroup[index].GroupPresentOutputCurrent;
  1005. // }
  1006. //
  1007. // // 黑白機
  1008. // if (ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == YES)
  1009. // {
  1010. // for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; count++)
  1011. // {
  1012. // float _vol_buf = outputVol;
  1013. // float _cur_buf = outputCur;
  1014. //
  1015. // // EVSE - 電壓
  1016. // _vol_buf /= 10;
  1017. // chargingInfo[count]->PresentChargingVoltage = _vol_buf;
  1018. // // EVSE - 電流
  1019. // _cur_buf /= 10;
  1020. // chargingInfo[count]->PresentChargingCurrent = _cur_buf;
  1021. // }
  1022. // }
  1023. //
  1024. // if ((chargingInfo[group]->SystemStatus >= SYS_MODE_PREPARE_FOR_EVSE && chargingInfo[group]->SystemStatus <= SYS_MODE_COMPLETE) ||
  1025. // (chargingInfo[group]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && chargingInfo[group]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
  1026. // {
  1027. // float _vol_buf = outputVol;
  1028. // float _cur_buf = outputCur;
  1029. //
  1030. // // EVSE - 電壓
  1031. // _vol_buf /= 10;
  1032. // chargingInfo[group]->PresentChargingVoltage = _vol_buf;
  1033. // // EVSE - 電流
  1034. // _cur_buf /= 10;
  1035. // chargingInfo[group]->PresentChargingCurrent = _cur_buf;
  1036. // }
  1037. // }
  1038. // else
  1039. // {
  1040. // float _vol_buf = ShmPsuData->PsuGroup[group].GroupPresentOutputVoltage;
  1041. // float _cur_buf = ShmPsuData->PsuGroup[group].GroupPresentOutputCurrent;
  1042. //
  1043. // // EVSE - 電壓
  1044. // _vol_buf /= 10;
  1045. // chargingInfo[group]->PresentChargingVoltage = _vol_buf;
  1046. // // EVSE - 電流
  1047. // _cur_buf /= 10;
  1048. // chargingInfo[group]->PresentChargingCurrent = _cur_buf;
  1049. // }
  1050. //
  1051. // PRINTF_FUNC("Gun_%d, PresentChargingVoltage = %f, PresentChargingCurrent = %f \n", group,
  1052. // chargingInfo[group]->PresentChargingVoltage,
  1053. // chargingInfo[group]->PresentChargingCurrent);
  1054. }
  1055. // no using -- GetOutputAndTempCallback End
  1056. void GetMisCallback(byte address, unsigned int value, byte type)
  1057. {
  1058. if (ShmPsuData->Work_Step < GET_SYS_CAP)
  1059. return;
  1060. if (IsOverModuleCount(address))
  1061. return;
  1062. byte group = FindTargetGroup(address);
  1063. byte addr = FindRealAddr(group, address);
  1064. // if (group == 1)
  1065. // address -= ShmPsuData->PsuGroup[group - 1].GroupPresentPsuQuantity;
  1066. if (type == 1)
  1067. {
  1068. ShmPsuData->PsuGroup[group].PsuModule[addr].FanSpeed_1 = value;
  1069. ShmPsuData->PsuGroup[group].PsuModule[addr].FanSpeed_2 = value;
  1070. ShmPsuData->PsuGroup[group].PsuModule[addr].FanSpeed_3 = value;
  1071. ShmPsuData->PsuGroup[group].PsuModule[addr].FanSpeed_4 = value;
  1072. }
  1073. else if (type == 2)
  1074. {
  1075. //printf("DC - group = %d, index = %d, value = %d \n", group, address, value);
  1076. // ShmPsuData->PsuGroup[group].PsuModule[addr].CriticalTemp1 = value;
  1077. // ShmPsuData->PsuGroup[group].PsuModule[addr].CriticalTemp2 = value;
  1078. // ShmPsuData->PsuGroup[group].PsuModule[addr].CriticalTemp3 = value;
  1079. ShmPsuData->PsuGroup[group].PsuModule[addr].ExletTemp = value;
  1080. }
  1081. else if (type == 3)
  1082. {
  1083. printf("PFC - group = %d, index = %d, value = %d \n", group, address, value);
  1084. }
  1085. }
  1086. void GetIavailableCallback(byte address, unsigned short Iavail, unsigned short Vext)
  1087. {
  1088. if (ShmPsuData->Work_Step < GET_SYS_CAP)
  1089. return;
  1090. if (IsOverModuleCount(address))
  1091. return;
  1092. // 經度 0.1
  1093. byte group = FindTargetGroup(address);
  1094. byte addr = FindRealAddr(group, address);
  1095. // if (group == 1)
  1096. // address -= ShmPsuData->PsuGroup[group - 1].GroupPresentPsuQuantity;
  1097. ShmPsuData->PsuGroup[group].PsuModule[addr].IAvailableCurrent = Iavail;
  1098. bool isPass = true;
  1099. int totalCur = 0;
  1100. byte sampleCount = 8;
  1101. if (Iavail == 0)
  1102. {
  1103. for (byte count = 0; count < sampleCount; count++)
  1104. {
  1105. chargingInfo[group]->SampleChargingCur[count] = Iavail;
  1106. }
  1107. }
  1108. else
  1109. {
  1110. // 該群的可輸出電流
  1111. for (byte index = 0; index < ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity; index++)
  1112. {
  1113. totalCur += ShmPsuData->PsuGroup[group].PsuModule[index].IAvailableCurrent;
  1114. }
  1115. for (byte count = 0; count < sampleCount; count++)
  1116. {
  1117. if (chargingInfo[group]->SampleChargingCur[count] == 0)
  1118. {
  1119. chargingInfo[group]->SampleChargingCur[count] = totalCur;
  1120. return;
  1121. }
  1122. else
  1123. {
  1124. if (chargingInfo[group]->SampleChargingCur[count] != totalCur)
  1125. {
  1126. chargingInfo[group]->SampleChargingCur[count] = totalCur;
  1127. isPass = false;
  1128. break;
  1129. }
  1130. }
  1131. }
  1132. }
  1133. if (isPass)
  1134. {
  1135. chargingInfo[group]->DeratingChargingCurrent = totalCur;
  1136. }
  1137. }
  1138. void GetPresentOutputFCallback(byte group, float outVol, float outCur)
  1139. {
  1140. // isinf : -1 = 負無窮,1 = 正無窮,0 = 其他
  1141. if (isinf(outVol) == 0)
  1142. ShmPsuData->PsuGroup[group].GroupPresentOutputVoltage = (unsigned short)(outVol * 10);
  1143. else
  1144. ShmPsuData->PsuGroup[group].GroupPresentOutputVoltage = 0;
  1145. if (isinf(outCur) == 0)
  1146. ShmPsuData->PsuGroup[group].GroupPresentOutputCurrent = (unsigned short)(outCur * 10);
  1147. else
  1148. ShmPsuData->PsuGroup[group].GroupPresentOutputCurrent = 0;
  1149. //printf("group = %d, Current = %d \n", group, ShmPsuData->PsuGroup[group].GroupPresentOutputCurrent);
  1150. if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_MAX ||
  1151. (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER &&
  1152. (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag >= _REASSIGNED_WAITING &&
  1153. ShmSysConfigAndInfo->SysInfo.ReAssignedFlag <= _REASSIGNED_COMP))
  1154. )
  1155. {
  1156. unsigned short outputVol = 0;
  1157. unsigned short outputCur = 0;
  1158. unsigned char _maxTOaver = 0;
  1159. for (byte index = 0; index < ShmPsuData->GroupCount; index++)
  1160. {
  1161. bool needtoAdd = true;
  1162. if (ShmPsuData->PsuGroup[index].GroupPresentOutputVoltage > outputVol)
  1163. outputVol = ShmPsuData->PsuGroup[index].GroupPresentOutputVoltage;
  1164. if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag >= _REASSIGNED_ADJUST_M_TO_A &&
  1165. ShmSysConfigAndInfo->SysInfo.ReAssignedFlag <= _REASSIGNED_RELAY_M_TO_A)
  1166. {
  1167. if (chargingInfo[index]->DividChargingCurrent == 0)
  1168. needtoAdd = false;
  1169. else
  1170. _maxTOaver = index;
  1171. }
  1172. if (needtoAdd)
  1173. outputCur += ShmPsuData->PsuGroup[index].GroupPresentOutputCurrent;
  1174. }
  1175. if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag >= _REASSIGNED_ADJUST_M_TO_A &&
  1176. ShmSysConfigAndInfo->SysInfo.ReAssignedFlag <= _REASSIGNED_RELAY_M_TO_A)
  1177. {
  1178. if (chargingInfo[_maxTOaver]->DividChargingCurrent != 0)
  1179. {
  1180. float _cur_buf = outputCur;
  1181. _cur_buf /= 10;
  1182. chargingInfo[_maxTOaver]->PresentChargingCurrent = _cur_buf;
  1183. }
  1184. }
  1185. // 黑白機
  1186. if (ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == YES)
  1187. {
  1188. for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; count++)
  1189. {
  1190. float _vol_buf = outputVol;
  1191. float _cur_buf = outputCur;
  1192. // EVSE - 電壓
  1193. _vol_buf /= 10;
  1194. chargingInfo[count]->PresentChargingVoltage = _vol_buf;
  1195. _cur_buf /= 10;
  1196. chargingInfo[count]->PresentChargingCurrent = _cur_buf;
  1197. }
  1198. }
  1199. if ((chargingInfo[group]->SystemStatus >= SYS_MODE_PREPARE_FOR_EVSE && chargingInfo[group]->SystemStatus <= SYS_MODE_COMPLETE) ||
  1200. (chargingInfo[group]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && chargingInfo[group]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) ||
  1201. chargingInfo[group]->SystemStatus == SYS_MODE_ALARM)
  1202. {
  1203. float _vol_buf = outputVol;
  1204. float _cur_buf = outputCur;
  1205. // EVSE - 電壓
  1206. _vol_buf /= 10;
  1207. chargingInfo[group]->PresentChargingVoltage = _vol_buf;
  1208. if (chargingInfo[group]->SystemStatus == SYS_MODE_COMPLETE ||
  1209. chargingInfo[group]->SystemStatus == SYS_MODE_ALARM)
  1210. {
  1211. chargingInfo[group]->PresentChargingCurrent = 0;
  1212. }
  1213. else
  1214. {
  1215. _cur_buf /= 10;
  1216. chargingInfo[group]->PresentChargingCurrent = _cur_buf;
  1217. }
  1218. }
  1219. }
  1220. else
  1221. {
  1222. float _vol_buf = ShmPsuData->PsuGroup[group].GroupPresentOutputVoltage;
  1223. float _cur_buf = ShmPsuData->PsuGroup[group].GroupPresentOutputCurrent;
  1224. // EVSE - 電壓
  1225. _vol_buf /= 10;
  1226. chargingInfo[group]->PresentChargingVoltage = _vol_buf;
  1227. _cur_buf /= 10;
  1228. chargingInfo[group]->PresentChargingCurrent = _cur_buf;
  1229. }
  1230. }
  1231. //==========================================
  1232. // 特規用指令
  1233. //==========================================
  1234. void GetOutputAndTempCallback(byte address, unsigned short outputVol_s,
  1235. unsigned short outputCur_s, unsigned short outputPower, unsigned char Temperature)
  1236. {
  1237. if (ShmPsuData->Work_Step < GET_SYS_CAP)
  1238. return;
  1239. if (IsOverModuleCount(address))
  1240. return;
  1241. byte group = FindTargetGroup(address);
  1242. byte addr = FindRealAddr(group, address);
  1243. // if (group == 1)
  1244. // address -= ShmPsuData->PsuGroup[group - 1].GroupPresentPsuQuantity;
  1245. ShmPsuData->PsuGroup[group].PsuModule[addr].CriticalTemp1 = Temperature;
  1246. ShmPsuData->PsuGroup[group].PsuModule[addr].CriticalTemp2 = Temperature;
  1247. ShmPsuData->PsuGroup[group].PsuModule[addr].CriticalTemp3 = Temperature;
  1248. // ShmPsuData->PsuGroup[group].PsuModule[address].ExletTemp = Temperature;
  1249. // PRINTF_FUNC("***Output Value and Temp*** group = %d, Vol = %d, Cur = %d \n",
  1250. // group, outputVol_s, outputCur_s);
  1251. }
  1252. void GetModuleStatusCallback(byte address, unsigned char isErr, unsigned char status,
  1253. unsigned char err1, unsigned char err2, unsigned char err3, unsigned char err4)
  1254. {
  1255. ShmDcCommonData->psuKeepCommunication = ShmDcCommonData->acContactSwitch;
  1256. int _timebuf = GetTimeoutValue(&ShmDcCommonData->_psuComm_time);
  1257. if (_timebuf > 1 || _timebuf < 0)
  1258. {
  1259. GetTimespecFunc(&ShmDcCommonData->_psuComm_time);
  1260. }
  1261. if (ShmPsuData->Work_Step < GET_SYS_CAP)
  1262. return;
  1263. if (IsOverModuleCount(address))
  1264. return;
  1265. byte group1 = FindTargetGroup(address);
  1266. byte addr = FindRealAddr(group1, address);
  1267. int alarm = err1 | (err2 << 8) | (err3 << 16) | (err4 << 24);
  1268. ShmPsuData->PsuGroup[group1].PsuModule[addr].AlarmCode = alarm;
  1269. if(AbnormalStopAnalysis(group1, alarm))
  1270. {
  1271. if (!ShmPsuData->PsuGroup[group1].GroupErrorFlag.bits.PsuFailure)
  1272. {
  1273. ShmPsuData->PsuGroup[group1].GroupErrorFlag.bits.PsuFailure = YES;
  1274. ShmPsuData->PsuStopChargeFlag = YES;
  1275. ShmDcCommonData->_isPsuErrorOccur = YES;
  1276. PRINTF_FUNC("Group_%d - Address_%d, PSU Error Occurred. \n", group1, addr);
  1277. }
  1278. }
  1279. }
  1280. void GetModuleInputCallback(byte address, unsigned short inputR,
  1281. unsigned short inputS, unsigned short inputT)
  1282. {
  1283. if (ShmPsuData->Work_Step < GET_SYS_CAP)
  1284. return;
  1285. if (IsOverModuleCount(address))
  1286. return;
  1287. byte group = FindTargetGroup(address);
  1288. byte addr = FindRealAddr(group, address);
  1289. // if (group == 1)
  1290. // address -= ShmPsuData->PsuGroup[group - 1].GroupPresentPsuQuantity;
  1291. ShmPsuData->PsuGroup[group].PsuModule[addr].InputVoltageL1 = inputR;
  1292. ShmPsuData->PsuGroup[group].PsuModule[addr].InputVoltageL2 = inputS;
  1293. ShmPsuData->PsuGroup[group].PsuModule[addr].InputVoltageL3 = inputT;
  1294. //PRINTF_FUNC("***Input*** address = %d, R = %d, S = %d, T = %d \n",
  1295. // address, inputR, inputS, inputT);
  1296. }
  1297. //==========================================
  1298. // Init all share memory
  1299. //==========================================
  1300. int InitShareMemory()
  1301. {
  1302. int result = PASS;
  1303. int MeterSMId;
  1304. //creat ShmSysConfigAndInfo
  1305. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  1306. {
  1307. #ifdef SystemLogMessage
  1308. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG %d \n");
  1309. #endif
  1310. result = FAIL;
  1311. }
  1312. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1313. {
  1314. #ifdef SystemLogMessage
  1315. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG \n");
  1316. #endif
  1317. result = FAIL;
  1318. }
  1319. //creat ShmStatusCodeData
  1320. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  1321. {
  1322. #ifdef SystemLogMessage
  1323. DEBUG_ERROR("shmget ShmStatusCodeData NG \n");
  1324. #endif
  1325. result = FAIL;
  1326. }
  1327. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1328. {
  1329. #ifdef SystemLogMessage
  1330. DEBUG_ERROR("shmat ShmStatusCodeData NG \n");
  1331. #endif
  1332. result = FAIL;
  1333. }
  1334. //creat ShmPsuData
  1335. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  1336. {
  1337. #ifdef SystemLogMessage
  1338. DEBUG_ERROR("shmget ShmPsuData NG \n");
  1339. #endif
  1340. result = FAIL;
  1341. }
  1342. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1343. {
  1344. #ifdef SystemLogMessage
  1345. DEBUG_ERROR("shmat ShmPsuData NG \n");
  1346. #endif
  1347. result = FAIL;
  1348. }
  1349. if ((MeterSMId = shmget(ShmCommonKey, sizeof(struct DcCommonInformation), IPC_CREAT | 0777)) < 0)
  1350. {
  1351. #ifdef SystemLogMessage
  1352. DEBUG_ERROR("shmget ShmCommonKey NG \n");
  1353. #endif
  1354. result = FAIL;
  1355. }
  1356. else if ((ShmDcCommonData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1357. {
  1358. #ifdef SystemLogMessage
  1359. DEBUG_ERROR("shmat ShmCommonKey NG \n");
  1360. #endif
  1361. result = FAIL;
  1362. }
  1363. return result;
  1364. }
  1365. //================================================
  1366. // Log function
  1367. //================================================
  1368. void OutputChargingLogFuncion(byte groupIndex)
  1369. {
  1370. // 列印時機 : 需求改變或輸出電壓與紀錄落差超過 5V 或者輸出電流與紀錄落差超過 0.5A
  1371. if (chargingOutputLogInfo[groupIndex][_CHARGING_LOG_NEED_VOL] != chargingInfo[groupIndex]->EvBatterytargetVoltage * 10 ||
  1372. (chargingInfo[groupIndex]->FireChargingVoltage <= chargingOutputLogInfo[groupIndex][_CHARGING_LOG_OUTPUT_VOL] - LOG_VOL_GAP ||
  1373. chargingInfo[groupIndex]->FireChargingVoltage >= chargingOutputLogInfo[groupIndex][_CHARGING_LOG_OUTPUT_VOL] + LOG_VOL_GAP))
  1374. {
  1375. chargingOutputLogInfo[groupIndex][_CHARGING_LOG_NEED_VOL] = chargingInfo[groupIndex]->EvBatterytargetVoltage * 10;
  1376. chargingOutputLogInfo[groupIndex][_CHARGING_LOG_OUTPUT_VOL] = chargingInfo[groupIndex]->FireChargingVoltage;
  1377. PRINTF_FUNC("Conn %d, EV Req Voltage : %.1f, EVSE Output Voltage = %.1f \n", groupIndex,
  1378. chargingOutputLogInfo[groupIndex][_CHARGING_LOG_NEED_VOL] / 10,
  1379. chargingOutputLogInfo[groupIndex][_CHARGING_LOG_OUTPUT_VOL] / 10);
  1380. }
  1381. if (chargingOutputLogInfo[groupIndex][_CHARGING_LOG_NEED_CUR] != chargingInfo[groupIndex]->EvBatterytargetCurrent * 10 ||
  1382. (chargingInfo[groupIndex]->PresentChargingCurrent <= chargingOutputLogInfo[groupIndex][_CHARGING_LOG_OUTPUT_CUR] - LOG_CUR_GAP ||
  1383. chargingInfo[groupIndex]->PresentChargingCurrent >= chargingOutputLogInfo[groupIndex][_CHARGING_LOG_OUTPUT_CUR] + LOG_CUR_GAP))
  1384. {
  1385. chargingOutputLogInfo[groupIndex][_CHARGING_LOG_NEED_CUR] = chargingInfo[groupIndex]->EvBatterytargetCurrent * 10;
  1386. chargingOutputLogInfo[groupIndex][_CHARGING_LOG_OUTPUT_CUR] = chargingInfo[groupIndex]->PresentChargingCurrent;
  1387. PRINTF_FUNC("Conn %d, EV Req Current : %.1f, EVSE Output Current = %.1f \n", groupIndex,
  1388. chargingOutputLogInfo[groupIndex][_CHARGING_LOG_NEED_CUR] / 10,
  1389. chargingOutputLogInfo[groupIndex][_CHARGING_LOG_OUTPUT_CUR]);
  1390. }
  1391. }
  1392. //================================================
  1393. // Main process
  1394. //================================================
  1395. void InitialPsuData()
  1396. {
  1397. ShmPsuData->SystemPresentPsuQuantity = 0;
  1398. PRINTF_FUNC("InitialPsuData : PSU Group = %d \n", ShmPsuData->GroupCount);
  1399. for (byte _groupCount = 0; _groupCount < ShmPsuData->GroupCount; _groupCount++)
  1400. {
  1401. ShmPsuData->PsuGroup[_groupCount].GroupAvailablePower = 0;
  1402. ShmPsuData->PsuGroup[_groupCount].GroupAvailableCurrent = 0;
  1403. chargingInfo[_groupCount]->PresentChargingVoltage = 0;
  1404. chargingInfo[_groupCount]->PresentChargingCurrent = 0;
  1405. ShmPsuData->PsuGroup[_groupCount].GroupErrorFlag.bits.PsuFailure = NO;
  1406. }
  1407. ShmPsuData->PsuStopChargeFlag = NO;
  1408. ShmDcCommonData->_isPsuErrorOccur = NO;
  1409. }
  1410. void Initialization()
  1411. {
  1412. bool isPass = false;
  1413. while(!isPass)
  1414. {
  1415. isPass = true;
  1416. for (byte _index = 0; _index < _gunCount; _index++)
  1417. {
  1418. if (!FindChargingInfoData(_index, &chargingInfo[0]))
  1419. {
  1420. DEBUG_ERROR("Module_PsuComm : FindChargingInfoData false \n");
  1421. isPass = false;
  1422. break;
  1423. }
  1424. }
  1425. sleep(1);
  1426. }
  1427. if (ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == YES)
  1428. ShmPsuData->GroupCount = 1;
  1429. else
  1430. ShmPsuData->GroupCount = _gunCount;
  1431. ShmPsuData->SystemAvailableCurrent = 0;
  1432. ShmPsuData->SystemAvailablePower = 0;
  1433. GetTimespecFunc(&ShmDcCommonData->_psuComm_time);
  1434. }
  1435. void CheckSmartChargingStep(byte chargingStatus)
  1436. {
  1437. // 跑切換均充的邏輯
  1438. if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_MAX)
  1439. {
  1440. // 確認 A 槍是否已經進入充電階段
  1441. if (chargingStatus == _CHARGING_GUN_STATUS_CHARGING)
  1442. {
  1443. if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_PREPARE_M_TO_A)
  1444. {
  1445. PRINTF_FUNC("======= Max -> Aver : Update new charging capacity. (Step 2) ======= \n");
  1446. ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_GET_NEW_CAP;
  1447. }
  1448. }
  1449. else if (chargingStatus == _CHARGING_GUN_STATUS_STOP)
  1450. {
  1451. if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_NONE)
  1452. {
  1453. PRINTF_FUNC("============= Max -> Aver : Charging mode = MAX. (Step 0) ============= \n");
  1454. ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
  1455. }
  1456. }
  1457. }
  1458. // 跑切換最大充邏輯
  1459. else if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER)
  1460. {
  1461. if (chargingStatus == _CHARGING_GUN_STATUS_CHARGING)
  1462. {
  1463. if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_PREPARE_A_TO_M)
  1464. {
  1465. PRINTF_FUNC("======= Aver -> Max : switch on the psu voltage. (Step 12) ======= \n");
  1466. preChargingCur = preChargingTarget = 0;
  1467. GetTimespecMFunc(&_max_time);
  1468. ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_ADJUST_A_TO_M;
  1469. }
  1470. }
  1471. else if (chargingStatus == _CHARGING_GUN_STATUS_STOP &&
  1472. ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_COMP)
  1473. {
  1474. PRINTF_FUNC("======= Aver -> Max : Charging mode = MAX. (Step 15) ======= \n");
  1475. ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_COMP;
  1476. }
  1477. }
  1478. // if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_PREPARE_M_TO_A)
  1479. // {
  1480. // if (isWaitingAver)
  1481. // {
  1482. // if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_MAX)
  1483. // {
  1484. // ShmSysConfigAndInfo->SysInfo.CanAverageCharging = canAverageCharging;
  1485. //
  1486. // if (canAverageCharging)
  1487. // {
  1488. // PRINTF_FUNC("======= Only to get the charging side capacity (Step 2) ======= \n");
  1489. // ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_GET_NEW_CAP;
  1490. // }
  1491. // else
  1492. // {
  1493. // PRINTF_FUNC("=============Smart Charging : _REASSIGNED_NONE============= Step 0 \n");
  1494. // ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
  1495. // }
  1496. // }
  1497. // else
  1498. // {
  1499. // PRINTF_FUNC("=============Smart Charging Aver mode : _REASSIGNED_NONE============= Step 0 \n");
  1500. // ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
  1501. // }
  1502. // }
  1503. // }
  1504. // else if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_PREPARE_A_TO_M)
  1505. // {
  1506. // if (isCharging)
  1507. // {
  1508. // if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER)
  1509. // {
  1510. // PRINTF_FUNC("======= To raise voltage of idle module to charging voltage (Step 12) ======= \n");
  1511. // preChargingCur = preChargingTarget = 0;
  1512. // gettimeofday(&_max_time, NULL);
  1513. // ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_ADJUST_A_TO_M;
  1514. // }
  1515. // else
  1516. // {
  1517. // PRINTF_FUNC("======= The Change to maximum charge mode is complete. (Step 15) ======= \n");
  1518. // ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_COMP;
  1519. // }
  1520. // }
  1521. // else
  1522. // {
  1523. // PRINTF_FUNC("======= The Change to maximum charge mode is complete. (Step 15) ======= \n");
  1524. // ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_COMP;
  1525. // }
  1526. // }
  1527. }
  1528. void PreCheckSmartChargingStep()
  1529. {
  1530. _maxChargingStatus = _CHARGING_GUN_STATUS_NONE;
  1531. isReadyToCharging = false;
  1532. for (byte index = 0; index < ShmPsuData->GroupCount; index++)
  1533. {
  1534. if ((chargingInfo[index]->SystemStatus >= SYS_MODE_PREPARE_FOR_EVSE && chargingInfo[index]->SystemStatus <= SYS_MODE_CHARGING) ||
  1535. (chargingInfo[index]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && chargingInfo[index]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
  1536. {
  1537. isReadyToCharging = true;
  1538. }
  1539. }
  1540. for (byte index = 0; index < ShmPsuData->GroupCount; index++)
  1541. {
  1542. if ((chargingInfo[index]->SystemStatus >= SYS_MODE_PREPARE_FOR_EVSE && chargingInfo[index]->SystemStatus < SYS_MODE_CHARGING) ||
  1543. (chargingInfo[index]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && chargingInfo[index]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
  1544. {
  1545. _maxChargingStatus = _CHARGING_GUN_STATUS_COMM;
  1546. }
  1547. else if (chargingInfo[index]->SystemStatus == SYS_MODE_CHARGING)
  1548. {
  1549. _maxChargingStatus = _CHARGING_GUN_STATUS_CHARGING;
  1550. break;
  1551. }
  1552. else if (chargingInfo[index]->SystemStatus == SYS_MODE_COMPLETE ||
  1553. chargingInfo[index]->SystemStatus == SYS_MODE_ALARM)
  1554. {
  1555. _maxChargingStatus = _CHARGING_GUN_STATUS_STOP;
  1556. }
  1557. }
  1558. CheckSmartChargingStep(_maxChargingStatus);
  1559. }
  1560. void Await()
  1561. {
  1562. usleep(CMD_DELAY_TIME);
  1563. }
  1564. bool MaxToAverChargingProc(byte groupIndex)
  1565. {
  1566. // 智能判斷 Start -----------------------------------------------------------
  1567. if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag >= _REASSIGNED_GET_NEW_CAP &&
  1568. ShmSysConfigAndInfo->SysInfo.ReAssignedFlag <= _REASSIGNED_RELAY_M_TO_A)
  1569. {
  1570. if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_GET_NEW_CAP)
  1571. {
  1572. if (chargingInfo[groupIndex]->DividChargingCurrent == 0)
  1573. {
  1574. chargingInfo[groupIndex]->DividChargingCurrent = ShmPsuData->PsuGroup[groupIndex].GroupPresentOutputCurrent;
  1575. PRINTF_FUNC("Index = %d, DividChargingCurrent = %.1f \n", groupIndex, chargingInfo[groupIndex]->DividChargingCurrent);
  1576. }
  1577. // 車端要求電流為該充電槍的額定輸出電流的範圍內
  1578. if ((chargingInfo[groupIndex]->EvBatterytargetCurrent * 10) <= ShmPsuData->PsuGroup[groupIndex].GroupPresentOutputCurrent + DERATING_GAP ||
  1579. deratingKeepCount >= DERATING_COUNT)
  1580. {
  1581. // 車端降載完成
  1582. PRINTF_FUNC("Index = %d, newEvCurrent = %f \n", groupIndex, (chargingInfo[groupIndex]->EvBatterytargetCurrent * 10));
  1583. PRINTF_FUNC("======= Max -> Aver : wait the target current is down. (Step 3) ======= \n");
  1584. ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_ADJUST_M_TO_A;
  1585. GetTimespecMFunc(&_derating_time);
  1586. deratingKeepCount = 0;
  1587. step3KeepCount = 0;
  1588. }
  1589. else
  1590. {
  1591. deratingKeepCount++;
  1592. if (deratingKeepCount % 3 == 0)
  1593. {
  1594. PRINTF_FUNC("Max To Ava mode (2) : Index = %d, EvBatterytargetCurrent = %f, TargetCurrent = %d, Count = %d \n",
  1595. groupIndex,
  1596. (chargingInfo[groupIndex]->EvBatterytargetCurrent * 10),
  1597. (ShmPsuData->PsuGroup[groupIndex].GroupPresentOutputCurrent + DERATING_GAP),
  1598. deratingKeepCount);
  1599. }
  1600. }
  1601. }
  1602. else if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_ADJUST_M_TO_A)
  1603. {
  1604. bool isChanged = false;
  1605. if (chargingInfo[groupIndex]->DividChargingCurrent == 0 ||
  1606. (chargingInfo[groupIndex]->DividChargingCurrent != 0 &&
  1607. (chargingInfo[groupIndex]->DividChargingCurrent == chargingInfo[groupIndex]->AvailableChargingCurrent) &&
  1608. chargingInfo[groupIndex]->AvailableChargingCurrent >= (chargingInfo[groupIndex]->EvBatterytargetCurrent * 10)))
  1609. {
  1610. for (byte subIndex = 0; subIndex < ShmPsuData->GroupCount; subIndex++)
  1611. {
  1612. if (chargingInfo[subIndex]->SystemStatus == SYS_MODE_REASSIGN)
  1613. {
  1614. // 當 B 模塊輸出電流小於 5A 及退開 relay
  1615. if ((ShmPsuData->PsuGroup[subIndex].GroupPresentOutputCurrent) <= 50)
  1616. isChanged = true;
  1617. break;
  1618. }
  1619. }
  1620. }
  1621. else if (chargingInfo[groupIndex]->PresentChargingCurrent == 0)
  1622. {
  1623. for (byte subIndex = 0; subIndex < ShmPsuData->GroupCount; subIndex++)
  1624. {
  1625. if (chargingInfo[subIndex]->SystemStatus == SYS_MODE_REASSIGN)
  1626. {
  1627. if ((ShmPsuData->PsuGroup[subIndex].GroupPresentOutputCurrent) <= CHK_CUR_RANGE)
  1628. isChanged = true;
  1629. break;
  1630. }
  1631. }
  1632. }
  1633. if (!isChanged)
  1634. {
  1635. if (step3KeepCount < DERATING_COUNT)
  1636. step3KeepCount++;
  1637. else
  1638. isChanged = true;
  1639. }
  1640. if (isChanged)
  1641. {
  1642. PRINTF_FUNC("Max To Ava mode (3-2) : Gun_%d, PresentChargingCurrent = %f, GroupPresentOutputCurrent = %d \n", groupIndex,
  1643. (chargingInfo[groupIndex]->PresentChargingCurrent * 10),
  1644. ShmPsuData->PsuGroup[groupIndex].GroupPresentOutputCurrent);
  1645. // 輸出端與車端要求電流接近
  1646. PRINTF_FUNC("======= Max -> Aver : off the Parallel relay. (Step 4) ======= \n");
  1647. ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_RELAY_M_TO_A;
  1648. }
  1649. else
  1650. {
  1651. int _t = GetTimeoutMValue(&_derating_time);
  1652. if (_t > 1000 || _t < 0)
  1653. {
  1654. PRINTF_FUNC("Max To Ava mode (3-1) : Gun_%d, AvailableChargingCurrent = %f, EvBatterytargetCurrent = %f, step3KeepCount = %d \n",
  1655. groupIndex,
  1656. chargingInfo[groupIndex]->AvailableChargingCurrent,
  1657. (chargingInfo[groupIndex]->EvBatterytargetCurrent * 10),
  1658. step3KeepCount);
  1659. PRINTF_FUNC("Max To Ava mode (3-1) : Gun_%d, PresentChargingCurrent = %f, GroupPresentOutputCurrent = %d, GroupCount = %d \n",
  1660. groupIndex,
  1661. (chargingInfo[groupIndex]->PresentChargingCurrent * 10),
  1662. ShmPsuData->PsuGroup[groupIndex].GroupPresentOutputCurrent,
  1663. ShmPsuData->GroupCount);
  1664. GetTimespecMFunc(&_derating_time);
  1665. }
  1666. }
  1667. }
  1668. }
  1669. else
  1670. {
  1671. chargingInfo[groupIndex]->DividChargingCurrent = 0;
  1672. chargingInfo[groupIndex]->MaxChargingToAverPassFlag = 0;
  1673. }
  1674. // 調整輸出電流 : 漸進調整方式
  1675. if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag >= _REASSIGNED_GET_NEW_CAP &&
  1676. ShmSysConfigAndInfo->SysInfo.ReAssignedFlag < _REASSIGNED_RELAY_M_TO_A)
  1677. {
  1678. if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag >= _REASSIGNED_ADJUST_M_TO_A)
  1679. {
  1680. // 當前充電中的目標電壓
  1681. float targetVol = (chargingInfo[groupIndex]->EvBatterytargetVoltage * 10);
  1682. byte reassignIndex = ELEMENT_NOT_FIND;
  1683. // 找到等待分配的槍
  1684. for (byte subIndex = 0; subIndex < ShmPsuData->GroupCount; subIndex++)
  1685. {
  1686. if (chargingInfo[subIndex]->SystemStatus == SYS_MODE_REASSIGN)
  1687. {
  1688. reassignIndex = subIndex;
  1689. break;
  1690. }
  1691. }
  1692. if (reassignIndex != ELEMENT_NOT_FIND)
  1693. {
  1694. if (GetTimeoutMValue(&_derating_time) <= 150 ||
  1695. chargingInfo[groupIndex]->MaxChargingToAverPassFlag == 0)
  1696. {
  1697. chargingInfo[groupIndex]->MaxChargingToAverPassFlag = 1;
  1698. if(chargingInfo[groupIndex]->EvBatterytargetCurrent <= PSU_MIN_OUTPUT_CUR)
  1699. chargingInfo[groupIndex]->EvBatterytargetCurrent = PSU_MIN_OUTPUT_CUR;
  1700. PresentOutputVol(groupIndex, targetVol, (chargingInfo[groupIndex]->EvBatterytargetCurrent * 10)); Await();
  1701. PresentOutputVol(reassignIndex, targetVol, CHK_CUR_RANGE); Await();
  1702. }
  1703. }
  1704. }
  1705. if ((chargingInfo[groupIndex]->EvBatterytargetVoltage * 10) == 0)
  1706. {
  1707. bool isNeedToClosePower = false;
  1708. for (byte index = 0; index < ShmPsuData->GroupCount; index++)
  1709. {
  1710. if (isStartOutputSwitch[index])
  1711. {
  1712. isNeedToClosePower = true;
  1713. }
  1714. isStartOutputSwitch[index] = false;
  1715. }
  1716. if (isNeedToClosePower)
  1717. {
  1718. SwitchPower(SYSTEM_CMD, PSU_POWER_OFF);
  1719. FlashLed(SYSTEM_CMD, PSU_FLASH_NORMAL);
  1720. }
  1721. }
  1722. }
  1723. else if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag >= _REASSIGNED_RELAY_M_TO_A)
  1724. {
  1725. //PRINTF_FUNC("set out (%d) value = %f******** 3 \n", groupIndex, chargingInfo[groupIndex]->EvBatterytargetCurrent);
  1726. if(chargingInfo[groupIndex]->EvBatterytargetCurrent <= PSU_MIN_OUTPUT_CUR)
  1727. chargingInfo[groupIndex]->EvBatterytargetCurrent = PSU_MIN_OUTPUT_CUR;
  1728. PresentOutputVol(groupIndex,
  1729. (chargingInfo[groupIndex]->EvBatterytargetVoltage * 10),
  1730. (chargingInfo[groupIndex]->EvBatterytargetCurrent * 10)); Await();
  1731. }
  1732. else
  1733. {
  1734. return false;
  1735. }
  1736. return true;
  1737. }
  1738. bool AverToMaxChargingProc(byte groupIndex)
  1739. {
  1740. if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag >= _REASSIGNED_ADJUST_A_TO_M)
  1741. {
  1742. byte reassignIndex = ELEMENT_NOT_FIND;
  1743. for (byte subIndex = 0; subIndex < ShmPsuData->GroupCount; subIndex++)
  1744. {
  1745. if (chargingInfo[subIndex]->SystemStatus == SYS_MODE_IDLE ||
  1746. chargingInfo[subIndex]->SystemStatus == SYS_MODE_RESERVATION ||
  1747. chargingInfo[subIndex]->SystemStatus == SYS_MODE_FAULT ||
  1748. chargingInfo[subIndex]->SystemStatus == SYS_MODE_MODE_REASSIGN_CHECK ||
  1749. chargingInfo[subIndex]->SystemStatus == SYS_MODE_COMPLETE ||
  1750. chargingInfo[subIndex]->SystemStatus == SYS_MODE_ALARM)
  1751. {
  1752. reassignIndex = subIndex;
  1753. if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag >= _REASSIGNED_WAITING)
  1754. {
  1755. preChargingCur = ShmPsuData->PsuGroup[subIndex].GroupPresentOutputCurrent;
  1756. }
  1757. else
  1758. preChargingCur = 0;
  1759. }
  1760. else
  1761. {
  1762. if ((ShmSysConfigAndInfo->SysInfo.ReAssignedFlag >= _REASSIGNED_WAITING) &&
  1763. (preChargingCur >= preChargingTarget - MIN_1A_CURRENT))
  1764. preChargingTarget += PRE_CHARG_STEP_CUR;
  1765. if (preChargingTarget >= (chargingInfo[subIndex]->EvBatterytargetCurrent * 10) / 2)
  1766. preChargingTarget = (chargingInfo[subIndex]->EvBatterytargetCurrent * 10) / 2;
  1767. }
  1768. }
  1769. if (reassignIndex != ELEMENT_NOT_FIND)
  1770. {
  1771. if (GetTimeoutMValue(&_max_time) <= 150)
  1772. {
  1773. //PRINTF_FUNC("set out (%d) value = %d******** 5 \n", reassignIndex, MIN_1A_CURRENT + preChargingTarget);
  1774. // 閒置模塊升壓,另對剛分配近來的模塊,預上升電流值 (preChargingCur)
  1775. PresentOutputVol(reassignIndex,
  1776. (chargingInfo[groupIndex]->EvBatterytargetVoltage * 10),
  1777. MIN_1A_CURRENT + preChargingTarget); Await();
  1778. }
  1779. byte _ovCahrgingCur = 0;
  1780. if (preChargingCur > PRE_CHARG_STEP_CUR)
  1781. _ovCahrgingCur = PRE_CHARG_STEP_CUR;
  1782. PresentOutputVol(groupIndex,
  1783. (chargingInfo[groupIndex]->EvBatterytargetVoltage * 10),
  1784. (chargingInfo[groupIndex]->EvBatterytargetCurrent * 10) - preChargingCur - _ovCahrgingCur); Await();
  1785. }
  1786. if ((chargingInfo[groupIndex]->EvBatterytargetVoltage * 10) == 0)
  1787. {
  1788. bool isNeedToClosePower = false;
  1789. for (byte index = 0; index < ShmPsuData->GroupCount; index++)
  1790. {
  1791. if (isStartOutputSwitch[index])
  1792. {
  1793. isNeedToClosePower = true;
  1794. }
  1795. isStartOutputSwitch[index] = false;
  1796. }
  1797. if (isNeedToClosePower)
  1798. {
  1799. SwitchPower(SYSTEM_CMD, PSU_POWER_OFF);
  1800. FlashLed(SYSTEM_CMD, PSU_FLASH_NORMAL);
  1801. }
  1802. }
  1803. else
  1804. {
  1805. bool isNeedToOpenPower = false;
  1806. for (byte index = 0; index < ShmPsuData->GroupCount; index++)
  1807. {
  1808. if (!isStartOutputSwitch[index])
  1809. {
  1810. isNeedToOpenPower = true;
  1811. }
  1812. isStartOutputSwitch[index] = true;
  1813. }
  1814. if (isNeedToOpenPower)
  1815. {
  1816. SwitchPower(SYSTEM_CMD, PSU_POWER_ON);
  1817. FlashLed(SYSTEM_CMD, PSU_FLASH_ON);
  1818. }
  1819. }
  1820. if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_ADJUST_A_TO_M)
  1821. {
  1822. bool balanceVol = true;
  1823. byte subIndex;
  1824. for (subIndex = 0; subIndex < ShmPsuData->GroupCount; subIndex++)
  1825. {
  1826. if (chargingInfo[subIndex]->SystemStatus == SYS_MODE_IDLE ||
  1827. chargingInfo[subIndex]->SystemStatus == SYS_MODE_FAULT ||
  1828. chargingInfo[subIndex]->SystemStatus == SYS_MODE_RESERVATION ||
  1829. chargingInfo[subIndex]->SystemStatus == SYS_MODE_COMPLETE ||
  1830. chargingInfo[subIndex]->SystemStatus == SYS_MODE_ALARM)
  1831. {
  1832. // 各群電壓接近平衡
  1833. if (((chargingInfo[subIndex]->PresentChargingVoltage * 10) < (chargingInfo[groupIndex]->PresentChargingVoltage * 10) - MIN_5V_VOLTAGE) ||
  1834. ((chargingInfo[subIndex]->PresentChargingVoltage * 10) < (chargingInfo[groupIndex]->EvBatterytargetVoltage * 10) - CHK_VOL_RANGE))
  1835. {
  1836. balanceVol = false;
  1837. }
  1838. break;
  1839. }
  1840. }
  1841. if (balanceVol)
  1842. {
  1843. // 閒置端與車端要求電壓接近
  1844. PRINTF_FUNC("======= Aver -> Max : switch on the Parallel relay. (Step 13) ======= \n");
  1845. ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_RELAY_A_TO_M;
  1846. }
  1847. else
  1848. {
  1849. int _tMax_1 = GetTimeoutMValue(&_max_time);
  1850. if (_tMax_1 > 500 || _tMax_1 < 0)
  1851. {
  1852. PRINTF_FUNC("Ava To Max mode (12) : Gun_%d, PresentChargingVoltage = %f, PresentChargingVoltage_V = %f, EvBatterytargetVoltage = %f \n", subIndex,
  1853. (chargingInfo[subIndex]->PresentChargingVoltage * 10),
  1854. ((chargingInfo[groupIndex]->PresentChargingVoltage * 10) - MIN_5V_VOLTAGE),
  1855. ((chargingInfo[groupIndex]->EvBatterytargetVoltage * 10) - CHK_VOL_RANGE));
  1856. GetTimespecMFunc(&_max_time);
  1857. }
  1858. }
  1859. }
  1860. else if(ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_WAITING)
  1861. {
  1862. int idleCurrent = 0;
  1863. int chargingCurrent = 0;
  1864. for (byte subIndex = 0; subIndex < ShmPsuData->GroupCount; subIndex++)
  1865. {
  1866. if (chargingInfo[subIndex]->SystemStatus == SYS_MODE_IDLE ||
  1867. chargingInfo[subIndex]->SystemStatus == SYS_MODE_RESERVATION ||
  1868. chargingInfo[subIndex]->SystemStatus == SYS_MODE_FAULT ||
  1869. chargingInfo[subIndex]->SystemStatus == SYS_MODE_MODE_REASSIGN_CHECK)
  1870. idleCurrent = ShmPsuData->PsuGroup[subIndex].GroupPresentOutputCurrent;
  1871. else
  1872. {
  1873. chargingCurrent = ShmPsuData->PsuGroup[subIndex].GroupPresentOutputCurrent;
  1874. }
  1875. }
  1876. if (idleCurrent >= chargingCurrent - PRE_CHARG_RANGE)
  1877. {
  1878. PRINTF_FUNC("======= Aver -> Max : Charging mode = MAX. (Step 15) ======= \n");
  1879. ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_COMP;
  1880. }
  1881. else
  1882. {
  1883. int _tMax_2 = GetTimeoutMValue(&_max_time);
  1884. if (_tMax_2 > 300 || _tMax_2 < 0)
  1885. {
  1886. GetTimespecMFunc(&_max_time);
  1887. }
  1888. }
  1889. }
  1890. }
  1891. else
  1892. {
  1893. return false;
  1894. }
  1895. return true;
  1896. }
  1897. void SwitchOffPowerCheck(byte groupIndex)
  1898. {
  1899. _maxChargingStatus = _CHARGING_GUN_STATUS_STOP;
  1900. for (byte index = 0; index < ShmPsuData->GroupCount; index++)
  1901. {
  1902. // 判斷另一把槍的狀態
  1903. if (index != groupIndex)
  1904. {
  1905. if ((chargingInfo[index]->SystemStatus >= SYS_MODE_PREPARE_FOR_EV && chargingInfo[index]->SystemStatus <= SYS_MODE_CHARGING) ||
  1906. (chargingInfo[index]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && chargingInfo[index]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
  1907. _maxChargingStatus = _CHARGING_GUN_STATUS_CHARGING;
  1908. else
  1909. _maxChargingStatus = _CHARGING_GUN_STATUS_STOP;
  1910. }
  1911. }
  1912. }
  1913. int main(void)
  1914. {
  1915. if(InitShareMemory() == FAIL)
  1916. {
  1917. #ifdef SystemLogMessage
  1918. DEBUG_ERROR("InitShareMemory NG\n");
  1919. #endif
  1920. if(ShmStatusCodeData != NULL)
  1921. {
  1922. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
  1923. }
  1924. sleep(5);
  1925. return 0;
  1926. }
  1927. PRINTF_FUNC("InitShareMemory OK\n");
  1928. // register callback function
  1929. RefreshStatus(&GetStatusCallback);
  1930. RefreshModuleCount(&GetModuleCountCallback);
  1931. RefreshAvailableCap(&GetAvailableCapCallback);
  1932. RefreshFwVersion(&GetFwCallback);
  1933. RefreshInputVol(&GetInputVoltageCallback);
  1934. RefreshGetOutput(&GetPresentOutputCallback);
  1935. RefreshMisInfo(&GetMisCallback);
  1936. RefreshIavailable(&GetIavailableCallback);
  1937. RefreshGetOutputF(&GetPresentOutputFCallback);
  1938. // GetPresentOutputCallback & GetStatusCallback
  1939. AutoMode_RefreshOutputAndTemp(&GetOutputAndTempCallback);
  1940. // GetStatusCallback
  1941. AutoMode_RefreshModuleStatus(&GetModuleStatusCallback);
  1942. // GetInputVoltageCallback
  1943. AutoMode_RefreshModuleInput(&GetModuleInputCallback);
  1944. sleep(2);
  1945. _gunCount = ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
  1946. // initial object
  1947. InitialPsuData();
  1948. Initialization();
  1949. libInitialize = InitialCommunication();
  1950. byte isInitialComp = NO;
  1951. if (ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == YES)
  1952. {
  1953. PRINTF_FUNC("Alter native mode. \n");
  1954. }
  1955. //main loop
  1956. while (libInitialize)
  1957. {
  1958. // 斷電狀態
  1959. if (ShmSysConfigAndInfo->SysInfo.AcContactorStatus == NO)
  1960. {
  1961. //一但 AC Off PSU 斷電全部的 PSU Group ID 會全部清 0
  1962. if (!isInitialComp)
  1963. {
  1964. ShmPsuData->Work_Step = INITIAL_START;
  1965. psuCmdSeq = _PSU_CMD_STATUS;
  1966. sleep(2);
  1967. InitialPsuData();
  1968. isInitialComp = YES;
  1969. }
  1970. ShmDcCommonData->psuKeepCommunication = ShmDcCommonData->acContactSwitch;
  1971. sleep(1);
  1972. continue;
  1973. }
  1974. else
  1975. {
  1976. if (isInitialComp)
  1977. GetTimespecFunc(&ShmDcCommonData->_psuComm_time);
  1978. isInitialComp = NO;
  1979. }
  1980. // 自檢失敗
  1981. if (ShmPsuData->Work_Step == _NO_WORKING)
  1982. {
  1983. PRINTF_FUNC("== PSU == self test fail. \n");
  1984. sleep(5);
  1985. }
  1986. else if (ShmDcCommonData->rebootCount < 1)
  1987. {
  1988. int _time = GetTimeoutValue(&ShmDcCommonData->_psuComm_time);
  1989. if (_time < 0)
  1990. GetTimespecFunc(&ShmDcCommonData->_psuComm_time);
  1991. if (_time > 30)
  1992. {
  1993. if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuComminicationErrWithCSU == NO)
  1994. {
  1995. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuComminicationErrWithCSU = YES;
  1996. ShmDcCommonData->rebootCount = 1;
  1997. PRINTF_FUNC("Psu is gone, reset one time. \n");
  1998. }
  1999. }
  2000. }
  2001. switch(ShmPsuData->Work_Step)
  2002. {
  2003. case INITIAL_START:
  2004. {
  2005. PRINTF_FUNC("== PSU == INITIAL_START \n");
  2006. GetTimespecMFunc(&_cmdSubPsuPriority_time);
  2007. sleep(5);
  2008. SwitchPower(SYSTEM_CMD, PSU_POWER_OFF);
  2009. SetWalkInConfig(SYSTEM_CMD, NO, 0);
  2010. for (byte index = 0; index < ShmPsuData->GroupCount; index++)
  2011. {
  2012. ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity = 0;
  2013. isStartOutputSwitch[index] = false;
  2014. }
  2015. ShmPsuData->Work_Step = GET_PSU_COUNT;
  2016. }
  2017. break;
  2018. case GET_PSU_COUNT:
  2019. {
  2020. int time = GetTimeoutMValue(&_cmdSubPsuPriority_time);
  2021. byte moduleCount = 0;
  2022. if (time < 0)
  2023. GetTimespecMFunc(&_cmdSubPsuPriority_time);
  2024. // 發送取得目前全部模組數量
  2025. GetModuleCount(SYSTEM_CMD);
  2026. if (time > 1000)
  2027. {
  2028. if (psuCmdSeq == _PSU_CMD_STATUS)
  2029. {
  2030. // 取得狀態 : 支援模塊不須按照順序功能
  2031. for (byte index = 0; index < ShmPsuData->GroupCount; index++)
  2032. {
  2033. GetStatus(index);
  2034. }
  2035. Await();
  2036. }
  2037. else if (psuCmdSeq == _PSU_CMD_GETCOUNT)
  2038. {
  2039. // 分別取各群模組數量
  2040. for (byte index = 0; index < ShmPsuData->GroupCount; index++)
  2041. {
  2042. // 總和各群模組數量
  2043. moduleCount += ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity;
  2044. // 取各群模組數量
  2045. GetModuleCount(index);
  2046. }
  2047. PRINTF_FUNC("== PSU == Connector Count = %d, moduleCount = %d, sysCount = %d\n",
  2048. ShmPsuData->GroupCount, moduleCount, ShmPsuData->SystemPresentPsuQuantity);
  2049. // 判斷系統數量與各群數量一致
  2050. if(moduleCount == ShmPsuData->SystemPresentPsuQuantity && moduleCount > 0)
  2051. {
  2052. _delayCount = 8;
  2053. if (ShmSysConfigAndInfo->SysInfo.BootingStatus == BOOTTING)
  2054. {
  2055. // 電樁在 Booting 的狀態 - 自檢
  2056. PRINTF_FUNC("== PSU == GET_SYS_CAP \n");
  2057. ShmPsuData->Work_Step = GET_SYS_CAP;
  2058. }
  2059. else
  2060. {
  2061. PRINTF_FUNC("== PSU == _WORK_CHARGING \n");
  2062. ShmPsuData->Work_Step = _WORK_CHARGING;
  2063. }
  2064. }
  2065. }
  2066. if (psuCmdSeq == _PSU_CMD_STATUS)
  2067. psuCmdSeq = _PSU_CMD_GETCOUNT;
  2068. else
  2069. psuCmdSeq = _PSU_CMD_STATUS;
  2070. GetTimespecMFunc(&_cmdSubPsuPriority_time);
  2071. }
  2072. }
  2073. break;
  2074. case GET_SYS_CAP:
  2075. {
  2076. int time = GetTimeoutMValue(&_cmdSubPsuPriority_time);
  2077. if (time < 0)
  2078. GetTimespecMFunc(&_cmdSubPsuPriority_time);
  2079. if (time > 500)
  2080. {
  2081. bool isFinish = true;
  2082. for (byte psuCount = 0; psuCount < ShmPsuData->SystemPresentPsuQuantity; psuCount++)
  2083. {
  2084. if (strcmp((char *)ShmPsuData->PsuVersion[psuCount].FwPrimaryVersion, "") == EQUAL ||
  2085. ShmPsuData->SystemAvailablePower <= 0 || ShmPsuData->SystemAvailableCurrent <= 0)
  2086. {
  2087. isFinish = false;
  2088. break;
  2089. }
  2090. }
  2091. if (!isFinish || _delayCount > 0)
  2092. {
  2093. for (byte index = 0; index < ShmPsuData->GroupCount; index++)
  2094. {
  2095. if (psuCmdSeq == _PSU_CMD_STATUS)
  2096. {
  2097. // 取得狀態 : 支援模塊不須按照順序功能
  2098. GetStatus(index);
  2099. }
  2100. else if (psuCmdSeq == _PSU_CMD_CAP)
  2101. {
  2102. _delayCount--;
  2103. // 取系統總輸出能力
  2104. GetModuleCap(index);
  2105. }
  2106. else if (psuCmdSeq == _PSU_CMD_VERSION)
  2107. {
  2108. // 取版號
  2109. GetModuleVer(index);
  2110. }
  2111. }
  2112. if (psuCmdSeq == _PSU_CMD_STATUS)
  2113. psuCmdSeq = _PSU_CMD_CAP;
  2114. else if (psuCmdSeq == _PSU_CMD_CAP)
  2115. psuCmdSeq = _PSU_CMD_VERSION;
  2116. else
  2117. psuCmdSeq = _PSU_CMD_STATUS;
  2118. }
  2119. else
  2120. {
  2121. // 判斷系統輸出額定功率與電流
  2122. PRINTF_FUNC("SystemAvailableCurrent = %d, SystemAvailablePower = %d \n",
  2123. ShmPsuData->SystemAvailableCurrent, ShmPsuData->SystemAvailablePower);
  2124. PRINTF_FUNC("== PSU == BOOTING_COMPLETE \n");
  2125. ShmPsuData->Work_Step = BOOTING_COMPLETE;
  2126. }
  2127. GetTimespecMFunc(&_cmdSubPsuPriority_time);
  2128. //GetTimespecFunc(&_log_time);
  2129. }
  2130. }
  2131. break;
  2132. case BOOTING_COMPLETE:
  2133. {
  2134. bool isSelfTestPass = true;
  2135. for (byte groupIndex = 0; groupIndex < _gunCount; groupIndex++)
  2136. {
  2137. if (chargingInfo[groupIndex]->SystemStatus == SYS_MODE_BOOTING)
  2138. {
  2139. isSelfTestPass = false;
  2140. }
  2141. }
  2142. if (isSelfTestPass)
  2143. ShmPsuData->Work_Step = _WORK_CHARGING;
  2144. sleep(1);
  2145. }
  2146. break;
  2147. case _WORK_CHARGING:
  2148. {
  2149. int time = GetTimeoutMValue(&_cmdSubPsuPriority_time);
  2150. //int _timebuf = 0;
  2151. if (time < 0)
  2152. GetTimespecMFunc(&_cmdSubPsuPriority_time);
  2153. // 低 Priority 的指令
  2154. if (time > 1500)
  2155. {
  2156. PreCheckSmartChargingStep();
  2157. startModuleFlag = true;
  2158. GetTimespecMFunc(&_cmdSubPsuPriority_time);
  2159. }
  2160. for (byte groupIndex = 0; groupIndex < _gunCount; groupIndex++)
  2161. {
  2162. if (psuCmdSeq == _PSU_CMD_CAP)
  2163. {
  2164. // 取系統總輸出能力
  2165. GetModuleCap(groupIndex);
  2166. }
  2167. else if (psuCmdSeq == _PSU_CMD_OUTPUT)
  2168. {
  2169. // 取各群輸出電壓電流 (float)
  2170. GetModuleOutputF(groupIndex);
  2171. }
  2172. else if (psuCmdSeq == _PSU_CMD_IVAILIABLE)
  2173. {
  2174. // 取得模塊輸出額定電流能力
  2175. GetModuleIavailable(groupIndex);
  2176. }
  2177. else if (psuCmdSeq == _PSU_CMD_TEMP)
  2178. {
  2179. // 取得模塊溫度
  2180. GetDcTemperature(groupIndex);
  2181. }
  2182. }
  2183. Await();
  2184. if (psuCmdSeq == _PSU_CMD_CAP)
  2185. psuCmdSeq = _PSU_CMD_OUTPUT;
  2186. else if (psuCmdSeq == _PSU_CMD_OUTPUT)
  2187. psuCmdSeq = _PSU_CMD_IVAILIABLE;
  2188. else if (psuCmdSeq == _PSU_CMD_IVAILIABLE)
  2189. psuCmdSeq = _PSU_CMD_TEMP;
  2190. else
  2191. psuCmdSeq = _PSU_CMD_CAP;
  2192. for (byte groupIndex = 0; groupIndex < _gunCount; groupIndex++)
  2193. {
  2194. // 針對各槍當前狀態,傳送需要回傳的資料指令
  2195. if (((chargingInfo[groupIndex]->SystemStatus >= SYS_MODE_PREPARE_FOR_EVSE && chargingInfo[groupIndex]->SystemStatus <= SYS_MODE_CHARGING) && chargingInfo[groupIndex]->RelayK1K2Status) ||
  2196. (chargingInfo[groupIndex]->SystemStatus >= SYS_MODE_PREPARE_FOR_EVSE && chargingInfo[groupIndex]->SystemStatus <= SYS_MODE_CHARGING && chargingInfo[groupIndex]->Type == _Type_GB) ||
  2197. (chargingInfo[groupIndex]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && chargingInfo[groupIndex]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
  2198. {
  2199. // _timebuf = GetTimeoutValue(&_log_time);
  2200. // if (_timebuf < 0)
  2201. // GetTimespecFunc(&_log_time);
  2202. //
  2203. // if (_timebuf > 1)
  2204. {
  2205. OutputChargingLogFuncion(groupIndex);
  2206. //GetTimespecFunc(&_log_time);
  2207. }
  2208. if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_MAX)
  2209. {
  2210. if (!MaxToAverChargingProc(groupIndex))
  2211. {
  2212. if(chargingInfo[groupIndex]->EvBatterytargetCurrent <= PSU_MIN_OUTPUT_CUR)
  2213. chargingInfo[groupIndex]->EvBatterytargetCurrent = PSU_MIN_OUTPUT_CUR;
  2214. PresentOutputVol(SYSTEM_CMD,
  2215. (chargingInfo[groupIndex]->EvBatterytargetVoltage * 10),
  2216. (chargingInfo[groupIndex]->EvBatterytargetCurrent * 10));
  2217. if ((chargingInfo[groupIndex]->EvBatterytargetVoltage * 10) == 0)
  2218. {
  2219. bool isNeedToClosePower = false;
  2220. for (byte index = 0; index < ShmPsuData->GroupCount; index++)
  2221. {
  2222. if (isStartOutputSwitch[index])
  2223. {
  2224. isNeedToClosePower = true;
  2225. }
  2226. isStartOutputSwitch[index] = false;
  2227. }
  2228. if (isNeedToClosePower)
  2229. {
  2230. SwitchPower(SYSTEM_CMD, PSU_POWER_OFF);
  2231. FlashLed(SYSTEM_CMD, PSU_FLASH_NORMAL);
  2232. }
  2233. }
  2234. else
  2235. {
  2236. {
  2237. bool isNeedToOpenPower = false;
  2238. for (byte index = 0; index < ShmPsuData->GroupCount; index++)
  2239. {
  2240. if (!isStartOutputSwitch[index])
  2241. {
  2242. isNeedToOpenPower = true;
  2243. }
  2244. isStartOutputSwitch[index] = true;
  2245. }
  2246. if (isNeedToOpenPower || startModuleFlag)
  2247. {
  2248. SwitchPower(SYSTEM_CMD, PSU_POWER_ON);
  2249. FlashLed(SYSTEM_CMD, PSU_FLASH_ON);
  2250. }
  2251. }
  2252. }
  2253. }
  2254. }
  2255. else if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER)
  2256. {
  2257. if (!AverToMaxChargingProc(groupIndex))
  2258. {
  2259. if (chargingInfo[groupIndex]->AvailableChargingCurrent > 0)
  2260. {
  2261. //PRINTF_FUNC("set out (%d) value = %f******** 7 \n", groupIndex, chargingInfo[groupIndex]->EvBatterytargetCurrent);
  2262. if(chargingInfo[groupIndex]->EvBatterytargetCurrent <= PSU_MIN_OUTPUT_CUR)
  2263. chargingInfo[groupIndex]->EvBatterytargetCurrent = PSU_MIN_OUTPUT_CUR;
  2264. PresentOutputVol(groupIndex,
  2265. (chargingInfo[groupIndex]->EvBatterytargetVoltage * 10),
  2266. (chargingInfo[groupIndex]->EvBatterytargetCurrent * 10)); Await();
  2267. if ((chargingInfo[groupIndex]->EvBatterytargetVoltage * 10) == 0)
  2268. {
  2269. if (isStartOutputSwitch[groupIndex])
  2270. {
  2271. isStartOutputSwitch[groupIndex] = false;
  2272. SwitchPower(groupIndex, PSU_POWER_OFF); Await();
  2273. FlashLed(groupIndex, PSU_FLASH_NORMAL); Await();
  2274. }
  2275. }
  2276. else
  2277. {
  2278. // if (chargingInfo[groupIndex]->SystemStatus == SYS_MODE_PREPARE_FOR_EVSE)
  2279. // {
  2280. // if (startModuleFlag)
  2281. // {
  2282. // isStartOutputSwitch[groupIndex] = true;
  2283. // SwitchSinglePower(ShmDcCommonData->connector[groupIndex][0], PSU_POWER_ON);
  2284. // FlashSingleLed(ShmDcCommonData->connector[groupIndex][0], PSU_FLASH_ON);
  2285. // }
  2286. // }
  2287. // else
  2288. {
  2289. if (!isStartOutputSwitch[groupIndex] || startModuleFlag)
  2290. {
  2291. isStartOutputSwitch[groupIndex] = true;
  2292. SwitchPower(groupIndex, PSU_POWER_ON); Await();
  2293. FlashLed(groupIndex, PSU_FLASH_ON); Await();
  2294. }
  2295. }
  2296. }
  2297. }
  2298. }
  2299. }
  2300. }
  2301. else if (chargingInfo[groupIndex]->SystemStatus >= SYS_MODE_TERMINATING &&
  2302. chargingInfo[groupIndex]->SystemStatus <= SYS_MODE_ALARM)
  2303. {
  2304. if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_MAX)
  2305. {
  2306. SwitchOffPowerCheck(groupIndex);
  2307. if (_maxChargingStatus == _CHARGING_GUN_STATUS_STOP)
  2308. {
  2309. bool isNeedToClosePower = false;
  2310. for (byte index = 0; index < ShmPsuData->GroupCount; index++)
  2311. {
  2312. if (isStartOutputSwitch[index])
  2313. {
  2314. isNeedToClosePower = true;
  2315. }
  2316. isStartOutputSwitch[index] = false;
  2317. }
  2318. if (isNeedToClosePower)
  2319. {
  2320. SwitchPower(SYSTEM_CMD, PSU_POWER_OFF);
  2321. FlashLed(SYSTEM_CMD, PSU_FLASH_NORMAL);
  2322. }
  2323. if (chargingInfo[groupIndex]->SystemStatus == SYS_MODE_COMPLETE ||
  2324. chargingInfo[groupIndex]->SystemStatus == SYS_MODE_ALARM)
  2325. {
  2326. if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag >= _REASSIGNED_PREPARE_M_TO_A &&
  2327. ShmSysConfigAndInfo->SysInfo.ReAssignedFlag <= _REASSIGNED_RELAY_M_TO_A)
  2328. {
  2329. // 代表在切換的過程中,停止充電了
  2330. if ((chargingInfo[groupIndex]->PresentChargingCurrent * 10) <= STOP_CURRENT)
  2331. ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_RELAY_M_TO_A;
  2332. }
  2333. }
  2334. }
  2335. else if (chargingInfo[groupIndex]->SystemStatus == SYS_MODE_COMPLETE)
  2336. {
  2337. // 代表充電的槍依舊在充電,欲進入充電的槍取消充電了
  2338. if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag >= _REASSIGNED_PREPARE_M_TO_A &&
  2339. ShmSysConfigAndInfo->SysInfo.ReAssignedFlag <= _REASSIGNED_RELAY_M_TO_A)
  2340. {
  2341. ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
  2342. }
  2343. }
  2344. }
  2345. else if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER)
  2346. {
  2347. // if (!isReadyToCharging)
  2348. // {
  2349. // bool isNeedToClosePower = false;
  2350. // for (byte index = 0; index < ShmPsuData->GroupCount; index++)
  2351. // {
  2352. // if (isStartOutputSwitch[index])
  2353. // {
  2354. // isNeedToClosePower = true;
  2355. // }
  2356. // isStartOutputSwitch[index] = false;
  2357. // }
  2358. //
  2359. // if (isNeedToClosePower)
  2360. // {
  2361. // SwitchPower(SYSTEM_CMD, PSU_POWER_OFF);
  2362. // FlashLed(SYSTEM_CMD, PSU_FLASH_NORMAL);
  2363. // }
  2364. // }
  2365. // else
  2366. // {
  2367. if (isStartOutputSwitch[groupIndex] &&
  2368. ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_NONE)
  2369. {
  2370. isStartOutputSwitch[groupIndex] = false;
  2371. SwitchPower(groupIndex, PSU_POWER_OFF); Await();
  2372. FlashLed(groupIndex, PSU_FLASH_NORMAL); Await();
  2373. }
  2374. //}
  2375. if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag >= _REASSIGNED_WAITING)
  2376. ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_COMP;
  2377. }
  2378. }
  2379. else if ((chargingInfo[groupIndex]->SystemStatus >= SYS_MODE_PREPARING && chargingInfo[groupIndex]->SystemStatus <= SYS_MODE_PREPARE_FOR_EV) &&
  2380. ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER)
  2381. {
  2382. //PRINTF_FUNC("%d ******** 7 \n", groupIndex);
  2383. if (isStartOutputSwitch[groupIndex])
  2384. {
  2385. isStartOutputSwitch[groupIndex] = false;
  2386. SwitchPower(groupIndex, PSU_POWER_OFF); Await();
  2387. FlashLed(groupIndex, PSU_FLASH_NORMAL); Await();
  2388. }
  2389. }
  2390. }
  2391. startModuleFlag = false;
  2392. break;
  2393. }
  2394. case _ALATON_MODE:
  2395. {
  2396. // int time = GetTimeoutMValue ( & _cmdSubPsuPriority_time );
  2397. //
  2398. // if (time < 0)
  2399. // GetTimespecMFunc ( & _cmdSubPsuPriority_time );
  2400. //
  2401. // // 低 Priority 的指令
  2402. // if (time > 1500)
  2403. // {
  2404. // PreCheckSmartChargingStep ();
  2405. // startModuleFlag = true;
  2406. // GetTimespecMFunc ( & _cmdSubPsuPriority_time );
  2407. // }
  2408. //
  2409. // for (byte groupIndex = 0; groupIndex < _gunCount; groupIndex ++)
  2410. // {
  2411. // if (psuCmdSeq == _PSU_CMD_CAP)
  2412. // {
  2413. // // 取系統總輸出能力
  2414. // GetModuleCap ( groupIndex );
  2415. // }
  2416. // else if (psuCmdSeq == _PSU_CMD_OUTPUT)
  2417. // {
  2418. // // 取各群輸出電壓電流 (float)
  2419. // GetModuleOutputF ( groupIndex );
  2420. // }
  2421. // else if (psuCmdSeq == _PSU_CMD_IVAILIABLE)
  2422. // {
  2423. // // 取得模塊輸出額定電流能力
  2424. // GetModuleIavailable ( groupIndex );
  2425. // }
  2426. // else if (psuCmdSeq == _PSU_CMD_TEMP)
  2427. // {
  2428. // // 取得模塊溫度
  2429. // GetDcTemperature ( groupIndex );
  2430. // }
  2431. // }
  2432. //
  2433. // Await ();
  2434. //
  2435. // if (psuCmdSeq == _PSU_CMD_CAP)
  2436. // psuCmdSeq = _PSU_CMD_OUTPUT;
  2437. // else if (psuCmdSeq == _PSU_CMD_OUTPUT)
  2438. // psuCmdSeq = _PSU_CMD_IVAILIABLE;
  2439. // else if (psuCmdSeq == _PSU_CMD_IVAILIABLE)
  2440. // psuCmdSeq = _PSU_CMD_TEMP;
  2441. // else
  2442. // psuCmdSeq = _PSU_CMD_CAP;
  2443. //
  2444. // for (byte psu = 0; psu < ShmPsuData->SystemPresentPsuQuantity; psu++)
  2445. // {
  2446. // if (psu == ShmDcCommonData->for_alston_test_1)
  2447. // {
  2448. // FlashSingleLed(psu, PSU_FLASH_NORMAL);
  2449. // }
  2450. // else
  2451. // {
  2452. // FlashSingleLed(psu, PSU_FLASH_ON);
  2453. // }
  2454. // }
  2455. }
  2456. break;
  2457. case _TEST_MODE:
  2458. {
  2459. // 在測試模式中,保持與模塊的通訊
  2460. int time = GetTimeoutMValue(&_cmdSubPsuPriority_time);
  2461. if (time < 0)
  2462. GetTimespecMFunc(&_cmdSubPsuPriority_time);
  2463. if (time > 1500)
  2464. {
  2465. for (byte index = 0; index < ShmPsuData->GroupCount; index++)
  2466. {
  2467. // 取系統總輸出能力
  2468. GetModuleCap(index); Await();
  2469. // 取各群輸出電壓電流 (float)
  2470. GetModuleOutputF(index); Await();
  2471. }
  2472. GetTimespecMFunc(&_cmdSubPsuPriority_time);
  2473. }
  2474. byte _switch = 0x00;
  2475. if ((chargingInfo[0]->EvBatterytargetVoltage * 10) > 0 && (chargingInfo[0]->EvBatterytargetCurrent * 10) > 0)
  2476. _switch = 0x01;
  2477. for (byte _groupCount_1 = 0; _groupCount_1 < ShmDcCommonData->conn_1_count; _groupCount_1++)
  2478. {
  2479. SetDirModulePresentOutput(ShmDcCommonData->connector[0][_groupCount_1],
  2480. (chargingInfo[0]->EvBatterytargetVoltage * 10),
  2481. (chargingInfo[0]->EvBatterytargetCurrent * 10),
  2482. _switch, _switch); Await();
  2483. }
  2484. for (byte _groupCount_2 = 0; _groupCount_2 < ShmDcCommonData->conn_2_count; _groupCount_2++)
  2485. {
  2486. SetDirModulePresentOutput(ShmDcCommonData->connector[1][_groupCount_2],
  2487. (chargingInfo[0]->EvBatterytargetVoltage * 10),
  2488. (chargingInfo[0]->EvBatterytargetCurrent * 10),
  2489. _switch, _switch); Await();
  2490. }
  2491. }
  2492. break;
  2493. }
  2494. usleep(20000);
  2495. }
  2496. return FAIL;
  2497. }