You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
107 lines
2.1 KiB
107 lines
2.1 KiB
package common_models
|
|
|
|
import (
|
|
"time"
|
|
)
|
|
|
|
type DeviceData struct {
|
|
DeviceId string
|
|
Name string
|
|
ThingId string
|
|
StructId int
|
|
TaskId string
|
|
AcqTime time.Time
|
|
RealTime time.Time
|
|
ErrCode int
|
|
Raw map[string]any
|
|
RawUnit map[string]string
|
|
DeviceInfo DeviceInfo
|
|
DimensionId string
|
|
//数据类型 常见有 comm="" ,RawTypeVib="vib"
|
|
DataType string
|
|
}
|
|
|
|
func (d *DeviceData) GetVibrationData() VibrationData {
|
|
vibData := VibrationData{}
|
|
if d.DataType == RawTypeVib {
|
|
if v, ok := d.Raw["filterFreq"]; ok {
|
|
if vv, ok := v.(float64); ok {
|
|
vibData.FilterFreq = vv
|
|
}
|
|
}
|
|
|
|
if v, ok := d.Raw["sampleFreq"]; ok {
|
|
if vv, ok := v.(float64); ok {
|
|
vibData.SampleFreq = vv
|
|
}
|
|
}
|
|
|
|
if v, ok := d.Raw["gainAmplifier"]; ok {
|
|
if vv, ok := v.(float64); ok {
|
|
vibData.GainAmplifier = byte(vv)
|
|
}
|
|
}
|
|
|
|
if v, ok := d.Raw["version"]; ok {
|
|
if vv, ok := v.(float64); ok {
|
|
vibData.Version = byte(vv)
|
|
}
|
|
}
|
|
|
|
if v, ok := d.Raw["triggerType"]; ok {
|
|
if vv, ok := v.(float64); ok {
|
|
vibData.TriggerType = byte(vv)
|
|
}
|
|
}
|
|
|
|
if v, ok := d.Raw["physicalvalue"]; ok {
|
|
|
|
if vSlice, ok := v.([]any); ok {
|
|
for _, vObj := range vSlice {
|
|
if vv, ok := vObj.(float64); ok {
|
|
vibData.Data = append(vibData.Data, vv)
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
//去直流
|
|
if len(vibData.Data) > 0 {
|
|
avg := func(dataArray []float64) float64 {
|
|
sum := 0.0
|
|
for _, f := range dataArray {
|
|
sum += f
|
|
}
|
|
return sum / float64(len(dataArray))
|
|
}(vibData.Data) //common_calc.GetAvg(vibData.Data)
|
|
|
|
for i := 0; i < len(vibData.Data); i++ {
|
|
vibData.Data[i] = vibData.Data[i] - avg
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
return vibData
|
|
}
|
|
|
|
// VibrationData 振动数据
|
|
type VibrationData struct {
|
|
Version byte
|
|
SampleFreq float64
|
|
FilterFreq float64
|
|
GainAmplifier byte
|
|
TriggerType byte
|
|
Data []float64 // 原始波形数据
|
|
Unit string
|
|
}
|
|
|
|
func (v *VibrationData) FormatParams() map[string]any {
|
|
return map[string]any{
|
|
"sampleFreq": v.SampleFreq,
|
|
"version": v.Version,
|
|
"filterFreq": v.FilterFreq,
|
|
"gainAmplifier": v.GainAmplifier,
|
|
"triggerType": v.TriggerType,
|
|
}
|
|
}
|
|
|