19
Remote Sonar Sensing over TCP/IP - Design Review #2 Patrick McGinty and Dave Morse

Remote Sonar Sensing over TCP/IP- Design Review #2 Patrick McGinty and Dave Morse

Embed Size (px)

Citation preview

Page 1: Remote Sonar Sensing over TCP/IP- Design Review #2 Patrick McGinty and Dave Morse

Remote Sonar Sensing over TCP/IP - Design Review #2

Patrick McGinty and Dave Morse

Page 2: Remote Sonar Sensing over TCP/IP- Design Review #2 Patrick McGinty and Dave Morse

Project Objectives

Implement a TCP/IP stack on the NEC 78F9418 Flash Microcontroller Interface with Cirrus Crystal CS8900A Ethernet controller chip in 8-bit modeSonar sensor on a servo motor used for distance rangingRemote software applet to control the system over the EthernetSupport ICMP echo requests, UDP transfers, and TCP connection functionality

Page 3: Remote Sonar Sensing over TCP/IP- Design Review #2 Patrick McGinty and Dave Morse

Project Specifications - ITimer Resolution & Ranges

PWM Interrupt Timer 0 Frequency = 9.76 kHz Resolution = 102.4 μs Cycles between interrupt = 195

PWM Interrupt Timer 1 Frequency = 19.5 kHz Resolution = 51.2 μs Cycles between interrupt ~ 6 - 42

Sonar Capture Timer Frequency = 156.3 kHz Resolution = 6.4μs Cycles between capture ~ 372 -

9767

Servo Resolution180 degree dynamic rangeSupport 13 possible positions in 15 degree intervals for the motorAccomplished with intervals of 3 on Interrupt Timer 1 from 6 to 42 timer cycles between interruptPosition 0 is +90 degrees (right)Position 6 is 0 degrees (forward)Position 12 is -90 degrees (left)

Page 4: Remote Sonar Sensing over TCP/IP- Design Review #2 Patrick McGinty and Dave Morse

Project Specifications - II

Sonar Range & Resolution Range : Sonar provides accurate distance measurements between

16 inches and 35 feet (420 inches) Resolution : Smallest distance interval that can be determined is

0.043 inches (distance corresponding to one clock tick) 6.4 s * (343 m / s) * (39.37 inches / m) = 0.086 inches Since the sound wave travels twice this distance due to the echo, the

resolution is 0.086 / 2 = 0.043 inches Accuracy : Sonar returns a distance value that is accurate to within

± 1.0 inch, and is typically even more accurate than that Beam width is rather wide (~ 15 degrees), so care must be taken

to ensure that other objects do not get in the way of the object to be sensed

Page 5: Remote Sonar Sensing over TCP/IP- Design Review #2 Patrick McGinty and Dave Morse

Project Specifications - IIIEthernet

Support Ethernet II (IEEE 802.2) Frames

Support single frames of any size in IEEE specification

IP No support for IP

fragmentation Support IPv4 packets only Static IP address programmed

in ROM

ARP Correctly respond to ARP

queries

ICMP Support ECHO requests of any

length <= 1518 (PING)

UDPSupport UDP packetsSupport for UDP Echo serverSupport for UDP remote sonar server

TCPSupport 2 simultaneous client connectionsSupport full TCP state machine in ROMSupport for TCP remote sonar server

HTTPSupport HTTP formatted packetsSupport HTTP GET for transmission of a static web page

Page 6: Remote Sonar Sensing over TCP/IP- Design Review #2 Patrick McGinty and Dave Morse

Supported Server Commands (UDP & TCP)

Move arm counterclockwise 15 degrees Responds with success or fail, current position

Move arm clockwise 15 degrees Responds with success or fail, current position

Move to any specified position Responds with success or fail, current position

Query position Responds with current position

Activate Sonar Responds with success and time delay in clock cycles, or

fail

Page 7: Remote Sonar Sensing over TCP/IP- Design Review #2 Patrick McGinty and Dave Morse

Datagram Command Format of Remote Sonar Servo Protocol

Datagram Command Format

Each field is 2 bytes long Header – Command –

Parameter

Datagram Response Format

Result byte (non-zero is failure)

Variable length parameter field

Header to Precede All Commands

Verifies datagram is a command for server

2 bytes (0x87, 0x65)

Move arm counterclockwise 15 degrees

ASCII bytes ( ‘c’, ‘c’ )

Move arm clockwise 15 degrees ASCII bytes ( ‘c’, ‘w’ )

Move to any specified position ASCII bytes ( ‘m’, ‘m’ )

Query position ASCII bytes ( ‘q’, ‘q’ )

Activate Sonar ASCII bytes ( ‘p’, ‘p’ )

Page 8: Remote Sonar Sensing over TCP/IP- Design Review #2 Patrick McGinty and Dave Morse

Datagram Response Format of Remote Sonar Servo Protocol

Datagram Response Format Result byte (non-zero is

failure) Variable length parameter

fieldMove arm counterclockwise 15 degrees

Success Response 1 byte - current servo

position Fail Response

ASCII error string till end of packet

Move arm clockwise 15 degrees Success Response

1 byte - current servo position

Fail Response ASCII error string till end

of packet

Move to any specified position Success Response

1 byte - current servo position

Fail Response ASCII error string till end of packet

Query position1 byte – current servo position

Activate Sonar Success Response

2 bytes – timer delay between ping and response

Fail Response ASCII error string till end of packet

Page 9: Remote Sonar Sensing over TCP/IP- Design Review #2 Patrick McGinty and Dave Morse

Ethernet Packet Processing

Define 2 64 byte buffers, rxB and txB

Receive Buffer rxB Buffer holds a 64 byte ‘page’ of the packet An initial fill request is made when the packet is received Data is read from the packet using ‘get’ functions, which retrieve data from the receive buffer (and do necessary byte swapping for the little-endian system) When the buffer is exhausted, it is automatically refilled and its page value is incremented

Transmit Buffer txB Buffer holds 64 bytes of transmit data at a time Buffer is filled with ‘put’ functions, which push bytes into the buffer When an attempt is made to push more data than the buffer can hold, it transfers its contents to the Ethernet Controller and increments its page value A final transmission request must be made for each transmitted packet

Checksum calculation Since the checksums are in the TCP and UDP headers, they must be calculated before the first page of transmit data is pushed Very little dynamic data for servo application, and checksums can be pre-calculated for long text strings such as error messages or web pages

Page 10: Remote Sonar Sensing over TCP/IP- Design Review #2 Patrick McGinty and Dave Morse

Closed: socket unable to send or receive network packetsListen: allows connection requests to be acceptedSyn_Rcvd: connection request from clientEstablished: send and receive data as neededFin_Wait_1: all data sent, server requests connection closeTime_Wait: client acknowledges closer with FIN,ACK packet

TCP/IP Server State

Transitions

Page 11: Remote Sonar Sensing over TCP/IP- Design Review #2 Patrick McGinty and Dave Morse

Completed Circuit Diagram

Page 12: Remote Sonar Sensing over TCP/IP- Design Review #2 Patrick McGinty and Dave Morse

Client application software

High level remote application on PC that communicates with micro controller over the EthernetClient application controls a sonar sensor mounted to a servo motor to perform remote distance sensingClient application supports a variety of control functions, and receives data from the sonar over the EthernetClient application implements aggregate functions using server application primitives, such as a sweep of all possible positions, returning the distance at eachThe software will demonstrate both TCP and UDP communications with the micro controllerServer can respond to ping operations to demonstrate ICMP support

Page 13: Remote Sonar Sensing over TCP/IP- Design Review #2 Patrick McGinty and Dave Morse
Page 14: Remote Sonar Sensing over TCP/IP- Design Review #2 Patrick McGinty and Dave Morse

Testing philosophy

Use Ethereal packet sniffing software Provides a byte by byte analysis of all traffic on line Used to verify correct responses to various packets Used to diagnose problems with packet processing

Verify correct code execution in NEC simulator

Debug code on hardware using LED outputs

Test client on PC used to generate test input packets, and validate correct responses

Multiple instances of test client used to verify multiple connections working

Verify that all sizes of packets up to 1518 bytes can be properly received and transmitted using the PING program

Verify PWM wave generated in software is correct using an oscilloscope

Verify correct servo positions visually

Exercise all possible client application commands and server primitives using both UDP and TCP modes of operation

Send faulty commands and packets to ensure that system will ignore these incorrect commands properly, and not crash

Place test objects known distances from sonar and verify that it returns that distance within tolerance

Page 15: Remote Sonar Sensing over TCP/IP- Design Review #2 Patrick McGinty and Dave Morse

Workload divisionTask Champion Completed?Acquire hardware components Patrick Yes

Assemble and mount hardware Patrick Yes

Wiring scheme Patrick Yes

Achieve connectivity between Ethernet controller and micro-controller

Dave Yes

Ethernet Driver Patrick Yes

Ethernet frame parsing Dave Yes

Buffer management scheme Dave Yes

ARP packet processing Dave Yes

IP packet processing Dave Yes

ICMP packet processing Dave Yes

UDP packet processing Dave Yes

Protocol design Patrick Yes

Servo controller code Patrick Yes

Sonar controller code Patrick Yes

Sonar calibration Patrick Yes

TCP packet decoding Patrick Yes, untested

TCP state machine Patrick No

HTTP processing, sample web page Dave No

Client application Dave Yes, beta stage

Final testing and debugging Both Testing is never complete

Final report, documentation on CD-ROM Both No

Web page for project TBD No

Page 16: Remote Sonar Sensing over TCP/IP- Design Review #2 Patrick McGinty and Dave Morse

Cost estimatesItem Quantity Price each

NEC 9418A Micro-controller board, development tools

1 Supplied by NEC

Cirrus CS8900A Ethernet IC board

1 $80

Sonar transducer w/ interface board

1 $55

Servo motor 1 $10

Small breadboard 1 $4

Voltage regulator 1 $2

IC board standoffs 3 (packages) $2

Plexiglass, screws, wires, LEDs, capacitor, headers

N/A $10

Variable voltage supply 1 $15

Protocol reference material

1 $60

Packet sniffer software 1 Freeware

IEEE OUI for MAC address

1 $1650…. Um no

TOTAL $238 total, $178 for components

Page 17: Remote Sonar Sensing over TCP/IP- Design Review #2 Patrick McGinty and Dave Morse

Power consumption estimates

Power P=VI Sonar – 100 mA Ethernet board – 55 mA NEC microcontroller – 5.6 mA Servo – 105 mA while moving

Total current draw (max) – 265.6 mA P = 5V * 265.6 mA = 1.328 W at most

Page 18: Remote Sonar Sensing over TCP/IP- Design Review #2 Patrick McGinty and Dave Morse

Potential problems

Susceptible to Denial Of Service attacks If the server is bombarded with incoming packets addressed to the

Ethernet controller’s MAC address, the buffers will overload in the Ethernet controller and a hard reset is necessary

Due to this limitation, it should be protected by a traffic limiting firewall in actual use

Haven’t yet verified that client application will properly run on Real-time lab computers, but shouldn’t pose a problemHasn’t been tested across long distances (over multiple routers)Large sonar beam width, so care must be taken to ensure that distance sensed corresponds to distance that user expects to be measuredSpeed of sound is based on room temperature, so using this device in extreme environments may result in less accurate measurements

Page 19: Remote Sonar Sensing over TCP/IP- Design Review #2 Patrick McGinty and Dave Morse

The beast