1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
/*
* RemoteSensor.cpp
*
* Created on: 23 Jul 2019
* Author: David
*/
#include "RemoteSensor.h"
#if SUPPORT_CAN_EXPANSION
#include "CAN/CanMessageGenericConstructor.h"
#include "CanMessageBuffer.h"
constexpr uint32_t RemoteTemperatureTimeoutMillis = 1000;
RemoteSensor::RemoteSensor(unsigned int sensorNum, CanAddress pBoardAddress) noexcept
: TemperatureSensor(sensorNum, "remote"), boardAddress(pBoardAddress)
{
}
GCodeResult RemoteSensor::Configure(GCodeBuffer& gb, const StringRef& reply)
{
bool seen = false;
TryConfigureSensorName(gb, seen);
CanMessageGenericConstructor cons(M308Params);
if (!cons.PopulateFromCommand(gb, reply))
{
return GCodeResult::error;
}
const GCodeResult ret = cons.SendAndGetResponse(CanMessageType::m308, boardAddress, reply);
if ((ret == GCodeResult::ok || ret == GCodeResult::warning) && StringStartsWith(reply.c_str(), "type "))
{
// It's just a query for the sensor parameters, so prefix the sensor number and name
String<StringLength50> temp;
temp.printf("Sensor %u ", GetSensorNumber());
if (GetSensorName() != nullptr)
{
temp.catf("(%s) ", GetSensorName());
}
reply.Insert(0, temp.c_str());
}
return ret;
}
void RemoteSensor::UpdateRemoteTemperature(CanAddress src, const CanSensorReport& report) noexcept
{
if (src == boardAddress)
{
SetResult(report.temperature, (TemperatureError)report.errorCode);
}
}
#endif
// End
|