Dependencies: EthernetNetIf NTPClient_NetServices mbed
Revision 0:d441275f622f, committed 2010-08-09
- Comitter:
- nucho
- Date:
- Mon Aug 09 07:01:43 2010 +0000
- Child:
- 1:b494b1b91ba3
- Commit message:
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/EthernetNetIf.lib Mon Aug 09 07:01:43 2010 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/donatien/code/EthernetNetIf/#bc7df6da7589
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HTTPClient.lib Mon Aug 09 07:01:43 2010 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/donatien/code/HTTPClient/#d97a4fc01c86
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ItemSet.cpp Mon Aug 09 07:01:43 2010 +0000 @@ -0,0 +1,74 @@ +#include "ItemSet.h" +#include "mbed.h" +using namespace mbed; + +ItemSet::ItemSet() { + firstItem = currentItem = NULL; + numOfItems = 0; +} + +Object* ItemSet::First() { + currentItem = firstItem; + if (currentItem == NULL) return(NULL); + + return(currentItem->object); +} + +Object* ItemSet::Next() { + if (currentItem != NULL) { + if (currentItem->nextItem != NULL) { + currentItem = currentItem->nextItem; + }else{ + return NULL; + } + return(currentItem->object); + } else { + return(NULL); + } +} + +void ItemSet::AddItem(Object* inObj) { + Item* theItem; + theItem = new Item; + theItem->object = inObj; + + if (numOfItems == 0) { + theItem->nextItem =NULL; + firstItem = theItem; + } else { + theItem->nextItem = firstItem; + firstItem =theItem; + } + + currentItem = theItem; + numOfItems++; + + return; +} + +int ItemSet::GetNumOfItems() { + return(numOfItems); +} + +Object* ItemSet::GetCurrentObject() { + + if (currentItem != NULL) { + return(currentItem->object); + } else { + return(NULL); + } +} + + +Object* ItemSet::SerchId(unsigned int inId) { + Item* item=firstItem; + + while (item != NULL) { + if (item->object->CompareId(inId)) { + return(item->object); + } + item = item->nextItem; + } + + return NULL; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ItemSet.h Mon Aug 09 07:01:43 2010 +0000 @@ -0,0 +1,26 @@ +#ifndef _INC_ITEMSET +#define _INC_ITEMSET + +#include "Object.h" +#include "mbed.h" +class Item{ +public: + Item* nextItem; + Object* object; +}; + +class ItemSet{ +private: + Item* firstItem; + Item* currentItem; + int numOfItems; +public: + ItemSet(); + Object* First(); + Object* Next(); + void AddItem(Object* inObj); + int GetNumOfItems(); + Object* GetCurrentObject(); + Object* SerchId(unsigned int inId); +}; +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MyRFID.cpp Mon Aug 09 07:01:43 2010 +0000 @@ -0,0 +1,40 @@ +#include "MyRFID.h" +#include "mbed.h" + +using namespace mbed; + +MyRFID::MyRFID(PinName tx, PinName rx) + : _rfid(tx,rx) {} + + + +int MyRFID::readable(void) { + return (_rfid.readable()); +} + +void MyRFID::baud(int baudrate) { + return (_rfid.baud(baudrate)); +} + +unsigned int MyRFID::read(void) { + + unsigned int id=0; + int len,i; + + _rfid.getc();//header + _rfid.getc();//header + len = _rfid.getc(); + + char data[len]; + for (i=0;i<len;i++) { + data[i]=_rfid.getc(); + } + if (data[0]==0x50) {//success + for (i=0;i<4;i++) { + id |= (data[4-i] << (i * 8)); + } + } else {//failre + } + + return id; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MyRFID.h Mon Aug 09 07:01:43 2010 +0000 @@ -0,0 +1,20 @@ +#ifndef MBED_MYRFID_H +#define MBED_MYRFID_H + +#include "mbed.h" + +namespace mbed { + +class MyRFID { +public: + MyRFID(PinName tx, PinName rx); + int readable(void); + unsigned int read (void); + void baud(int baudrate); +private: + Serial _rfid; + +}; +} + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/NTPClient.lib Mon Aug 09 07:01:43 2010 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/donatien/code/NTPClient/#7c3f1199256a
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Object.h Mon Aug 09 07:01:43 2010 +0000 @@ -0,0 +1,8 @@ +#ifndef _INC_OBJECT +#define _INC_OBJECT + +class Object{ +public: + virtual bool CompareId(unsigned int id) = 0; +}; +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TextLCD.lib Mon Aug 09 07:01:43 2010 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/simon/code/TextLCD/#44f34c09bd37
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Aug 09 07:01:43 2010 +0000 @@ -0,0 +1,154 @@ +#include "mbed.h" +#include "TextLCD.h" +#include "EthernetNetIf.h" +#include "HTTPClient.h" +#include "NTPClient.h" +#include "ItemSet.h" +#include "member.h" +#include "MyRFID.h" + + +EthernetNetIf eth; +NTPClient ntp; + +LocalFileSystem local("local"); + +Serial pc(USBTX, USBRX); // tx, rx + +MyRFID rfid(p28, p27);//tx,rx +InterruptIn rfid_irq(p21); + +TextLCD lcd(p5, p6, p11, p12, p13, p14); // rs, e, d0-d3 + +BusOut myleds(LED1, LED2, LED3, LED4); + +const char user[] = "hamrobot"; +const char pass[] = "kesi56KN"; +const char login_msg[] = " is login now."; +const char logout_msg[] = " is logout now."; +const char url[] = "http://api.supertweet.net/1/statuses/update.xml"; +const char ntp_server[] = "0.uk.pool.ntp.org"; + +bool card_flag=false; + +void cardIRQ() { + card_flag=true; +} + +void LED_KnightRider(int rideTime) { + for (int i=0; i<4; i++) { + myleds = 1 << i; + wait_ms(rideTime); + } + for (int i=0;i<3;i++) { + myleds =4>>i; + wait_ms(rideTime); + } + myleds=0; +} + +int main() { + ItemSet memberList; + Object* theObj; + + rfid.baud(19200); + printf("Init\n"); + lcd.printf("Init\n"); + + char sendmsg[255]; + char buf[40]; + time_t ctTime; + HTTPClient twitter; + HTTPMap msg; + + unsigned int id; + + //ethernet setup + printf("Setting up...\n"); + EthernetErr ethErr = eth.setup(); + if(ethErr) + { + printf("Error %d in setup.\n", ethErr); + return -1; + } + printf("Setup OK\r\n"); + + //twitter auth + twitter.basicAuth(user, pass); //We use basic authentication, replace with you account's parameters + + //RTC setup + Host server(IpAddr(), 123, ntp_server); + ntp.setTime(server); + + //read member.txt + pc.printf("Opening File...\n"); // Drive should be marked as removed + FILE *fp = fopen("/local/member.txt", "r"); + char name_buf[255]; + while (fscanf( fp, "%[^,],%d\n",name_buf, &id) != EOF ) { + memberList.AddItem(new member(name_buf,id)); + } + delete [] name_buf; + fclose(fp); + + rfid_irq.rise(&cardIRQ); + + while (1) { + lcd.locate(0,0); + ctTime = time(NULL)+32400;//JST time + strftime(buf,sizeof(buf),"%Y/%m/%d %a\n%H:%M:%S Ready!", localtime(&ctTime)); + printf("%s\n", buf); + lcd.printf("%s", buf); + wait(0.5); + + if (card_flag) { + lcd.cls(); + strcpy(sendmsg,""); + + id = rfid.read(); + pc.printf("id=%u\n",id); + theObj = memberList.SerchId(id);//checkId + + if (theObj != NULL) {//list has same ID + lcd.locate(0,0); + lcd.printf("%s\n",((member*)theObj)->GetName()); + lcd.printf("id=%u",((member*)theObj)->GetId()); + + strcat(sendmsg,((member*)theObj)->GetName()); + strftime(buf,sizeof(buf), " (%Y/%m/%d %a %H:%M:%S)", localtime(&ctTime)); + + if (((member*)theObj)->GetEnter()) {//member is logined + strcat(sendmsg,logout_msg); + strcat(sendmsg,buf); + pc.printf("%s\n",sendmsg); + msg["status"] = sendmsg; + + ((member*)theObj)->SetEnter(false); + } else {//member is logouted + strcat(sendmsg,login_msg); + strcat(sendmsg,buf); + pc.printf("%s\n",sendmsg); + msg["status"] = sendmsg; + + ((member*)theObj)->SetEnter(true); + } + twitter.post(url, msg, NULL);//tweet + + LED_KnightRider(50); + LED_KnightRider(50); + + lcd.cls(); + } else {//list no have id + lcd.cls(); + lcd.locate(0,0); + lcd.printf("Who are you?\n"); + lcd.printf("id=%u\n",id); + wait(5); + + lcd.cls(); + } + card_flag=false; + } + } +} + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Aug 09 07:01:43 2010 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/9114680c05da
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/member.cpp Mon Aug 09 07:01:43 2010 +0000 @@ -0,0 +1,63 @@ +#include "member.h" +#include "mbed.h" + +using namespace mbed; + +member::member(char* inName,unsigned int inId) { + SetName(inName); + SetId(inId); + //printf("name:%s\tid:%u",name,id); + enter=false; +} + +void member::SetName(char* inName){ + +/* + if(name != NULL){ + delete [] name; + } +*/ + name = new char[strlen(inName)+1]; + strcpy(name,inName); + return; +} + +void member::SetId(unsigned int inId){ + id = inId; + return; +} + +void member::SetEnter(bool inEnter){ + enter = inEnter; + return; +} + +char* member::GetName(void){ + return name; +} + +unsigned int member::GetId(void){ + return id; +} + +unsigned int member::GetEnter(void){ + return enter; +} + +void member::Print(void){ + printf("name:%s\tid:%u\n",name,id); +} + +bool member::CompareId(unsigned int inId){ + if(inId == id) return true; + else return false; +} + +/* +int member::Compare(Object* inObj){ + int theRet; + + theRet = strcmp(name, ((member*)inObj)->GetName()); + return theRet; +} +*/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/member.h Mon Aug 09 07:01:43 2010 +0000 @@ -0,0 +1,25 @@ +#ifndef _INC_MEMBER +#define _INC_MEMBER + +#include "Object.h" +class member : public Object{ +//class member{ +private: + char* name; + unsigned int id; + bool enter; + +public: + member(char* inName,unsigned int inId); + + void SetName(char* inName); + void SetId(unsigned int inId); + void SetEnter(bool inEnter); + char* GetName(void); + unsigned int GetId(void); + unsigned int GetEnter(void); + + virtual void Print(void); + virtual bool CompareId(unsigned int id); +}; +#endif