[Tinyos-2-commits] CVS: tinyos-2.x/support/sdk/cpp/sf tcpcomm.cpp, 1.6, 1.7 sfpacket.h, 1.2, 1.3 sfpacket.cpp, 1.3, 1.4

akoepke andreaskoepke at users.sourceforge.net
Fri May 2 02:21:25 PDT 2008


Update of /cvsroot/tinyos/tinyos-2.x/support/sdk/cpp/sf
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv3063

Modified Files:
	tcpcomm.cpp sfpacket.h sfpacket.cpp 
Log Message:
- write a packet in one go to the tcp side
- some hand-written functions replaced by their library equivalents


Index: tcpcomm.cpp
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/support/sdk/cpp/sf/tcpcomm.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** tcpcomm.cpp	21 Apr 2008 19:57:47 -0000	1.6
--- tcpcomm.cpp	2 May 2008 09:21:22 -0000	1.7
***************
*** 211,225 ****
  bool TCPComm::writePacket(int pFD, SFPacket &pPacket)
  {
!     char len = pPacket.getLength();
      int err;
!     if (writeFD(pFD, &len, 1, &err) != 1)
!     {
!         return false;
!     }
!     if (writeFD(pFD, pPacket.getPayload(), len, &err) != len)
!     {
!         return false;
!     }
!     return true;
  }
  
--- 211,217 ----
  bool TCPComm::writePacket(int pFD, SFPacket &pPacket)
  {
!     int len = pPacket.getTcpLength();
      int err;
!     return (writeFD(pFD, pPacket.getTcpPayload(), len, &err) == len);
  }
  

Index: sfpacket.h
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/support/sdk/cpp/sf/sfpacket.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** sfpacket.h	6 Jul 2007 20:29:12 -0000	1.2
--- sfpacket.h	2 May 2008 09:21:22 -0000	1.3
***************
*** 67,72 ****
  /** member vars **/
  protected:
!     /* payload buffer */
!     char payloadBuffer[cMaxPacketLength];
      /* length of byte buffer */
      int length;
--- 67,73 ----
  /** member vars **/
  protected:
!     /* internal buffer */
!     char buffer[cMaxPacketLength + 1];
!     
      /* length of byte buffer */
      int length;
***************
*** 93,96 ****
--- 94,103 ----
      int getLength() const;
  
+     /* return the length that shall be transmitted via TCP */
+     int getTcpLength() const;
+ 
+     /* return the payload of the TCP packet */
+     const char* getTcpPayload();
+     
      /* returns the seqno of this packet */
      int getSeqno() const;

Index: sfpacket.cpp
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/support/sdk/cpp/sf/sfpacket.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** sfpacket.cpp	21 Apr 2008 19:57:47 -0000	1.3
--- sfpacket.cpp	2 May 2008 09:21:23 -0000	1.4
***************
*** 33,38 ****
  #include "sfpacket.h"
  
! SFPacket::SFPacket(int pType, int pSeqno)
! {
      length = 0;
      seqno = pSeqno;
--- 33,37 ----
  #include "sfpacket.h"
  
! SFPacket::SFPacket(int pType, int pSeqno) {
      length = 0;
      seqno = pSeqno;
***************
*** 41,46 ****
  
  // copy constructor
! SFPacket::SFPacket(const SFPacket &pPacket)
! {
      length = pPacket.getLength();
      type = pPacket.getType();
--- 40,44 ----
  
  // copy constructor
! SFPacket::SFPacket(const SFPacket &pPacket) {
      length = pPacket.getLength();
      type = pPacket.getType();
***************
*** 56,71 ****
  const char* SFPacket::getPayload() const
  {
!     if ( ((type == SF_PACKET_ACK) || (type == SF_PACKET_NO_ACK)))
!     {
!         return payloadBuffer;
      }
!     else
!     {
          return NULL;
      }
  }
  
! int SFPacket::getLength() const
! {
      return length;
  }
--- 54,66 ----
  const char* SFPacket::getPayload() const
  {
!     if(((type == SF_PACKET_ACK) || (type == SF_PACKET_NO_ACK))) {
!         return buffer + 1;
      }
!     else {
          return NULL;
      }
  }
  
! int SFPacket::getLength() const {
      return length;
  }
***************
*** 86,93 ****
      {
          length = pLength;
!         for (int i=0; i < pLength; i++)
!         {
!             payloadBuffer[i] = *(pBuffer+i);
!         }
          return true;
      }
--- 81,85 ----
      {
          length = pLength;
!         memcpy(buffer + 1, pBuffer, pLength);
          return true;
      }
***************
*** 115,139 ****
  {
      bool retval=false;
!     if (!((pPacket.getType() != type) || (pPacket.getLength() != length) || pPacket.getSeqno() != seqno))
!     {
!         if ((type == SF_PACKET_ACK) || (type == SF_PACKET_NO_ACK))
!         {
!             const char* cmpBuffer = pPacket.getPayload();
!             if (cmpBuffer) {
! 	        retval = true;
!                 // compare buffers
!                 for (int i=0; i < length; i++)
!                 {
!                     if (payloadBuffer[i] != cmpBuffer[i])
!                     {
!                         i = length;
!                         retval = false;
!                     }
!                 }
! 	    }
!         }
!         else
!         {
!             retval = true;
          }
      }
--- 107,113 ----
  {
      bool retval=false;
!     if((pPacket.getType() == type) && (pPacket.getLength() == length) && (pPacket.getSeqno() == seqno)) {
!         if((type == SF_PACKET_ACK) || (type == SF_PACKET_NO_ACK)) {
!             retval = (memcmp(pPacket.getPayload(), getPayload(), length) == 0);
          }
      }
***************
*** 141,142 ****
--- 115,128 ----
  }
  
+     /* return the length that shall be transmitted via TCP */
+ int SFPacket::getTcpLength() const {
+     return length + 1;
+ }
+ 
+ /* return the payload of the TCP packet */
+ const char* SFPacket::getTcpPayload() {
+     char l = length;
+     buffer[0] = l;
+     return buffer;
+ }
+ 



More information about the Tinyos-2-commits mailing list