-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFtdiStreamBuf.cpp
More file actions
44 lines (33 loc) · 866 Bytes
/
Copy pathFtdiStreamBuf.cpp
File metadata and controls
44 lines (33 loc) · 866 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "FtdiStreamBuf.hpp"
namespace jdd{
FtdiStreamBuf::FtdiStreamBuf(unsigned int vid, unsigned int pid,
string description, string serialNum):
ftdi(vid, pid, description, serialNum)
{
}
FtdiStreamBuf::~FtdiStreamBuf() throw()
{
}
int FtdiStreamBuf::overflow(int c)
{
//push data into buffer, growing if needed
writeBuf.push_back(c);
return 0;//signal success
}
int FtdiStreamBuf::underflow()
{
//read next byte from ftdi device
ftdi.get( (uint8_t*)&readBuf, sizeof(readBuf) );
//set streambuf's get pointers
setg( (char*)&readBuf, (char*)&readBuf, (char*)&readBuf + 1 );
return readBuf;
}
int FtdiStreamBuf::sync()
{
//write buffer to ftdi device
ftdi.put( &writeBuf[0], writeBuf.size() );
//empty buffer
writeBuf.clear();
return 0;//signal success
}
}//namespace