From 376727840c73607ff07433c4e58e6f9b036d3f62 Mon Sep 17 00:00:00 2001 From: William Clark Date: Mon, 5 Dec 2022 13:12:17 +0000 Subject: [PATCH] CJC --- config.toml | 12 ++-------- core/th7/service.go | 56 ++++++++++++++++++++++++++++++--------------- 2 files changed, 40 insertions(+), 28 deletions(-) diff --git a/config.toml b/config.toml index d74183b..632b457 100644 --- a/config.toml +++ b/config.toml @@ -1,21 +1,13 @@ [TH7] port = 8080 logfreq = 60 -debug = true [DB] type = "sqlite3" path = "test.db" -[Channel_1] -type = 'k' +[Channel_2] +type = 'K' unit = 'C' gain = 106.8 offset = 2.4 - -[Channel_5] -type = 'N' -unit = 'F' - -[Channel_6] -type = 'S' \ No newline at end of file diff --git a/core/th7/service.go b/core/th7/service.go index 97ebe06..b28827f 100644 --- a/core/th7/service.go +++ b/core/th7/service.go @@ -3,6 +3,8 @@ package th7 import ( "fmt" "log" + temp_data "th7/data/temperature" + "th7/temperature" "th7/thermocouple" "time" ) @@ -79,30 +81,48 @@ func startCacheService(t *TH7Adapter) { for k := range t.cfg.Channels { tc := t.cfg.Channels[k].Thermo + + // if we can apply CJC with this configuration ... if thermocouple.WithinTemperatureRange(tc, pcb_temperature) { - // if we can apply CJC with this configuration ... + cjc_uv, err := thermocouple.UV(tc, pcb_temperature) if err != nil { log.Println("Error doing CJC", err) - } else { - - data[k].Value -= cjc_uv - data[k].Unit = t.cfg.Channels[k].Unit - - new_value_c, err := thermocouple.C(tc, data[k].Value) - if err != nil { - log.Println("Error converting UV to C", t.cfg.Channels[k], data[k].Value) - } - - //TODO: different temp units - data[k].Value = new_value_c + cjc_uv = 0.0 + } + + data[k].Value -= cjc_uv + data[k].Unit = t.cfg.Channels[k].Unit + data[k].Id = t.cfg.Channels[k].Id + + } + // CJC can not be applied + // board temp out of range for specified thermocouple type + // perhaps just subtract board temperature? dont know + //fmt.Println("No valid CJC for Channel", t.cfg.Channels[k].Id) + + // if the temperature unit is "None", it is probably for UV only. + // so do not convert it to a value using t/c polys + if data[k].Unit != temp_data.None { + new_value_c, err := thermocouple.C(tc, data[k].Value) + if err != nil { + log.Println("Error converting UV to C", t.cfg.Channels[k].Id, data[k].Value) + new_value_c = data[k].Value + } + + data[k].Value = new_value_c + + // It is celsius by default + switch data[k].Unit { + + case temp_data.F: + data[k].Value = temperature.F(temp_data.C, data[k].Value) + + case temp_data.K: + data[k].Value = temperature.K(temp_data.C, data[k].Value) + } - } else { - // CJC can not be applied - // board temp out of range for specified thermocouple type - // perhaps just subtract board temperature? dont know - fmt.Println("No valid CJC for Channel", t.cfg.Channels[k].Id) } }