package crm3000 import ( "encoding/hex" "io/ioutil" "log" "testing" "time" "github.com/stretchr/testify/require" ) func TestMessageNewFormat(t *testing.T) { hexBytes, err := ioutil.ReadFile("testdata/payload_imei_v1.0.2.hex") require.Nil(t, err) data, err := hex.DecodeString(string(hexBytes)) require.Nil(t, err) msg, err := Decode(data) require.Nil(t, err) require.NotNil(t, msg) // XXX timestamps are not sent with this real payload require.Equal(t, time.Unix(0, 0), msg.Timestamp) require.Equal(t, time.Duration(0), msg.Timedelta) require.Len(t, msg.BatteryVoltage, 10) require.ElementsMatch(t, msg.BatteryVoltage, []float32{3.614, 3.615, 3.614, 3.615, 3.616, 3.615, 3.615, 3.616, 3.615, 3.616}) require.Len(t, msg.PT1000Temperature, 10) require.ElementsMatch(t, msg.PT1000Temperature, []float32{22.925, 22.874, 22.965, 22.94, 22.957, 23.008, 22.98, 23.031, 23.02, 23.082}) require.Len(t, msg.Accelero, 10) require.ElementsMatch(t, msg.Accelero, []AcceleroValue{{2, 0, 192}, {2, 1, 191}, {2, 1, 193}, {2, 1, 191}, {2, 1, 192}, {2, 0, 191}, {2, 2, 192}, {3, 1, 192}, {2, 1, 192}, {2, 1, 192}, }, ) require.Len(t, msg.CPUTemperature, 10) require.ElementsMatch(t, msg.CPUTemperature, []float32{22, 22.25, 22.25, 22.25, 22.25, 22.25, 22.25, 22.25, 22.25, 22.25}, ) require.Len(t, msg.CapTouch, 10) require.ElementsMatch(t, msg.CapTouch, []uint16{81, 81, 81, 81, 81, 81, 81, 81, 81, 81}) require.Equal(t, "863703039106237", msg.IMEI) log.Printf("fw %+v", msg.SerialAndFwVersion) }