Commit c2215294c76ebb77e6f1e74232f2908ebb1d9951

Authored by Jeroen88
1 parent 39060413

Reorder EasyOpenTherm.h by moving all enum class constants below, so the public …

…class member functions of OpenTherm are more visible, because this is the main API!
Showing 1 changed file with 85 additions and 61 deletions
src/EasyOpenTherm.h
@@ -28,8 +28,8 @@ @@ -28,8 +28,8 @@
28 #include <Arduino.h> 28 #include <Arduino.h>
29 29
30 30
31 -class OTDataLinkLayer; // Foreward declaration  
32 -class OTPhysicalLayer; // Foreward declaration 31 +class OTDataLinkLayer; // Forward declaration
  32 +class OTPhysicalLayer; // Forward declaration
33 33
34 34
35 class OpenTherm { 35 class OpenTherm {
@@ -47,6 +47,46 @@ public: @@ -47,6 +47,46 @@ public:
47 uint8_t & secondaryFlags); 47 uint8_t & secondaryFlags);
48 48
49 49
  50 + enum class READ_WRITE_DATA_ID; // Forward declaration of DATA-IDs that can be used to write the MSB (Most ignificant Byte) to the boiler and read the LSB from it.
  51 + enum class READ_DATA_ID; // Forward declaration of DATA-IDs that can be used to read values from the boiler
  52 + enum class WRITE_DATA_ID; // Forward declaration of DATA-IDs that can be used to write values to the boiler
  53 + enum class ERROR_CODES; // Forward declaration of ERROR_CODES, like timeouts, returned through the physical layer
  54 +
  55 +
  56 + bool read(READ_DATA_ID msgID,
  57 + uint16_t & value);
  58 +
  59 + bool read(READ_DATA_ID msgID,
  60 + int16_t & value);
  61 +
  62 + bool read(READ_DATA_ID msgID,
  63 + uint8_t & valueMSB,
  64 + uint8_t & valueLSB);
  65 +
  66 + bool read(READ_DATA_ID msgID,
  67 + int8_t & valueMSB,
  68 + int8_t & valueLSB);
  69 +
  70 + bool read(READ_DATA_ID msgID,
  71 + float & value);
  72 +
  73 + bool write(WRITE_DATA_ID msgID,
  74 + uint16_t value);
  75 +
  76 + bool write(WRITE_DATA_ID msgID,
  77 + uint8_t valueMSB,
  78 + uint8_t valueLSB);
  79 +
  80 + bool write(WRITE_DATA_ID msgID,
  81 + float value);
  82 +
  83 + bool readWrite(READ_WRITE_DATA_ID msgID,
  84 + uint8_t valueMSB,
  85 + uint8_t & valueLSB);
  86 +
  87 + ERROR_CODES error();
  88 +
  89 +
50 enum class READ_WRITE_DATA_ID { 90 enum class READ_WRITE_DATA_ID {
51 // Class 1 : Control and Status Information 91 // Class 1 : Control and Status Information
52 STATUS = 0, // flag8, flag8 Mandatory; Primary status, secondary status 92 STATUS = 0, // flag8, flag8 Mandatory; Primary status, secondary status
@@ -222,6 +262,8 @@ public: @@ -222,6 +262,8 @@ public:
222 }; 262 };
223 263
224 264
  265 + // Flags used by ::status(primaryFlags, secondaryFlags); The flags starting with PRIMARY_ are sent from the thermostat to the boiler and the flgas starting with SECONDARY_ are received
  266 + // from the boiler
225 enum class STATUS_FLAGS { 267 enum class STATUS_FLAGS {
226 // Primary device is MSB 268 // Primary device is MSB
227 PRIMARY_CH_ENABLE = (0b00000001), // CH is Central Heating 269 PRIMARY_CH_ENABLE = (0b00000001), // CH is Central Heating
@@ -241,6 +283,18 @@ public: @@ -241,6 +283,18 @@ public:
241 }; 283 };
242 284
243 285
  286 + // Configuration flags returned by calling ::read(OpenTherm::READ_DATA_ID::SECONDARY_CONFIGURATION, configurationFlags, memberID);
  287 + enum class CONFIGURATION_FLAGS {
  288 + SECONDARY_DHW_PRESENT = (0b00000001),
  289 + SECONDARY_CONTROL_TYPE = (0b00000010),
  290 + SECONDARY_COOLING = (0b00000100),
  291 + SECONDARY_DHW = (0b00001000),
  292 + SECONDARY_LOW_OFF_PUMP_CTRL = (0b00010000),
  293 + SECONDARY_CH2_PRESENT = (0b00100000),
  294 + };
  295 +
  296 +
  297 + // A few known member IDs returned by calling ::read(OpenTherm::READ_DATA_ID::SECONDARY_CONFIGURATION, configurationFlags, memberID);
244 enum MEMBER_IDS: uint8_t { // May be extended with other manufacturer OpenTherm member IDs. Maybe incorrect 298 enum MEMBER_IDS: uint8_t { // May be extended with other manufacturer OpenTherm member IDs. Maybe incorrect
245 AWB = 2, 299 AWB = 2,
246 BRINK = 2, 300 BRINK = 2,
@@ -266,6 +320,7 @@ public: @@ -266,6 +320,7 @@ public:
266 }; 320 };
267 321
268 322
  323 + // Fault flags returned by calling ::read(OpenTherm::READ_DATA_ID::FAULT_FLAGS, faultFlags, OEMFaultCode);
269 enum class FAULT_FLAGS { 324 enum class FAULT_FLAGS {
270 SERVICE_REQUEST = (0b00000001), 325 SERVICE_REQUEST = (0b00000001),
271 LOCKOUT_RESET = (0b00000010), 326 LOCKOUT_RESET = (0b00000010),
@@ -276,16 +331,7 @@ public: @@ -276,16 +331,7 @@ public:
276 }; 331 };
277 332
278 333
279 - enum class CONFIGURATION_FLAGS {  
280 - SECONDARY_DHW_PRESENT = (0b00000001),  
281 - SECONDARY_CONTROL_TYPE = (0b00000010),  
282 - SECONDARY_COOLING = (0b00000100),  
283 - SECONDARY_DHW = (0b00001000),  
284 - SECONDARY_LOW_OFF_PUMP_CTRL = (0b00010000),  
285 - SECONDARY_CH2_PRESENT = (0b00100000),  
286 - };  
287 -  
288 - 334 + // Remote parameter flags returned by calling ::read(OpenTherm::READ_DATA_ID::REMOTE_PARAMETER, remoteParameterTEFlags, remoteParameterRWFlags);
289 enum class REMOTE_PARAMETER_FLAGS { 335 enum class REMOTE_PARAMETER_FLAGS {
290 TRANSFER_ENABLE_DHW_SETPOINT = (0b00000001), 336 TRANSFER_ENABLE_DHW_SETPOINT = (0b00000001),
291 TRANSFER_ENABLE_MAX_CH_SETPOINT = (0b00000010), 337 TRANSFER_ENABLE_MAX_CH_SETPOINT = (0b00000010),
@@ -295,18 +341,23 @@ public: @@ -295,18 +341,23 @@ public:
295 }; 341 };
296 342
297 343
  344 +
  345 + // Remote parameter flags returned by calling ::read(OpenTherm::READ_DATA_ID::REMOTE_OVERRIDE_FUNCTION, reserved, remoteOverrideFlags);
298 enum class REMOTE_OVERRIDE_FLAGS { 346 enum class REMOTE_OVERRIDE_FLAGS {
299 MANUAL_CHANGE_PRIORITY = (0b00000001), 347 MANUAL_CHANGE_PRIORITY = (0b00000001),
300 REMOTE_CHANGE_PRIORITY = (0b00000010), 348 REMOTE_CHANGE_PRIORITY = (0b00000010),
301 }; 349 };
302 350
303 351
  352 + // Remote parameter flags returned by calling ::readWrite(OpenTherm::READ_WRITE_DATA_ID::COMMAND_CODE, remoteCommand, cmdResponseCode);
304 enum class REMOTE_COMMANDS { 353 enum class REMOTE_COMMANDS {
305 BLOR = (1), // Boiler Lock-out Reset command 354 BLOR = (1), // Boiler Lock-out Reset command
306 CHWF = (2), // CH water filling 355 CHWF = (2), // CH water filling
307 }; 356 };
308 357
309 358
  359 + // Flags used by ::readWrite(OpenTherm::READ_WRITE_DATA_ID::HVAC_STATUS, primaryFlags, secondaryFlags); The flags starting with PRIMARY_ are sent from the thermostat to the HVAC
  360 + // and the flags starting with SECONDARY_ are received from the HVAC. This is comparable to the ::status() call for a boiler.
310 enum class HVAC_STATUS_FLAGS { 361 enum class HVAC_STATUS_FLAGS {
311 // Primary device is MSB 362 // Primary device is MSB
312 PRIMARY_VENTILATION_ENABLE = (0b00000001), 363 PRIMARY_VENTILATION_ENABLE = (0b00000001),
@@ -347,48 +398,17 @@ public: @@ -347,48 +398,17 @@ public:
347 }; 398 };
348 399
349 400
  401 + // ::error(); returns the result of the latest call to ::read();, ::write(); or ::readWrite();
350 enum class ERROR_CODES { 402 enum class ERROR_CODES {
351 - OK,  
352 - UNKNOWN_DATA_ID,  
353 - INVALID_DATA,  
354 - SEND_TIMEOUT,  
355 - RECEIVE_TIMEOUT,  
356 - PARITY_ERROR,  
357 - UNKNOWN_ERROR, 403 + OK, // Everything is OK
  404 + UNKNOWN_DATA_ID, // The DATA-ID sent by the primary to the secondary is not supported by the secondary
  405 + INVALID_DATA, // The DATA-ID sent by the primary to the secondary is supported but the sent value is out of bounds
  406 + SEND_TIMEOUT, // The primary could not send within timeout period (should not occur if timeouts are reasonable)
  407 + RECEIVE_TIMEOUT, // The secondary did not respond within timeout period
  408 + PARITY_ERROR, // The secondary's response had a parity error
  409 + UNKNOWN_ERROR, // Unknown error (should not occur)
358 }; 410 };
359 411
360 - bool read(READ_DATA_ID msgID,  
361 - uint16_t & value);  
362 -  
363 - bool read(READ_DATA_ID msgID,  
364 - int16_t & value);  
365 -  
366 - bool read(READ_DATA_ID msgID,  
367 - uint8_t & valueMSB,  
368 - uint8_t & valueLSB);  
369 -  
370 - bool read(READ_DATA_ID msgID,  
371 - int8_t & valueMSB,  
372 - int8_t & valueLSB);  
373 -  
374 - bool read(READ_DATA_ID msgID,  
375 - float & value);  
376 -  
377 - bool write(WRITE_DATA_ID msgID,  
378 - uint16_t value);  
379 -  
380 - bool write(WRITE_DATA_ID msgID,  
381 - uint8_t valueMSB,  
382 - uint8_t valueLSB);  
383 -  
384 - bool write(WRITE_DATA_ID msgID,  
385 - float value);  
386 -  
387 - bool readWrite(READ_WRITE_DATA_ID msgID,  
388 - uint8_t valueMSB,  
389 - uint8_t & valueLSB);  
390 -  
391 - ERROR_CODES error();  
392 412
393 private: 413 private:
394 bool _execute(OTDataLinkLayer & data); 414 bool _execute(OTDataLinkLayer & data);
@@ -407,17 +427,8 @@ private: @@ -407,17 +427,8 @@ private:
407 427
408 class OTDataLinkLayer { 428 class OTDataLinkLayer {
409 public: 429 public:
410 - enum class MSG_TYPE {  
411 - PRIMARY_TO_SECONDARY_READ_DATA = (0b0000000UL << 24), // value >> 28 := 0  
412 - PRIMARY_TO_SECONDARY_WRITE_DATA = (0b0010000UL << 24), // value >> 28 := 1  
413 - PRIMARY_TO_SECONDARY_INVALID_DATA = (0b0100000UL << 24), // value >> 28 := 2  
414 - PRIMARY_TO_SECONDARY_RESERVED = (0b0110000UL << 24), // value >> 28 := 3 430 + enum class MSG_TYPE; // Forward declaration
415 431
416 - SECONDARY_TO_PRIMARY_READ_ACK = (0b1000000UL << 24), // value >> 28 := 4  
417 - SECONDARY_TO_PRIMARY_WRITE_ACK = (0b1010000UL << 24), // value >> 28 := 5  
418 - SECONDARY_TO_PRIMARY_DATA_INVALID = (0b1100000UL << 24), // value >> 28 := 6  
419 - SECONDARY_TO_PRIMARY_UNKNOWN_DATA_ID = (0b1110000UL << 24) // value >> 28 := 7  
420 - };  
421 432
422 OTDataLinkLayer(); 433 OTDataLinkLayer();
423 434
@@ -454,6 +465,19 @@ public: @@ -454,6 +465,19 @@ public:
454 465
455 bool unknownDataID(); 466 bool unknownDataID();
456 467
  468 +
  469 + enum class MSG_TYPE {
  470 + PRIMARY_TO_SECONDARY_READ_DATA = (0b0000000UL << 24), // value >> 28 := 0
  471 + PRIMARY_TO_SECONDARY_WRITE_DATA = (0b0010000UL << 24), // value >> 28 := 1
  472 + PRIMARY_TO_SECONDARY_INVALID_DATA = (0b0100000UL << 24), // value >> 28 := 2
  473 + PRIMARY_TO_SECONDARY_RESERVED = (0b0110000UL << 24), // value >> 28 := 3
  474 +
  475 + SECONDARY_TO_PRIMARY_READ_ACK = (0b1000000UL << 24), // value >> 28 := 4
  476 + SECONDARY_TO_PRIMARY_WRITE_ACK = (0b1010000UL << 24), // value >> 28 := 5
  477 + SECONDARY_TO_PRIMARY_DATA_INVALID = (0b1100000UL << 24), // value >> 28 := 6
  478 + SECONDARY_TO_PRIMARY_UNKNOWN_DATA_ID = (0b1110000UL << 24) // value >> 28 := 7
  479 + };
  480 +
457 private: 481 private:
458 uint32_t _frame; 482 uint32_t _frame;
459 483