Changed Line Structure for config and person files, added credits_left to person, fixed read_person

This commit is contained in:
Lukas Bachschwell 2015-09-22 21:32:18 +02:00
parent ac39f31527
commit 4b854998c8
6 changed files with 62 additions and 111 deletions

BIN
.DS_Store vendored

Binary file not shown.

View File

@ -1,16 +0,0 @@
personCount: 003
drink number 1: Beer
price: 250
drink number 2: Fanta
price: 120
drink number 3: Schartnerbombe
price: 184
drink number 4: Cola
price: 130
drink number 5: Apfelspritzer
price: 100

View File

@ -36,6 +36,7 @@ typedef struct{
char name[NAME_LEN + 1];
char rfid_uuid[13];
uint8_t finger_uuid;
uint8_t credits_left;
int drinks_taken[NUM_OF_DRINKS];
}Person;
@ -43,7 +44,6 @@ typedef struct{
Beerbox* read_beerbox(Beerbox *box);
Beerbox* add_drink(Beerbox *box);
Person read_person(Beerbox *box, char *filename);
void print_person(Beerbox *box, Person *aperson);
int update_pers_file(Beerbox *box, Person *aperson);

View File

@ -224,14 +224,14 @@ Beerbox* read_beerbox(Beerbox *box) {
}
// get personcount Basically not needed...
// char tmpStr[19];
// read_line_from_file(read, tmpStr, sizeof(tmpStr));
// if (strlen(tmpStr)) {
// sscanf(tmpStr, "personCount: %d", &box->personCount);
// }
//
// sprintf(leckmich, "%i persons known!\n", box->personCount );
// Serial.print(leckmich);
// char tmpStr[19];
// read_line_from_file(read, tmpStr, sizeof(tmpStr));
// if (strlen(tmpStr)) {
// sscanf(tmpStr, "personCount: %d", &box->personCount);
// }
//
// sprintf(leckmich, "%i persons known!\n", box->personCount );
// Serial.print(leckmich);
//get drinks
for (i = 0 ; i < NUM_OF_DRINKS ; i++) {
@ -274,17 +274,9 @@ Beerbox* read_beerbox(Beerbox *box) {
Person read_person(Beerbox *box, char *filename) {
Person aperson;
File read;
int num_read = 0;
int index;
int tmp_int = 0;
char tmp[(DRINK_NAME_MAX_LENGTH + 1) * NUM_OF_DRINKS];
char tmp_drink_name[DRINK_NAME_MAX_LENGTH + 1];
int i = 0;
char tmp[21];//longest line is rfid_uuid
//giving the full filename here, since it makes stuff easier
@ -301,56 +293,48 @@ Person read_person(Beerbox *box, char *filename) {
strcpy(aperson.file_name, filename);
//reset momentary array
for (int i = 0; i < NUM_OF_DRINKS; i++) {
aperson.drinks_taken[i] = -1;
}
//First read all the metadata
//name
read_line_from_file(read, tmp, sizeof(tmp));
strcpy(aperson.name, tmp);
Serial.println("before memset");
//rfid_uuid
memset(aperson.rfid_uuid, 0, 13);
read_line_from_file(read, tmp, sizeof(tmp));
sscanf(tmp, " %*s %12s", aperson.rfid_uuid);
//Serial.print(aperson.rfid_uuid);
sscanf(tmp, "rfid_uuid: %12s", aperson.rfid_uuid);
Serial.println(aperson.rfid_uuid);
//finger_uuid
read_line_from_file(read, tmp, sizeof(tmp));
sscanf(tmp, " %*s %d", &aperson.finger_uuid);
//Serial.println(aperson.finger_uuid);
sscanf(tmp, "finger_uuid: %d", &aperson.finger_uuid);
Serial.println(aperson.finger_uuid);
//credits_left
read_line_from_file(read, tmp, sizeof(tmp));
sscanf(tmp, "credits_left: %d", &aperson.credits_left);
Serial.println(aperson.credits_left);
while (read_line_from_file(read, tmp, sizeof(tmp)), strlen(tmp) > 0) {
int tmpCount = 0;
int tmpDrink = 0;
i = 0;
sscanf(tmp, " %*s %s", tmp_drink_name);
for (i = 0; (i < NUM_OF_DRINKS) && (strcmp(box->drinks[i].name, tmp_drink_name)); i++) {
Serial.print("It´s not drink No :");
Serial.print(i+1);
Serial.println(box->drinks[i].name);
sscanf(tmp, "drink_Count_%d: %d",&tmpDrink, &tmpCount);
if (strlen(tmp)) {
Serial.print("drink: ");
Serial.print(tmpDrink);
Serial.print(" count: ");
Serial.println(tmpCount);
}
Serial.println("in");
if (i == NUM_OF_DRINKS) {
//Is it in?
//Serial.print("Drink \"%s\" does not exist in box!\n", tmp_drink_name);
} else {
read_line_from_file(read, tmp, sizeof(tmp));
sscanf(tmp, " %*s %d", &aperson.drinks_taken[i]);
//Serial.print(">>Quantity: %d\n", aperson.drinks_taken[i].quantity);
read_line_from_file(read, tmp, sizeof(tmp));
//Serial.print(">>Total: %d\n\n", aperson.drinks_taken[i].total);
}
}
//print_person(box, &aperson);
//comment back in once it is fixed
//update_pers_file(box, &aperson);
read.close();
return aperson;
}
@ -361,23 +345,25 @@ void print_person(Beerbox *box, Person *aperson) {
sprintf(leckmich, "\nPerson is called \"%s\" and has the filename \"%s\".\n", aperson->name, aperson->file_name);
Serial.write(leckmich);
//sprintf(leckmich, "rfid_uuid: %s\n", aperson->rfid_uuid);
//Serial.write(leckmich);
sprintf(leckmich, "rfid_uuid: %s\n", aperson->rfid_uuid);
Serial.write(leckmich);
sprintf(leckmich, "finger_uuid: %u\n", aperson->finger_uuid);
Serial.print(leckmich);
sprintf(leckmich, "credits_left: %u\n", aperson->credits_left);
Serial.print(leckmich);
for (i = 0; i < NUM_OF_DRINKS; i++) {
if (aperson->drinks_taken[i] != -1) {
sprintf(leckmich, "\nDrink: %s\n", box->drinks[i].name);
Serial.write(leckmich);
sprintf(leckmich, "Consumed: %d\n", aperson->drinks_taken[i]);
Serial.write(leckmich);
sprintf(leckmich, "Total: %d.%02d Euro\n", aperson->drinks_taken[i]*box->drinks[i].price / 100, (aperson->drinks_taken[i]*box->drinks[i].price) % 100);
Serial.write(leckmich);
/* //Rework that
sprintf(leckmich, "\nDrink: %s\n", box->drinks[i].name);
Serial.write(leckmich);
sprintf(leckmich, "Consumed: %d\n", aperson->drinks_taken[i]);
Serial.write(leckmich);
sprintf(leckmich, "Total: %d.%02d Euro\n", aperson->drinks_taken[i]*box->drinks[i].price / 100, (aperson->drinks_taken[i]*box->drinks[i].price) % 100);
Serial.write(leckmich);
*/
}
}
@ -507,7 +493,7 @@ void readAllPersons () {
if (!entry.isDirectory()) {
int8_t len = strlen(entry.name());
if(strstr(strlwr(entry.name() + (len - 4)), ".per"))
if (strstr(strlwr(entry.name() + (len - 4)), ".per"))
{
//Yeah it is a person!
Serial.print("Person: ");

View File

@ -1,12 +1,8 @@
Alex
rfid_uuid: 123456789
finger_uuid: 987654321
Drink: Beer
Consumed: 6
Total: 1500
Drink: Schartnerbombe
Consumed: 6
Total: 1104
rfid_uuid: 123456789
finger_uuid: 003
credits_left: 100
drink_Count_1: 6
drink_Count_2: 0
drink_Count_3: 0
drink_Count_4: 0

View File

@ -1,23 +1,8 @@
Lukas
rfid_uuid: 123456789
finger_uuid: 987654321
Drink: Beer
Consumed: 6
Total: 1500
Drink: Fanta
Consumed: 6
Total: 720
Drink: Schartnerbombe
Consumed: 6
Total: 1104
Drink: Cola
Consumed: 6
Total: 780
rfid_uuid: 126789345
finger_uuid: 001
credits_left: 100
drink_Count_1: 4
drink_Count_2: 3
drink_Count_3: 0
drink_Count_4: 0