Development mbed library for MAX32630FTHR
Dependents: blinky_max32630fthr
tools/host_tests/udpecho_client_auto.py@3:1198227e6421, 2016-12-16 (annotated)
- Committer:
- switches
- Date:
- Fri Dec 16 16:27:57 2016 +0000
- Revision:
- 3:1198227e6421
- Parent:
- 0:5c4d7b2438d3
Changed ADC scale for MAX32625 platforms to 1.2V full scale to match MAX32630 platforms
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
switches | 0:5c4d7b2438d3 | 1 | """ |
switches | 0:5c4d7b2438d3 | 2 | mbed SDK |
switches | 0:5c4d7b2438d3 | 3 | Copyright (c) 2011-2013 ARM Limited |
switches | 0:5c4d7b2438d3 | 4 | |
switches | 0:5c4d7b2438d3 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); |
switches | 0:5c4d7b2438d3 | 6 | you may not use this file except in compliance with the License. |
switches | 0:5c4d7b2438d3 | 7 | You may obtain a copy of the License at |
switches | 0:5c4d7b2438d3 | 8 | |
switches | 0:5c4d7b2438d3 | 9 | http://www.apache.org/licenses/LICENSE-2.0 |
switches | 0:5c4d7b2438d3 | 10 | |
switches | 0:5c4d7b2438d3 | 11 | Unless required by applicable law or agreed to in writing, software |
switches | 0:5c4d7b2438d3 | 12 | distributed under the License is distributed on an "AS IS" BASIS, |
switches | 0:5c4d7b2438d3 | 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
switches | 0:5c4d7b2438d3 | 14 | See the License for the specific language governing permissions and |
switches | 0:5c4d7b2438d3 | 15 | limitations under the License. |
switches | 0:5c4d7b2438d3 | 16 | """ |
switches | 0:5c4d7b2438d3 | 17 | |
switches | 0:5c4d7b2438d3 | 18 | import sys |
switches | 0:5c4d7b2438d3 | 19 | import socket |
switches | 0:5c4d7b2438d3 | 20 | from sys import stdout |
switches | 0:5c4d7b2438d3 | 21 | from SocketServer import BaseRequestHandler, UDPServer |
switches | 0:5c4d7b2438d3 | 22 | |
switches | 0:5c4d7b2438d3 | 23 | class UDPEchoClient_Handler(BaseRequestHandler): |
switches | 0:5c4d7b2438d3 | 24 | def handle(self): |
switches | 0:5c4d7b2438d3 | 25 | """ One handle per connection |
switches | 0:5c4d7b2438d3 | 26 | """ |
switches | 0:5c4d7b2438d3 | 27 | data, socket = self.request |
switches | 0:5c4d7b2438d3 | 28 | socket.sendto(data, self.client_address) |
switches | 0:5c4d7b2438d3 | 29 | if '{{end}}' in data: |
switches | 0:5c4d7b2438d3 | 30 | |
switches | 0:5c4d7b2438d3 | 31 | print data |
switches | 0:5c4d7b2438d3 | 32 | else: |
switches | 0:5c4d7b2438d3 | 33 | sys.stdout.write('.') |
switches | 0:5c4d7b2438d3 | 34 | stdout.flush() |
switches | 0:5c4d7b2438d3 | 35 | |
switches | 0:5c4d7b2438d3 | 36 | class UDPEchoClientTest(): |
switches | 0:5c4d7b2438d3 | 37 | |
switches | 0:5c4d7b2438d3 | 38 | def send_server_ip_port(self, selftest, ip_address, port_no): |
switches | 0:5c4d7b2438d3 | 39 | c = selftest.mbed.serial_readline() # 'UDPCllient waiting for server IP and port...' |
switches | 0:5c4d7b2438d3 | 40 | if c is None: |
switches | 0:5c4d7b2438d3 | 41 | selftest.print_result(selftest.RESULT_IO_SERIAL) |
switches | 0:5c4d7b2438d3 | 42 | return |
switches | 0:5c4d7b2438d3 | 43 | selftest.notify(c.strip()) |
switches | 0:5c4d7b2438d3 | 44 | |
switches | 0:5c4d7b2438d3 | 45 | selftest.notify("HOST: Sending server IP Address to target...") |
switches | 0:5c4d7b2438d3 | 46 | connection_str = ip_address + ":" + str(port_no) + "\n" |
switches | 0:5c4d7b2438d3 | 47 | selftest.mbed.serial_write(connection_str) |
switches | 0:5c4d7b2438d3 | 48 | |
switches | 0:5c4d7b2438d3 | 49 | c = selftest.mbed.serial_readline() # 'UDPCllient waiting for server IP and port...' |
switches | 0:5c4d7b2438d3 | 50 | if c is None: |
switches | 0:5c4d7b2438d3 | 51 | self.print_result(selftest.RESULT_IO_SERIAL) |
switches | 0:5c4d7b2438d3 | 52 | return |
switches | 0:5c4d7b2438d3 | 53 | selftest.notify(c.strip()) |
switches | 0:5c4d7b2438d3 | 54 | return selftest.RESULT_PASSIVE |
switches | 0:5c4d7b2438d3 | 55 | |
switches | 0:5c4d7b2438d3 | 56 | def test(self, selftest): |
switches | 0:5c4d7b2438d3 | 57 | # We need to discover SERVEP_IP and set up SERVER_PORT |
switches | 0:5c4d7b2438d3 | 58 | # Note: Port 7 is Echo Protocol: |
switches | 0:5c4d7b2438d3 | 59 | # |
switches | 0:5c4d7b2438d3 | 60 | # Port number rationale: |
switches | 0:5c4d7b2438d3 | 61 | # |
switches | 0:5c4d7b2438d3 | 62 | # The Echo Protocol is a service in the Internet Protocol Suite defined |
switches | 0:5c4d7b2438d3 | 63 | # in RFC 862. It was originally proposed for testing and measurement |
switches | 0:5c4d7b2438d3 | 64 | # of round-trip times[citation needed] in IP networks. |
switches | 0:5c4d7b2438d3 | 65 | # |
switches | 0:5c4d7b2438d3 | 66 | # A host may connect to a server that supports the Echo Protocol using |
switches | 0:5c4d7b2438d3 | 67 | # the Transmission Control Protocol (TCP) or the User Datagram Protocol |
switches | 0:5c4d7b2438d3 | 68 | # (UDP) on the well-known port number 7. The server sends back an |
switches | 0:5c4d7b2438d3 | 69 | # identical copy of the data it received. |
switches | 0:5c4d7b2438d3 | 70 | SERVER_IP = str(socket.gethostbyname(socket.getfqdn())) |
switches | 0:5c4d7b2438d3 | 71 | SERVER_PORT = 7 |
switches | 0:5c4d7b2438d3 | 72 | |
switches | 0:5c4d7b2438d3 | 73 | # Returning none will suppress host test from printing success code |
switches | 0:5c4d7b2438d3 | 74 | server = UDPServer((SERVER_IP, SERVER_PORT), UDPEchoClient_Handler) |
switches | 0:5c4d7b2438d3 | 75 | print "HOST: Listening for UDP connections..." |
switches | 0:5c4d7b2438d3 | 76 | self.send_server_ip_port(selftest, SERVER_IP, SERVER_PORT) |
switches | 0:5c4d7b2438d3 | 77 | server.serve_forever() |