Code to convert Yokogawa messages to CAN bus

Dependencies:   USBHost mbed

Files at this revision

API Documentation at this revision

Comitter:
tomhillman
Date:
Wed Sep 09 12:48:29 2015 +0000
Commit message:
Basic version implemented on Converter for Makani Efficiency Testing

Changed in this revision

USBHost.lib 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/USBHost.lib	Wed Sep 09 12:48:29 2015 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/teams/YASA-Motors/code/USBHost/#10dc3db97a06
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Sep 09 12:48:29 2015 +0000
@@ -0,0 +1,98 @@
+#include "mbed.h"
+#include "USBHostSerial.h"
+
+DigitalOut led(LED1);
+Serial pc(USBTX, USBRX);
+
+
+long i;
+long j;
+long k;
+long start;
+int l;
+long m;
+int myArray[8] = { 46, 47, 48, 52, 61, 62, 63, 67};
+int8_t sendTest[8];
+int main() {
+    pc.printf("\nMain started \r\n");
+    CAN can1(p30, p29);
+    can1.frequency(500000);
+    USBHostSerial serial;
+    
+    char buf2[1024];
+    while(1) {
+       
+        pc.printf("Start\r\n");
+
+    
+        // try to connect a serial device
+        while(!serial.connect())
+        {
+            pc.printf("Trying to connect \r\n");
+            wait(1);
+            }
+        
+        pc.printf("Connected \r\n");
+        wait(1);
+        LPC_UART0->FCR |= 0x06;
+        wait(1);
+        while (1) {
+            i = 0;
+            int test = 0;
+            led=!led; 
+            serial.flush();
+            wait(0.1);
+            
+            for(m=0;m<8;m++){
+            i = 0;
+            serial.flush();
+            wait(0.1);
+            serial.printf("NUM:NORM:VAL? %d\r\n", myArray[m]); // send SCPI command // just \n works
+            wait(0.1);
+            
+            test = 1;
+            while (i<=30) {
+                test = serial.available();
+                buf2[i] = serial.getc();
+                pc.printf("%c", buf2[i], test);
+                i++;
+                }
+                serial.flush();
+                
+            j = 0;    
+            
+            
+            for(j=0;j<i;j++){
+                if(buf2[j]==0x23){ // look for "#" that marks start of data
+                    break;
+                    }
+                }
+            start = j+7;
+            i = start-1;k=1;
+                pc.printf("Item(%d): 0x%X.%X.%X.%X ",myArray[m],buf2[i],buf2[i+1],buf2[i+2],buf2[i+3]);
+
+               for(l=0;l<4;l++){
+                    
+                    sendTest[l] = (int8_t)buf2[i+l];
+                }
+                
+                if(can1.write(CANMessage((1024+m+1), (const char *) &sendTest[0], 8))){pc.printf(" Can Sent..\r\n");}
+                //can1.write(CANMessage((1024+m+1), (const char *) &sendTest[0], 8));
+
+                
+  
+            }
+            
+                        // if device disconnected, try to connect it again
+            if (!serial.connected()){
+                pc.printf("Connection Lost!\r\n");
+                break;
+                }
+                
+            wait(1);
+            }
+        }
+        
+        
+        
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Sep 09 12:48:29 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/8ab26030e058
\ No newline at end of file