PageRenderTime 46ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/ATF2/control-software/Matlab/ps/ps_guistart.m

http://atf2flightsim.googlecode.com/
Objective C | 252 lines | 244 code | 8 blank | 0 comment | 69 complexity | 44bd4105b45d98b28a3b3f7ece012825 MD5 | raw file
Possible License(s): BSD-2-Clause, LGPL-2.0, IPL-1.0, BSD-3-Clause
  1. function ps_guistart(psList)
  2. warning('off','MATLAB:dispatcher:InexactMatch')
  3. global PS
  4. % Initialisation
  5. PS.errMessages={};
  6. PS.allowedErrMess={'MESSAGE BUFFER EMPTY'};
  7. PS.doMonitor=true;
  8. PS.doModule=true; % Ensure module:status.SCAN to 1 sec periodic if true
  9. PS.doBulk=true;
  10. PS.modcurConv=50/410;
  11. % Power supplies in use
  12. if isdeployed
  13. if isempty(psList) || ~isnumeric(str2double(psList))
  14. fid=fopen([getenv('PSIOC'),'/st.cmd']);
  15. fline=fgetl(fid);
  16. psList=[];
  17. while ~isnumeric(fline)
  18. t=regexp(fline,'^epscDriverInit("PS(\d+)','tokens');
  19. if ~isempty(t); psList=[psList str2double(t{1}{1})]; end; %#ok<AGROW>
  20. fline=fgetl(fid);
  21. end
  22. fclose(fid);
  23. PS.inuse = psList;
  24. else
  25. PS.inuse = str2num(psList); %#ok<ST2NM>
  26. end % get PS list
  27. else
  28. if exist('psList','var')
  29. PS.inuse = psList;
  30. else
  31. fid=fopen([getenv('PSIOC'),'/st.cmd']);
  32. fline=fgetl(fid);
  33. psList=[];
  34. while ~isnumeric(fline)
  35. t=regexp(fline,'^epscDriverInit("PS(\d+)','tokens');
  36. if ~isempty(t); psList=[psList str2double(t{1}{1})]; end; %#ok<AGROW>
  37. fline=fgetl(fid);
  38. end
  39. fclose(fid);
  40. PS.inuse = psList;
  41. end % if psList passed
  42. end % isdeployed?
  43. % Error message buffer init
  44. for iPS=1:length(psList)
  45. PS.errMessages(iPS).str={};
  46. end % for iPS
  47. % Form EPICS command strings
  48. PS.cmd.stat={};
  49. PS.pointer=zeros(length(PS.inuse),1);
  50. % Get sim mode
  51. [PS.simMode.val PS.simMode.time] = lcaget(['PS',num2str(psList(1)),':simMode']);
  52. for iPS=PS.inuse
  53. ind=length(PS.cmd.stat)+1;
  54. PS.cmd.stat{ind,1}=['PS',num2str(iPS),':readADC.PROC']; PS.cmd.statVal(ind,1)=1;
  55. PS.cmd.statOval{ind,1}=['PS',num2str(iPS),':stat.PROC']; PS.cmd.statOvalVal(ind,1)=1;
  56. PS.cmd.stat1Read{ind,1}=['PS',num2str(iPS),':status1.VAL'];
  57. PS.cmd.stat2Read{ind,1}=['PS',num2str(iPS),':status2.VAL'];
  58. PS.cmd.stat3Read{ind,1}=['PS',num2str(iPS),':status3.VAL'];
  59. PS.cmd.stat4Read{ind,1}=['PS',num2str(iPS),':status4.VAL'];
  60. PS.cmd.curRead{ind,1}=['PS',num2str(iPS),':current.VAL'];
  61. PS.cmd.tRamp{ind,1}=['PS',num2str(iPS),':rampTimeConv.VAL'];
  62. PS.cmd.curSet{ind,1}=['PS',num2str(iPS),':currentDES.VAL'];
  63. PS.cmd.curStore{ind,1}=['PS',num2str(iPS),':currentSTORE.VAL'];
  64. PS.cmd.errMess{ind,1}=['PS',num2str(iPS),':readErr.PROC']; PS.cmd.errMessVal(ind,1)=1;
  65. PS.cmd.errMessRead{ind,1}=['PS',num2str(iPS),':errorString.VAL'];
  66. PS.cmd.pwrOn{ind,1}=['PS',num2str(iPS),':pwrOn.PROC']; PS.cmd.pwrOnVal(ind,1)=1;
  67. PS.cmd.pwrOff{ind,1}=['PS',num2str(iPS),':pwrOff.PROC']; PS.cmd.pwrOffVal(ind,1)=1;
  68. PS.cmd.ramp{ind,1}=['PS',num2str(iPS),':setCurrent.PROC']; PS.cmd.rampVal(ind,1)=1;
  69. PS.cmd.rampHold{ind,1}=['PS',num2str(iPS),':setCurrentHold.PROC']; PS.cmd.rampHoldVal(ind,1)=1;
  70. PS.cmd.resetInterlocks{ind,1}=['PS',num2str(iPS),':resetInterlocks.PROC']; PS.cmd.resetInterlocksVal(ind,1)=1;
  71. PS.cmd.resetController{ind,1}=['PS',num2str(iPS),':resetController.PROC']; PS.cmd.resetControllerVal(ind,1)=1;
  72. PS.ptr(ind,1)=iPS;
  73. PS.alarm(ind,1)=0;
  74. % Expert panel stuff
  75. PS.cmd.chassisConfig{ind,1}=['PS',num2str(iPS),':chassisConfig.VAL'];
  76. PS.cmd.magnetID{ind,1}=['PS',num2str(iPS),':magnetID.VAL'];
  77. PS.cmd.ipAddr{ind,1}=['PS',num2str(iPS),':ipAddr.VAL'];
  78. PS.cmd.regAtoV{ind,1}=['PS',num2str(iPS),':regTransA_per_V.VAL'];
  79. PS.cmd.auxAtoV{ind,1}=['PS',num2str(iPS),':auxTransA_per_V.VAL'];
  80. PS.cmd.gndAtoV{ind,1}=['PS',num2str(iPS),':gndCurA_per_V.VAL'];
  81. PS.cmd.psVtoV{ind,1}=['PS',num2str(iPS),':psV_per_V.VAL'];
  82. PS.cmd.serNum{ind,1}=['PS',num2str(iPS),':chassisSerialNum.VAL'];
  83. PS.cmd.firmVer{ind,1}=['PS',num2str(iPS),':firmwareVer.VAL'];
  84. PS.cmd.adcOff{ind,1}=['PS',num2str(iPS),':adcOff.VAL'];
  85. PS.cmd.adcGain{ind,1}=['PS',num2str(iPS),':adcGain.VAL'];
  86. PS.cmd.dacOff{ind,1}=['PS',num2str(iPS),':dacOff.VAL'];
  87. PS.cmd.dacGain{ind,1}=['PS',num2str(iPS),':dacGain.VAL'];
  88. PS.cmd.refV{ind,1}=['PS',num2str(iPS),':refV.VAL'];
  89. PS.cmd.calDate{ind,1}=['PS',num2str(iPS),':calDate.VAL'];
  90. PS.cmd.auxI{ind,1}=['PS',num2str(iPS),':auxI.VAL'];
  91. PS.cmd.dacI{ind,1}=['PS',num2str(iPS),':dacI.VAL'];
  92. PS.cmd.ripI{ind,1}=['PS',num2str(iPS),':ripI.VAL'];
  93. PS.cmd.gndI{ind,1}=['PS',num2str(iPS),':gndI.VAL'];
  94. PS.cmd.chassisTemp{ind,1}=['PS',num2str(iPS),':chassisTemp.VAL'];
  95. PS.cmd.psV{ind,1}=['PS',num2str(iPS),':psV.VAL'];
  96. PS.cmd.spareV{ind,1}=['PS',num2str(iPS),':spareV.VAL'];
  97. PS.cmd.lastRst{ind,1}=['PS',num2str(iPS),':lastRst.VAL'];
  98. PS.cmd.lastOff{ind,1}=['PS',num2str(iPS),':lastOff.VAL'];
  99. PS.cmd.calErr{ind,1}=['PS',num2str(iPS),':calErr.VAL'];
  100. PS.cmd.selfTest{ind,1}=['PS',num2str(iPS),':selfTest.VAL'];
  101. PS.cmd.digErrLim{ind,1}=['PS',num2str(iPS),':digErrLim.VAL'];
  102. PS.cmd.sd_iLow{ind,1}=['PS',num2str(iPS),':standardise:iLow.VAL'];
  103. PS.cmd.sd_iHigh{ind,1}=['PS',num2str(iPS),':standardise:iHigh.VAL'];
  104. PS.cmd.sd_waitLow{ind,1}=['PS',num2str(iPS),':standardise:waitLow.VAL'];
  105. PS.cmd.sd_waitHigh{ind,1}=['PS',num2str(iPS),':standardise:waitHigh.VAL'];
  106. PS.cmd.sd_nCycles{ind,1}=['PS',num2str(iPS),':standardise:nCycles.VAL'];
  107. % Module Commands
  108. PS.cmd.modStat{ind,1}=['PS',num2str(iPS),':module:status.PROC']; % Command to fill Module status records (SCAN=periodic)
  109. PS.cmd.modEnable{ind,1}=['PS',num2str(iPS),':module:enable.VAL']; % Enable Module command (VAL=module #, 0=all)
  110. PS.cmd.modDisable{ind,1}=['PS',num2str(iPS),':module:disable.VAL']; % Enable Disable command (VAL=module #)
  111. PS.cmd.modDataValid{ind,1}=['PS',num2str(iPS),':module:dataValid.RVAL']; % Data valid flag
  112. PS.cmd.modNum{ind,1}=['PS',num2str(iPS),':module:number.VAL']; % Number of modules reported
  113. PS.cmd.modFaultFlags{ind,1}=['PS',num2str(iPS),':module:faultFlags.VAL']; % Flags reporting faulty modules
  114. PS.cmd.modDisableFlags{ind,1}=['PS',num2str(iPS),':module:disableFlags.VAL']; % Flags reporting disabled modules
  115. PS.cmd.modCurrents{ind,1}=['PS',num2str(iPS),':module:currents.VAL']; % Array of reported module currents
  116. % Bulk PS command strings
  117. if PS.simMode.val
  118. field='SVAL';
  119. else
  120. field='RVAL';
  121. end % if simMode
  122. PS.cmd.bulkPwr{ind,1}=['BPS',num2str(iPS),':pwrOnOff'];
  123. PS.cmd.bulkFaultReset{ind,1}=['BPS',num2str(iPS),':faultReset'];
  124. PS.cmd.bulkStatus{ind,1}=['BPS',num2str(iPS),':status.',field];
  125. PS.cmd.bulkV{ind,1}=['BPS',num2str(iPS),':outputVoltage.VAL'];
  126. % Get data for which BPS drives which PS (need to give commands to last
  127. % allocated BPS record)
  128. t=regexp(lcaGet(['BPS',num2str(iPS),':pwrOnOff.OUT']),'REMOTE_CONTROL\[(-?\d+)\]','tokens');
  129. bulkList(ind,1)=abs(str2double(t{1}{1})); %#ok<AGROW>
  130. end % for iPS
  131. for ibulk=1:max(bulkList)
  132. bm{ibulk}=find(bulkList==ibulk); %#ok<AGROW>
  133. for ib=1:length(bm{ibulk})
  134. bulkMatch{ibulk}{ib}=num2str(bm{ibulk}(ib)); %#ok<AGROW>
  135. end % for ib
  136. end % for ibulk
  137. for ind=1:length(PS.cmd.bulkPwr)
  138. for ibulk=1:length(bulkMatch)
  139. if ismember(ind,str2double(bulkMatch{ibulk}))
  140. sm=str2double(sort(bulkMatch{ibulk}));
  141. whichPS(ind)=sm(end); %#ok<AGROW>
  142. break;
  143. end % if member bulkMatch
  144. end % for ibulk
  145. PS.cmd.bulkPwr{ind,1}=['BPS',num2str(whichPS(ind)),':pwrOnOff'];
  146. PS.cmd.bulkFaultReset{ind,1}=['BPS',num2str(whichPS(ind)),':faultReset'];
  147. PS.cmd.bulkStatus{ind,1}=['BPS',num2str(whichPS(ind)),':status.',field];
  148. PS.cmd.bulkV{ind,1}=['BPS',num2str(whichPS(ind)),':outputVoltage.VAL'];
  149. end % for ips
  150. % GUI parameters
  151. PS.guiCol.green = [0 1 0.501961];
  152. PS.guiCol.red = [1 0 0];
  153. PS.guiCol.orange = [1 0.501961 0];
  154. PS.guiCol.black = [0 0 0];
  155. % Get PS status (all PS's)
  156. ps_stat(0);
  157. % Launch main GUI
  158. PS.gui.main = ps_control;
  159. ps_stat(0);
  160. % Start monitor process
  161. monitorSetup=[];
  162. controlMonitorPVs={PS.cmd.stat1Read{:};
  163. PS.cmd.stat2Read{:};
  164. PS.cmd.stat3Read{:};
  165. PS.cmd.stat4Read{:}};
  166. if PS.doModule
  167. controlMonitorPVs={controlMonitorPVs{:},...
  168. PS.cmd.modDisableFlags{:},...
  169. PS.cmd.modDataValid{:},...
  170. PS.cmd.modFaultFlags{:}}';
  171. end % if doModule
  172. bulkList=unique(whichPS);
  173. if PS.doBulk
  174. for ibulk=1:length(bulkList)
  175. controlMonitorPVs={controlMonitorPVs{:},...
  176. PS.cmd.bulkStatus{bulkList(ibulk)}}';
  177. end % for ibulk
  178. end % if doBulk
  179. while 1
  180. % Clear monitor channels and exit if main GUI closed
  181. if ~isfield(PS,'gui') || ~isfield(PS.gui,'main')
  182. lcaclear();
  183. break
  184. end % if gui still open
  185. % Fix case where main gui window killed but gui flag still there
  186. try
  187. findobj(PS.gui.main.figure1);
  188. catch
  189. lcaclear();
  190. break
  191. end % try/catch
  192. % If monitor requested, setup monitors and update status entries
  193. if isfield(PS,'doMonitor') && PS.doMonitor
  194. if ~isfield(monitorSetup,'main')
  195. % Main control panel monitors
  196. lcaSetMonitor({controlMonitorPVs{:}}');
  197. monitorSetup.main=true;
  198. % EPSC panel monitors
  199. for iPS=PS.inuse
  200. if isfield(PS,'gui') && ~isfield(monitorSetup,['ps_panel',num2str(iPS)])
  201. lcaSetMonitor(PS.cmd.curRead{PS.ptr==iPS}); % Current readback monitor
  202. monitorSetup.(['ps_panel',num2str(iPS)])=true;
  203. end % is panel open for iPS?
  204. end % for iPS
  205. % Module panel monitors
  206. if PS.doModule
  207. for iPS=PS.inuse
  208. if isfield(PS,'gui') && ~isfield(monitorSetup,['psModule_panel',num2str(iPS)])
  209. lcaSetMonitor(PS.cmd.modCurrents{PS.ptr==iPS}); % Currents readback monitor
  210. monitorSetup.(['psModule_panel',num2str(iPS)])=true;
  211. end % is panel open for iPS?
  212. end % for iPS
  213. end % if doModule
  214. end % if monitor setup
  215. % Check for any status report changes
  216. flags=lcaNewMonitorValue({controlMonitorPVs{:}}');
  217. % if sum(flags);
  218. % ps_stat(unique(ceil(mod((find(flags>0))/length(controlMonitorPVs),length(controlMonitorPVs))))); end;
  219. if sum(flags); ps_stat(0); end;
  220. % Check for any current readback value changes
  221. panelsActive=fieldnames(PS.gui);
  222. for iPanel=1:length(panelsActive)
  223. % Update EPSC panel gui's
  224. psPanelNum=regexp(panelsActive{iPanel},'ps_panel(\d+)','tokens');
  225. if ~isempty(psPanelNum)
  226. if lcaNewMonitorValue(PS.cmd.curRead{PS.ptr==str2double(psPanelNum{1})})>0; ps_stat(find(PS.ptr==str2double(psPanelNum{1}))); end;
  227. end % if ps_panel
  228. % Update at refresh rate if expert panel open
  229. expPanelNum=regexp(panelsActive{iPanel},'psExpert_panel(\d+)','tokens');
  230. if ~isempty(expPanelNum)
  231. ps_stat(find(PS.ptr==str2double(expPanelNum{1})));
  232. end % if expert panel open
  233. % Update EPSC Module panel gui's
  234. if PS.doModule
  235. modPanelNum=regexp(panelsActive{iPanel},'psModule_panel(\d+)','tokens');
  236. if ~isempty(modPanelNum)
  237. if lcaNewMonitorValue(PS.cmd.modCurrents{PS.ptr==str2double(modPanelNum{1})})>0; ps_stat(find(PS.ptr==str2double(modPanelNum{1}))); end;
  238. end % if ps_panel
  239. end % if doModule
  240. end % for iPanel
  241. end % if monitor
  242. pause(0.2);
  243. drawnow;
  244. end % monitor loop