mirror of
https://github.com/bitlair/bitlair_doorduino.git
synced 2025-05-13 20:20:08 +02:00
added: command to list button ids
This commit is contained in:
parent
8ed6f9a983
commit
f5a3d726b4
1 changed files with 41 additions and 0 deletions
|
@ -217,9 +217,13 @@ bool GetButtonSecret(uint8_t* addr, uint8_t* secret)
|
|||
{
|
||||
uint16_t startaddr = i * STORAGESIZE;
|
||||
bool sameaddr = true;
|
||||
bool isempty = true;
|
||||
for (uint16_t j = 0; j < ADDRSIZE; j++)
|
||||
{
|
||||
uint8_t eeprombyte = EEPROM.read(startaddr + j);
|
||||
if (isempty && eeprombyte != 0xFF)
|
||||
isempty = false;
|
||||
|
||||
if (eeprombyte != addr[j])
|
||||
{
|
||||
sameaddr = false;
|
||||
|
@ -227,6 +231,9 @@ bool GetButtonSecret(uint8_t* addr, uint8_t* secret)
|
|||
}
|
||||
}
|
||||
|
||||
if (isempty)
|
||||
continue;
|
||||
|
||||
if (sameaddr)
|
||||
{
|
||||
Serialprintf("DEBUG: getting secret from slot %i\n", i);
|
||||
|
@ -243,6 +250,34 @@ bool GetButtonSecret(uint8_t* addr, uint8_t* secret)
|
|||
return false;
|
||||
}
|
||||
|
||||
void ListButtons()
|
||||
{
|
||||
Serial.println("button list start");
|
||||
|
||||
for (uint16_t i = 0; i < EEPROMSIZE / STORAGESIZE; i++)
|
||||
{
|
||||
uint16_t startaddr = i * STORAGESIZE;
|
||||
uint8_t buttonid[ADDRSIZE];
|
||||
bool isempty = true;
|
||||
for (uint16_t j = 0; j < ADDRSIZE; j++)
|
||||
{
|
||||
uint8_t eeprombyte = EEPROM.read(startaddr + j);
|
||||
if (isempty && eeprombyte != 0xFF)
|
||||
isempty = false;
|
||||
|
||||
buttonid[j] = eeprombyte;
|
||||
}
|
||||
|
||||
if (isempty)
|
||||
continue;
|
||||
|
||||
Serialprintf("button: ");
|
||||
for (uint16_t j = 0; j < ADDRSIZE; j++)
|
||||
Serialprintf("%02x", buttonid[j]);
|
||||
Serialprintf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
bool AuthenticateButton(uint8_t* addr, uint8_t* secret)
|
||||
{
|
||||
uint8_t mac_from_ibutton[SHA1SIZE];
|
||||
|
@ -373,6 +408,7 @@ bool GetHexWordFromCMD(char* cmdbuf, uint8_t cmdbuffill, uint8_t* wordpos, uint8
|
|||
|
||||
#define CMD_ADD_BUTTON "add_button"
|
||||
#define CMD_REMOVE_BUTTON "remove_button"
|
||||
#define CMD_LIST_BUTTONS "list_buttons"
|
||||
|
||||
void ParseCMD(char* cmdbuf, uint8_t cmdbuffill)
|
||||
{
|
||||
|
@ -381,6 +417,7 @@ void ParseCMD(char* cmdbuf, uint8_t cmdbuffill)
|
|||
|
||||
bool isadd = strncmp(CMD_ADD_BUTTON, cmdbuf, strlen(CMD_ADD_BUTTON)) == 0;
|
||||
bool isremove = strncmp(CMD_REMOVE_BUTTON, cmdbuf, strlen(CMD_REMOVE_BUTTON)) == 0;
|
||||
bool islist = strncmp(CMD_LIST_BUTTONS, cmdbuf, strlen(CMD_LIST_BUTTONS)) == 0;
|
||||
|
||||
if (isadd || isremove)
|
||||
{
|
||||
|
@ -428,6 +465,10 @@ void ParseCMD(char* cmdbuf, uint8_t cmdbuffill)
|
|||
RemoveButton(addr);
|
||||
}
|
||||
}
|
||||
else if (islist)
|
||||
{
|
||||
ListButtons();
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("Unknown command");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue