Sample RS232 class lib inherits Serial Class

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
terrytamyh
Date:
Mon Jun 16 23:05:40 2014 +0000
Commit message:
Sample RS232 class lib inherits Serial Class

Changed in this revision

DataLoggerRS232/DataLoggerRS232.cpp Show annotated file Show diff for this revision Revisions of this file
DataLoggerRS232/DataLoggerRS232.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DataLoggerRS232/DataLoggerRS232.cpp	Mon Jun 16 23:05:40 2014 +0000
@@ -0,0 +1,51 @@
+#include "mbed.h"
+#include "DataLoggerRS232.h"
+
+
+DataLoggerRS232::DataLoggerRS232(PinName tx, PinName rx, const char* name) : Serial(tx, rx, name) {
+    printf("Here!! \r\n");
+    // set up ring buffer
+    ringBuffer = new char[65536];
+    // pointer to first sample 
+    rHead = ringBuffer;
+    // pointer to indicate position in the Ring Buffer
+    rPos = ringBuffer;
+    // pointer to indicate display position in the Ring Buffer
+    rDisplay = ringBuffer;
+    
+    printf("DataLogger_RS232 Ring Buffer setup complete!\r\n");
+}
+
+void DataLoggerRS232::get_ECU_databyte() {
+        
+        while(Serial::readable()) {
+            
+            MSserial = Serial::getc();
+                // save the sample into ring buffer
+                if( rPos == &ringBuffer[65535] )
+                rPos = ringBuffer;
+                else 
+                rPos++;
+            
+            *rPos = MSserial;
+            
+            count++;
+        }
+        printf("get_ECU_databyte !!\r\n");
+}
+
+void DataLoggerRS232::display_ECU_databyte() {
+        
+        while (rDisplay != rPos) {
+            printf("%d, %X\n\r",count,rDisplay);
+            if( rDisplay == &ringBuffer[65535] )
+                rDisplay = ringBuffer;
+                else 
+                rDisplay++;   
+        }
+        printf("display_ECU_databyte !!\r\n");
+}
+
+
+DataLoggerRS232::~DataLoggerRS232() {
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DataLoggerRS232/DataLoggerRS232.h	Mon Jun 16 23:05:40 2014 +0000
@@ -0,0 +1,33 @@
+#include "mbed.h"
+
+#ifndef DataLogger_RS232_H_
+#define DataLogger_RS232_H_
+
+class DataLoggerRS232 : public Serial
+{
+public:
+    
+    DataLoggerRS232(PinName tx,PinName rx, const char* name=NULL);
+    
+    virtual ~DataLoggerRS232();
+    
+    int count;
+    void get_ECU_databyte();
+    void display_ECU_databyte();
+   
+private:
+
+    // Serial serial;
+    
+    char c;
+    char MSserial;
+    
+    char* ringBuffer;
+    char* rHead;
+    char* rPos;
+    char* rDisplay;
+    
+
+};
+
+#endif // DataLogger_RS232_H_ 
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Jun 16 23:05:40 2014 +0000
@@ -0,0 +1,28 @@
+#include "mbed.h"
+#include "DataLoggerRS232.h"
+ 
+Serial pc (USBTX, USBRX); // tx, rx
+DataLoggerRS232 dataLogger (p9,p10);  // tx, rx
+
+char DLcommand;
+
+int main() {    
+
+    pc.baud(115200);
+    pc.printf("PC and Datalogger serial set up complete !!\n\r");
+    dataLogger.baud(115200);
+    pc.printf("Here !!\n\r");
+    
+    while(1) {
+        if(pc.readable()) {
+            
+            dataLogger.count = 0;
+            DLcommand = pc.getc();
+            pc.printf("\n\r%c\n\r",DLcommand);
+            
+            dataLogger.putc(DLcommand);
+            dataLogger.get_ECU_databyte();
+        }
+        dataLogger.display_ECU_databyte();     
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Jun 16 23:05:40 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/0b3ab51c8877
\ No newline at end of file