Main MRPT website > C++ reference for MRPT 1.5.9
CInterfaceFTDI_common.cpp
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +---------------------------------------------------------------------------+ */
9 
10 #include "hwdrivers-precomp.h" // Precompiled headers
11 
13 
14 using namespace mrpt;
15 using namespace mrpt::hwdrivers;
16 
17 /*-------------------------------------------------------------
18  Read
19 -------------------------------------------------------------*/
20 size_t CInterfaceFTDI::Read(void *Buffer, size_t Count)
21 {
22  if (!Count) return 0;
23 
24  // Employ a circular_buffer to speed-up lots of small readings:
25  if (m_readBuffer.size()>=Count)
26  {
27  // It's enough with the data in the buffer:
28  m_readBuffer.pop_many(reinterpret_cast<uint8_t*>(Buffer),Count);
29  return Count;
30  }
31  else
32  {
33  // More data must be read:
34  uint8_t buf[4000];
35 
36  unsigned long nActualRead=0;
37  unsigned long to_read=std::min(m_readBuffer.available(),sizeof(buf));
38 
39  ftdi_read(buf,to_read,&nActualRead); //ftdi_read(Buffer,(unsigned long)Count, &ret );
40 
41  // Save data into the circular buffer:
42  m_readBuffer.push_many(buf,nActualRead);
43 
44  // Read the required amount of bytes:
45  size_t nActualReturn = std::min( m_readBuffer.size(), Count );
46 
47  m_readBuffer.pop_many(reinterpret_cast<uint8_t*>(Buffer),nActualReturn);
48 
49  return nActualReturn;
50  }
51 }
52 
53 /*-------------------------------------------------------------
54  Write
55 -------------------------------------------------------------*/
56 size_t CInterfaceFTDI::Write(const void *Buffer, size_t Count)
57 {
58  unsigned long ret=0;
59  ftdi_write(Buffer,(unsigned long)Count, &ret );
60  return (size_t)ret;
61 }
62 
63 /*-------------------------------------------------------------
64  Seek
65 -------------------------------------------------------------*/
66 uint64_t CInterfaceFTDI::Seek(int64_t Offset, CStream::TSeekOrigin Origin)
67 {
68  MRPT_UNUSED_PARAM(Offset);
69  MRPT_UNUSED_PARAM(Origin);
70  return 0;
71 }
72 
73 /*-------------------------------------------------------------
74  getTotalBytesCount
75 -------------------------------------------------------------*/
77 {
78  return 0;
79 }
80 
81 /*-------------------------------------------------------------
82  getPosition
83 -------------------------------------------------------------*/
85 {
86  return 0;
87 }
88 
89 /*-------------------------------------------------------------
90  ReadBufferImmediate
91 -------------------------------------------------------------*/
92 size_t CInterfaceFTDI::ReadBufferImmediate(void *Buffer, size_t Count)
93 {
94  unsigned long nRead;
95  ftdi_read(Buffer, Count, &nRead);
96  return nRead;
97 }
uint64_t getPosition()
This virtual method does nothing in this class.
#define min(a, b)
void ftdi_write(const void *lpvBuffer, unsigned long dwBuffSize, unsigned long *lpdwBytes)
size_t available() const
The maximum number of elements that can be written ("push") without rising an overflow error...
size_t size() const
Return the number of elements available for read ("pop") in the buffer (this is NOT the maximum size ...
Contains classes for various device interfaces.
size_t Write(const void *Buffer, size_t Count)
Introduces a pure virtual method responsible for writing to the stream.
void pop_many(T *out_array, size_t count)
Pop a number of elements into a user-provided array.
unsigned char uint8_t
Definition: rptypes.h:43
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
__int64 int64_t
Definition: rptypes.h:51
uint64_t Seek(int64_t Offset, CStream::TSeekOrigin Origin=sFromBeginning)
This virtual method does nothing in this class.
size_t Read(void *Buffer, size_t Count)
Introduces a pure virtual method responsible for reading from the stream.
void ftdi_read(void *lpvBuffer, unsigned long dwBuffSize, unsigned long *lpdwBytesRead)
unsigned __int64 uint64_t
Definition: rptypes.h:52
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
virtual size_t ReadBufferImmediate(void *Buffer, size_t Count)
Reads a block of bytes from the stream into Buffer, and returns the amound of bytes actually read...
uint64_t getTotalBytesCount()
This virtual method does nothing in this class.
void push_many(T *array_elements, size_t count)
Insert an array of elements in the buffer.
mrpt::utils::circular_buffer< uint8_t > m_readBuffer
Used in Read.



Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020