mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-07-11 22:03:01 -06:00
Bazaar/Serial : added function to send a byte buffer
git-svn-id: svn://ultimatepp.org/upp/trunk@10773 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
d6bb88b615
commit
0387437fbd
3 changed files with 32 additions and 25 deletions
|
|
@ -89,6 +89,7 @@ class Serial
|
|||
String Read(size_t reqSize = 0, uint32_t timeout = 0);
|
||||
|
||||
// writes data
|
||||
bool Write(uint8_t const *buf, uint32_t len, uint32_t timeout = 0);
|
||||
bool Write(String const &data, uint32_t timeout = 0);
|
||||
|
||||
// check if opened
|
||||
|
|
|
|||
|
|
@ -416,24 +416,23 @@ String Serial::Read(size_t reqSize, uint32_t timeout)
|
|||
return data;
|
||||
}
|
||||
|
||||
// writes data
|
||||
bool Serial::Write(String const &data, uint32_t timeout)
|
||||
// write buffer
|
||||
bool Serial::Write(uint8_t const *buf, uint32_t len, uint32_t timeout)
|
||||
{
|
||||
int dLen = data.GetCount();
|
||||
if (!timeout)
|
||||
return (write(fd, ~data, data.GetCount()) == dLen);
|
||||
return (write(fd, buf, len) == len);
|
||||
|
||||
uint32_t tim = msecs() + timeout;
|
||||
const char *dPos = ~data;
|
||||
const uint8_t *dPos = buf;
|
||||
for (;;)
|
||||
{
|
||||
int written = write(fd, dPos, dLen);
|
||||
if (written == dLen)
|
||||
uint32_t written = write(fd, dPos, len);
|
||||
if (written == len)
|
||||
return true;
|
||||
if (written >= 0)
|
||||
{
|
||||
dPos += written;
|
||||
dLen -= written;
|
||||
len -= written;
|
||||
continue;
|
||||
}
|
||||
if ((uint32_t)msecs() >= tim)
|
||||
|
|
@ -442,6 +441,12 @@ bool Serial::Write(String const &data, uint32_t timeout)
|
|||
return false;
|
||||
}
|
||||
|
||||
// writes string
|
||||
bool Serial::Write(String const &data, uint32_t timeout)
|
||||
{
|
||||
return Write((const uint8_t *)~data, data.GetCount(), timeout);
|
||||
}
|
||||
|
||||
// check if opened
|
||||
bool Serial::IsOpened(void) const
|
||||
{
|
||||
|
|
|
|||
|
|
@ -432,42 +432,43 @@ String Serial::Read ( size_t reqSize, uint32_t timeout )
|
|||
return res;
|
||||
}
|
||||
|
||||
// writes data
|
||||
bool Serial::Write ( String const &data, uint32_t timeout )
|
||||
// write buffer
|
||||
bool Serial::Write(uint8_t const *buf, uint32_t len, uint32_t timeout)
|
||||
{
|
||||
unsigned long count = 0;
|
||||
uint32_t count = 0;
|
||||
|
||||
int dLen = data.GetCount();
|
||||
|
||||
if ( !timeout )
|
||||
if (!timeout)
|
||||
{
|
||||
WriteFile ( fd, ~data, dLen, &count, NULL );
|
||||
return count == dLen;
|
||||
WriteFile(fd, buf, len, &count, NULL);
|
||||
return count == len;
|
||||
}
|
||||
|
||||
uint32_t tim = msecs() + timeout;
|
||||
const char *dPos = buf;
|
||||
|
||||
const char *dPos = ~data;
|
||||
|
||||
for ( ;; )
|
||||
for (;;)
|
||||
{
|
||||
WriteFile ( fd, dPos, dLen, &count, NULL );
|
||||
if ( count == dLen )
|
||||
WriteFile(fd, dPos, len, &count, NULL);
|
||||
if (count == len )
|
||||
return true;
|
||||
|
||||
if ( count > 0 )
|
||||
if(count > 0)
|
||||
{
|
||||
dPos += count;
|
||||
dLen -= count;
|
||||
len -= count;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( ( uint32_t ) msecs() >= tim )
|
||||
if((uint32_t)msecs() >= tim)
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// writes string
|
||||
bool Serial::Write(String const &data, uint32_t timeout)
|
||||
{
|
||||
return Write((const uint8_t *)~data, data.GetCount(), timeout);
|
||||
}
|
||||
|
||||
// check if opened
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue