need help making a database

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hello freaks!

I am interfacing an RFID module with ATmega164P, and i use Atmel studio 6.0 sp2. The module simply returns 4-byte UID over uart. I have hardcoded some UIDs and i make comparison using memcmp but now i want to make a generalized function which, on-demand, saves the 4-byte UID.

Please note the UID needs to be saved in such a way that later i can do a search over database to see if a given 4-byte ID exists in database or not. Multiple UIDs needs to be saved so function must take care of indexing itself.

I intend to save at least 10, 4-byte UIDs. The usual method i choose is to make arrays e.g:

Card1[4],card2[4],...cardN[4];

and later use lots of IFs to see which UID is it

if (memcmp(receivedByteRF,Card1,sizeInt) == 0 )
					{
						LCDcmd(0xC0);
						LCDstring("User is XXXX"); 						
					}
else if (memcmp(receivedByteRF,Card2,sizeInt) == 0 )
					{
						LCDcmd(0xC0);
						LCDstring("User is YYYY");
					}

Considering the new requirements, this method cannot work since i need to save multiple IDs, able to make a comparison and never to overwrite (indexes on its own)

I have never done such a work so i was wondering what are some good ways of accomplishing the task, any guidance is appreciated.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Your search terms are "database (doubly) linked list". I once posted an extensive solution here showing how to create a doubly-linked list.

Of course your next question is where are you actually going to store the data and does it need to be non-volatile.

Creating a linked list in SRAM is all very well ... until the power goes out!

EDIT: wow Google is good at ferreting things out:

https://www.avrfreaks.net/index.p...

As you'll read there - it's easy to create a growing database with a single linked list but if you want to randomly remove elements "in the middle" it makes life a whole lot easier if the list is double linked.

BTW this stuff is not new, it's computer science. A bunch of very clever blokes back 50-100 years ago worked out all the science of how to do stuff like this. Any good book on computer science will tell you all about it. Things like how to make binary trees to quickly find things in the data and so on. (when you Google it doesn't start at record 1 and keep memcmp()ing until it reaches record 4,000,000,000,000 - it's a bit cleverer than that!).