RealtimeCompLab2

Dependencies:   mbed

Fork of PPP-Blinky by Nicolas Nackel

Revision:
63:9253b0e1b7d8
Parent:
62:f192926e42f1
Child:
64:677b9713a120
--- a/main.cpp	Sun Jun 04 20:32:27 2017 +0000
+++ b/main.cpp	Sun Jun 04 20:47:53 2017 +0000
@@ -141,11 +141,11 @@
 
 int pc_getBuf() // get one character from the buffer
 {
-        __disable_irq(); // critical section start
-        int x = ppp.rx.buf[ ppp.rx.tail ];
-        ppp.rx.tail=(ppp.rx.tail+1)&(BUFLEN-1);
-        __enable_irq(); // critical section end
-        return x;
+    __disable_irq(); // critical section start
+    int x = ppp.rx.buf[ ppp.rx.tail ];
+    ppp.rx.tail=(ppp.rx.tail+1)&(BUFLEN-1);
+    __enable_irq(); // critical section end
+    return x;
 }
 
 void processHDLCFrame(int start, int end)   // process received frame
@@ -274,13 +274,13 @@
     char * udpPkt = ppp.pkt.buf+4; // udp packet start
     int headerSizeIP = (( udpPkt[0]&0xf)*4);
     char * udpBlock = udpPkt + headerSizeIP; // udp info start
-#ifndef SERIAL_PORT_MONITOR_NO    
+#ifndef SERIAL_PORT_MONITOR_NO
     char * udpSrc = udpBlock; // source port
     char * udpDst = udpBlock+2; // destination port
-#endif    
+#endif
     char * udpLen = udpBlock+4; // udp data length
     char * udpInf = udpBlock+8; // actual start of info
-#ifndef SERIAL_PORT_MONITOR_NO    
+#ifndef SERIAL_PORT_MONITOR_NO
     int srcPort = (udpSrc[0]<<8) | udpSrc[1];
     int dstPort = (udpDst[0]<<8) | udpDst[1];
     char * srcIP = udpPkt+12; // udp src addr
@@ -363,10 +363,10 @@
         ipTTL[0]--; // decrement time to live
         char * srcAdr = ipPkt+12;
         char * dstAdr = ipPkt+16;
-#ifndef SERIAL_PORT_MONITOR_NO        
+#ifndef SERIAL_PORT_MONITOR_NO
         int icmpIdent = (icmpType[4]<<8)|icmpType[5];
         int icmpSequence = (icmpType[6]<<8)|icmpType[7];
-#endif        
+#endif
         debug("ICMP PING %d.%d.%d.d %d.%d.%d.%d ", srcAdr[0],srcAdr[1],srcAdr[2],srcAdr[3],dstAdr[0],dstAdr[1],dstAdr[2],dstAdr[3]);
         debug("Ident %04x Sequence %04d ",icmpIdent,icmpSequence);
         char src[4];
@@ -421,7 +421,7 @@
 void dumpHeaderIP ()
 {
     char * ipPkt = ppp.pkt.buf+4; // ip packet start
-#ifndef SERIAL_PORT_MONITOR_NO    
+#ifndef SERIAL_PORT_MONITOR_NO
     char * version =    ipPkt; // top 4 bits
     char * ihl =        ipPkt; // bottom 4 bits
     char * dscp =       ipPkt+1; // top 6 bits
@@ -432,7 +432,7 @@
     char * ttl =        ipPkt+8; // 1 byte
     char * protocol =   ipPkt+9; // 1 byte
     char * headercheck= ipPkt+10; // 2 bytes
-#endif    
+#endif
     char * srcAdr =     ipPkt+12; // 4 bytes
     char * dstAdr =     ipPkt+16; // 4 bytes = total of 20 bytes
 
@@ -446,7 +446,7 @@
     int flagsIP = flags[0]>>14&3;
     int ttlIP = ttl[0];
     int protocolIP = protocol[0];
-    int checksumIP = (headercheck[0]<<8)|headercheck[1];    
+    int checksumIP = (headercheck[0]<<8)|headercheck[1];
 #endif
 
     char srcIP [16];
@@ -461,15 +461,15 @@
 {
     int headerSizeIP     = (ppp.pkt.buf[4]&0xf)*4; // header size of ip portion
     char * tcpStart      =  ppp.pkt.buf+4+headerSizeIP; // start of tcp packet
-#ifndef SERIAL_PORT_MONITOR_NO    
+#ifndef SERIAL_PORT_MONITOR_NO
     char * seqtcp        = tcpStart + 4;  // 4 bytes
     char * acktcp        = tcpStart + 8;  // 4 bytes
-#endif    
+#endif
     char * flagbitstcp   = tcpStart + 12; // 9 bits
-#ifndef SERIAL_PORT_MONITOR_NO    
+#ifndef SERIAL_PORT_MONITOR_NO
     unsigned int seq = (seqtcp[0]<<24)|(seqtcp[1]<<16)|(seqtcp[2]<<8)|(seqtcp[3]);
     unsigned int ack = (acktcp[0]<<24)|(acktcp[1]<<16)|(acktcp[2]<<8)|(acktcp[3]);
-#endif    
+#endif
     int flags = ((flagbitstcp[0]&1)<<8)|flagbitstcp[1];
 
     char flagInfo[10];
@@ -658,10 +658,10 @@
     headercheck[0]=0; // IP header checksum
     headercheck[1]=0; // IP header checksum
     headerCheckSum(); // calculate the IP header checksum
-    
+
     // now we have to build a 12-byte TCP "pseudo-header" in front of the TCP header (containing some IP header values) in order to correctly calculate the TCP checksum
-    // this header  contains the most important parts of the IP header, i.e. source and destination address, protocol number and data length. 
-    
+    // this header  contains the most important parts of the IP header, i.e. source and destination address, protocol number and data length.
+
     char * pseudoHeader = s-12; // mark the start of the TCP pseudo-header
     memcpy(tempHold, pseudoHeader, 12); // preserve the 12 bytes in the IP header where the TCP pseudo-Header must be built
     memcpy( pseudoHeader+0, srcAdr, 8); // IP source and destination addresses from IP header
@@ -671,7 +671,7 @@
     memset( pseudoHeader+11, tcpSize, 1); // size of IP data (TCP packet size)
 
     // pseudo-header built, now we can calculate TCP checksum
-    
+
     checksumtcp[0]=0;
     checksumtcp[1]=0;
     int pseudoHeaderSum=dataCheckSum(pseudoHeader,tcpSize+12); // calculate the TCP checksum starting at the pseudo-header
@@ -706,7 +706,7 @@
 void TCPpacket()
 {
     char * ipPkt = ppp.pkt.buf+4; // ip packet start
-#ifndef SERIAL_PORT_MONITOR_NO    
+#ifndef SERIAL_PORT_MONITOR_NO
     char * version =    ipPkt;    // top 4 bits
     char * ihl =        ipPkt;    // bottom 4 bits
     char * dscp =       ipPkt+1;  // top 6 bits
@@ -717,7 +717,7 @@
     char * ttl =        ipPkt+8;  // 1 byte
     char * protocol =   ipPkt+9;  // 1 byte
     char * headercheck= ipPkt+10; // 2 bytes
-#endif    
+#endif
     char * srcAdr =     ipPkt+12; // 4 bytes
     char * dstAdr =     ipPkt+16; // 4 bytes = total of 20 bytes
 
@@ -732,7 +732,7 @@
     int ttlIP = ttl[0];
     int protocolIP = protocol[0];
     int checksumIP = (headercheck[0]<<8)|headercheck[1];
-#endif    
+#endif
     char srcIP [16];
     snprintf(srcIP,16, "%d.%d.%d.%d", srcAdr[0],srcAdr[1],srcAdr[2],srcAdr[3]);
     char dstIP [16];