Skip to content

Add getTimeout() call to ATParser. Add payload for RX callback in BufferedSerial. #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions ATParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ class ATParser
_timeout = timeout;
}

/**
* Retrieve the timeout between commands
*/
int getTimeout() {
return _timeout;
}

/**
* Sets string of characters to use as line delimiters
*
Expand All @@ -108,7 +115,7 @@ class ATParser
_delimiter = delimiter;
_delim_size = strlen(delimiter);
}

/**
* Allows echo to be on or off
*
Expand Down Expand Up @@ -206,7 +213,7 @@ class ATParser

/**
* Attach a callback for out-of-band data
*
*
* @param prefix string on when to initiate callback
* @param func callback to call when string is read
* @note out-of-band data is only processed during a scanf call
Expand All @@ -230,5 +237,6 @@ class ATParser
* Flushes the underlying stream
*/
void flush();

};
#endif
16 changes: 8 additions & 8 deletions BufferedSerial/Buffer/MyBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @brief Software Buffer - Templated Ring Buffer for most data types
* @author sam grove
* @version 1.0
* @see
* @see
*
* Copyright (c) 2013
*
Expand All @@ -20,7 +20,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "MyBuffer.h"

template <class T>
Expand All @@ -29,22 +29,22 @@ MyBuffer<T>::MyBuffer(uint32_t size)
_buf = new T [size];
_size = size;
clear();

return;
}

template <class T>
MyBuffer<T>::~MyBuffer()
{
delete [] _buf;

return;
}

template <class T>
uint32_t MyBuffer<T>::getSize()
{
return this->_size;
uint32_t MyBuffer<T>::getSize()
{
return this->_size;
}

template <class T>
Expand All @@ -53,7 +53,7 @@ void MyBuffer<T>::clear(void)
_wloc = 0;
_rloc = 0;
memset(_buf, 0, _size);

return;
}

Expand Down
38 changes: 19 additions & 19 deletions BufferedSerial/Buffer/MyBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @brief Software Buffer - Templated Ring Buffer for most data types
* @author sam grove
* @version 1.0
* @see
* @see
*
* Copyright (c) 2013
*
Expand All @@ -20,7 +20,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef MYBUFFER_H
#define MYBUFFER_H

Expand All @@ -47,7 +47,7 @@
* int pos = 0;
*
* while(buf.available())
* {
* {
* whats_in_there[pos++] = buf;
* }
* printf("%c %c\n", whats_in_there[0], whats_in_there[1]);
Expand All @@ -71,40 +71,40 @@ class MyBuffer
* @param size The size of the buffer
*/
MyBuffer(uint32_t size = 0x100);

/** Get the size of the ring buffer
* @return the size of the ring buffer
*/
uint32_t getSize();

/** Destry a Buffer and release it's allocated memory
*/
~MyBuffer();

/** Add a data element into the buffer
* @param data Something to add to the buffer
*/
void put(T data);

/** Remove a data element from the buffer
* @return Pull the oldest element from the buffer
*/
T get(void);

/** Get the address to the head of the buffer
* @return The address of element 0 in the buffer
*/
T *head(void);

/** Reset the buffer to 0. Useful if using head() to parse packeted data
*/
void clear(void);

/** Determine if anything is readable in the buffer
* @return 1 if something can be read, 0 otherwise
*/
uint32_t available(void);

/** Overloaded operator for writing to the buffer
* @param data Something to put in the buffer
* @return
Expand All @@ -114,25 +114,25 @@ class MyBuffer
put(data);
return *this;
}

/** Overloaded operator for reading from the buffer
* @return Pull the oldest element from the buffer
*/
* @return Pull the oldest element from the buffer
*/
operator int(void)
{
return get();
}

uint32_t peek(char c);

};

template <class T>
inline void MyBuffer<T>::put(T data)
{
_buf[_wloc++] = data;
_wloc %= (_size-1);

return;
}

Expand All @@ -141,15 +141,15 @@ inline T MyBuffer<T>::get(void)
{
T data_pos = _buf[_rloc++];
_rloc %= (_size-1);

return data_pos;
}

template <class T>
inline T *MyBuffer<T>::head(void)
{
T *data_pos = &_buf[0];

return data_pos;
}

Expand Down
23 changes: 12 additions & 11 deletions BufferedSerial/BufferedSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ extern "C" int BufferedPrintfC(void *stream, int size, const char* format, va_li
BufferedSerial::BufferedSerial(PinName tx, PinName rx, uint32_t buf_size, uint32_t tx_multiple, const char* name)
: RawSerial(tx, rx) , _rxbuf(buf_size), _txbuf((uint32_t)(tx_multiple*buf_size))
{
RawSerial::attach(this, &BufferedSerial::rxIrq, Serial::RxIrq);
RawSerial::attach(callback(this, &BufferedSerial::rxIrq), Serial::RxIrq);
this->_buf_size = buf_size;
this->_tx_multiple = tx_multiple;
this->_tx_multiple = tx_multiple;
return;
}

Expand Down Expand Up @@ -69,13 +69,13 @@ int BufferedSerial::puts(const char *s)
{
if (s != NULL) {
const char* ptr = s;

while(*(ptr) != 0) {
_txbuf = *(ptr++);
}
_txbuf = '\n'; // done per puts definition
BufferedSerial::prime();

return (ptr - s) + 1;
}
return 0;
Expand All @@ -101,12 +101,12 @@ ssize_t BufferedSerial::write(const void *s, size_t length)
if (s != NULL && length > 0) {
const char* ptr = (const char*)s;
const char* end = ptr + length;

while (ptr != end) {
_txbuf = *(ptr++);
}
BufferedSerial::prime();

return ptr - (const char*)s;
}
return 0;
Expand All @@ -117,10 +117,11 @@ void BufferedSerial::rxIrq(void)
{
// read from the peripheral and make sure something is available
if(serial_readable(&_serial)) {
_rxbuf = serial_getc(&_serial); // if so load them into a buffer
int v = serial_getc(&_serial);
_rxbuf = v; // if so load them into a buffer
// trigger callback if necessary
if (_cbs[RxIrq]) {
_cbs[RxIrq]();
_cbs[RxIrq](v);
}
}

Expand All @@ -138,7 +139,7 @@ void BufferedSerial::txIrq(void)
RawSerial::attach(NULL, RawSerial::TxIrq);
// trigger callback if necessary
if (_cbs[TxIrq]) {
_cbs[TxIrq]();
_cbs[TxIrq](0);
}
break;
}
Expand All @@ -153,13 +154,13 @@ void BufferedSerial::prime(void)
if(serial_writable(&_serial)) {
RawSerial::attach(NULL, RawSerial::TxIrq); // make sure not to cause contention in the irq
BufferedSerial::txIrq(); // only write to hardware in one place
RawSerial::attach(this, &BufferedSerial::txIrq, RawSerial::TxIrq);
RawSerial::attach(callback(this, &BufferedSerial::txIrq), RawSerial::TxIrq);
}

return;
}

void BufferedSerial::attach(Callback<void()> func, IrqType type)
void BufferedSerial::attach(Callback<void(int)> func, IrqType type)
{
_cbs[type] = func;
}
Expand Down
Loading