Reading Gcode in LocalFiileSystem and encodeing int array

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
satoyuki1111
Date:
Mon Oct 08 04:50:37 2018 +0000
Commit message:
first commit;

Changed in this revision

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
diff -r 000000000000 -r 2299aeb93bb5 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Oct 08 04:50:37 2018 +0000
@@ -0,0 +1,73 @@
+#include "mbed.h"
+#include "string"
+
+#define CODE_LENGTH 100
+LocalFileSystem local("local");
+
+
+int main()
+{
+    char   buf[256];
+    string code[1][CODE_LENGTH] = {};
+    int    data[3][CODE_LENGTH] = {0};
+    bool   find[3] = {0};
+    
+    FILE *fp = fopen( "/local/out.txt", "r");
+    if ( fp == NULL ) 
+        printf("Exception");
+    
+    else
+    {
+        for(int i = 0;fgets(buf,sizeof(buf), fp) != NULL;i++)
+        {
+            if(i > CODE_LENGTH)
+                return 0;
+            
+            for(int n = 0;buf[n] != '\0';n++)
+                code[0][i] = code[0][i]+buf[n];
+                
+            printf("%s",code[0][i].c_str());
+            int pos[3] = {code[0][i].find("x"),code[0][i].find("y"),code[0][i].find("z")};
+            
+            for(int p = 0;p < sizeof(pos)/sizeof(int);p++)
+                find[p] = (pos[p] != code[0][i].npos) ? true:false;
+    
+            for(int p = 0;p < sizeof(pos)/sizeof(int);p++)
+            {
+                char trans[1] = {};
+                string sw_code = find[p] ? code[0][i].substr(pos[p],1) : "I";
+                sw_code.copy(trans,1);
+                switch(trans[0])
+                {
+                    case 'x':
+                        if(find[1])
+                            data[0][i] = atoi(code[0][i].substr(pos[0]+1,pos[1] - 1).c_str());   
+                        else if(find[2])
+                            data[0][i] = atoi(code[0][i].substr(pos[0]+1,pos[2] - 1).c_str());
+                        else
+                            data[0][i] = atoi(code[0][i].substr(pos[0]+1,code[0][i].size() - 1).c_str());
+                    break;
+                    
+                    case 'y':
+                        if(find[2])
+                            data[1][i] = atoi(code[0][i].substr(pos[1]+1,pos[2] - 1).c_str());
+                        else
+                            data[1][i] = atoi(code[0][i].substr(pos[1]+1,code[0][i].size() - 1).c_str());
+                    break;
+                    
+                    case 'z':
+                        data[2][i] = atoi(code[0][i].substr(pos[2]+1,code[0][i].size() - 1).c_str());
+                    break;
+                    
+                    default:
+                    break;
+                }    
+            }
+            printf("x=%d ,y=%d ,z=%d \n\r",data[0][i],data[1][i],data[2][i]);
+        }
+    }
+    fclose(fp);
+    
+    
+    
+}
diff -r 000000000000 -r 2299aeb93bb5 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Oct 08 04:50:37 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/e95d10626187
\ No newline at end of file