300 likes | 457 Views
CSE 145. Underwater Modem Project Networking Library Robert Chen. Purpose. Goal: To develop an API that will enable programmable devices and appliances to easily interface with the underwater acoustic modem Deliverable: C API and programming library Requirements:
E N D
CSE 145 Underwater Modem Project Networking Library Robert Chen
Purpose • Goal: To develop an API that will enable programmable devices and appliances to easily interface with the underwater acoustic modem • Deliverable: C API and programming library • Requirements: • Portable on different platforms • Microcontrollers, Computers, Cell Phones, etc. • Easy to use, well documented
Modem Components Packet/Host Layer Transport Datalink/Network FPGA/DSP Physical Layer PSK FSK DSSS ASK Transducer/Amplifier
Simple Model SOFTWARE ZONE “string” 1010001010011111010001010010…. HARDWARE ZONE HARDWARE ZONE 1010001010011111010001010010…. SOFTWARE ZONE “string”
Frame Format = 8 bits Total: 72 bits / 9 bytes • Data Bytes • Type • CRC • Counter • To • From
Simple Example Frame sendString(0x02, “HI!”); 0x01 0x02 0x25 0x00 ‘H’ ‘I’ ‘!’ ‘/0’ 0xE9
Example Programs • Program 1 (0x21): • sendString(0x31, “HELLO WORLD!!!”); • Program 2 (0x31): • recvString(0x21, “%s”, buffer);
Program 1: String to Frames 0x01 0x00 0x00 0x00 ‘H’ ‘E’ ‘L’ ‘L’ 0x00 0x01 0x00 0x00 0x00 ‘O’ ‘ ’ ‘W’ ‘O’ 0x00 0x01 0x00 0x00 0x00 ‘R’ ‘L’ ‘D’ ‘!’ 0x00 0x01 0x00 0x00 0x00 ‘!’ ‘!’ ‘/0’ ‘/0’ 0x00 • String is broken up • Put into frames that hold 4 bytes each
Program 1: Addressing 0x01 0x31 0x21 0x00 ‘H’ ‘E’ ‘L’ ‘L’ 0x00 0x01 0x31 0x21 0x00 ‘O’ ‘ ’ ‘W’ ‘O’ 0x00 0x01 0x31 0x21 0x00 ‘R’ ‘L’ ‘D’ ‘!’ 0x00 0x01 0x31 0x21 0x00 ‘!’ ‘!’ ‘/0’ ‘/0’ 0x00 Fill in To / From address fields
Program 1: TX Queue • Frames are then added to transmit queue in string order • What happens now? • Blocking Implementation • Process queue immediately • Non-Blocking Implementation • Manual function call to process queue when convenient, i.e. by interrupt
Program 1: Process TX Queue 0x01 0x31 0x21 0x00 ‘H’ ‘E’ ‘L’ ‘L’ 0x00 0x01 0x31 0x21 0x00 ‘O’ ‘ ’ ‘W’ ‘O’ 0x00 0x01 0x31 0x21 0x00 ‘R’ ‘L’ ‘D’ ‘!’ 0x00 0x01 0x31 0x21 0x00 ‘!’ ‘!’ ‘/0’ ‘/0’ 0x00 0x01 0x31 0x21 0x00 ‘/0’ ‘/0’ ‘/0’ ‘/0’ 0x00 • For all frames on TX Queue: • POP and add to a window of size X • Window = fixed length set of frames, 5 in this ex.
Program 1: Numbering and CRC 0x01 0x31 0x21 0x00 ‘H’ ‘E’ ‘L’ ‘L’ 0xB7 0x01 0x31 0x21 0x01 ‘O’ ‘ ’ ‘W’ ‘O’ 0x9F 0x01 0x31 0x21 0x02 ‘R’ ‘L’ ‘D’ ‘!’ 0x03 0x01 0x31 0x21 0x03 ‘!’ ‘!’ ‘/0’ ‘/0’ 0x25 0x01 0x31 0x21 0x04 ‘/0’ ‘/0’ ‘/0’ ‘/0’ 0xC0 Number off Frames Calculate CRC – Cyclic Redundancy Check
Program 1: Send Window START HERE STOP HERE For all frames in window, send byte by byte as a stream of bytes Waits for ACK responses
Program 2: Receive Window #1 #2 #3 #4 #5 • Receive stream of bytes • Known:WINDOW SIZE XFRAME LENGTH • 5 X 9 bytes = 45 bytes
Program 2: Reconstitute Frames OK! 0x01 0x31 0x21 0x00 ‘H’ ‘E’ ‘L’ ‘L’ 0xB7 BAD! 0x01 0x31 0x21 0x01 ‘O’ ‘ ’ ‘X’ ‘L’ 0x9F OK! 0x01 0x31 0x21 0x02 ‘R’ ‘L’ ‘D’ ‘!’ 0x03 BAD! 0x01 0x31 0x21 0x03 ‘!’ ‘!’ ‘/0’ ‘/0’ 0x00 OK! 0x01 0x31 0x21 0x04 ‘/0’ ‘/0’ ‘/0’ ‘/0’ 0xC0 Perform CRC check on each received frame
Program 2: ACK Response 0x01 0x31 0x21 0x00 ‘H’ ‘E’ ‘L’ ‘L’ 0xB7 0x06 0x21 0x31 0x00 0x00 0x00 0x00 0x00 0x7F • For all OK frames • Respond: “I got frame #X” • For all BAD frames, do nothing • Sender will send the missing frame again if it doesn’t get a valid response before timeout
Program 2: Re-build Window 0x01 0x31 0x01 0x00 ‘H’ ‘E’ ‘L’ ‘L’ 0xB7 0x01 0x31 0x01 0x01 ‘O’ ‘ ’ ‘W’ ‘O’ 0x9F 0x01 0x31 0x01 0x02 ‘R’ ‘L’ ‘D’ ‘!’ 0x03 0x01 0x31 0x01 0x03 ‘!’ ‘!’ ‘/0’ ‘/0’ 0x25 0x01 0x31 0x01 0x04 ‘/0’ ‘/0’ ‘/0’ ‘/0’ 0xC0
Program 2: Reform String ‘H’ ‘E’ ‘L’ ‘L’ ‘O’ ‘ ’ ‘W’ ‘O’ ‘R’ ‘L’ ‘D’ ‘!’ ‘!’ ‘!’ ‘/0’ ‘/0’ ‘/0’ ‘/0’ ‘/0’ ‘/0’ • “HELLO WORLD!!!000000” • Assume 0 = ‘/0’
Example Program • Program 1 (0x21): • sendString(0x31, “HELLO WORLD!!!”); • Program 2 (0x31): • recvString(0x21, “%s”, buffer);
Simulation Application #1 Library COM 4 | | COM 5 Library Application #2
Design Constraints • Use of a constant time, fixed sized queue which does not use the heap • No use of heap: • Flaky memory management support on some embedded platforms. • The runtime memory space of the library is known by compile time • “The lowest average instruction path length required to allocate a single memory slot was 52 (as measured with an instruction level profiler on a variety of software)” • Small CRC algorithm, 8 bit output • Plain standard C, no special libraries
Key Features • KISS Principle • Usability- Printf style statements • Works with many data types • Easy to Debug and Troubleshoot • Flexible, rapid development • Tradeoff • Less efficient, sends more data • May be slightly disadvantageous in a low power setting
Possible Applications • Underwater UAV • sendString(0xF3, “x: %d y: %d z: %d”, my_x, my_y, my_z); • recvString(0xF3, “x: %d y: %d z: %d”, &uav_x, &uav_y, &uav_z); • Underwater Sensor Platform • sendString(0xF2, “temperature: %2.f, oxygen: %d”, temp, oxy); • recvString(0xF2, “temperature: %2.f, oxygen: %d”, &temp, &oxy);
Possible Applications (cont’d) • Communications Device for Divers • sbroadcast(“%s: %s”, username, message); • rbroadcast(“%s: %s”, buddy, his_message); • Message Beacon on a Buoy floating above an Underwater Archaeological Dig • sbroadcast(“BUOY 3 IS GRID 7B ”); • rbroadcast(“%s”, broadcastbuffer);
Room for Improvement • Interface and test with actual hardware • Experiment with… • Different Environments • Dynamically adjust according to error rate • Different windows sizes and frame data field lengths
Challenges & Problems Late project start Matlab+ Serial =
Results Library is highly functional and usable Major objectives achieved, project is a success
Acknowledgements • Thanks! • Prof. Ryan Kastner • DibaMirza • Jennifer Trezzo • Nancy Wu