Slide 1

Slide 1 text

Building Embedded Systems with Twisted Vijay Kumar B.

Slide 2

Slide 2 text

The Problem Lots of shared resources in any office. books, CDs development kits, add-ons, pen drives, sdcards, SIM cards, … Engineers use these resources to complete their task. What happens after the task is completed? left at the engineer’s workplace, and then forgotten. stored in some randome location, and then forgotten. handed over to another engineer, and to another, … and many such possibilities, resulting in the resource getting lost.

Slide 3

Slide 3 text

The Solution Use a shelf to keep all the resources to be tracked. Use a notebook to track the resources. When an engineer takes a resource from shelf, an entry is to be made.

Slide 4

Slide 4 text

Pitfalls Does not work! Day 1: entries were made. Day 2: few people made the entry. Day 3: the notebook was gone! There is no way to intimate the user to return back the item, after use.

Slide 5

Slide 5 text

Restate the Requirements A shelf - for resources to be tracked. The system should track who took a resource, from the shelf. The system should intimate the engineer to return the resource, after a period of one week. Should be fully automated - no human intervention. Return of the resource, and renewal of the resource can be manual.

Slide 6

Slide 6 text

Design Each engineer is given an RFID card. Each resource to be tracked has an RFID tag. Every time the engineer has to take a resource Swipes his RFID card Swipes the RFID tag of all the resources An embedded system takes this information and pushes to a server on the Internet. The server will then intimate the engineer after a period of 1 week, to return the resource or renew.

Slide 7

Slide 7 text

Block Diagram

Slide 8

Slide 8 text

Application State Machine

Slide 9

Slide 9 text

RFID Reader RFID Reader from RhydoLabz. Provides the RFID read through a serial interface.

Slide 10

Slide 10 text

RFID Serial Data Format Each RFID card contains a unique 10 byte ID string. When the RFID card is swiped, the reader produces the following string. LF D0 D1 D2 D3 D4 D5 D6 D7 D8 D9 CR

Slide 11

Slide 11 text

Twisted based RFID Listener from twisted.internet import reactor from twisted.protocols.basic import LineReceiver from twisted.internet.serialport import SerialPort class RFIDListener(LineReceiver): def __init__(self, app_sm): self.delimiter = '\r' self.app_sm = app_sm def lineReceived(self, line): rfid = line.lstrip() print rfid app_sm = AppSM() rfid_listener = RFIDListener(app_sm) SerialPort(rfid_listener, "/dev/ttyS0", reactor, 9600) reactor.run()

Slide 12

Slide 12 text

Platform Atmel AT91SAM9260: ARM9, 180 MHz, 64MB SDRAM Runs Embedded Debian Grip distribution off an SD-Card. Python and Twisted Debian packages installed.

Slide 13

Slide 13 text

How to Enforce It? Anybody can take an item without swiping his card or the resource! Not on purpose, but … Engineers are forgetful. In a hurry, to complete the task. New engineers do not know the system.

Slide 14

Slide 14 text

Alerts and Tripwires Rig up the shelf with a tripwire. Raise an audible alert, if the shelf is opened without a card swipe. Reminds engineers, about the procedure!

Slide 15

Slide 15 text

Block Diagram

Slide 16

Slide 16 text

Application State Machine

Slide 17

Slide 17 text

Reed Switch The reed switch is an electrical switch operated by an applied magnetic field. It consists of a pair of contacts on ferrous metal reeds in a airtight sealed glass envelope. The contacts may be normally open, closing when a magnetic field is present, … — Wikipedia

Slide 18

Slide 18 text

Reed Switch Operation

Slide 19

Slide 19 text

Door Sensor Door sensor based on reed switch. Magnet on the door, reed switch on the frame.

Slide 20

Slide 20 text

Twisted based Reed Switch Listener from serial import Serial from twisted.internet import reactor from twisted.internet.task import LoopingCall class ReedSwitchListener(object): def __init__(self, app_sm, serial_dev, baud): self.serial = Serial(serial_dev, baud) self.app_sm = app_sm loop = LoopingCall(self.__listen_reed) loop.start(0.5) def __listen_reed(self): print self.serial.getCTS() app_sm = AppSM() listener = ReedSwitchListener(app_sm, "/dev/ttyS0", 9600) reactor.run()

Slide 21

Slide 21 text

Credits Reed Switch Animation from Wikimedia Commons by Stefan Riepl Reed Switch Photo from Wikimedia Commons by Andre Karwath RFID Reader Photo is from RhydoLabz. Door Sensor Photo is from Adafruit.