Example program for the C027Interface

Dependencies:   C027Interface NetworkSocketAPI mbed

Committer:
geky
Date:
Fri Apr 15 16:10:15 2016 +0000
Revision:
56:62bb3fbd1b7e
Parent:
50:a9926b8b21fe
Child:
57:f3faa28dc87e
Ported Hello World program to C027Interface

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sam_grove 0:1984a177ff56 1 /* NetworkSocketAPI Example Program
sam_grove 0:1984a177ff56 2 * Copyright (c) 2015 ARM Limited
sam_grove 0:1984a177ff56 3 *
sam_grove 0:1984a177ff56 4 * Licensed under the Apache License, Version 2.0 (the "License");
sam_grove 0:1984a177ff56 5 * you may not use this file except in compliance with the License.
sam_grove 0:1984a177ff56 6 * You may obtain a copy of the License at
sam_grove 0:1984a177ff56 7 *
sam_grove 0:1984a177ff56 8 * http://www.apache.org/licenses/LICENSE-2.0
sam_grove 0:1984a177ff56 9 *
sam_grove 0:1984a177ff56 10 * Unless required by applicable law or agreed to in writing, software
sam_grove 0:1984a177ff56 11 * distributed under the License is distributed on an "AS IS" BASIS,
sam_grove 0:1984a177ff56 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
sam_grove 0:1984a177ff56 13 * See the License for the specific language governing permissions and
sam_grove 0:1984a177ff56 14 * limitations under the License.
sam_grove 0:1984a177ff56 15 */
sam_grove 0:1984a177ff56 16
sam_grove 0:1984a177ff56 17 #include "mbed.h"
geky 56:62bb3fbd1b7e 18 #include "C027Interface.h"
Christopher Haster 30:f80540b6e2db 19 #include "TCPSocket.h"
sam_grove 0:1984a177ff56 20
geky 56:62bb3fbd1b7e 21 DigitalOut myled(LED1);
sam_grove 50:a9926b8b21fe 22 void flash()
sam_grove 50:a9926b8b21fe 23 {
sam_grove 50:a9926b8b21fe 24 myled = !myled;
sam_grove 50:a9926b8b21fe 25 }
sam_grove 0:1984a177ff56 26
geky 56:62bb3fbd1b7e 27 C027Interface cell;
geky 56:62bb3fbd1b7e 28 TCPSocket socket(&cell);
sam_grove 2:7283ce112304 29
sam_grove 0:1984a177ff56 30 int main()
sam_grove 20:4cb9ef3b0cc9 31 {
sam_grove 20:4cb9ef3b0cc9 32 Ticker t;
sam_grove 24:471a07e886ae 33 t.attach(flash, 0.4f);
bridadan 14:c47437f5dae8 34 printf("NetworkSocketAPI Example\r\n");
sam_grove 4:cb8a17dd6746 35
geky 56:62bb3fbd1b7e 36 cell.connect();
sam_grove 50:a9926b8b21fe 37
geky 56:62bb3fbd1b7e 38 const char *ip = cell.getIPAddress();
geky 56:62bb3fbd1b7e 39 const char *mac = cell.getMACAddress();
Christopher Haster 30:f80540b6e2db 40 printf("IP Address is: %s\r\n", (ip) ? ip : "No IP");
Christopher Haster 30:f80540b6e2db 41 printf("MAC Address is: %s\r\n", (mac) ? mac : "No MAC");
sarahmarshy 22:1d355289fc18 42
Christopher Haster 30:f80540b6e2db 43 socket.open("time-a.nist.gov", 37);
Christopher Haster 30:f80540b6e2db 44 printf("time-a.nist.gov resolved to: %s\r\n", socket.getIPAddress());
sarahmarshy 21:979b1db5d7da 45
sam_grove 24:471a07e886ae 46 char recieved[100] = {0};
Christopher Haster 30:f80540b6e2db 47 int32_t size = 0;
Christopher Haster 30:f80540b6e2db 48 size = socket.recv(recieved, sizeof(recieved));
Christopher Haster 30:f80540b6e2db 49
Christopher Haster 30:f80540b6e2db 50 socket.close();
geky 56:62bb3fbd1b7e 51 cell.disconnect();
Christopher Haster 30:f80540b6e2db 52
Christopher Haster 30:f80540b6e2db 53 printf("Recieved: %ld bytes, %02x%02x%02x%02x\r\n", size,
sam_grove 50:a9926b8b21fe 54 recieved[0], recieved[1], recieved[2], recieved[3]);
sam_grove 24:471a07e886ae 55 printf("NetworkSocketAPI Example Finished\r\n");
sam_grove 0:1984a177ff56 56 }