allow access to device verification function

This commit is contained in:
Kilian Bracher 2024-06-27 02:22:01 +02:00
parent fa9ab6a252
commit c88b00dfe1
Signed by: k.bracher
SSH Key Fingerprint: SHA256:mXpyZkK7RDiJ7qeHCKJX108woM0cl5TrCvNBJASu6lM
2 changed files with 12 additions and 24 deletions

View File

@ -1,5 +1,4 @@
#include "DS2482_HAL.h" #include "DS2482_HAL.h"
#include "errors.h"
#include <stdint.h> #include <stdint.h>
static I2C_HandleTypeDef* hi2c; static I2C_HandleTypeDef* hi2c;
@ -188,7 +187,7 @@ static uint8_t crc8;
// Setup the search to find the device type 'family_code' on the next call // Setup the search to find the device type 'family_code' on the next call
// to OWNext() if it is present. // to OWNext() if it is present.
// //
static void OWTargetSetup(uint8_t family_code) { [[maybe_unused]] static void OWTargetSetup(uint8_t family_code) {
int i; int i;
// set the search state to find SearchFamily type devices // set the search state to find SearchFamily type devices
@ -204,7 +203,7 @@ static void OWTargetSetup(uint8_t family_code) {
// Setup the search to skip the current device type on the next call // Setup the search to skip the current device type on the next call
// to OWNext(). // to OWNext().
// //
static void OWFamilySkipSetup() { [[maybe_unused]] static void OWFamilySkipSetup() {
// set the Last discrepancy to last family discrepancy // set the Last discrepancy to last family discrepancy
LastDiscrepancy = LastFamilyDiscrepancy; LastDiscrepancy = LastFamilyDiscrepancy;
LastFamilyDiscrepancy = 0; LastFamilyDiscrepancy = 0;
@ -413,21 +412,16 @@ static inline bool OWNext() {
return OWSearch(); return OWSearch();
} }
//--------------------------------------------------------------------------
// Verify the device with the ROM number in ROM_NO buffer is present.
// Return true : device verified present
// false : device not present
//
static bool OWVerify() {
uint8_t rom_backup[8];
int i, rslt, ld_backup, ldf_backup, lfd_backup;
// keep a backup copy of the current state // Verify the device with the ROM number in ROM_NO buffer is present.
for (i = 0; i < 8; i++) HAL_StatusTypeDef ds2482_1w_verify_device(uint64_t device, bool* present) {
uint8_t rom_backup[8];
int i, rslt;
for (int i = 0; i < 8; i++) {
ROM_NO[i] = (device >> (i * 8)) & 0xFF;
rom_backup[i] = ROM_NO[i]; rom_backup[i] = ROM_NO[i];
ld_backup = LastDiscrepancy; }
ldf_backup = LastDeviceFlag;
lfd_backup = LastFamilyDiscrepancy;
// set search to find the same device // set search to find the same device
LastDiscrepancy = 64; LastDiscrepancy = 64;
@ -444,14 +438,7 @@ static bool OWVerify() {
} }
} else } else
rslt = false; rslt = false;
// restore the search state
for (i = 0; i < 8; i++)
ROM_NO[i] = rom_backup[i];
LastDiscrepancy = ld_backup;
LastDeviceFlag = ldf_backup;
LastFamilyDiscrepancy = lfd_backup;
// return the result of the verify // return the result of the verify
return rslt; return rslt;
} }

View File

@ -47,5 +47,6 @@ HAL_StatusTypeDef ds2482_1w_read_byte(uint8_t* byte);
HAL_StatusTypeDef ds2482_1w_triplet(uint8_t dir); HAL_StatusTypeDef ds2482_1w_triplet(uint8_t dir);
HAL_StatusTypeDef ds2482_1w_search(uint16_t max_devices, uint64_t devices[static max_devices]); HAL_StatusTypeDef ds2482_1w_search(uint16_t max_devices, uint64_t devices[static max_devices]);
HAL_StatusTypeDef ds2482_1w_verify_device(uint64_t device, bool* present);
#endif // DS2482_HAL_H #endif // DS2482_HAL_H