From 4b854998c81c03871d5dc103607bc0b87cbec123 Mon Sep 17 00:00:00 2001 From: Lukas Bachschwell Date: Tue, 22 Sep 2015 21:32:18 +0200 Subject: [PATCH] Changed Line Structure for config and person files, added credits_left to person, fixed read_person --- .DS_Store | Bin 6148 -> 6148 bytes beerbox.config | 16 -------- beerbox.h | 2 +- beerbox.ino | 108 +++++++++++++++++++++---------------------------- p001.per | 18 ++++----- p002.per | 29 ++++--------- 6 files changed, 62 insertions(+), 111 deletions(-) delete mode 100644 beerbox.config diff --git a/.DS_Store b/.DS_Store index 93cdd5166c81cb30e4f2adab41bed59435f56452..f7851ea23a150e6172fcf7c2af92c1e7a6e74069 100644 GIT binary patch delta 83 zcmZoMXfc?u)KWq`pMimag+Y%YogtHSwwaydFFyd$)EF@U diff --git a/beerbox.config b/beerbox.config deleted file mode 100644 index 1fe321e..0000000 --- a/beerbox.config +++ /dev/null @@ -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 diff --git a/beerbox.h b/beerbox.h index e0837bb..f62dcef 100644 --- a/beerbox.h +++ b/beerbox.h @@ -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); diff --git a/beerbox.ino b/beerbox.ino index cc69e08..9c72289 100644 --- a/beerbox.ino +++ b/beerbox.ino @@ -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) { - - 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); - + int tmpCount = 0; + int tmpDrink = 0; + + 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,15 +493,15 @@ 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: "); Serial.println(entry.name()); Person thisPerson = read_person(box, entry.name()); //print_person(box, &thisPerson); - - + + } } entry.close(); diff --git a/p001.per b/p001.per index 8f359fa..dca357d 100644 --- a/p001.per +++ b/p001.per @@ -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 diff --git a/p002.per b/p002.per index b3b3007..b54b7c7 100644 --- a/p002.per +++ b/p002.per @@ -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