Raspberry Pi Weighting Control System
This project serves as a simple weighting control system, that was realized as a Bachelor Thesis
|
Handles database querries. More...
#include <db_driver.h>
Public Member Functions | |
db_driver (db_driver_conf *conf) | |
Construct a new db driver object from configuration. More... | |
db_driver (const char *host="localhost", const char *user="pi", const char *passwd="raspberry", const char *db="control_system", unsigned int port=3306, const char *socket=NULL, unsigned long cflags=0) | |
Construct a new db driver object through value passing. This is inteded for testing and debugging purposes. More... | |
bool | is_open () |
int | query_user_credentials (user_cred *creds, const char *uname) |
Selects username, password and status into @creds filtered by @uname. More... | |
int | query_user_data (user_cont *usr, const char *uname=nullptr, uint8_t *rfid_serial=nullptr, uint8_t rfid_ser_len=0) |
Selects all user data into user container @usr. Data is selected by either username or rfid_serial. If both are provided rfid takes precedence. More... | |
int | query_username (std::string &uname, unsigned long id) |
int | query_measurement_headers (user_cont *usr) |
int | query_measurement (measurement *m, unsigned long id) |
int | query_continuous_measurement (std::vector< measurement > &ms, unsigned long m_number, unsigned long measuree_id) |
int | is_measurement_continuous (unsigned long m_number, unsigned long measuree_id) |
int | is_username_available (const char *uname) |
int | is_rfid_serial_available (uint8_t *serial, uint8_t ser_len) |
int | increment_user_measurement_count (unsigned long id) |
int | can_login_subuser (const char *uname) |
int | update_user_rfid (unsigned long user_id, uint8_t *serial, uint8_t ser_len) |
int | insert_user (user_cont *new_usr, const char *password) |
int | insert_measurement (measurement *m) |
void | test_insert_with_binary () |
void | test_select_with_binary () |
Handles database querries.
Definition at line 41 of file db_driver.h.
db_driver::db_driver | ( | db_driver_conf * | conf | ) |
Construct a new db driver object from configuration.
conf |
Definition at line 24 of file db_driver.cpp.
db_driver::db_driver | ( | const char * | host = "localhost" , |
const char * | user = "pi" , |
||
const char * | passwd = "raspberry" , |
||
const char * | db = "control_system" , |
||
unsigned int | port = 3306 , |
||
const char * | socket = NULL , |
||
unsigned long | cflags = 0 |
||
) |
Construct a new db driver object through value passing. This is inteded for testing and debugging purposes.
Definition at line 52 of file db_driver.cpp.
int db_driver::can_login_subuser | ( | const char * | uname | ) |
Checks if user with @uname is a pacient, so he can be logged as subuser. Returns 0 for true.
Definition at line 1555 of file db_driver.cpp.
int db_driver::increment_user_measurement_count | ( | unsigned long | id | ) |
Increments user measrue count after a measurement is successfully performed for user with @id
Definition at line 1517 of file db_driver.cpp.
int db_driver::insert_measurement | ( | measurement * | m | ) |
Inserts measurement with data read from @m. Returns 0 on success.
Definition at line 1765 of file db_driver.cpp.
int db_driver::insert_user | ( | user_cont * | new_usr, |
const char * | password | ||
) |
Inserts new user into the database with data read from @new_user and @password (password isn't stored in user container) Returns 0 on success.
Definition at line 1678 of file db_driver.cpp.
int db_driver::is_measurement_continuous | ( | unsigned long | m_number, |
unsigned long | measuree_id | ||
) |
Queries the database to see if measurement wiht number @m_number of user with id @masuree_id. Returns 1 if the measuring is continous, 9 if its a single measuring, other values otherwise
Definition at line 1314 of file db_driver.cpp.
bool db_driver::is_open | ( | ) |
Checks if database is open
Definition at line 71 of file db_driver.cpp.
int db_driver::is_rfid_serial_available | ( | uint8_t * | serial, |
uint8_t | ser_len | ||
) |
Queries the database to see if rfid @serial (length @ser_len) is available for new user registration. Returns 0 if name is available
Definition at line 1461 of file db_driver.cpp.
int db_driver::is_username_available | ( | const char * | uname | ) |
Queries the database to see if @uname is available for new user registration. Returns 0 if name is available
Definition at line 1405 of file db_driver.cpp.
int db_driver::query_continuous_measurement | ( | std::vector< measurement > & | ms, |
unsigned long | m_number, | ||
unsigned long | measuree_id | ||
) |
queries continuous measurements (they have same measurement number but different measurement_part) every user's measurement number should be unique. Don't select all the info that query_measurement does.
Definition at line 1054 of file db_driver.cpp.
int db_driver::query_measurement | ( | measurement * | m, |
unsigned long | id | ||
) |
Definition at line 720 of file db_driver.cpp.
int db_driver::query_measurement_headers | ( | user_cont * | usr | ) |
Selects basic information about measurements, that is initialized into @usr cont variable for headers. These headers are used to list users measurements
Definition at line 580 of file db_driver.cpp.
int db_driver::query_user_credentials | ( | user_cred * | creds, |
const char * | uname | ||
) |
Selects username, password and status into @creds filtered by @uname.
Definition at line 75 of file db_driver.cpp.
int db_driver::query_user_data | ( | user_cont * | usr, |
const char * | uname = nullptr , |
||
uint8_t * | rfid_serial = nullptr , |
||
uint8_t | rfid_ser_len = 0 |
||
) |
Selects all user data into user container @usr. Data is selected by either username or rfid_serial. If both are provided rfid takes precedence.
Definition at line 199 of file db_driver.cpp.
int db_driver::query_username | ( | std::string & | uname, |
unsigned long | id | ||
) |
Selects username into @uname for user with id = @id
Definition at line 498 of file db_driver.cpp.
void db_driver::test_insert_with_binary | ( | ) |
Test insert with binary data
Definition at line 1910 of file db_driver.cpp.
void db_driver::test_select_with_binary | ( | ) |
Test select with binary data
Definition at line 1957 of file db_driver.cpp.
int db_driver::update_user_rfid | ( | unsigned long | user_id, |
uint8_t * | serial, | ||
uint8_t | ser_len | ||
) |
Updates users @user_id rfid card with @serial (len @ser_len). However this is currently not used. Returns 0 on success.
Definition at line 1635 of file db_driver.cpp.