-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sht41: properly format serial number
- Loading branch information
Showing
6 changed files
with
108 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright (c) 2024, Open Control Systems authors | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <cstdint> | ||
|
||
#define SHT_SENSOR_SERIAL_NUMBER_LEN 4 | ||
|
||
#define SHT_SENSOR_SERIAL_NUMBER_STR "%02X:%02X:%02X:%02X" | ||
|
||
#define SHT_SENSOR_SERIAL_NUMBER_TO_STR(serial_number) \ | ||
serial_number[0], serial_number[1], serial_number[2], serial_number[3] | ||
|
||
namespace ocs { | ||
namespace sensor { | ||
namespace sht41 { | ||
|
||
//! SHT sensor serial number, MSB byte order. | ||
using SerialNumber = uint8_t[SHT_SENSOR_SERIAL_NUMBER_LEN]; | ||
|
||
} // namespace sht41 | ||
} // namespace sensor | ||
} // namespace ocs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright (c) 2024, Open Control Systems authors | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
#include <cstdio> | ||
#include <cstring> | ||
|
||
#include "freertos/FreeRTOSConfig.h" | ||
|
||
#include "ocs_sensor/sht41/serial_number_to_str.h" | ||
|
||
namespace ocs { | ||
namespace sensor { | ||
namespace sht41 { | ||
|
||
serial_number_to_str::serial_number_to_str(const SerialNumber& serial_number) { | ||
memset(buf_, 0, sizeof(buf_)); | ||
|
||
configASSERT(snprintf(buf_, sizeof(buf_), SHT_SENSOR_SERIAL_NUMBER_STR, | ||
SHT_SENSOR_SERIAL_NUMBER_TO_STR(serial_number)) | ||
== str_length); | ||
} | ||
|
||
const char* serial_number_to_str::c_str() const { | ||
return buf_; | ||
} | ||
|
||
} // namespace sht41 | ||
} // namespace sensor | ||
} // namespace ocs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright (c) 2024, Open Control Systems authors | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <cstring> | ||
|
||
#include "ocs_core/noncopyable.h" | ||
#include "ocs_sensor/sht41/serial_number.h" | ||
|
||
namespace ocs { | ||
namespace sensor { | ||
namespace sht41 { | ||
|
||
//! Format sensor serial number to string. | ||
class serial_number_to_str : public core::NonCopyable<> { | ||
public: | ||
static const unsigned str_length = strlen("AA:BB:CC:DD"); | ||
|
||
//! Initialize. | ||
serial_number_to_str(const SerialNumber& serial_number); | ||
|
||
//! Return formatted serial number. | ||
const char* c_str() const; | ||
|
||
private: | ||
char buf_[str_length + 1]; | ||
}; | ||
|
||
} // namespace sht41 | ||
} // namespace sensor | ||
} // namespace ocs |