Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BufferedSerial
Dependents: ESP8266 Final_Project_2 Final_Project CHEN_Final_Project
Revision 6:51f1171b5ebc, committed 2015-07-17
- Comitter:
- geky
- Date:
- Fri Jul 17 21:00:23 2015 +0000
- Parent:
- 5:26bc9255b751
- Child:
- 7:d1b193880af1
- Commit message:
- Exposed raw read/write methods
Changed in this revision
| ATParser.cpp | Show annotated file Show diff for this revision Revisions of this file |
| ATParser.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/ATParser.cpp Fri Jul 17 17:23:57 2015 +0000
+++ b/ATParser.cpp Fri Jul 17 21:00:23 2015 +0000
@@ -56,6 +56,33 @@
_serial->getc();
}
+// read/write handling with timeouts
+int ATParser::write(const char *data, int size) {
+ int i;
+
+ for (i = 0; i < size; i++) {
+ if (putc(data[i]) < 0)
+ return i;
+ }
+
+ return i;
+}
+
+int ATParser::read(char *data, int size) {
+ int i;
+
+ for (i = 0; i < size; i++) {
+ int c = getc();
+
+ if (c < 0)
+ return i;
+
+ data[i] = c;
+ }
+
+ return i;
+}
+
// getline/putline handling with timeouts/bounds checking
bool ATParser::_putline(const char *line) {
@@ -165,11 +192,8 @@
// We only succeed if all characters in the response is matched
if (count >= 0 && (_buffer+offset)[count] == 0) {
// Reuse the front end of the buffer
- int j;
- for (j = 0; j < i; j++) {
- _buffer[j] = response[j];
- }
- _buffer[j] = 0;
+ memcpy(_buffer, response, i);
+ _buffer[i] = 0;
// Store the found results
vsscanf(_buffer+offset, _buffer, args);
--- a/ATParser.h Fri Jul 17 17:23:57 2015 +0000
+++ b/ATParser.h Fri Jul 17 21:00:23 2015 +0000
@@ -157,6 +157,24 @@
*/
int getc();
+ /**
+ * Write an array of bytes to the underlying stream
+ *
+ * @param data the array of bytes to write
+ * @param size number of bytes to write
+ * @return number of bytes written
+ */
+ int write(const char *data, int size);
+
+ /**
+ * Read an array of bytes from the underlying stream
+ *
+ * @param data the destination for the read bytes
+ * @param size number of bytes to read
+ * @return number of bytes read
+ */
+ int read(char *data, int size);
+
/**
* Flushes the underlying stream
*/