Advertisement
Guest User

Untitled

a guest
May 25th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.74 KB | None | 0 0
  1. Dim oUDI : Set oUDI = CreateUDI
  2.  
  3. Class BeltminderCycle
  4.  
  5. Private p_Index
  6. Private p_FunctionType
  7. Private p_OrderOfThisType
  8. Private p_StartTime
  9. Private p_EndTime
  10. Private p_Duration
  11. Private p_TelltaleObjIndex
  12. Private p_ChimeObjIndex
  13.  
  14. Dim timestamp_channel_number, amplitude_channel_number
  15.  
  16. Private Sub Class_Initialize
  17. p_Index = 0
  18. p_FunctionType = ""
  19. p_OrderOfThisType = 0
  20. p_StartTime = 0
  21. p_EndTime = 0
  22. p_Duration = 0
  23. p_ChimeObjIndex = 0
  24. p_TelltaleObjIndex = 0
  25. End Sub
  26.  
  27. Public Property Get Index
  28. Index = p_Index
  29. End Property
  30. Public Property Let Index(value2let)
  31. p_Index = value2let
  32. End Property
  33.  
  34. Public Property Get FunctionType
  35. FunctionType = p_FunctionType
  36. End Property
  37. Public Property Let FunctionType(value2let)
  38. p_FunctionType = value2let
  39. End Property
  40.  
  41.  
  42. Public Property Get OrderOfThisType
  43. OrderOfThisType = p_OrderOfThisType
  44. End Property
  45. Public Property Let OrderOfThisType(value2let)
  46. p_OrderOfThisType = value2let
  47. End Property
  48.  
  49. Public Property Get StartTime
  50. StartTime = p_StartTime
  51. End Property
  52. Public Property Let StartTime(value2let)
  53. p_StartTime = value2let
  54. End Property
  55.  
  56. Public Property Get EndTime
  57. EndTime = p_EndTime
  58. End Property
  59. Public Property Let EndTime(value2let)
  60. p_EndTime = value2let
  61. End Property
  62.  
  63. Public Property Get Duration
  64. Duration = p_EndTime - p_StartTime
  65. End Property
  66.  
  67. Public Property Get TelltaleObjIndex
  68. TelltaleObjIndex = p_TelltaleObjIndex
  69. End Property
  70. Public Property Let TelltaleObjIndex(value2let)
  71. p_TelltaleObjIndex = value2let
  72. End Property
  73.  
  74. Public Property Get ChimeObjIndex
  75. ChimeObjIndex = p_ChimeObjIndex
  76. End Property
  77. Public Property Let ChimeObjIndex(value2let)
  78. p_ChimeObjIndex = value2let
  79. End Property
  80.  
  81.  
  82. Public Sub Reinitialize
  83. p_Index = null
  84. p_TimestampCh = null
  85. p_AmplitudeCh = null
  86. p_FunctionType = null
  87. p_OrderOfThisType = null
  88. p_StartTime = null
  89. p_EndTime = null
  90. p_Duration = null
  91. p_ChimeObjIndex = null
  92. p_TelltaleObjIndex = null
  93. End Sub
  94.  
  95. End Class
  96.  
  97. Class TelltaleCycle
  98.  
  99. Private p_Index
  100. Private p_TimestampCh
  101. Private p_AmplitudeCh
  102. Private p_FunctionType
  103. Private p_OrderOfThisType
  104. Private p_StartTime
  105. Private p_EndTime
  106. Private p_Duration
  107. Private p_HowManyPeriods
  108. Dim Size
  109.  
  110. Dim timestamp_channel_number, amplitude_channel_number, PeriodBeginningsTime, PeriodBeginningsAmplitude
  111.  
  112. Private Sub Class_Initialize
  113. p_Index = 0
  114. p_TimestampCh = ""
  115. p_AmplitudeCh = ""
  116. p_FunctionType = ""
  117. p_OrderOfThisType = 0
  118. p_StartTime = 0
  119. p_EndTime = 0
  120. p_Duration = 0
  121. p_HowManyPeriods = 0
  122. End Sub
  123.  
  124. Public Property Get Index
  125. Index = p_Index
  126. End Property
  127.  
  128. Public Property Let Index(value2let)
  129. p_Index = value2let
  130. End Property
  131.  
  132. Public Property Get TimestampCh
  133. TimestampCh = p_TimestampCh
  134. End Property
  135.  
  136. Public Property Let TimestampCh(value2let)
  137. Dim oMyChn, aString
  138. p_TimestampCh = value2let
  139. Set oMyChn = Data.GetChannel(value2let)
  140. p_TimestampCh = oMyChn.Name
  141. aString = Split(oMyChn.Name, "_", -1, 1)
  142. p_FunctionType = aString(2) & "_" & aString(3)
  143. p_OrderOfThisType = aString(4)
  144. p_StartTime = CHDx(1,CNo(value2let))
  145. p_EndTime = CHDx(ChnLength(value2let),CNo(value2let))
  146. p_Duration = p_EndTime - p_StartTime
  147. End Property
  148.  
  149. Public Property Get AmplitudeCh
  150. AmplitudeCh = p_AmplitudeCh
  151. End Property
  152.  
  153. Public Property Let AmplitudeCh(value2let)
  154. Dim oMyChn
  155. p_AmplitudeCh = value2let
  156. Set oMyChn = Data.GetChannel(value2let)
  157. p_AmplitudeCh = oMyChn.Name
  158. End Property
  159.  
  160. Public Property Get FunctionType
  161. FunctionType = p_FunctionType
  162. End Property
  163.  
  164. Public Property Get OrderOfThisType
  165. OrderOfThisType = p_OrderOfThisType
  166. End Property
  167.  
  168. Public Property Get StartTime
  169. StartTime = p_StartTime
  170. End Property
  171.  
  172. Public Property Get EndTime
  173. EndTime = p_EndTime
  174. End Property
  175.  
  176. Public Property Get Duration
  177. Duration = p_Duration
  178. End Property
  179.  
  180. Public Property Get HowManyPeriods
  181.  
  182. Dim iLoop, TimeChnLength,PBT,PBA
  183.  
  184.  
  185. Call LogFileWrite("p_FunctionType: " & p_FunctionType)
  186.  
  187.  
  188. If ((p_FunctionType <> "NotFlashing_NA")) Then
  189. Call ChnDifferentiate("ProcessedChannels/Telltale_Timestamp_" & p_FunctionType & "_" & p_OrderOfThisType,"ProcessedChannels/Telltale_Amplitude_" & p_FunctionType & "_" & p_OrderOfThisType,"ProcessedChannels/DifferentiatedX","ProcessedChannels/DifferentiatedY")
  190. Call ChnPeakFind("ProcessedChannels/DifferentiatedX","ProcessedChannels/DifferentiatedY","ProcessedChannels/PeakX","ProcessedChannels/PeakY",10000,"Max.Peaks","Amplitude")
  191. TimeChnLength = ChnLength(CNo("ProcessedChannels/PeakX"))
  192.  
  193. Dim temp
  194. reDim PBT(TimeChnLength), PBA(TimeChnLength)
  195. For iLoop = 1 to TimeChnLength
  196. PBT(iLoop - 1) = CHDx(iLoop,CNo("ProcessedChannels/PeakX"))
  197. PBA(iLoop - 1) = PNo(p_TimestampCh,PBT(iLoop - 1))
  198. temp = PBA(iLoop - 1)
  199. PBA(iLoop - 1) = CHDx(PBA(iLoop - 1),CNo(p_AmplitudeCh))
  200. Next
  201.  
  202. PeriodBeginningsTime = PBT
  203. PeriodBeginningsAmplitude = PBA
  204. HowManyPeriods = Ubound(PeriodBeginningsTime)
  205.  
  206. Call ChnDel("ProcessedChannels/DifferentiatedX")
  207. Call ChnDel("ProcessedChannels/DifferentiatedY")
  208. Call ChnDel("ProcessedChannels/PeakX")
  209. Call ChnDel("ProcessedChannels/PeakY")
  210. End If
  211. End Property
  212.  
  213. Public Sub Reinitialize
  214. p_Index = 0
  215. p_TimestampCh = ""
  216. p_AmplitudeCh = ""
  217. p_FunctionType = ""
  218. p_OrderOfThisType = 0
  219. p_StartTime = 0
  220. p_EndTime = 0
  221. p_Duration = 0
  222. p_HowManyPeriods = 0
  223. End Sub
  224.  
  225. End Class
  226.  
  227. Class ChimeCycle
  228.  
  229. Private p_Index
  230. Private p_TimestampCh
  231. Private p_AmplitudeCh
  232. Private p_FunctionType
  233. Private p_OrderOfThisType
  234. Private p_StartTime
  235. Private p_EndTime
  236. Private p_Duration
  237. Private p_HowManyPeriods
  238.  
  239. Dim timestamp_channel_number, amplitude_channel_number, Periods
  240.  
  241. Private Sub Class_Initialize
  242. p_Index = 0
  243. p_TimestampCh = ""
  244. p_AmplitudeCh = ""
  245. p_FunctionType = ""
  246. p_OrderOfThisType = 0
  247. p_StartTime = 0
  248. p_EndTime = 0
  249. p_Duration = 0
  250. p_HowManyPeriods = 0
  251. End Sub
  252.  
  253. Public Property Get Index
  254. Index = p_Index
  255. End Property
  256. Public Property Let Index(value2let)
  257. p_Index = value2let
  258. End Property
  259.  
  260. Public Property Get TimestampCh
  261. TimestampCh = p_TimestampCh
  262. End Property
  263. Public Property Let TimestampCh(value2let)
  264. Dim oMyChn, aString, iLoop
  265. p_TimestampCh = value2let
  266. Set oMyChn = Data.GetChannel(value2let)
  267. p_TimestampCh = oMyChn.Name
  268. aString = Split(oMyChn.Name, "_", -1, 1)
  269. p_FunctionType = aString(2) & "_" & aString(3)
  270. p_OrderOfThisType = aString(4)
  271. p_StartTime = CHDx(1,CNO(value2let))
  272. p_EndTime = CHDx(ChnLength(value2let),CNo(value2let))
  273. p_Duration = p_EndTime - p_StartTime + 0.030
  274. Periods = p_Duration/1
  275. End Property
  276.  
  277. Public Property Get AmplitudeCh
  278. AmplitudeCh = p_AmplitudeCh
  279. End Property
  280. Public Property Let AmplitudeCh(value2let)
  281. Dim oMyChn
  282. p_AmplitudeCh = value2let
  283. Set oMyChn = Data.GetChannel(value2let)
  284. p_AmplitudeCh = oMyChn.Name
  285. End Property
  286.  
  287. Public Property Get FunctionType
  288. FunctionType = p_FunctionType
  289. End Property
  290.  
  291. Public Property Get OrderOfThisType
  292. OrderOfThisType = p_OrderOfThisType
  293. End Property
  294.  
  295. Public Property Get StartTime
  296. StartTime = p_StartTime
  297. End Property
  298.  
  299. Public Property Get EndTime
  300. EndTime = p_EndTime
  301. End Property
  302.  
  303. Public Property Get Duration
  304. Duration = p_Duration
  305. End Property
  306.  
  307. Public Property Get HowManyPeriods
  308. HowManyPeriods = Periods
  309. End Property
  310.  
  311. Public Sub Reinitialize
  312. p_Index = 0
  313. p_TimestampCh = ""
  314. p_AmplitudeCh = ""
  315. p_FunctionType = ""
  316. p_OrderOfThisType = 0
  317. p_StartTime = 0
  318. p_EndTime = 0
  319. p_Duration = 0
  320. p_HowManyPeriods = 0
  321. End Sub
  322.  
  323. End Class
  324.  
  325. Function GenerateTimestampChn(TimestampChnName,AmplitudeChn,Fs,NewGrp)
  326. Dim ChannelLength, ret, iLoop
  327.  
  328. ChannelLength = ChnLength(AmplitudeChn)
  329. ret = ChnAlloc(TimestampChnName, ChannelLength, 1, DataTypeFloat64,"Numeric",NewGrp)
  330.  
  331. For iLoop = 1 to ChannelLength
  332. CHD(iLoop,CNo(ret(0))) = iLoop/Fs
  333. Next
  334.  
  335. GenerateTimestampChn = ret(0)
  336.  
  337. End Function
  338.  
  339. Function ProcessNoise(AmplitudeChn,TimestampChn,Threshold,NewGrp)
  340. Dim iLoop, NewChn, L_TimestampChn, L_AmplitudeChn, L_Threshold
  341. L_TimestampChn = TimestampChn
  342. L_AmplitudeChn = AmplitudeChn
  343. L_Threshold = Threshold
  344.  
  345. NewChn=ChnAlloc(ChnName(L_AmplitudeChn) & "_Processed", ChnLength(L_AmplitudeChn), 1, ChnValueDataType(L_AmplitudeChn),"Numeric",NewGrp)
  346. L_AmplitudeChn = ChnCopy(L_AmplitudeChn,NewChn(0))
  347. NewChn=ChnAlloc(ChnName(L_TimestampChn) & "_Processed", ChnLength(L_TimestampChn), 1, ChnValueDataType(L_TimestampChn),"Numeric",NewGrp)
  348. L_TimestampChn = ChnCopy(L_TimestampChn,NewChn(0))
  349.  
  350. For iLoop = 1 to ChnLength(L_AmplitudeChn)
  351. If (CHDx(iLoop,CNo(L_AmplitudeChn))<L_Threshold) Then
  352. CHDx(iLoop,CNo(L_AmplitudeChn)) = NULL
  353. CHDx(iLoop,CNo(L_TimestampChn)) = NULL
  354. End If
  355. Next
  356.  
  357. CHD(iLoop-1,L_AmplitudeChn) = 0
  358. CHD(iLoop-1,L_TimestampChn) = 0
  359.  
  360. Call Portal.Refresh
  361. Call oUDI.Sleep(100)
  362. Call ChnNovHandle(L_TimestampChn,L_AmplitudeChn,"Delete","XY",1,0,0)
  363.  
  364. NewChn = array(L_TimestampChn,L_AmplitudeChn)
  365. ProcessNoise = NewChn
  366.  
  367. End Function
  368.  
  369. Function IdentifyChime(TimestampChn, AmplitudeChn, ChimesThreshold,NewGrp)
  370.  
  371. Dim ChimesCounter, InitialWarningCounter, BeltminderACounter, BeltminderBCounter, UndefinedChimeCounter
  372. Dim iLoop, iLoop2, max, I
  373. Dim MyChannels(1), elements(), aux2(), ChnNumber
  374. Dim Timestamp, Amplitude, AmplitudeChnLength
  375. Dim InitialWarningThreshold, BeltminderAThreshold, BeltminderBThreshold
  376.  
  377. TimestampChn = CNo(TimestampChn)
  378. AmplitudeChn = CNo(AmplitudeChn)
  379.  
  380. InitialWarningCounter = 0
  381. BeltminderACounter = 0
  382. BeltminderBCounter = 0
  383. UndefinedChimeCounter = 0
  384.  
  385. InitialWarningThreshold = ChimesThreshold(0)
  386. BeltminderAThreshold = ChimesThreshold(1)
  387. BeltminderBThreshold = ChimesThreshold(2)
  388.  
  389. AmplitudeChnLength = ChnLength(AmplitudeChn)
  390.  
  391. reDim chime(1,AmplitudeChnLength)
  392. reDim aux(AmplitudeChnLength,1)
  393.  
  394. For iLoop = 1 to AmplitudeChnLength
  395.  
  396. Call oUDI.Sleep(100)
  397.  
  398. max = 0
  399. iLoop2=0
  400.  
  401. If (iLoop<AmplitudeChnLength) Then
  402. Do
  403. Timestamp = CHDx(iLoop,TimestampChn)
  404. Amplitude = CHDx(iLoop,AmplitudeChn)
  405. If (Amplitude <> 0) Then
  406. chime(0,iLoop2) = Timestamp
  407. chime(1,iLoop2) = Amplitude
  408. If (Amplitude>max) Then
  409. max=Amplitude
  410. End If
  411. End If
  412.  
  413. iLoop2=iLoop2+1
  414. iLoop=iLoop+1
  415.  
  416. Loop While((iLoop<AmplitudeChnLength) AND ((CHDx(iLoop,TimestampChn)-chime(0,iLoop2-1))<2))
  417.  
  418. End If
  419.  
  420. If(max>BeltminderBThreshold) Then
  421. InitialWarningCounter=InitialWarningCounter+1
  422. MyChannels(0) = "Chime_Timestamp_InitialWarning_NA_" & InitialWarningCounter
  423. MyChannels(1) = "Chime_Amplitude_InitialWarning_NA_" & InitialWarningCounter
  424. ElseIf((max<BeltminderBThreshold) AND (max>BeltminderAThreshold)) Then
  425. BeltminderBCounter=BeltminderBCounter+1
  426. MyChannels(0) = "Chime_Timestamp_Beltminder_B_" & BeltminderBCounter
  427. MyChannels(1) = "Chime_Amplitude_Beltminder_B_" & BeltminderBCounter
  428. ElseIf(max<BeltminderAThreshold) Then
  429. BeltminderACounter=BeltminderACounter+1
  430. MyChannels(0) = "Chime_Timestamp_Beltminder_A_" & BeltminderACounter
  431. MyChannels(1) = "Chime_Amplitude_Beltminder_A_" & BeltminderACounter
  432. Else
  433. UndefinedChimeCounter=UndefinedChimeCounter+1
  434. MyChannels(0) = "Chime_Timestamp_UndefinedChimeThreshold_NA_" & UndefinedChimeCounter
  435. MyChannels(1) = "Chime_Amplitude_UndefinedChimeThreshold_NA_" & UndefinedChimeCounter
  436. End If
  437.  
  438. reDim aux2(1,iLoop2-1)
  439. For I=0 to Ubound(aux2,2)
  440. aux2(0,I) = chime(0,I)
  441. aux2(1,I) = chime(1,I)
  442. Next
  443. Erase chime
  444. reDim chime(1,AmplitudeChnLength)
  445.  
  446. ChnNumber = ArrayToChannels(aux2,MyChannels)
  447. Call ChnMove(ChnNumber(0), NewGrp)
  448. Call ChnMove(ChnNumber(1), NewGrp)
  449. ChnNumber(0) = "[" & NewGrp & "]/" & MyChannels(0)
  450. ChnNumber(1) = "[" & NewGrp & "]/" & MyChannels(1)
  451.  
  452.  
  453. Erase aux2
  454.  
  455. ChimesCounter = InitialWarningCounter + BeltminderACounter + BeltminderBCounter + UndefinedChimeCounter
  456.  
  457. aux(ChimesCounter-1,0) = ChnNumber(0)
  458. aux(ChimesCounter-1,1) = ChnNumber(1)
  459.  
  460. Next
  461.  
  462. reDim elements(ChimesCounter-1,1)
  463.  
  464. For I=0 to Ubound(elements)
  465. elements(I,0) = aux(I,0)
  466. elements(I,1) = aux(I,1)
  467. Next
  468.  
  469. IdentifyChime = elements 'Returns a channel list as a vector. The return are numbers.
  470.  
  471. Erase aux
  472. Erase elements
  473.  
  474. End Function
  475.  
  476. Function IdentifyTelltale(TimestampChn, AmplitudeChn, TelltaleBeltminderAMinPeriodOn, TelltaleBeltminderABMaxPeriodOn,NewGrp)
  477.  
  478. Dim TelltalesCounter, NotFlashingCounter, BeltminderACounter, BeltminderBCounter, UndefinedTelltaleCounter
  479. Dim iLoop, iLoop2, iLoop3, NoChangeLength, diff, I
  480. Dim Change, NoChange, LastValley, aux2, LastValley2
  481. Dim MyChannels(1), elements(), ChnNumber, TelltaleLength, Falling, Rising
  482. Dim Timestamp, Amplitude, AmplitudeChnLength, NoChangeLengthMax
  483.  
  484. TimestampChn = CNo(TimestampChn)
  485. AmplitudeChn = CNo(AmplitudeChn)
  486.  
  487. NotFlashingCounter = 0
  488. BeltminderACounter = 0
  489. BeltminderBCounter = 0
  490. UndefinedTelltaleCounter = 0
  491. NoChangeLengthMax = 0
  492.  
  493. AmplitudeChnLength = ChnLength(AmplitudeChn)
  494.  
  495. reDim Telltale(1,AmplitudeChnLength)
  496. reDim cycle(1,AmplitudeChnLength)
  497. reDim aux(AmplitudeChnLength,1)
  498.  
  499. for iLoop3 = 1 to AmplitudeChnLength
  500. Telltale(0,iLoop3 - 1) = CHDx(iLoop3,TimestampChn)
  501. Telltale(1,iLoop3 - 1) = CHDx(iLoop3,AmplitudeChn)
  502. next
  503. TelltaleLength = Ubound(telltale,2)
  504.  
  505. iLoop3 = 0
  506. Do While (Telltale(1,iLoop3)=0)
  507. iLoop3=iLoop3+1
  508. Loop
  509. iLoop3=iLoop3+1
  510.  
  511. For iLoop = iLoop3 to TelltaleLength
  512.  
  513. Call oUDI.Sleep(100)
  514.  
  515. NoChangeLength = 0
  516. NoChangeLengthMax = 0
  517. Change = 0
  518. iLoop2 = 0
  519.  
  520. If (iLoop < AmplitudeChnLength) Then
  521. Do While((iLoop < AmplitudeChnLength) AND (Telltale(1,iLoop) = 0))
  522. iLoop = iLoop + 1
  523. Loop
  524. End If
  525.  
  526. If (iLoop < AmplitudeChnLength) Then
  527. Do While((iLoop < AmplitudeChnLength) AND (NoChangeLength < (1+0.4)*TelltaleBeltminderABMaxPeriodOn))
  528.  
  529. cycle(0,iLoop2) = Telltale(0,iLoop)
  530. cycle(1,iLoop2) = Telltale(1,iLoop)
  531.  
  532. If (iLoop <> 0) Then
  533. If (Telltale(1,iLoop - 1) <> Telltale(1,iLoop)) Then
  534. Change = Telltale(0,iLoop)
  535. LastValley = iLoop2
  536. LastValley2 = iLoop
  537. If (Telltale(1,iLoop) = 1) Then
  538. Rising = Telltale(0,iLoop)
  539. Else
  540. Falling = Telltale(0,iLoop)
  541. If (NoChangeLengthMax < (Falling - Rising)) Then
  542. NoChangeLengthMax = Falling - Rising
  543. End If
  544. End If
  545. ElseIf ((Change <> 0) AND (Telltale(1,iLoop - 1) = Telltale(1,iLoop))) Then
  546. NoChange = Telltale(0,iLoop)
  547. NoChangeLength = NoChange - Change
  548. End If
  549. End If
  550.  
  551. iLoop = iLoop + 1
  552. iLoop2 = iLoop2 + 1
  553. Loop
  554.  
  555. aux2 = cycle
  556. redim preserve aux2(1,LastValley-1)
  557. iLoop = LastValley2
  558.  
  559. If(NoChangeLengthMax > (1+0.4)*TelltaleBeltminderABMaxPeriodOn) Then 'Above 40% of Beltminder A or B maximum period it is considered not flashing state
  560. NotFlashingCounter = NotFlashingCounter + 1
  561. MyChannels(0) = "Telltale_Timestamp_NotFlashing_NA_" & NotFlashingCounter
  562. MyChannels(1) = "Telltale_Amplitude_NotFlashing_NA_" & NotFlashingCounter
  563. ElseIf((NoChangeLengthMax > (1-0.1)*TelltaleBeltminderAMinPeriodOn)) Then '10% of error is acceptable
  564. BeltminderACounter = BeltminderACounter + 1
  565. MyChannels(0) = "Telltale_Timestamp_Beltminder_A_" & BeltminderACounter
  566. MyChannels(1) = "Telltale_Amplitude_Beltminder_A_" & BeltminderACounter
  567. ElseIf(NoChangeLengthMax < (1-0.1)*TelltaleBeltminderAMinPeriodOn) Then '10% of error is acceptable
  568. BeltminderBCounter = BeltminderBCounter + 1
  569. MyChannels(0) = "Telltale_Timestamp_Beltminder_B_" & BeltminderBCounter
  570. MyChannels(1) = "Telltale_Amplitude_Beltminder_B_" & BeltminderBCounter
  571. Else
  572. UndefinedTelltaleCounter = UndefinedTelltaleCounter + 1
  573. MyChannels(0) = "Telltale_Timestamp_UndefinedTelltaleThreshold_NA_" & UndefinedTelltaleCounter
  574. MyChannels(1) = "Telltale_Amplitude_UndefinedTelltaleThreshold_NA_" & UndefinedTelltaleCounter
  575. End If
  576.  
  577. aux2(1,0) = 0
  578. aux2(1,Ubound(aux2)) = 0
  579.  
  580. ChnNumber = ArrayToChannels(aux2,MyChannels,true)
  581. Call ChnMove(ChnNumber(0), NewGrp)
  582. Call ChnMove(ChnNumber(1), NewGrp)
  583. ChnNumber(0) = "[" & NewGrp & "]/" & MyChannels(0)
  584. ChnNumber(1) = "[" & NewGrp & "]/" & MyChannels(1)
  585.  
  586. TelltalesCounter = NotFlashingCounter + BeltminderACounter + BeltminderBCounter + UndefinedTelltaleCounter
  587.  
  588. aux(TelltalesCounter - 1,0) = ChnNumber(0)
  589. aux(TelltalesCounter - 1,1) = ChnNumber(1)
  590.  
  591. End If
  592. Next
  593.  
  594. reDim elements(TelltalesCounter - 1,1)
  595.  
  596. For I = 0 to Ubound(elements)
  597. elements(I,0) = aux(I,0)
  598. elements(I,1) = aux(I,1)
  599. Next
  600.  
  601. IdentifyTelltale = elements 'Returns a channel list as a vector. The return are numbers.
  602.  
  603. Erase aux
  604. Erase elements
  605.  
  606. End Function
  607.  
  608. Function BeltminderFunction(Arg)
  609.  
  610. Dim ret, iLoop, iLoop2, BeltminderCounter
  611. Dim Fs 'Sample rate (log sample rate = 100Hz)
  612. Dim Threshold 'NoChangeLengthimum noise amplitude
  613. Dim TimestampChn, TimestampChn2, ChimeAmplitudeChn, ProcessedTimestampChn, ProcessedChimeAmplitudeChn, GeneratedChns, NewGrp
  614. Dim TelltaleAmplitudeChn
  615. Dim chime1, telltale
  616. Dim TelltaleBeltminderAMinPeriodOn, TelltaleBeltminderABMaxPeriodOn
  617. Dim ChimesThreshold(3)
  618.  
  619. Fs = BeltminderFunctionArgs(0)
  620. TimestampChn = BeltminderFunctionArgs(1)
  621. ChimeAmplitudeChn = BeltminderFunctionArgs(2)
  622.  
  623.  
  624. NewGrp = GroupIndexGet(GroupCreate("ProcessedChannels"))
  625.  
  626. TimestampChn = GenerateTimestampChn(TimestampChn,ChimeAmplitudeChn,Fs,NewGrp)
  627. TimestampChn2 = TimestampChn
  628.  
  629. ''''''''''''''''''''''''''''''''''''''''''''''''''
  630. 'CHIME PROCESSING
  631. ''''''''''''''''''''''''''''''''''''''''''''''''''
  632. Threshold = BeltminderFunctionArgs(3)
  633. ret = ProcessNoise(ChimeAmplitudeChn,TimestampChn,Threshold,NewGrp)
  634. ProcessedTimestampChn = ret(0)
  635. ProcessedChimeAmplitudeChn = ret(1)
  636.  
  637. Call oUDI.Sleep(100)
  638.  
  639. ChimesThreshold(0) = BeltminderFunctionArgs(7) 'Initial warning chime threshold
  640. ChimesThreshold(1) = BeltminderFunctionArgs(8) 'Beltminder A chime threshold
  641. ChimesThreshold(2) = BeltminderFunctionArgs(9) 'Beltminder B chime threshold
  642.  
  643. GeneratedChns = IdentifyChime(ProcessedTimestampChn,ProcessedChimeAmplitudeChn, ChimesThreshold,NewGrp)
  644.  
  645. ReDim chime1 (Ubound(GeneratedChns,1))
  646. For iLoop = 0 to Ubound(chime1)
  647. Set chime1(iLoop) = New ChimeCycle
  648.  
  649. chime1(iLoop).Index = iLoop
  650. chime1(iLoop).TimestampCh = GeneratedChns(iLoop,0)
  651. chime1(iLoop).AmplitudeCh = GeneratedChns(iLoop,1)
  652. Next
  653. ''''''''''''''''''''''''''''''''''''''''''''''''''
  654. 'TELLTALE PROCESSING
  655. ''''''''''''''''''''''''''''''''''''''''''''''''''
  656. TelltaleAmplitudeChn = BeltminderFunctionArgs(4)
  657. TelltaleBeltminderAMinPeriodOn = BeltminderFunctionArgs(5)
  658. TelltaleBeltminderABMaxPeriodOn = BeltminderFunctionArgs(6)
  659.  
  660. GeneratedChns = IdentifyTelltale(TimestampChn,TelltaleAmplitudeChn, TelltaleBeltminderAMinPeriodOn, TelltaleBeltminderABMaxPeriodOn,NewGrp)
  661.  
  662. ReDim telltale1 (Ubound(GeneratedChns,1))
  663. For iLoop = 0 to Ubound(telltale1)
  664. Set telltale1(iLoop) = New TelltaleCycle
  665.  
  666. telltale1(iLoop).Index = iLoop
  667. telltale1(iLoop).TimestampCh = GeneratedChns(iLoop,0)
  668. telltale1(iLoop).AmplitudeCh = GeneratedChns(iLoop,1)
  669. Next
  670. ''''''''''''''''''''''''''''''''''''''''''''''''''
  671. 'BELTMINDER WARNING FUNCTION PROCESSING
  672. ''''''''''''''''''''''''''''''''''''''''''''''''''
  673. Dim telltale1_Temp, chime1_Temp, NoFlashingNoChimeOrder
  674. telltale1_Temp = telltale1
  675. chime1_Temp = chime1
  676.  
  677. BeltminderCounter = 0
  678. NoFlashingNoChimeOrder = 1
  679. For iLoop = 0 to Ubound(telltale1_Temp)
  680. For iLoop2 = 0 to Ubound(chime1_Temp)
  681.  
  682. If((chime1_Temp(iLoop2).FunctionType <> "InitialWarning_NA") AND (telltale1_Temp(iLoop).FunctionType = "NotFlashing_NA")) Then
  683. ReDim Preserve beltminder1(BeltminderCounter)
  684. Set beltminder1(BeltminderCounter) = New BeltminderCycle
  685. beltminder1(BeltminderCounter).Index = BeltminderCounter
  686. beltminder1(BeltminderCounter).FunctionType = telltale1_Temp(iLoop).FunctionType
  687. beltminder1(BeltminderCounter).OrderOfThisType = NoFlashingNoChimeOrder
  688. beltminder1(BeltminderCounter).StartTime = telltale1_Temp(iLoop).StartTime
  689. beltminder1(BeltminderCounter).EndTime = telltale1_Temp(iLoop).EndTime
  690. beltminder1(BeltminderCounter).ChimeObjIndex = "N/A"
  691. beltminder1(BeltminderCounter).TelltaleObjIndex = telltale1_Temp(iLoop).Index
  692. BeltminderCounter = BeltminderCounter + 1
  693. NoFlashingNoChimeOrder = NoFlashingNoChimeOrder + 1
  694. chime1_Temp(iLoop2).Reinitialize
  695. telltale1_Temp(iLoop).Reinitialize
  696.  
  697. End If
  698.  
  699. If((chime1_Temp(iLoop2).FunctionType = "InitialWarning_NA") AND (telltale1_Temp(iLoop).FunctionType = "NotFlashing_NA")) Then
  700. ReDim Preserve beltminder1(BeltminderCounter)
  701. Set beltminder1(BeltminderCounter) = New BeltminderCycle
  702. beltminder1(BeltminderCounter).Index = BeltminderCounter
  703. beltminder1(BeltminderCounter).FunctionType = chime1_Temp(iLoop2).FunctionType
  704. beltminder1(BeltminderCounter).OrderOfThisType = chime1_Temp(iLoop2).OrderOfThisType
  705. If(telltale1_Temp(iLoop).StartTime < chime1_Temp(iLoop2).StartTime) Then
  706. beltminder1(BeltminderCounter).StartTime = telltale1_Temp(iLoop).StartTime
  707. Else beltminder1(BeltminderCounter).StartTime = chime1_Temp(iLoop2).StartTime
  708. End If
  709. If(telltale1_Temp(iLoop).EndTime > chime1_Temp(iLoop2).EndTime) Then
  710. beltminder1(BeltminderCounter).EndTime = telltale1_Temp(iLoop).EndTime
  711. Else beltminder1(BeltminderCounter).EndTime = chime1_Temp(iLoop2).EndTime
  712. End If
  713. beltminder1(BeltminderCounter).ChimeObjIndex = chime1_Temp(iLoop2).Index
  714. beltminder1(BeltminderCounter).TelltaleObjIndex = telltale1_Temp(iLoop).Index
  715. BeltminderCounter = BeltminderCounter + 1
  716. chime1_Temp(iLoop2).Reinitialize
  717. telltale1_Temp(iLoop).Reinitialize
  718. End If
  719.  
  720. If((telltale1_Temp(iLoop).FunctionType <> "") AND (telltale1_Temp(iLoop).FunctionType = chime1_Temp(iLoop2).FunctionType) AND (telltale1_Temp(iLoop).OrderOfThisType = chime1_Temp(iLoop2).OrderOfThisType)) Then
  721. ReDim Preserve beltminder1(BeltminderCounter)
  722. Set beltminder1(BeltminderCounter) = New BeltminderCycle
  723. beltminder1(BeltminderCounter).Index = BeltminderCounter
  724. beltminder1(BeltminderCounter).FunctionType = chime1_Temp(iLoop2).FunctionType
  725. beltminder1(BeltminderCounter).OrderOfThisType = chime1_Temp(iLoop2).OrderOfThisType
  726. If(telltale1_Temp(iLoop).StartTime < chime1_Temp(iLoop2).StartTime) Then
  727. beltminder1(BeltminderCounter).StartTime = telltale1_Temp(iLoop).StartTime
  728. Else beltminder1(BeltminderCounter).StartTime = chime1_Temp(iLoop2).StartTime
  729. End If
  730. If(telltale1_Temp(iLoop).EndTime > chime1_Temp(iLoop2).EndTime) Then
  731. beltminder1(BeltminderCounter).EndTime = telltale1_Temp(iLoop).EndTime
  732. Else beltminder1(BeltminderCounter).EndTime = chime1_Temp(iLoop2).EndTime
  733. End If
  734. beltminder1(BeltminderCounter).ChimeObjIndex = chime1_Temp(iLoop2).Index
  735. beltminder1(BeltminderCounter).TelltaleObjIndex = telltale1_Temp(iLoop).Index
  736. BeltminderCounter = BeltminderCounter + 1
  737. chime1_Temp(iLoop2).Reinitialize
  738. telltale1_Temp(iLoop).Reinitialize
  739. End IF
  740. Next
  741. Next
  742.  
  743. Erase telltale1_Temp
  744. Erase chime1_Temp
  745.  
  746. 'For iLoop2 = 0 to Ubound(beltminder1)
  747. ' Call LogFileWrite( "Index: " & beltminder1(iLoop2).Index & vbCrLf &"FunctionType: " & beltminder1(iLoop2).FunctionType & vbCrLf & "OrderOfThisType: " & beltminder1(iLoop2).OrderOfThisType & vbCrLf & "StartTime: " & beltminder1(iLoop2).StartTime & vbCrLf & "EndTime: " & beltminder1(iLoop2).EndTime & vbCrLf & "Duration: " & beltminder1(iLoop2).Duration & vbCrLf & "ChimeObjIndex: " & beltminder1(iLoop2).ChimeObjIndex & vbCrLf & "TelltaleObjIndex: " & beltminder1(iLoop2).TelltaleObjIndex)
  748. 'Next
  749.  
  750. BeltminderFunction = Array (chime1, telltale1, beltminder1,TimestampChn2)
  751.  
  752. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement