OpenAccess privlige functions

 

#define PRIV_ACCESS 0 //allowed to enter space
#define PRIV_ADDUSER 1 //allowed to add or remove users
#define PRIV_DOORBELL 2 //allowed to set doorbell mode
#define PRIV_DOORHOLD 3 //allowed to set door hold mode

This has to do with the privilege bits, it defines what a given key has the ability to do.  They are read by:

void read_EE_priv(int index)
{
priv = EEPROM1024.read(((index+1) * entry_size) + 31);//keeps command byte unwritten
return;
}

This reads the given index’s privilege bits into the working global memory (yeah, global variables, sue me).  This is called whenever a user is to be put in global memory or checking to see if the user is present:

boolean user_present(int i)
{
read_EE_priv(i);
if(priv != 0)
{
return 1;
}
else
{
return 0;
}
}

Or if the user is allowed to enter the space:

boolean can_enter(int i)
{
read_EE_priv(i);
if((priv & bit(PRIV_ACCESS)) == bit(PRIV_ACCESS))
{
return 1;
}
else
{
return 0;
}
}

This sets bits to be used later:

read_EE_name(i);
read_EE_priv(i);
read_EE_hash(i);
//Serial.print(“win: “);
//serial_user_print(i);
if((priv & bit(PRIV_ADDUSER)) == bit(PRIV_ADDUSER))
{
can_add = 1;
//Serial.println(“can add”);
}
if((priv & bit(PRIV_DOORBELL)) == bit(PRIV_DOORBELL))
{
can_doorbell = 1;
//Serial.println(“can doorbell”);
}
if((priv & bit(PRIV_DOORHOLD)) == bit(PRIV_DOORHOLD))
{
can_doorhold = 1;
//Serial.println(“can door hold”);
}

I could have done these all at once, or I could have done them all separately, but this is how it ended up.  the “can_***” are also global variables, those get set after a user is made active and before those checks are made (to allow the actions restricted by the privilege bits).  The functions it allows/disallows are things that we thought not all users should have:

  • add user: to learn new keys to the system
  • doorbell: put the door in a mode where pressing a button opens the door with no key for parties and such (6 hour default)
  • door hold: means that you do not need to use a key while loading stuff from your car (10 minute default)

Those last two functions are defined here (add user will get its own article):

//doorbell mode stuff
boolean doorbell = 0; //in doorbell mode?
boolean can_doorbell = 0; //can a given user enter doorbell mode?
unsigned long doorbell_start = 0; //used for count down timer
unsigned long doorbell_dur = (1000*60*60*6); //timeout for doorbell in hours (default 6)

 

//door hold mode stuff
boolean doorhold = 0; //in door hold mode?
boolean can_doorhold = 0; //can a given user enter door hold mode?
unsigned long doorhold_start = 0; //used for count down timer
unsigned long doorhold_dur = (1000*60*10); //timeout for door hold in minutes

The way those timeout is here:

if(doorbell) //doorbell timer loop
{
if (current_time – doorbell_start > doorbell_dur)
{
doorbell = 0;
}
}
//Serial.println(“past doorbell”);
if(doorhold) //door hold timer loop
{
if (current_time – doorhold_start > doorhold_dur)
{
doorhold = 0;
}
}
//Serial.println(“past doorhold”);

The way those modes are activated and deactivated:

void exit_doorbell_mode()
{
logging(logDate());
logging(” – “);
loggingln(“exit doorbell mode”);
LCD_clear();
LCD_displn(“doorbell mode”,0);
LCD_displn(“deactivated”,1);
doorbell = 0;
//doorbell_start = 0;
//can_doorbell = 0;
}
void enter_doorbell_mode()
{
logging(logDate());
logging(” – “);
loggingln(“enter doorbell mode”);
LCD_clear();
LCD_displn(“doorbell mode”,0);
LCD_displn(“activated”,1);
doorbell =1;
doorbell_start = current_time;
//can_doorbell = 0;
}
void exit_doorhold_mode()
{
logging(logDate());
logging(” – “);
loggingln(“exit door hold mode”);
LCD_clear();
LCD_displn(“door hold mode”,0);
LCD_displn(“deactivated”,1);
doorhold = 0;
//doorhold_start = 0;
//can_doorhold = 0;
}
void enter_doorhold_mode()
{
logging(logDate());
logging(” – “);
loggingln(“enter door hold mode”);
LCD_clear();
LCD_displn(“door hold mode”,0);
LCD_displn(“activated”,1);
doorhold =1;
doorhold_start = current_time;
//can_doorhold = 0;
}

The evaluation of keypresses to get into and out of those modes will be discussed elsewhere.  This is part of the greater OpenAccess project.

Advertisements

2 Responses to “OpenAccess privlige functions”

  1. OpenAccess eeprom functions | Evan's Techie-Blog Says:

    […] about a user at a given address.  A more verbose version could be written to decode the priv bits as […]

  2. OpenAccess 3.0 replacement software | Evan's Techie-Blog Says:

    […] privlige functions […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: