PTP echo test

Files CCore/inc/net/PTPEchoTest.h CCore/src/net/PTPEchoTest.cpp

EchoTest class is a simple PTP::ServerDevice processor class. It accepts PTP transactions with service id equals 10000 and function id equals 1.


class EchoTest : NoCopy
 {
   ....

  public: 
  
   static const ServiceIdType ServiceId = 10000 ;
   static const FunctionIdType FunctionId = 1 ;
   
   struct Ext;
  
   explicit EchoTest(StrLen ptp_server_name);
   
   ~EchoTest();

   PacketMultipointDevice * getMPDevice() const;
 };

The client info payload must start with the data length, encoded as an uint32 value in bigendian byte order and continues with arbitrary data payload of this length. EchoTest sends the packet back with the error code equals 0 and the same data payload.

getMPDevice() returns the pointer to the PacketMultipointDevice object the PTP server is attached to.


struct Input
 {
  uint32 service_id;  // 10000
  uint32 function_id; // 1
  uint32 len;
  uint8 data[len];
 };

struct Output
 {
  uint32 service_id;  // 10000
  uint32 function_id; // 1
  uint32 error_id;    // 0
  uint8 data[len];
 };

I.e. the output packet content is almost the same as the input, except the len field is erased.

This class is designed for the testing purpose.

The inner class EchoTest::Ext can be used to perform transactions from the PTP::ClientDevice, using Ext extension.


struct EchoTest::Ext : ExtBase<EchoTest::ServiceId,EchoTest::FunctionId,MovePacketBuf>
 {
  struct InputType // + uint8 info[len];
   {
    static const uint32 MaxLen = MaxInfoLen ;
   
    uint32 len;
    
    explicit InputType(ulen len_) : len(len_) {}
    
    // save object
    
    enum { SaveLoadLen = SaveLenCounter<uint32>::SaveLoadLen };
  
    template <class Dev>
    void save(Dev &dev) const;
   };
   
  struct OutputType
   {
    PtrLen<const uint8> info;
    
    // load object
    
    template <class Dev>
    void load(Dev &dev);
   };
   
  PtrLen<const uint8> info; 
  
  void done(const OutputType &output);
 };