mirror of
https://github.com/bitlair/bitlair_doorduino.git
synced 2025-05-13 12:20:07 +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;
|
uint16_t startaddr = i * STORAGESIZE;
|
||||||
bool sameaddr = true;
|
bool sameaddr = true;
|
||||||
|
bool isempty = true;
|
||||||
for (uint16_t j = 0; j < ADDRSIZE; j++)
|
for (uint16_t j = 0; j < ADDRSIZE; j++)
|
||||||
{
|
{
|
||||||
uint8_t eeprombyte = EEPROM.read(startaddr + j);
|
uint8_t eeprombyte = EEPROM.read(startaddr + j);
|
||||||
|
if (isempty && eeprombyte != 0xFF)
|
||||||
|
isempty = false;
|
||||||
|
|
||||||
if (eeprombyte != addr[j])
|
if (eeprombyte != addr[j])
|
||||||
{
|
{
|
||||||
sameaddr = false;
|
sameaddr = false;
|
||||||
|
@ -227,6 +231,9 @@ bool GetButtonSecret(uint8_t* addr, uint8_t* secret)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isempty)
|
||||||
|
continue;
|
||||||
|
|
||||||
if (sameaddr)
|
if (sameaddr)
|
||||||
{
|
{
|
||||||
Serialprintf("DEBUG: getting secret from slot %i\n", i);
|
Serialprintf("DEBUG: getting secret from slot %i\n", i);
|
||||||
|
@ -243,6 +250,34 @@ bool GetButtonSecret(uint8_t* addr, uint8_t* secret)
|
||||||
return false;
|
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)
|
bool AuthenticateButton(uint8_t* addr, uint8_t* secret)
|
||||||
{
|
{
|
||||||
uint8_t mac_from_ibutton[SHA1SIZE];
|
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_ADD_BUTTON "add_button"
|
||||||
#define CMD_REMOVE_BUTTON "remove_button"
|
#define CMD_REMOVE_BUTTON "remove_button"
|
||||||
|
#define CMD_LIST_BUTTONS "list_buttons"
|
||||||
|
|
||||||
void ParseCMD(char* cmdbuf, uint8_t cmdbuffill)
|
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 isadd = strncmp(CMD_ADD_BUTTON, cmdbuf, strlen(CMD_ADD_BUTTON)) == 0;
|
||||||
bool isremove = strncmp(CMD_REMOVE_BUTTON, cmdbuf, strlen(CMD_REMOVE_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)
|
if (isadd || isremove)
|
||||||
{
|
{
|
||||||
|
@ -428,6 +465,10 @@ void ParseCMD(char* cmdbuf, uint8_t cmdbuffill)
|
||||||
RemoveButton(addr);
|
RemoveButton(addr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (islist)
|
||||||
|
{
|
||||||
|
ListButtons();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Serial.println("Unknown command");
|
Serial.println("Unknown command");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue