increased chunk size

Dependencies:   HTTPClient-SSL

Fork of MTS-Socket by MultiTech

Committer:
mfiore
Date:
Mon Jun 23 14:33:39 2014 +0000
Revision:
12:9efe3cc3cb6c
Parent:
10:42220b7df921
Child:
14:7643ed024fe8
change all instances of SUCCESS to MTS_SUCCESS

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mfiore 9:b2e3862705fc 1 #ifndef TESTUDPSOCKET_H
mfiore 9:b2e3862705fc 2 #define TESTUDPSOCKET_H
mfiore 9:b2e3862705fc 3
mfiore 9:b2e3862705fc 4 #include "mtsas.h"
mfiore 9:b2e3862705fc 5
mfiore 9:b2e3862705fc 6 using namespace mts;
mfiore 9:b2e3862705fc 7
mfiore 9:b2e3862705fc 8 class TestUDPSocket : public TestCollection
mfiore 9:b2e3862705fc 9 {
mfiore 9:b2e3862705fc 10 public:
mfiore 9:b2e3862705fc 11 TestUDPSocket();
mfiore 9:b2e3862705fc 12 virtual void run();
mfiore 9:b2e3862705fc 13
mfiore 9:b2e3862705fc 14 private:
mfiore 9:b2e3862705fc 15 MTSSerialFlowControl* io;
mfiore 9:b2e3862705fc 16 Cellular* radio;
mfiore 9:b2e3862705fc 17 UDPSocket* sock;
mfiore 9:b2e3862705fc 18 };
mfiore 9:b2e3862705fc 19
mfiore 9:b2e3862705fc 20 const char UDP_TEST_SERVER[] = "";
mfiore 9:b2e3862705fc 21 const int UDP_TEST_PORT = -1;
mfiore 9:b2e3862705fc 22
mfiore 9:b2e3862705fc 23 const char TEST_PATTERN[] = "abcdefghijklmnopqrstuvwzyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}|\r\n"
mfiore 9:b2e3862705fc 24 "abcdefghijklmnopqrstuvwzyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}/\r\n"
mfiore 9:b2e3862705fc 25 "abcdefghijklmnopqrstuvwzyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}-\r\n"
mfiore 9:b2e3862705fc 26 "abcdefghijklmnopqrstuvwzyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}\\\r\n"
mfiore 9:b2e3862705fc 27 "abcdefghijklmnopqrstuvwzyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}|\r\n"
mfiore 9:b2e3862705fc 28 "abcdefghijklmnopqrstuvwzyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}/\r\n"
mfiore 9:b2e3862705fc 29 "abcdefghijklmnopqrstuvwzyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}-\r\n"
mfiore 9:b2e3862705fc 30 "abcdefghijklmnopqrstuvwzyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}\\\r\n"
mfiore 9:b2e3862705fc 31 "abcdefghijklmnopqrstuvwzyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}*\r\n";
mfiore 9:b2e3862705fc 32
mfiore 9:b2e3862705fc 33 TestUDPSocket::TestUDPSocket() : TestCollection("TestUDPSocket") {}
mfiore 9:b2e3862705fc 34
mfiore 9:b2e3862705fc 35 void TestUDPSocket::run() {
mfiore 10:42220b7df921 36 const char APN[] = "";
mfiore 10:42220b7df921 37
mfiore 9:b2e3862705fc 38 Endpoint remote;
mfiore 9:b2e3862705fc 39 remote.set_address(UDP_TEST_SERVER, UDP_TEST_PORT);
mfiore 9:b2e3862705fc 40
mfiore 9:b2e3862705fc 41 MTSLog::setLogLevel(MTSLog::TRACE_LEVEL);
mfiore 9:b2e3862705fc 42 Test::start("Setup");
mfiore 9:b2e3862705fc 43 io = new MTSSerialFlowControl(D8, D2, D3, D6);
mfiore 9:b2e3862705fc 44 io->baud(115200);
mfiore 9:b2e3862705fc 45 radio = CellularFactory::create(io);
mfiore 9:b2e3862705fc 46 if (! radio) {
mfiore 9:b2e3862705fc 47 Test::assertTrue(false);
mfiore 9:b2e3862705fc 48 }
mfiore 9:b2e3862705fc 49 radio->configureSignals(D4, D7, RESET);
mfiore 9:b2e3862705fc 50 Transport::setTransport(radio);
mfiore 9:b2e3862705fc 51
mfiore 9:b2e3862705fc 52 for (int i = 0; i < 10; i++) {
mfiore 9:b2e3862705fc 53 if (i >= 10) {
mfiore 9:b2e3862705fc 54 Test::assertTrue(false);
mfiore 9:b2e3862705fc 55 }
mfiore 12:9efe3cc3cb6c 56 if (radio->setApn(APN) == MTS_SUCCESS) {
mfiore 9:b2e3862705fc 57 break;
mfiore 9:b2e3862705fc 58 } else {
mfiore 9:b2e3862705fc 59 wait(1);
mfiore 9:b2e3862705fc 60 }
mfiore 9:b2e3862705fc 61 }
mfiore 9:b2e3862705fc 62 for (int i = 0; i < 3; i++) {
mfiore 9:b2e3862705fc 63 if (i >= 3) {
mfiore 9:b2e3862705fc 64 Test::assertTrue(false);
mfiore 9:b2e3862705fc 65 }
mfiore 9:b2e3862705fc 66 if (radio->connect()) {
mfiore 9:b2e3862705fc 67 break;
mfiore 9:b2e3862705fc 68 } else {
mfiore 9:b2e3862705fc 69 wait(1);
mfiore 9:b2e3862705fc 70 }
mfiore 9:b2e3862705fc 71 }
mfiore 9:b2e3862705fc 72
mfiore 9:b2e3862705fc 73 for (int i = 0; i < 5; i++) {
mfiore 9:b2e3862705fc 74 if (i >= 5) {
mfiore 9:b2e3862705fc 75 Test::assertTrue(false);
mfiore 9:b2e3862705fc 76 }
mfiore 9:b2e3862705fc 77 if (radio->ping()) {
mfiore 9:b2e3862705fc 78 break;
mfiore 9:b2e3862705fc 79 } else {
mfiore 9:b2e3862705fc 80 wait(1);
mfiore 9:b2e3862705fc 81 }
mfiore 9:b2e3862705fc 82 }
mfiore 9:b2e3862705fc 83
mfiore 9:b2e3862705fc 84 sock = new UDPSocket();
mfiore 9:b2e3862705fc 85 sock->set_blocking(false, 10000);
mfiore 9:b2e3862705fc 86 Test::end();
mfiore 9:b2e3862705fc 87
mfiore 9:b2e3862705fc 88 /* set up an UDP echo server using netcat
mfiore 9:b2e3862705fc 89 * nc -e /bin/cat -l -u -p TEST_PORT
mfiore 9:b2e3862705fc 90 * this should echo back anything you send to it
mfiore 9:b2e3862705fc 91 */
mfiore 9:b2e3862705fc 92
mfiore 9:b2e3862705fc 93 int bufsize = 1024;
mfiore 9:b2e3862705fc 94 char buf[bufsize];
mfiore 9:b2e3862705fc 95 int size = 0;
mfiore 9:b2e3862705fc 96
mfiore 9:b2e3862705fc 97 for (int i = 0; i < 10; i++) {
mfiore 9:b2e3862705fc 98 Test::start("Test UDP");
mfiore 9:b2e3862705fc 99 logInfo("sending to remote");
mfiore 9:b2e3862705fc 100 size = sock->sendTo(remote, (char*) TEST_PATTERN, sizeof(TEST_PATTERN));
mfiore 9:b2e3862705fc 101 if (size != sizeof(TEST_PATTERN)) {
mfiore 9:b2e3862705fc 102 logError("failed to send - only sent %d bytes", size);
mfiore 9:b2e3862705fc 103 Test::assertTrue(false);
mfiore 9:b2e3862705fc 104 }
mfiore 9:b2e3862705fc 105 logInfo("receiving from remote");
mfiore 9:b2e3862705fc 106 size = sock->receiveFrom(remote, buf, bufsize);
mfiore 9:b2e3862705fc 107 if (size != sizeof(TEST_PATTERN)) {
mfiore 9:b2e3862705fc 108 logError("failed to receive - only received %d bytes", size);
mfiore 9:b2e3862705fc 109 Test::assertTrue(false);
mfiore 9:b2e3862705fc 110 } else {
mfiore 9:b2e3862705fc 111 for (int j = 0; j < sizeof(TEST_PATTERN); j++) {
mfiore 9:b2e3862705fc 112 if (buf[j] != TEST_PATTERN[j]) {
mfiore 9:b2e3862705fc 113 logError("patterns don't match at %d, pattern [%#02X] received [%#02X]", j, TEST_PATTERN[j], buf[j]);
mfiore 9:b2e3862705fc 114 Test::assertTrue(false);
mfiore 9:b2e3862705fc 115 }
mfiore 9:b2e3862705fc 116 }
mfiore 9:b2e3862705fc 117 }
mfiore 9:b2e3862705fc 118 Test::end();
mfiore 9:b2e3862705fc 119 wait(5);
mfiore 9:b2e3862705fc 120 }
mfiore 9:b2e3862705fc 121 }
mfiore 9:b2e3862705fc 122
mfiore 9:b2e3862705fc 123 #endif