Skip to content

Commit

Permalink
Add bounds checking to sendSensorTemp()
Browse files Browse the repository at this point in the history
Plus some minor code & style cleanups.
For #1859
  • Loading branch information
crankyoldgit committed Aug 23, 2022
1 parent 5396d5d commit dd860e7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
33 changes: 17 additions & 16 deletions src/ir_Argo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ const uint16_t kArgoOneSpace = 2200;
const uint16_t kArgoZeroSpace = 900;
const uint32_t kArgoGap = kDefaultMessageGap; // Made up value. Complete guess.

const uint8_t kArgoSensorCheck = 52; // Part of the sensor message check calc.
const uint8_t kArgoSensorFixed = 0b011;

using irutils::addBoolToString;
using irutils::addIntToString;
using irutils::addLabeledString;
Expand Down Expand Up @@ -64,23 +67,21 @@ void IRArgoAC::send(const uint16_t repeat) {

/// Send current room temperature for the iFeel feature as a silent IR
/// message (no acknowledgement from the device).
/// @param[in] temp The temperature in degrees celsius.
/// @param[in] degrees The temperature in degrees celsius.
/// @param[in] repeat Nr. of times the message will be repeated.
void IRArgoAC::sendSensorTemp(const uint8_t temp, const uint16_t repeat) {
const uint8_t tempc = temp - kArgoTempDelta;
const uint8_t check = 52 + tempc;
const uint8_t end = 0b011;

ArgoProtocol data;
_stateReset(&data);
// data.raw[2] = (tempc << 3) | (check >> 5);
data.SensorT = tempc;
data.CheckHi = check >> 5;
// data.raw[3] = (check << 3) | end;
data.CheckLo = check;
data.Fixed = end;
_checksum(&data);
_irsend.sendArgo(data.raw, kArgoStateLength, repeat);
void IRArgoAC::sendSensorTemp(const uint8_t degrees, const uint16_t repeat) {
const uint8_t temp = std::max(std::min(degrees, kArgoMaxRoomTemp),
kArgoTempDelta) - kArgoTempDelta;
const uint8_t check = kArgoSensorCheck + temp;

ArgoProtocol data;
_stateReset(&data);
data.SensorT = temp;
data.CheckHi = check >> 5;
data.CheckLo = check;
data.Fixed = kArgoSensorFixed;
_checksum(&data);
_irsend.sendArgo(data.raw, kArgoStateLength, repeat);
}
#endif // SEND_ARGO

Expand Down
3 changes: 2 additions & 1 deletion src/ir_Argo.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright 2017 Schmolders
// Copyright 2022 crankyoldgit
/// @file
/// @brief Support for Argo Ulisse 13 DCI Mobile Split ACs.

Expand Down Expand Up @@ -145,7 +146,7 @@ class IRArgoAC {

#if SEND_ARGO
void send(const uint16_t repeat = kArgoDefaultRepeat);
void sendSensorTemp(const uint8_t temp,
void sendSensorTemp(const uint8_t degrees,
const uint16_t repeat = kArgoDefaultRepeat);
/// Run the calibration to calculate uSec timing offsets for this platform.
/// @return The uSec timing offset needed per modulation of the IR Led.
Expand Down

0 comments on commit dd860e7

Please sign in to comment.