otsdaq_prepmodernization  v2_05_02_indev
NimPlus_app.js
1 //NimPlus_app JS
2 //Created by Ben Hawks (bhawks at fnal.gov)
3 /*
4 TODO
5 
6  - (Later) Have the ability to load previous versions of config?
7 
8  --- Save Procedure ---
9  set subsetBasePath value
10  -> getSubsetRecords
11  -> getFieldsOfRecords
12  -> setFieldValuesForRecords
13  -> popUpSaveModifiedTablesForm
14  -> activateGroup
15  -> getFieldValuesForRecords
16 
17 
18 
19 */
20 
21 
22 
23 var _TABLE_BOOL_TYPE_TRUE_COLOR = "rgb(201, 255, 201)";
24 var _TABLE_BOOL_TYPE_FALSE_COLOR = "rgb(255, 178, 178)";
25 var _nimUids = null;
26 var timeout = null; //voltField timeout value, used to wait till user done entering a value
27 var stepTimeout = null;
28 var trigTimeout = null; //triggerSyncWordCalc timeout val, used to wait till user done entering a value
29 var modifiedList = []; //List of values that are modified, used to keep track of what values need to be updated
30 var invalidInput = false; //Track if any textbox input is invalid, used to prevent saving if there is
31 var loadMuxArr = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
32 var syncArray = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] //empty array for 40Mhz Sync Word, 24 bits
33 var inputMuxArray = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] //Empty Input Mux Array, 4 vals per fw block, current max of 4 fw blocks/Physical NIM+ Unit
34 var outputMuxArray = [0,0,0,0,0,0,0,0] //Empty Output Mux Array, 4 vals per NimPlus Board, current max of 2 NimPlus Boards/Physical NIM+ Unit
35 var accelMaskArray = [0,0,0,0,0,0,0,0] //empty array for Accel Clock Sync Word, 8 bits, only 1 true max
36 var tMuxAArray = [[0,0,0,0,0,0,0,0,0]]; //empty array for Trigger Mux Bank A
37 var tMuxBArray= [[0,0,0,0,0,0,0,0,0]]; //empty array for Trigger Mux Bank B
38 var logicArray = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] //empty array for coincidence logic word
39 var _subsetBasePath = "FENIMPlusInterfaceTable";
40 var _modifiedTables = [];
41 var writeFEInterfaceStatus = false;
42 var FEInterfaceStatusValue = "";
43 var ogBoardState = "";
44 var fieldList = [["NimStatus","Status"],
45 ["NimPlusIP","InterfaceIPAddress"],
46 ["NimPlusPort","InterfacePort"],
47 ["otsHostIP","HostIPAddress"],
48 ["otsHostPort","HostPort"],
49 ["ChAInEn","LogicInputChannelA"],
50 ["ChBInEn","LogicInputChannelB"],
51 ["ChCInEn","LogicInputChannelC"],
52 ["ChDInEn","LogicInputChannelD"],
53 ["ChEInEn","LogicInputChannelE"],
54 ["ChFInEn","LogicInputChannelF"],
55 ["ChGInEn","LogicInputChannelG"],
56 ["ChHInEn","LogicInputChannelH"],
57 ["useExtClk","UseExternalClock"],
58 ["addressOffset","AddressOffset"],
59 ["PrimaryCfg","PrimaryBoardConfig"],
60 ["boardVersion","BoardVersion"],
61 ["inMux1","InputMuxConfig"],
62 ["outMux1","OutputMuxConfig"],
63 ["OutputSourceOutput1","TriggerInputChannel1"],
64 ["OutputSourceOutput2","TriggerInputChannel2"],
65 ["ChAInInv","InvertPolarityInputChannelA"],
66 ["ChBInInv","InvertPolarityInputChannelB"],
67 ["ChCInInv","InvertPolarityInputChannelC"],
68 ["ChDInInv","InvertPolarityInputChannelD"],
69 ["ChEInInv","InvertPolarityInputChannelE"],
70 ["ChFInInv","InvertPolarityInputChannelF"],
71 ["ChGInInv","InvertPolarityInputChannelG"],
72 ["ChHInInv","InvertPolarityInputChannelH"],
73 ["ChADacEl1","DACValueChannelA"],
74 ["ChBDacEl1","DACValueChannelB"],
75 ["ChCDacEl1","DACValueChannelC"],
76 ["ChDDacEl1","DACValueChannelD"],
77 ["ChEDacEl1","DACValueChannelE"],
78 ["ChFDacEl1","DACValueChannelF"],
79 ["ChGDacEl1","DACValueChannelG"],
80 ["ChHDacEl1","DACValueChannelH"],
81 ["ChAOutMux","OutputMuxSelectChannelA"],
82 ["ChBOutMux","OutputMuxSelectChannelB"],
83 ["ChCOutMux","OutputMuxSelectChannelC"],
84 ["ChDOutMux","OutputMuxSelectChannelD"],
85 ["ChAOutInv","InvertPolarityOutputChannelA"],
86 ["ChBOutInv","InvertPolarityOutputChannelB"],
87 ["ChCOutInv","InvertPolarityOutputChannelC"],
88 ["ChDOutInv","InvertPolarityOutputChannelD"],
89 ["Sync1","ClockMaskSetup"],
90 ["AccSync1","40MHzClockDelay"],
91 ["EnableSync0","EnableClockMaskTriggerOutputChannel0"],
92 ["EnableSync1","EnableClockMaskTriggerOutputChannel1"],
93 ["EnableSync2","EnableClockMaskTriggerOutputChannel2"],
94 ["VetoCount","TimeVetoTriggerOutputChannel0"],
95 ["Veto1Count","TimeVetoTriggerOutputChannel1"],
96 ["Veto2Count","TimeVetoTriggerOutputChannel2"],
97 ["VetoSourceOutput0","VetoSourceTriggerOutputChannel0"],
98 ["VetoSourceOutput1","VetoSourceTriggerOutputChannel1"],
99 ["VetoSourceOutput2","VetoSourceTriggerOutputChannel2"],
100 ["PsCount","PrescaleTriggerOutputChannel0"],
101 ["PsCount1","PrescaleTriggerOutputChannel1"],
102 ["PsCount2","PrescaleTriggerOutputChannel2"],
103 ["SL0","CoincidenceLogicWord"],
104 ["bkpEnableA","EnableBackPressureNwFmcPta1"],
105 ["bkpEnableB","EnableBackPressureNwFmcPta2"],
106 ["SGPulseCnt","SignalGeneratorPulseCount"],
107 ["SGHighPer","SignalGeneratorHighPeriod"],
108 ["SGLowPer","SignalGeneratorLowPeriod"],
109 ["sigGenEn","SignalGeneratorEnable"],
110 ["sigGenInv","SignalGeneratorInvertPolarity"],
111 ["ChADelayEl","DelayInputChannelA"],
112 ["ChAWidthEl","WidthInputChannelA"],
113 ["ChBDelayEl","DelayInputChannelB"],
114 ["ChBWidthEl","WidthInputChannelB"],
115 ["ChCDelayEl","DelayInputChannelC"],
116 ["ChCWidthEl","WidthInputChannelC"],
117 ["ChDDelayEl","DelayInputChannelD"],
118 ["ChDWidthEl","WidthInputChannelD"],
119 ["ChEDelayEl","DelayInputChannelE"],
120 ["ChEWidthEl","WidthInputChannelE"],
121 ["ChFDelayEl","DelayInputChannelF"],
122 ["ChFWidthEl","WidthInputChannelF"],
123 ["ChGDelayEl","DelayInputChannelG"],
124 ["ChGWidthEl","WidthInputChannelG"],
125 ["ChHDelayEl","DelayInputChannelH"],
126 ["ChHWidthEl","WidthInputChannelH"],
127 ["ChSNDelayEl","DelayTriggerOutputChannel0"],
128 ["ChSNWidthEl","WidthTriggerOutputChannel0"],
129 ["ChSCMS1DelayEl","DelayTriggerOutputChannel1"],
130 ["ChSCMS1WidthEl","WidthTriggerOutputChannel1"],
131 ["ChSCMS2DelayEl","DelayTriggerOutputChannel2"],
132 ["ChSCMS2WidthEl","WidthTriggerOutputChannel2"],
133 ["triggerDelaySecs","SecondsDelayBeforeStartingTriggers"],
134 ["ExtClkSel","ExternalClockSource"],
135 ["bkpOutSel0","BackpressureTriggerOutputChannel0"],
136 ["bkpOutSel1","BackpressureTriggerOutputChannel1"],
137 ["bkpOutSel2","BackpressureTriggerOutputChannel2"],
138 ["TMuxB1","TriggerMuxSelectionsBankB"],
139 ["TMuxA1","TriggerMuxSelectionsBankA"],
140 ["triggerFilename","TriggerCountAtRunStopFilename"],
141 ["BurstEn","EnableBurstData"],
142 ["BurstLogicDelay","BurstDataLogicSampleDelay"],
143 ["BurstMuxSel","BurstDataMuxSelect"],
144 ["BurstGateInputCh","BurstDataGateInputChannel"]
145 
146 ]
147 
148 //----------------------------------------- Save Functions -----------------------------------------
149 
150 
151 // Save Page Function
152 function savePageValues(e) {
153  if(modifiedList.length > 0){
154  if (invalidInput == false) {
155 
156 
157 
158 // ConfigurationAPI.getSubsetRecords(
159 // _subsetBasePath /*subsetBasePath*/ ,
160 // "", //"FEInterfacePluginName=FEOtsUDPTemplateInterface"/*filterList*/,
161 // getNimFieldsForSave /*responseHandler*/ ,
162 // _modifiedTables /*modifiedTables*/ )
163  if(writeFEInterfaceStatus == false){ //Dont need to set FEInterface status
164  console.log("Don't need to write to FEInterfaceTable, skipping that write.");
165  ConfigurationAPI.getFieldsOfRecords(
166  _subsetBasePath, selUID,//["NimPlus0"]
167  "",/*_editableFieldList*/
168  -1,//maxDepth
169  setNimFieldValuesForSave,//responseHandler
170  //_modifiedTables//modifiedTables
171  )
172  }
173  else{
174  console.log("Need to write to FEInterfaceTable...");
175  ConfigurationAPI.getFieldsOfRecords( //Need to set FEInterface status
176  "FEInterfaceTable", selUID,//["NimPlus0"]
177  "",/*_editableFieldList*/
178  -1,//maxDepth
179  setFEInterfaceStatusForSave,//responseHandler
180  //_modifiedTables//modifiedTables
181  )
182  }
183 
184 
185 
186  } else {
187  document.getElementById("saveEl").innerHTML = "Warning! Unable to save, some fields contain invalid values";
188  console.log("Warning! Textbox on page has invalid value, aborting save...")
189  console.log("Please check the following fields for possible invalid values (some might beSigNorm/ correct)");
190  Debug.log("NimPlus Configuration Changes NOT Saved, Invalid value(s) in fields", Debug.HIGH_PRIORITY);
191  console.log(modifiedList);
192  }
193  }
194  else{
195  Debug.log("Error! No Changes to Save!", Debug.WARN_PRIORITY);
196  }
197 }
198 
199 
200 /* //Unused Function, still useful as reference
201 function getNimFieldsForSave(nimUids) {
202  if (nimUids.length == 0) {
203  Debug.log("No NIMPlus UID's found", Debug.HIGH_PRIORITY);
204  return;
205  }
206  _nimUids = nimUids;
207  console.log("getNimUIDs' Input: \n")
208  console.log(nimUids);
209  console.log("\n");
210  Debug.log("getNimUIDs ", Debug.INFO_PRIORITY);
211 
212  ConfigurationAPI.getFieldsOfRecords(
213  _subsetBasePath, nimUids,//["NimPlus0"]
214  "",//_editableFieldList
215  -1,//maxDepth
216  setNimFieldValuesForSave,//responseHandler
217  _modifiedTables//modifiedTables
218  );
219 }
220 */
221  function setFEInterfaceStatusForSave(recFields){
222  //console.log("setFEInterfaceStatusForSave hit");
223  var valsToWrite = [];
224  var objToWrite = [];
225  //Debug.log("recFields found = " + recFields.length);
226 
227  //console.log("setFEInterfaceStatusForSave input: \n");
228  //console.log(recFields);
229  //console.log("\n");
230  for (let a of recFields) {
231  if(a.fieldColumnName == "Status" && a.fieldRelativePath == "") {
232  objToWrite.push(a); //objects to update
233  valsToWrite.push(FEInterfaceStatusValue); //values for the corresponding objects
234  }
235  else{
236  //console.log("Status field not there?!?!")
237  }
238  }
239  ogBoardState = FEInterfaceStatusValue;
240  //console.log(objToWrite);
241  //console.log(valsToWrite);
242 
243  ConfigurationAPI.setFieldValuesForRecords(
244  "FEInterfaceTable",//subsetBasePath
245  selUID,//recordArr
246  objToWrite,//fieldObjArr
247  valsToWrite,//valueArr
248  FEInterfaceToNIMPlusConfigWrite,//responseHandler
249  _modifiedTables//modifiedTables
250  )
251 
252 }
253 
254  function FEInterfaceToNIMPlusConfigWrite(newModifiedTables){
255  _modifiedTables.push(newModifiedTables[0])
256  //console.log("FEInterfaceToNimplus handoff hit");
257  //console.log(newModifiedTables[0]);
258  //console.log(_modifiedTables);
259  ConfigurationAPI.getFieldsOfRecords(
260  _subsetBasePath, selUID,//["NimPlus0"]
261  "",/*_editableFieldList*/
262  -1,//maxDepth
263  setNimFieldValuesForSave,//responseHandler
264  _modifiedTables//modifiedTables
265  )
266 
267 }
268 function setNimFieldValuesForSave(recFields) {
269  var valsToWrite = [];
270  var objToWrite = [];
271  //Debug.log("recFields found = " + recFields.length);
272 
273  //console.log("setNimFields input: \n");
274  //console.log(recFields);
275  //console.log("\n");
276 
277 
278 //Compare Modified list and list of returned fields, populate a 2 arrays with the objects and data to write
279 //to the table of the elements of the page that have been modified since last save
280  for (let i of modifiedList) {
281  for (let a of recFields) {
282  if(a.fieldColumnName == i[0]) {
283  objToWrite.push(a); //objects to update
284  valsToWrite.push(i[1]); //values for the corresponding objects
285  //console.log("Object found");
286  }
287  else{
288  //console.log("\nno match for " + a.fieldColumnName);
289  }
290  }
291  }
292  //console.log(objToWrite);
293  //console.log(valsToWrite);
294 
295  ConfigurationAPI.setFieldValuesForRecords(
296  _subsetBasePath,//subsetBasePath
297  selUID,//recordArr
298  objToWrite,//fieldObjArr
299  valsToWrite,//valueArr
300  saveNimTableDialog,//responseHandler
301  _modifiedTables//modifiedTables
302  )
303 
304 };
305 
306 function saveNimTableDialog(newModifiedTables){
307  modifiedList = [];
308  //console.log(newModifiedTables);
309  //console.log(_modifiedTables);
310  _modifiedTables = newModifiedTables.splice(0);
311  //console.log(_modifiedTables);
312  ConfigurationAPI.saveModifiedTables(
313  _modifiedTables,
314  activateNimTables
315  )
316 };
317 function activateNimTables(SavedTable,SavedGroup,SavedAlias){
318  for(let i of SavedGroup) {
319  ConfigurationAPI.activateGroup(i.groupName, i.groupKey, false)
320  }
321 
322  //#43c130 = green color, alerts user that changes are saved
323  $("body").css("background-color", "#43c130");
324  //Table Updates Here
325  Debug.log("NimPlus Configuration Changes Saved to UID " + selUID[0], Debug.INFO_PRIORITY);
326  console.log("Page Values Saved");
327  console.log(modifiedList);
328  _modifiedTables = [];
329  writeFEInterfaceStatus = false;
330  document.getElementById("saveEl").innerHTML = "Save Successful!";
331 
332 };
333 
334 
335 //------------------------------------Error Check etc. Functions------------------------------------
336 
337 
338 
339 //Calculate the 40 Mhz Sync Mask
340 function syncMaskCalc(val,a) {
341  syncArray[a]=val;
342  var n = 0;
343  var l = syncArray.length;
344  for (var i = 0; i < l; i++) {
345  n |= ((syncArray[i]?1:0) << i)
346  //n = (n << 1) + (syncArray[i]?1:0);
347  };
348  //console.log(n)
349  $("#triggerSyncWord").val(n);
350  return n;
351 }
352 
353 function inputMuxCalc(val,a) {
354  inputMuxArray[a]=val;
355  var n = 0;
356  var l = inputMuxArray.length;
357  for (var i = 0; i < l; i++) {
358  n |= ((inputMuxArray[i]) << i*2)
359  //n = (n << 1) + (syncArray[i]?1:0);
360  };
361  console.log(inputMuxArray)
362  return n;
363 }
364 
365 function outputMuxCalc(val,a) {
366  outputMuxArray[a]=val;
367  var n = 0;
368  var l = outputMuxArray.length;
369  for (var i = 0; i < l; i++) {
370  n |= ((outputMuxArray[i]) << i*2)
371  //n = (n << 1) + (syncArray[i]?1:0);
372  };
373  console.log(outputMuxArray)
374  return n;
375 }
376 
377 
378 
379 //Calculate the Accelerator Clock Sync Mask
380 function accelMaskCalc(val,a) {
381  n = (val?1:0) << a // Should only have 1 bit true ever, so dont save values like the 40Mhz mask
382  //console.log(n);
383  return n;
384 }
385 
386 //Calculate the Coincidence Logic Word
387 function LogicWordCalc(val,a) {
388  logicArray[a]=val;
389  var n = 0;
390  var l = logicArray.length;
391  for (var i = 0; i < l; i++) {
392  n = (n << 1) + (logicArray[i]?1:0);
393  }
394  //console.log(n)
395  return n;
396 }
397 
398 //Calculate the Trigger Mux Word for Bank A
399 function TMuxAWordCalc(val,a) {
400  tMuxAArray[0][a]=val;
401  return JSON.stringify(tMuxAArray);
402 }
403 
404 //Calculate the Trigger Mux Word for Bank B
405 function TMuxBWordCalc(val,a) {
406  tMuxBArray[0][a]=val;
407  return JSON.stringify(tMuxBArray);
408 }
409 
410 
411 //Return an element by it's ID string
412 function elByID(id) {
413  e = document.getElementById(id);
414  return e;
415 }
416 //Return an element's value by it's ID String
417 function valByID(id) {
418  e = document.getElementById(id);
419  return e.value;
420 }
421 
422 //Set invalid input flag to false to allow saving
423 function validInput(e) {
424  invalidInput = false;
425 }
426 
427 //Set invalid input flag to true to disallow saving
428 function invalidValue(e) {
429  invalidInput = true;
430 }
431 
432 //Delay&Width Error Checking
433 function dwValidCheck(firstVal, secondValElId, msgElId) {
434  firstVal = parseInt(firstVal);
435  var secondVal = parseInt(document.getElementById(secondValElId).value);
436  if ((firstVal + secondVal) > 64) {
437  //console.log((firstVal + secondVal));
438  document.getElementById(msgElId).innerHTML = "Invald Delay/Width Combination! Sum of Delay and Width should be <=64!";
439  $("#" + msgElId).css("background-color", "red");
440  invalidInput = true;
441  } else {
442  document.getElementById(msgElId).innerHTML = "";
443  $("#" + msgElId).css("background-color", "#eee");
444  invalidInput = false;
445  }
446 
447 }
448 
449 //Add a value to the list to save into the selected row (UID) of the NIMPlus table
450  function addModifiedList(tableVal, tableDat) {
451  //#fcd125 = yellow color, notifies user that there are unsaved changes on the page
452  $("body").css("background-color", "#fcd125")
453  document.getElementById("saveEl").innerHTML = "Unsaved Changes are Present";
454 
455  var modifiedListNames = modifiedList.map(function(value,index) { return value[0]; });
456  existsAt = null;
457  existsAt = $.inArray(tableVal, modifiedListNames);
458  //document.getElementById("saveEl").innerHTML = "";
459  if (existsAt < 0) {
460  //console.log(existsAt);
461  //console.log($.inArray(tableVal, modifiedList[0]));
462  //console.log(tableVal);
463  //console.log(modifiedList[0]);
464  //console.log([tableVal, tableDat]);
465  modifiedList.push([tableVal, tableDat]);
466  //console.log(modifiedList);
467 // console.log(modifiedList);
468  } else {
469  modifiedList[existsAt] = [tableVal,tableDat];
470  //console.log(" element already exists in modified list, not updating list...")
471  }
472 
473 }
474  function FEInterfaceSetStatus(state){
475  //console.log("ogBoardState = " + ogBoardState);
476  //console.log("desired board state = " + state);
477 
478  FEInterfaceStatusValue = state;
479  if(state == ogBoardState)
480  writeFEInterfaceStatus = false;
481  else
482  writeFEInterfaceStatus = true;
483 
484  //console.log("writeFEInterfaceStatus = " + writeFEInterfaceStatus)
485 
486 }
487 
488 //Dac Control Functions to link all 3 inputs together
489 //Dac ranges from 0-3.3 volts with 4096 (0-4095) steps of resolution, input must be step value
490 
491 //Update the volt field and steps when the slider is changed
492 function voltSlider(myValue, VoltElId, StepsElId) {
493  voltVal = (((10000 * ((myValue * (33 / 40950)))) + (((8 - (10000 * ((myValue * (33 / 40950)))) % 8)))) / 10000) - 0.0008;
494  document.getElementById(StepsElId).value = myValue;
495  document.getElementById(VoltElId).value = voltVal.toFixed(4);
496  invalidInput = false;
497 }
498 
499 //A litte ugly, but it works
500 //Update the volt slider and steps when the field is changed
501 function voltField(VoltElId, SlideElId, StepElId) {
502  clearTimeout(timeout);
503  timeout = setTimeout(function () {
504  myValue = VoltElId.value;
505  newValue = (((10000 * myValue) + (((8 - (10000 * myValue) % 8)))) / 10000) - 0.0008;
506  document.getElementById(SlideElId).value = Math.round((40950000 * newValue / 33000));
507  document.getElementById(StepElId).value = Math.round((40950000 * newValue / 33000));
508  VoltElId.value = newValue.toFixed(4);
509  //console.log(newValue)
510  //console.log(newValue.toFixed(4));
511  invalidInput = false;
512  }, 900);
513 
514 
515 }
516 function voltSteps(myValue, VoltElId, SlideElId) {
517  voltVal = (((10000 * ((myValue * (33 / 40950)))) + (((8 - (10000 * ((myValue * (33 / 40950)))) % 8)))) / 10000) - 0.0008;
518  document.getElementById(SlideElId).value = (myValue);
519  document.getElementById(VoltElId).value = voltVal.toFixed(4) //(myValue * 33 / 40950);
520  invalidInput = false;
521 }
522 
523 function triggerSyncWordCalc(val){
524  clearTimeout(trigTimeout);
525  setTimeout(function () {
526  for(bitCnt=0; bitCnt<=23; bitCnt++){
527  elByID("Sync"+(bitCnt+1).toString()).checked=((val>>(bitCnt)) % 2 != 0); //intentionally reversing bit order
528  syncArray[bitCnt]=((val>>(bitCnt)) % 2 != 0); //intentionally reversing bit order
529  /*
530  elByID("Sync"+(bitCnt+1).toString()).checked=((val>>(23-bitCnt)) % 2 != 0); //intentionally reversing bit order
531  syncArray[bitCnt]=((val>>(23-bitCnt)) % 2 != 0); //intentionally reversing bit order
532  */
533  }
534  },900)
535 }
536 
537 // ------------------------------ JQuery UI Stuff ------------------------------
538 
539 $(document).ready(function () {
540  // Set Background color
541  //#6b86ff = Light Blue, indicates page is unchanged/ @ default state
542  $("body").css("background-color", "#6b86ff")
543 
544  // CSS for Inner (hidden) divs
545  //Hide the divs by default
546 
547  //InChEnCtl
548  $("#InChEnCtl").hide();
549 
550  //BoardCfgCtl
551  $("#BoardCfgCtl").hide();
552 
553  //DacCtl
554  $("#DacCtl").hide();
555 
556  //DWConfig
557  $("#DWConfigCtl").hide();
558 
559  //InMuxCtl
560  $("#InMuxCtl").hide();
561 
562  //OutMuxCtl
563  $("#OutMuxCtl").hide();
564  /*
565  //ResetCtl
566  $("#ResetCtl").hide();
567 
568  //EnableCtl
569  $("#EnableCtl").hide();
570  */
571  //SyncCtl
572  $("#SyncCtl").hide();
573 
574  //VetoCtl
575  $("#VetoCtl").hide();
576 
577  //PsCtl
578  $("#PsCtl").hide();
579 
580  //SelLogCtl
581  $("#SelLogCtl").hide();
582 
583  //BkpCtl
584  $("#BkpCtl").hide();
585 
586  //SigGenCtl
587  $("#SigGenCtl").hide();
588 
589  //ConnCtl
590  $("#ConnCtl").hide();
591 
592  //BurstCtl
593  $("#BurstCtl").hide();
594 
595 
596 
597  //Setup button actions to hide/show the divs
598 
599  $("#InChEnCtlBtn").click(function () {
600  $("#InChEnCtl").toggle(400);
601  });
602 
603  $("#BoardCfgCtlBtn").click(function () {
604  $("#BoardCfgCtl").toggle(400);
605  });
606 
607  $("#DacCtlBtn").click(function () {
608  $("#DacCtl").toggle(400);
609  });
610 
611  $("#DWConfigBtn").click(function () {
612  $("#DWConfigCtl").toggle(400);
613  });
614 
615  $("#InMuxCtlBtn").click(function () {
616  $("#InMuxCtl").toggle(400);
617  });
618 
619  $("#OutMuxCtlBtn").click(function () {
620  $("#OutMuxCtl").toggle(400);
621  });
622  /*
623  $("#ResetCtlBtn").click(function(){
624  $("#ResetCtl").toggle(400);
625  });
626 
627  $("#EnableCtlBtn").click(function(){
628  $("#EnableCtl").toggle(400);
629  });
630  */
631  $("#SyncCtlBtn").click(function () {
632  $("#SyncCtl").toggle(400);
633  });
634 
635  $("#VetoCtlBtn").click(function () {
636  $("#VetoCtl").toggle(400);
637  });
638 
639  $("#PsCtlBtn").click(function () {
640  $("#PsCtl").toggle(400);
641  });
642 
643  $("#SelLogCtlBtn").click(function () {
644  $("#SelLogCtl").toggle(400);
645  });
646 
647  $("#BkpCtlBtn").click(function () {
648  $("#BkpCtl").toggle(400);
649  });
650 
651  $("#SigGenCtlBtn").click(function () {
652  $("#SigGenCtl").toggle(400);
653  });
654 
655  $("#ConnCtlBtn").click(function () {
656  $("#ConnCtl").toggle(400);
657  });
658 
659  $("#BurstCtlBtn").click(function () {
660  $("#BurstCtl").toggle(400);
661  });
662 
663 
664  //Setup IP Address Mask for input
665  $('.ip_address').mask('0ZZ.0ZZ.0ZZ.0ZZ', {translation: {'Z': {pattern: /[0-9]/, optional: true}}});
666 
667  //Setup Hex/Dec mask for triggerSyncWord input
668  $('#triggerSyncWord').mask('ZZHHHHHHL', {'translation': {
669  Z: {pattern: /[0x]/, optional: true},
670  H: {pattern: /[A-Fa-f0-9]/},
671  L: {pattern: /[0-9]/}
672  }
673  });
674 
675  //Setup trigger sync word as a spinner
676  var spinner = $( "#triggerSyncWord" ).spinner({
677  min: 0,
678  max: 1777215
679  });
680  $("#triggerSyncWord").on("spinstop", function(){
681  triggerSyncWordCalc(this.value);
682  addModifiedList('AcceleratorClockMask',this.value);
683  });
684  //console.log(spinner);
685  //console.log("jquery ui setup done!")
686 
687  //Grab values to populate fields
688  ConfigurationAPI.getSubsetRecords(
689  _subsetBasePath /*subsetBasePath*/ ,
690  "", //"FEInterfacePluginName=FEOtsUDPTemplateInterface"/*filterList*/,
691  getNimUidsForList /*responseHandler*/ ,
692  _modifiedTables /*modifiedTables*/ )
693 
694 
695 });
696 
697 // ---------------------------------------------- Field Population ------------------------------------------------------
698 
699 var selUID;
700 var bitCnt;
701 
702 function getNimUidsForList(nimUids) {
703  if (nimUids.length == 0) {
704  Debug.log("No NIMPlus UID's found", Debug.HIGH_PRIORITY);
705  return;
706  }
707  else{
708  _nimUids = nimUids;
709  //console.log("getNimUIDs' Input: \n")
710  //console.log(nimUids);
711  //console.log("\n");
712  //Debug.log("getNimUIDs ", Debug.INFO_PRIORITY);
713  //console.log(nimUids)
714  //console.log("first index: " + nimUids[0])
715  $.each(nimUids, function(val, text) {
716  $('#nimUIDSelect').append( $('<option></option>').val(text).html(text) )
717  $('#nimUIDToCopySelect').append( $('<option></option>').val(text).html(text) )
718  //console.log(val)
719  //console.log(text)
720  });
721  selUID = [nimUids[0]];
722  //console.log(selUID);
723  ConfigurationAPI.getFieldsOfRecords(
724  _subsetBasePath, selUID,//["NimPlus0"]
725  "",/*_editableFieldList*/
726  -1,//maxDepth
727  getNimFieldsForPage,//responseHandler
728  _modifiedTables//modifiedTablesto
729  );
730  }
731 }
732 
733 function getNimFieldsForPage(recFields){
734  //console.log("recFields: \n");
735  //console.log(recFields);
736  ConfigurationAPI.getFieldValuesForRecords(
737  _subsetBasePath, selUID,
738  recFields,
739  getNimValuesForPage,
740  _modifiedTables)
741 }
742 
743 function getNimValuesForPage(recFields) {
744  //Debug.log("recFields found = " + recFields.length);
745 
746  //console.log("getNimValuesForPage input: \n");
747  //console.log(recFields);
748  //console.log("\n");
749 
750  for (let i of fieldList) {
751  for (let a of recFields) {
752  // console.log(i)
753  //console.log(a.fieldPath)
754  //console.log(a.fieldPath.includes(i[1]));
755  if(a.fieldPath.includes(i[1])) { //found value
756  try{
757  if(elByID(i[0]).type == "checkbox" && !a.fieldPath.includes("CoincidenceLogicWord") && !a.fieldPath.includes("TriggerClockMask") && !a.fieldPath.includes("AcceleratorClockMask"))
758  {
759  if(a.fieldValue == "Yes" || a.fieldValue == "True" || a.fieldValue == "On"){
760  elByID(i[0]).checked = true;
761  //console.log("checkbox element " + i[0] + " set to checked = true")
762  }
763  else{
764  elByID(i[0]).checked = false;
765  //console.log("checkbox element " + i[0] + " set to checked = false")
766  }
767  }
768  else if(a.fieldPath.includes("CoincidenceLogicWord")){
769  for(bitCnt=0; bitCnt<=15; bitCnt++){
770  elByID("SL"+bitCnt.toString()).checked=((a.fieldValue>>(bitCnt)) % 2 != 0);
771  logicArray[bitCnt]=((a.fieldValue>>(15-bitCnt)) % 2 != 0); //intentionally reversing bit order
772  }
773 
774  //console.log("Coincidence Logic Word set");
775  }
776  else if(a.fieldPath.includes("TriggerClockMask")){
777  for(bitCnt=0; bitCnt<=23; bitCnt++){
778 // elByID("Sync"+(bitCnt+1).toString()).checked=((a.fieldValue>>(23-bitCnt)) % 2 != 0); //intentionally reversing bit order
779 // syncArray[bitCnt]=((a.fieldValue>>(23-bitCnt)) % 2 != 0); //intentionally reversing bit order
780 // }
781  elByID("Sync"+(bitCnt+1).toString()).checked=((a.fieldValue>>(bitCnt)) % 2 != 0);
782  syncArray[bitCnt]=((a.fieldValue>>(bitCnt)) % 2 != 0);
783  }
784  elByID("triggerSyncWord").value = a.fieldValue;
785  //console.log("Trigger Clock Mask set")
786  }
787  else if(a.fieldPath.includes("AcceleratorClockMask")){
788  for(bitCnt=0; bitCnt<=7; bitCnt++){
789  elByID("AccSync"+(bitCnt+1).toString()).checked=((a.fieldValue>>(bitCnt)) % 2 != 0);
790  accelMaskArray[bitCnt]=((a.fieldValue>>(bitCnt)) % 2 != 0);
791  }
792  //console.log("Accelerator Clock Mask set")
793  }
794  else if(a.fieldPath.includes("Status")){
795  if(a.fieldValue == "Yes" || a.fieldValue == "True" || a.fieldValue == "On"){
796  ogBoardState = "On";
797  elByID(i[0]).value = "On";
798  //console.log("NimPlus Status " + i[0] + " set to On/Enabled")
799  }
800  else{
801  ogBoardState = "Off";
802  elByID(i[0]).value = "Off";
803  //console.log("NimPlus Status " + i[0] + " set to Off/Disabled")
804  }
805  }
806  else if(a.fieldPath.includes("TriggerMuxSelectionsBankA")){
807  loadMuxArr = JSON.parse(a.fieldValue);
808  for(k=0; k<=8; k++){
809  elByID("TMuxA"+(k+1).toString()).value=loadMuxArr[0][k];
810  tMuxAArray[0][k]=loadMuxArr[0][k];
811  }
812  //console.log("Loaded TMux Bank A with values: " + loadMuxArr );
813  }
814  else if(a.fieldPath.includes("TriggerMuxSelectionsBankB")){
815  loadMuxArr = JSON.parse(a.fieldValue);
816  for(k=0; k<=8; k++){
817  elByID("TMuxB"+(k+1).toString()).value=loadMuxArr[0][k];
818  tMuxBArray[0][k]=loadMuxArr[0][k];
819  }
820 
821  //console.log("Loaded TMux Bank B with values: " + loadMuxArr);
822  }
823  else if(a.fieldPath.includes("InputMuxConfig")){
824  console.log("hit1")
825  var muxWrd = a.fieldValue;
826  for(k=0; k<8; k++){ // 8 inputs
827  loadMuxArr[k]=(muxWrd & 3)
828  console.log(muxWrd)
829  muxWrd = muxWrd >>> 2;
830  var currEL = "inMux"+(k+1).toString()
831  console.log(currEL);
832  elByID(currEL).value=loadMuxArr[k];
833  inputMuxArray[k]=loadMuxArr[k];
834  console.log(inputMuxArray);
835  }
836  //console.log("Loaded TMux Bank A with values: " + loadMuxArr );
837  }
838  else if(a.fieldPath.includes("OutputMuxConfig")){
839  //loadMuxArr = JSON.parse(a.fieldValue);
840  console.log("hit2")
841  var muxWrd = a.fieldValue;
842  for(k=0; k<4; k++){ //4 outputs
843  loadMuxArr[k]=(muxWrd & 3)
844  console.log(muxWrd)
845  muxWrd = muxWrd >>> 2;
846  var currEL = "outMux"+(k+1).toString();
847  console.log(currEL);
848  elByID(currEL).value=loadMuxArr[k];
849  outputMuxArray[k]=loadMuxArr[k];
850  console.log(outputMuxArray);
851  }
852 
853  //console.log("Loaded TMux Bank B with values: " + loadMuxArr);
854  }
855  else if(elByID(i[0]).id=="ChADacEl1"){
856  voltSteps(a.fieldValue, "ChADacEl2", "ChADacEl0")
857  elByID(i[0]).value = a.fieldValue
858  //console.log("Set CH A Dac")
859  }
860  else if(elByID(i[0]).id=="ChBDacEl1"){
861  voltSteps(a.fieldValue, "ChBDacEl2", "ChBDacEl0")
862  elByID(i[0]).value = a.fieldValue
863  //console.log("Set CH B Dac")
864  }
865  else if(elByID(i[0]).id=="ChCDacEl1"){
866  voltSteps(a.fieldValue, "ChCDacEl2", "ChCDacEl0")
867  elByID(i[0]).value = a.fieldValue
868  //console.log("Set CH C Dac")
869  }
870  else if(elByID(i[0]).id=="ChDDacEl1"){
871  voltSteps(a.fieldValue, "ChDDacEl2", "ChDDacEl0")
872  elByID(i[0]).value = a.fieldValue
873  //console.log("Set CH D Dac")
874  }
875  else{
876  elByID(i[0]).value = a.fieldValue;
877  //console.log("set element " + i[0] + " to value " + a.fieldValue + " from " + a.fieldPath)
878  }
879  }
880  catch(e){
881  console.log("\n!!!_-_-_WARNING_-_-_!!!\n");
882  console.log("Exception occured while trying to set an element supposedly named " + i[0] + " to the value of " + a.fieldValue + " from the field " + a.fieldPath);
883  console.log("Incoming exception data...\n");
884  console.log(e);
885  console.log("\n!!!_-_-_END WARNING_-_-_!!!\n");
886  }
887 
888  }
889  else if(a.fieldPath.includes("EnableExpertWebappFeatures")){ //Show/Hide expert features
890  if(a.fieldValue == "Yes"){
891  $("#SigGenBox").show() //Signal Generator
892  $("#BkpBox").show() //Backpressure Vetos
893  $("#SyncBox").show() //40Mhz Sync
894  $("#BurstBox").show() //40Mhz Sync
895  }
896  else{
897  $("#SigGenBox").hide() //Signal Generator
898  $("#BkpBox").hide() //Backpressure Vetos
899  $("#SyncBox").hide() //40Mhz Sync
900  $("#BurstBox").hide() //40Mhz Sync
901  }
902  }
903  else if(a.fieldPath.includes("PrimaryBoardConfig")){ //Show/Hide expert features
904  if(a.fieldValue == "True"){
905  $("#BoardCfgBox").show() //Signal Generator
906  $("#DacBox").show() //Signal Generator
907  }
908  else{
909  $("#BoardCfgBox").hide() //Signal Generator
910  $("#DacBox").hide() //Signal Generator
911  }
912  }
913  else{/*
914  console.log("\nno match for " + a.fieldColumnName);
915  console.log(a.fieldColumnName);
916  console.log(i[1]);
917  console.log(a.fieldColumnName == i[1]);
918  */
919  }
920  }
921  }
922 
923 
924 
925 };
926 
927 //Update form data when UID is swiched
928 function getNimValuesOnUIDSelect(selValue) {
929 
930  selUID = [selValue];
931  //console.log(selUID);
932  ConfigurationAPI.getFieldsOfRecords(
933  _subsetBasePath, selUID,//["NimPlus0"]
934  "",/*_editableFieldList*/
935  -1,//maxDepth
936  getNimFieldsForPage,//responseHandler
937  _modifiedTables//modifiedTables
938  );
939 
940 };
941 
942 
943 //----------------------------------------------"Add New Nimplus" stuff ---------------------------------------------------------------------
944 
945 //--------------------------- Modal Setup ------------------------------ Unstable/Disabled for release
946 /*
947 window.onload = function() {
948 var modal = elByID('newNimPlusPopup');
949 var openBtn = elByID('addNewNIMPlus');
950 var xBtn = document.getElementsByClassName("close")[0];
951 var cancelBtn = elByID('cancelNewNIMPlusAdd');
952 
953 
954 //Open Modal
955 openBtn.onclick = function() {
956  modal.style.display = "block";
957  elByID("newNIMUIDErr").innerHTML = ""
958  elByID("newNIMUID").value = ""
959 }
960 //Close Modal
961 xBtn.onclick = function() {
962  modal.style.display = "none";
963 }
964 cancelBtn.onclick = function() {
965  modal.style.display = "none";
966 }
967 }
968 
969 
970 var gottenFields = [];
971 var copyUID;
972 var alphaNumRegEx = /^[a-z0-9]+$/i
973 var _recFields = [];
974 function checkNewNIMPlusUID(){
975  if(alphaNumRegEx.test(valByID("newNIMUID"))){
976  elByID("newNIMUIDErr").innerHTML = ""
977  selUID = [valByID("newNIMUID")]
978  copyUID = [valByID("nimUIDToCopySelect")]
979  //create new UID stuff
980  ConfigurationAPI.addSubsetRecords( //NimPlusConfiguration
981  "FENIMPlusInterfaceTable",
982  selUID, //new NIMUID
983  loadNewNIMPlusConfigTable,
984  _modifiedTables);
985 
986  ConfigurationAPI.addSubsetRecords( //NimPlusOptionalConfiguration
987  "FENIMPlusInterfaceOptionalConfiguration",
988  selUID, //new NIMUID
989  loadNewNIMPlusOptionalConfigTable,
990  _modifiedTables);
991 
992  ConfigurationAPI.addSubsetRecords( //FEInterfaces
993  "FEInterfaceTable",
994  selUID, //new NIMUID
995  loadNewNIMPlusFEInterfaceTable,
996  _modifiedTables);
997 
998  }
999  else{
1000  elByID("newNIMUIDErr").innerHTML = "New NIMPlus UID MUST be Alphanumeric (A-Z, 0-9) Characters only!"
1001  console.log("Bad New UID")
1002  }
1003 
1004 }
1005 
1006 
1007 
1008 //Inital Response handlers
1009 function loadNewNIMPlusConfigTable(newModifiedTables){
1010  //assume only one table modified
1011  if(newModifiedTables.length)
1012  _modifiedTables.push(newModifiedTables[0]);
1013  //console.log("New row in NimPlusConfiguration created")
1014 }
1015 function loadNewNIMPlusOptionalConfigTable(newModifiedTables){
1016  if(newModifiedTables.length)
1017  _modifiedTables .push(newModifiedTables[0]);
1018  ConfigurationAPI.getFieldsOfRecords(
1019  _subsetBasePath, copyUID,
1020  "",
1021  -1,//maxDepth
1022  getNimFieldValuesForNewNIMPlus,
1023  _modifiedTables)
1024 }
1025 function loadNewNIMPlusFEInterfaceTable(newModifiedTables){
1026  if(newModifiedTables.length)
1027  _modifiedTables.push(newModifiedTables[0]);
1028 }
1029 
1030 
1031 
1032 
1033 //Copying table for NimPlus Config Vals
1034 function getNimFieldValuesForNewNIMPlus(recFields) {
1035  gottenFields = recFields.slice(0);
1036  ConfigurationAPI.getFieldValuesForRecords(
1037  _subsetBasePath, copyUID,
1038  recFields,
1039  setNimOptionalLinkForNewNIMPlus,
1040  _modifiedTables)
1041 }
1042 
1043 
1044 function setNimOptionalLinkForNewNIMPlus(recFields) {
1045  var valsToWrite = [];
1046  var objToWrite = [];
1047  _recFields = recFields.splice(0);
1048  //...forge some objects
1049  var linkObj = {}
1050  linkObj.fieldTableName = "FENIMPlusInterfaceTable"
1051  linkObj.fieldUID = selUID[0]
1052  linkObj.fieldColumnName = "LinkToOptionalParameters"
1053  linkObj.fieldRelativePath = ""
1054  linkObj.fieldColumnType = "ChildLink-optionalParameters"
1055  linkObj.fieldColumnDataType = "VARCHAR2"
1056  linkObj.fieldColumnDataChoicesArr = []
1057  linkObj.fieldColumnDefaultValue = ""
1058  var linkUIDObj = {};
1059  linkUIDObj.fieldTableName = "FENIMPlusInterfaceTable"
1060  linkUIDObj.fieldUID = selUID[0]
1061  linkUIDObj.fieldColumnName = "LinkToOptionalParametersUID"
1062  linkUIDObj.fieldRelativePath = ""
1063  linkUIDObj.fieldColumnType = "ChildLinkUID-optionalParameters"
1064  linkUIDObj.fieldColumnDataType = "VARCHAR2"
1065  linkUIDObj.fieldColumnDataChoicesArr = [0]
1066  linkUIDObj.fieldColumnDefaultValue = ""
1067  objToWrite = [linkObj,linkUIDObj]
1068  valsToWrite = ["FENIMPlusInterfaceOptionalConfiguration",selUID[0]]
1069 
1070 
1071  ConfigurationAPI.setFieldValuesForRecords(
1072  _subsetBasePath,//subsetBasePath
1073  selUID,//recordArr
1074  objToWrite,//fieldObjArr
1075  valsToWrite,//valueArr
1076  setNimFieldValuesForNewNIMPlus,//responseHandler
1077  _modifiedTables)//modifiedTables
1078 
1079 }
1080 
1081 function setNimFieldValuesForNewNIMPlus(newModifiedTables) {
1082  var valsToWrite = [];
1083  var objToWrite = [];
1084  for (let j of _modifiedTables){
1085  if (j.tableName ==_subsetBasePath){
1086  _modifiedTables[_modifiedTables.indexOf(j)] = newModifiedTables[0];
1087  }
1088  }
1089  //Debug.log("recFields found = " + recFields.length);
1090 
1091  console.log("setNimFields input: \n");
1092  console.log(_recFields);
1093  console.log("\n");
1094  console.log(gottenFields);
1095 
1096 
1097  for (let i of gottenFields) {
1098  objToWrite.push(i);
1099  }
1100  for (let a of _recFields) {
1101  valsToWrite.push(a.fieldValue);
1102 
1103  }
1104 
1105  console.log(objToWrite);
1106  console.log(valsToWrite);
1107 
1108  ConfigurationAPI.setFieldValuesForRecords(
1109  _subsetBasePath,//subsetBasePath
1110  selUID,//recordArr
1111  objToWrite,//fieldObjArr
1112  valsToWrite,//valueArr
1113  saveNimTableDialog,//responseHandler
1114  _modifiedTables)//modifiedTables
1115 }
1116 */