Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- proc startup {} {
- #lista zmiennych globalnych
- global a
- set a 0
- global b
- set b 0
- global reference
- set reference 1
- global reference1
- set reference1 1
- global reference2
- set reference2 1
- global min_value
- set min_value 0
- global max_value
- set max_value 0
- global listoperator
- set listoperator {}
- global c_value
- set c_value 0
- global n_value
- set n_value 0
- global integral
- set integral 0
- global c_time
- set c_time 0
- global c_time1
- set c_time1 0
- global n_time
- set n_time 0
- global n_time1
- set n_time1 0
- global integral_check
- set integral_check 0
- #zmienna globalna w innym zapisie
- set ::sum 0
- #interwał czasowy
- antInstallHook "5 s"
- #zainicjalizowanie/stworzenie kanałów, które wyświetlać będą konkretne wartości
- antInitializeChannels "Test_channel_1_Callback_From_Sine" {Access: "Writable" ValueType: "Double" Format: "#0" Unit: "kV" Logging: "1" ReadingHook: "1m"}
- antInitializeChannels "Test_channel_2_Callback_From_Square" {Access: "Writable" ValueType: "Double" Format: "#0" Unit: "kJ" Logging: "1" ReadingHook: "1m"}
- antInitializeChannels "Test_channel_3_Aritmetic_Function" {Access: "Writable" ValueType: "Double" Format: "#0" Unit: "MPH" Logging: "1" ReadingHook: "1m"}
- antInitializeChannels "Test_channel_4_Sum_Of_Sine_And_Square" {Access: "Writable" ValueType: "Double" Format: "#0" Unit: "kg" Logging: "1" ReadingHook: "1m"}
- antInitializeChannels "Test_channel_5_Product_Of_Sine_And_Square" {Access: "Writable" ValueType: "Double" Format: "#0" Unit: "oz" Logging: "1" ReadingHook: "1m"}
- antInitializeChannels "Test_channel_6_Sine_Value_Powered_By_Module_Property" {Access: "Writable" ValueType: "Double" Format: "#0" Unit: "lux" Logging: "1" ReadingHook: "1m"}
- antInitializeChannels "Test_channel_7_Minimal_Sine_Value" {Access: "Writable" ValueType: "Double" Format: "#0" Unit: "W" Logging: "1" ReadingHook: "1m"}
- antInitializeChannels "Test_channel_8_Maximal_Sine_Value" {Access: "Writable" ValueType: "Double" Format: "#0" Unit: "mA" Logging: "1" ReadingHook: "1m"}
- antInitializeChannels "Test_channel_9_Sum_Of_Last_10_Sine_Values" {Access: "Writable" ValueType: "Double" Format: "#0" Unit: "s" Logging: "1" ReadingHook: "1m"}
- antInitializeChannels "Test_channel_10_Integral_Of_Sine" {Access: "Writable" ValueType: "Double" Format: "#0" Unit: "lbs" Logging: "1" ReadingHook: "1m"}
- antInitializeChannels "Test_channel_11_Derivative_Of_Sine" {Access: "Writable" ValueType: "Double" Format: "#0" Unit: "km" Logging: "1" ReadingHook: "1m"}
- #zainstalowanie wywołań wartości kanałów: Sine i Square z Generatora
- antInstallChannelCallback *Generator/Sine {} "callback"
- antInstallChannelCallback *Generator/Square {} "callback1"
- }
- proc shutdown {} {
- # Actions on module's shutdown
- }
- proc timerHook {hook_name timestamp} {
- if {$hook_name eq "5 s"} {
- # Action on particular hook
- #ustalenie wartości kanału '3' na losową wartość podniesioną do potęgi 900
- antSetChannelValue "Test_channel_3_Aritmetic_Function" [expr pow(rand(),900)]
- }
- }
- #procedura dodawania elementów listy
- proc ladd {l} {
- set total 0.0;
- foreach nxt $l {
- set total [expr {$total + $nxt}]};
- return $total
- }
- #procedura callback dla kanału Sine
- proc callback {channel_name timestamp channel_value status} {
- #odwolanie do zmiennych globalnych
- global a
- global b
- global reference
- global reference1
- global reference2
- global min_value
- global max_value
- global listoperator
- global c_value
- global n_value
- global c_time
- global c_time1
- global n_time
- global n_time1
- global integral_check
- #zadeklarowanie zmiennej 'a' równiej wartości kanału Sine
- set a $channel_value
- #zadeklarowanie zmiennej 'b' równej propertiesowi modułu
- set c [antGetSetting "ExponentOfPower"]
- #porównywanie wartosci z kanalu z wykorzystaniem zmiennej 'reference'
- #1 - wstępne przypisanie pierwszej wartości kanału zarówno jako wartość minimalna oraz maksymalna
- if {$reference==1} {
- set min_value $channel_value
- set max_value $channel_value
- #wyzerowanie odniesienia, żeby nie przypisywana więcej była wartość wstępna
- set reference 0
- }
- #2 - jeżeli kolejna wartość kanału jest mniejsza od dotychczasowej wartości minimalnej, wartość minimalna zostaje nadpisana tą wartością
- if ($min_value>$channel_value) {
- set min_value $channel_value
- }
- #3 - jeżeli kolejna wartość kanału jest większa od dotyhczasowej wartości maksymalnej, wartośc maksymalna zostaje nadpisana tą wartością
- if ($max_value<$channel_value) {
- set max_value $channel_value
- }
- if {1 == $status} {
- #zagregowanie 10 najnowszych wartości kanału Sine
- lappend listoperator $channel_value
- #jeżeli lista zawiera 10 elementów
- if {[llength $listoperator]==10} {
- #następuje zsumowanie 10 wartości kanału w oparciu o utworzoną wcześniej procedurę listadditon
- set ::sum [ladd $listoperator]
- #ustalenie wartości kanału '9' na sumę 10 wartości kanału Sine
- antSetChannelValue "Test_channel_9_Sum_Of_Last_10_Sine_Values" $::sum
- #po wyciągnięciu sumy 10 wartości kanału, następuje wyzerowanie listoperatora oraz przechowującej sumę zmiennej suma
- set listoperator [lreplace $listoperator 0 0]
- set ::sum 0
- }
- # #obliczenie całki wartości kanału = suma[aktualna wartość*timestamp]
- # if ($reference1==1) {
- #
- # set c_time $timestamp
- # set reference1 0
- #
- # } else {
- # set n_time1 $timestamp
- #
- # antSetChannelValue "Test_channel_10_Integral_Of_Sine" [expr {($n_value - $c_value)/($n_time1 - $c_time1)}]
- # set c_time $n_time
- #obliczanie różniczki wartości kanału = (aktualna wartość - poprzednia wartość)/(aktualny czas - poprzedni czas)
- if ($reference1==1) {
- set c_value $channel_value
- set c_time1 $timestamp
- set reference1 0
- } else {
- set n_value $channel_value
- set n_time1 $timestamp
- antLog debug [expr ($n_time1 - $c_time1)]
- antSetChannelValue "Test_channel_11_Derivative_Of_Sine" [expr {($n_value - $c_value)/($n_time1 - $c_time1)}]
- set integral_check [expr $integral_check + [expr {($n_time1 - $c_time1)*$channel_value}]]
- antSetChannelValue "Test_channel_10_Integral_Of_Sine" $integral_check
- set c_time1 $n_time1
- set c_value $n_value
- }
- #}
- #ustalenie wartości kanału '1' na wartość kanału Sine
- antSetChannelValue "Test_channel_1_Callback_From_Sine" $channel_value
- #ustalenie wartości kanału '6' na wartość kanału Sine podniesiona do potęgi równej propertiesowi modułu (x^y)
- antSetChannelValue "Test_channel_6_Sine_Value_Powered_By_Module_Property" [expr pow($channel_value, $c)]
- #ustalenie wartości kanału '7' na wartość minimalną kanału Sine
- antSetChannelValue "Test_channel_7_Minimal_Sine_Value" $min_value
- #ustalenie wartości kanału '8' na wartość maksymalną kanału Sine
- antSetChannelValue "Test_channel_8_Maximal_Sine_Value" $max_value
- #wyświetlenie logów informujących o pobranej wartości
- antLog "Sine value is $channel_value"
- antLog "The value of channel $channel_name has been set to $channel_value at [antTimeToString $timestamp]"
- } else {
- antLog "Failed to set channel $channel_name"
- }
- }
- #procedura callback1 dla kanału 'Square''
- proc callback1 {channel_name timestamp channel_value status} {
- #odwołanie do zmiennych globalnych
- global a
- global b
- if {1 == $status} {
- #zadeklarowanie zmiennej 'b' równiej wartości kanału Square
- set b $channel_value
- #ustalenie wartości kanału '2' na wartość kanału Square
- antSetChannelValue "Test_channel_2_Callback_From_Square" $channel_value
- #ustalenie wartości kanału '4' równej sumie wartości kanałów Sine i Square
- antSetChannelValue "Test_channel_4_Sum_Of_Sine_And_Square" [expr $a+$b]
- #ustalenie wartości kanału '5' równej iloczynowi wartości kanałów Sine i Square
- antSetChannelValue "Test_channel_5_Product_Of_Sine_And_Square" [expr $a*$b]
- #wyświetlenie logów informujących o pobranych wartościach kanału, sumy oraz iloczynu
- antLog "Square value is $channel_value"
- antLog "The value of channel $channel_name has been set to $channel_value at [antTimeToString $timestamp]"
- antLog "The damned sum of Sine and Square channel values is: [expr $a+$b]"
- antLog "A deprecated product of Sine and Square channel values is: [expr $a*$b]"
- } else {
- antLog "Failed to set channel $channel_name"
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement