@@ -145,20 +145,24 @@ void write_probe(const char* when)
145145 constexpr uint32_t RESTORE_INTERVAL_MS {20 };
146146
147147 const std::vector<uint8_t > pattern{0x5A , 0xA5 };
148- const bool wrote = uhf.writeBank (m5::uhf::Bank::User, 0 , pattern.data (), static_cast <uint16_t >(pattern.size ()));
149- M5_LOGI (" Writing one word %s: %s" , when, wrote ? " allowed" : " refused" );
150- lcd.printf (" write %s: %s\n " , when, wrote ? " ok" : " no" );
148+ const auto wrote = uhf.writeBank (m5::uhf::Bank::User, 0 , pattern.data (), static_cast <uint16_t >(pattern.size ()));
149+ // A tag that says no has not been written to; one that says nothing may have been, which is
150+ // a different thing to be told and the reason is what tells them apart
151+ M5_LOGI (" Writing one word %s: %s" , when, wrote ? " allowed" : m5::uhf::reasonAsString (wrote.error ()));
152+ lcd.printf (" write %s: %s\n " , when, wrote ? " ok" : m5::uhf::tagUnchanged (wrote.error ()) ? " no" : " ?" );
151153 if (!wrote) {
152154 return ;
153155 }
154156 const std::vector<uint8_t > zero{0x00 , 0x00 };
157+ m5::uhf::Result restored{m5::stl::unexpected<m5::uhf::Reason>{m5::uhf::Reason::NoAnswer}};
155158 for (uint8_t i = 0 ; i < RESTORE_ATTEMPTS ; ++i) {
156- if (uhf.writeBank (m5::uhf::Bank::User, 0 , zero.data (), static_cast <uint16_t >(zero.size ()))) {
159+ restored = uhf.writeBank (m5::uhf::Bank::User, 0 , zero.data (), static_cast <uint16_t >(zero.size ()));
160+ if (restored) {
157161 return ;
158162 }
159163 m5::utility::delay (RESTORE_INTERVAL_MS );
160164 }
161- M5_LOGE (" FAILED TO RESTORE the word; the tag still holds 5AA5" );
165+ M5_LOGE (" FAILED TO RESTORE the word (%s) ; the tag still holds 5AA5" , m5::uhf::reasonAsString (restored. error ()) );
162166}
163167
164168// ! @brief Address the tag again with a password, since that is what decides the state it is in
@@ -183,9 +187,10 @@ bool set_access_password(const m5::uhf::Tag& tag, const uint32_t password)
183187{
184188 const std::vector<uint8_t > data{static_cast <uint8_t >(password >> 24 ), static_cast <uint8_t >(password >> 16 ),
185189 static_cast <uint8_t >(password >> 8 ), static_cast <uint8_t >(password)};
186- if (!uhf.writeBank (m5::uhf::Bank::Reserved, ACCESS_PASSWORD_WORD , data.data (),
187- static_cast <uint16_t >(data.size ()))) {
188- M5_LOGE (" Failed to store the access password %08X" , password);
190+ const auto stored =
191+ uhf.writeBank (m5::uhf::Bank::Reserved, ACCESS_PASSWORD_WORD , data.data (), static_cast <uint16_t >(data.size ()));
192+ if (!stored) {
193+ M5_LOGE (" Failed to store the access password %08X: %s" , password, m5::uhf::reasonAsString (stored.error ()));
189194 lcd.println (" password: failed" );
190195 return false ;
191196 }
@@ -215,10 +220,11 @@ bool set_access_password(const m5::uhf::Tag& tag, const uint32_t password)
215220bool set_lock (const m5::uhf::LockTarget target, const m5::uhf::LockAction action, const char * what)
216221{
217222 const std::vector<m5::uhf::LockSetting> settings{m5::uhf::LockSetting (target, action)};
218- const bool ok = uhf.lock (settings);
219- M5_LOGI (" %s: %s" , what, ok ? " the tag carried it out" : " failed" );
220- lcd.printf (" %s: %s\n " , what, ok ? " ok" : " NG" );
221- return ok;
223+ const auto result = uhf.lock (settings);
224+ // EPC Gen2 gives no way to read a tag's lock bits, so what the reader says is all there is
225+ M5_LOGI (" %s: %s" , what, result ? " the tag carried it out" : m5::uhf::reasonAsString (result.error ()));
226+ lcd.printf (" %s: %s\n " , what, result ? " ok" : " NG" );
227+ return static_cast <bool >(result);
222228}
223229
224230void lock_and_open (m5::uhf::Tag& tag)
0 commit comments