|
| 1 | +#include <Arduino.h> |
| 2 | +#include <HardwareSerial.h> |
| 3 | +#include <inttypes.h> |
| 4 | +#include <utility/uip_debug.h> |
| 5 | +extern "C" { |
| 6 | + #import "utility/uip.h" |
| 7 | +} |
| 8 | + |
| 9 | +struct uip_conn con[UIP_CONNS]; |
| 10 | + |
| 11 | +void |
| 12 | +UIPDebug::uip_debug_printconns() |
| 13 | +{ |
| 14 | + for(uint8_t i=0;i<UIP_CONNS;i++) |
| 15 | + { |
| 16 | + if (uip_debug_printcon(&con[i],&uip_conns[i])) |
| 17 | + { |
| 18 | + Serial.print("connection["); |
| 19 | + Serial.print(i); |
| 20 | + Serial.println("] changed."); |
| 21 | + } |
| 22 | + } |
| 23 | +} |
| 24 | + |
| 25 | +bool |
| 26 | +UIPDebug::uip_debug_printcon(struct uip_conn *lhs,struct uip_conn *rhs) |
| 27 | +{ |
| 28 | + bool changed = false; |
| 29 | + if (!uip_ipaddr_cmp(lhs->ripaddr,rhs->ripaddr)) |
| 30 | + { |
| 31 | + Serial.print(" ripaddr: "); |
| 32 | + uip_debug_printbytes((const uint8_t *)lhs->ripaddr,4); |
| 33 | + Serial.print(" -> "); |
| 34 | + uip_debug_printbytes((const uint8_t *)rhs->ripaddr,4); |
| 35 | + Serial.println(); |
| 36 | + uip_ipaddr_copy(lhs->ripaddr,rhs->ripaddr); |
| 37 | + changed = true; |
| 38 | + } |
| 39 | + if (lhs->lport != rhs->lport) |
| 40 | + { |
| 41 | + Serial.print(" lport: "); |
| 42 | + Serial.print(htons(lhs->lport)); |
| 43 | + Serial.print(" -> "); |
| 44 | + Serial.println(htons(rhs->lport)); |
| 45 | + lhs->lport = rhs->lport; |
| 46 | + changed = true; |
| 47 | + } |
| 48 | + if (lhs->rport != rhs->rport) |
| 49 | + { |
| 50 | + Serial.print(" rport: "); |
| 51 | + Serial.print(htons(lhs->rport)); |
| 52 | + Serial.print(" -> "); |
| 53 | + Serial.println(htons(rhs->rport)); |
| 54 | + lhs->rport = rhs->rport; |
| 55 | + changed = true; |
| 56 | + } |
| 57 | + if ((uint32_t)lhs->rcv_nxt[0] != (uint32_t)rhs->rcv_nxt[0]) |
| 58 | + { |
| 59 | + Serial.print(" rcv_nxt: "); |
| 60 | + uip_debug_printbytes(lhs->rcv_nxt,4); |
| 61 | + Serial.print(" -> "); |
| 62 | + uip_debug_printbytes(rhs->rcv_nxt,4); |
| 63 | + *((uint32_t *)&lhs->rcv_nxt[0]) = (uint32_t)rhs->rcv_nxt[0]; |
| 64 | + Serial.println(); |
| 65 | + changed = true; |
| 66 | + } |
| 67 | + if ((uint32_t)lhs->snd_nxt[0] != (uint32_t)rhs->snd_nxt[0]) |
| 68 | + { |
| 69 | + Serial.print(" snd_nxt: "); |
| 70 | + uip_debug_printbytes(lhs->snd_nxt,4); |
| 71 | + Serial.print(" -> "); |
| 72 | + uip_debug_printbytes(rhs->snd_nxt,4); |
| 73 | + *((uint32_t *)&lhs->snd_nxt[0]) = (uint32_t)rhs->snd_nxt[0]; |
| 74 | + Serial.println(); |
| 75 | + changed = true; |
| 76 | + } |
| 77 | + if (lhs->len != rhs->len) |
| 78 | + { |
| 79 | + Serial.print(" len: "); |
| 80 | + Serial.print(lhs->len); |
| 81 | + Serial.print(" -> "); |
| 82 | + Serial.println(rhs->len); |
| 83 | + lhs->len = rhs->len; |
| 84 | + changed = true; |
| 85 | + } |
| 86 | + if (lhs->mss != rhs->mss) |
| 87 | + { |
| 88 | + Serial.print(" mss: "); |
| 89 | + Serial.print(lhs->mss); |
| 90 | + Serial.print(" -> "); |
| 91 | + Serial.println(rhs->mss); |
| 92 | + lhs->mss = rhs->mss; |
| 93 | + changed = true; |
| 94 | + } |
| 95 | + if (lhs->initialmss != rhs->initialmss) |
| 96 | + { |
| 97 | + Serial.print(" initialmss: "); |
| 98 | + Serial.print(lhs->initialmss); |
| 99 | + Serial.print(" -> "); |
| 100 | + Serial.println(rhs->initialmss); |
| 101 | + lhs->initialmss = rhs->initialmss; |
| 102 | + changed = true; |
| 103 | + } |
| 104 | + if (lhs->sa != rhs->sa) |
| 105 | + { |
| 106 | + Serial.print(" sa: "); |
| 107 | + Serial.print(lhs->sa); |
| 108 | + Serial.print(" -> "); |
| 109 | + Serial.println(rhs->sa); |
| 110 | + lhs->sa = rhs->sa; |
| 111 | + changed = true; |
| 112 | + } |
| 113 | + if (lhs->sv != rhs->sv) |
| 114 | + { |
| 115 | + Serial.print(" sv: "); |
| 116 | + Serial.print(lhs->sv); |
| 117 | + Serial.print(" -> "); |
| 118 | + Serial.println(rhs->sv); |
| 119 | + lhs->sv = rhs->sv; |
| 120 | + changed = true; |
| 121 | + } |
| 122 | + if (lhs->rto != rhs->rto) |
| 123 | + { |
| 124 | + Serial.print(" rto: "); |
| 125 | + Serial.print(lhs->rto); |
| 126 | + Serial.print(" -> "); |
| 127 | + Serial.println(rhs->rto); |
| 128 | + lhs->rto = rhs->rto; |
| 129 | + changed = true; |
| 130 | + } |
| 131 | + if (lhs->tcpstateflags != rhs->tcpstateflags) |
| 132 | + { |
| 133 | + Serial.print(" tcpstateflags: "); |
| 134 | + Serial.print(lhs->tcpstateflags); |
| 135 | + Serial.print(" -> "); |
| 136 | + Serial.println(rhs->tcpstateflags); |
| 137 | + lhs->tcpstateflags = rhs->tcpstateflags; |
| 138 | + changed = true; |
| 139 | + } |
| 140 | + if (lhs->timer != rhs->timer) |
| 141 | + { |
| 142 | + Serial.print(" timer: "); |
| 143 | + Serial.print(lhs->timer); |
| 144 | + Serial.print(" -> "); |
| 145 | + Serial.println(rhs->timer); |
| 146 | + lhs->timer = rhs->timer; |
| 147 | + changed = true; |
| 148 | + } |
| 149 | + if (lhs->nrtx != rhs->nrtx) |
| 150 | + { |
| 151 | + Serial.print(" nrtx: "); |
| 152 | + Serial.print(lhs->nrtx); |
| 153 | + Serial.print(" -> "); |
| 154 | + Serial.println(rhs->nrtx); |
| 155 | + lhs->nrtx = rhs->nrtx; |
| 156 | + changed = true; |
| 157 | + } |
| 158 | + return changed; |
| 159 | +} |
| 160 | + |
| 161 | +void |
| 162 | +UIPDebug::uip_debug_printbytes(const uint8_t *data, uint8_t len) |
| 163 | +{ |
| 164 | + for(uint8_t i=0;i<len;i++) |
| 165 | + { |
| 166 | + Serial.print(data[i]); |
| 167 | + if (i<len-1) |
| 168 | + Serial.print(","); |
| 169 | + } |
| 170 | +} |
0 commit comments