Skip to content

THC Version 2

Andreas Drollinger edited this page Nov 8, 2019 · 2 revisions

THC - Version 2

The THC version 2 contains several changes compared to the version 1. These changes require some adaptations of the user configuration scripts. This document summarizes both the relevant internal changes of THC and the required user configuration script adaptations.

The internal changes are :

Description
THC namespace All THC core functions and variables are now placed inside the namespace ::thc.
Module namespaces All modules are placed inside their namespace ::thc::<ModuleName>.
THC API extensions New functions are available to configure THC and to read the device states.

The following section provides guidelines to update user configuration scripts from THC version 1 to THC version 2.

THC configuration

THC 2 provides a dedicated function to define the heartbeat of the system.

THC 1

 set HeartBeatMS 1000

THC 2

 thc::DefineHeartBeat 1000 MS

THC core namespace change

Any THC core functions are now placed in the namespace ::thc.

THC 1

 DefineLog 1 "/var/thc/thc_server.log" 1

 DefineDevice LightLiving,state      -get {thc_zWay "SwitchBinary 8.1"} \
                                    -set {thc_zWay "SwitchBinary 8.1"}
 }

THC 2

 thc::DefineLog 1 "/var/thc/thc_server.log" 1

 thc::DefineDevice LightLiving,state -get {thc_zWay "SwitchBinary 8.1"} \
                                    -set {thc_zWay "SwitchBinary 8.1"}
 }

Also any THC core variables that were previously placed in the global namespace are now accessible via the ::thc namespace (example for variables Event and State).

THC 1

 DefineJob -tag Surv -description "Alarm detection" \
           -condition {$Event(Alarm,state)==1} {
    Set {Sirene,state LightLiving,state} 1
 }

 DefineJob -tag RdmLight -time +5s -repeat 1m -description "Random light activity" \
           -condition {$State(Alarm,state)!=1} {
    thc_RandomLight::Control
    Log "Changed light, time=$Time"
 }

THC 2

 thc::DefineJob -tag Surv -description "Alarm detection" \
                -condition {$Event(Alarm,state)==1} {
    thc::Set {Sirene,state LightLiving,state} 1
 }

 thc::DefineJob -tag RdmLight -time +5s -repeat 1m -description "Random light activity" \
                -condition {$thc::State(Alarm,state)!=1} {
    thc::RandomLight::Control
    Log "Changed light, time=$thc::Time"
 }

THC module namespace change

While THC version 1 placed a module into the namespace ::thc_<Module>, THC version 2 places it into namespace ::thc::Module.

THC 1

 thc_Web::Start 8086

 thc_zWay::Init "http://localhost:8083"

THC 2

 thc::Web::Start 8086

 thc::zWay::Init "http://localhost:8083"

Module specific adaptations

The module thc_RandomLight uses a new configuration function to set the geographical location and time zone.

THC 1

 namespace eval thc_RandomLight {
   set Longitude 6.8250
   set Latitude 47.1013
   set Zone "auto"

   Define LightLiv,state         -time {7.2 $SunriseT-0.3 $SunsetT+0.0 21.5} -min_interval 0.30 -probability_on 0.2
   ...

THC 2

 	namespace eval thc::RandomLight {
   Configure -longitude 6.8250 -latitude 47.1013 -zone "auto"

   Define LightLiv,state         -time {7.2 $SunriseT-0.3 $SunsetT+0.0 21.5} -min_interval 0.30 -probability_on 0.2
 ...