Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: snet.cpp
- Revision:
- 2:397316d97354
- Parent:
- 1:9c211ac06a12
- Child:
- 3:59f3c806f127
diff -r 9c211ac06a12 -r 397316d97354 snet.cpp
--- a/snet.cpp Thu Mar 05 00:18:25 2015 +0000
+++ b/snet.cpp Tue Mar 31 22:27:25 2015 +0000
@@ -1,17 +1,51 @@
+/*
+ The MIT License (MIT)
+
+ Copyright (c) 2015 Tom Soulanille
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+
+ @file snet.cpp
+ @purpose simple networking
+ @version 0.1
+ @date 31 March 2015
+ @author Tom Soulanille
+*/
+
#include "snet.h"
-//extern MODSERIAL pc;
-
-//extern void print_hex(uint8_t *p, int len);
-
-//volatile uint32_t enet_rx_cnt;
-//volatile int enet_rx_balance;
+#if 0
+// if not otherwise available, use this to print memory in hex
+void print_hex(const uint8_t *p, int len) {
+ while (len > 0) {
+ for (int i=0; i<16 && len-->0; i++) {
+ printf(" 0x%02x", *p++);
+ }
+ printf("\r\n");
+ }
+}
+#endif
const uint8_t Snet::broadcast_mac[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
const uint8_t Snet::ipEtherType[] = { 0x08, 0x00 };
const uint8_t Snet::arp_req_payload_prefix[] = { 0x0, 0x1, 0x8, 0x0, 0x6, 0x4, 0x0, 0x1 };
-
Snet::Snet(): eth()
{
eth.address((char *) my_mac);
@@ -73,7 +107,8 @@
};
void Snet::got_unicast(uint8_t *buf, int len) {
- if (memcmp(&buf[ENET_ETHERTYPE_O], ipEtherType, 2)) return; // IP packets only from this point
+ if (memcmp(&buf[ENET_ETHERTYPE_O], ipEtherType, 2)) return;
+ // IP packets only from this point
// printf("Unicast from: %02x:%02x:%02x:%02x:%02x:%02x %d\r\n",
// buf[6], buf[7], buf[8], buf[9], buf[10], buf[11], enet_rx_int_cnt);
memcpy(correspondent_mac, &buf[ENET_SMAC_O], sizeof(correspondent_mac));