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.
Dependents: WRS_mechanamu_test WRS2019_master
Revision 2:4fc4593498d7, committed 2018-10-11
- Comitter:
- satoyuki1111
- Date:
- Thu Oct 11 11:07:31 2018 +0000
- Parent:
- 1:4ebb30d54be7
- Child:
- 3:09ee560a3007
- Commit message:
- Gcode sequencer v1.2;
Changed in this revision
| MakeSequencer.cpp | Show annotated file Show diff for this revision Revisions of this file |
| MakeSequencer.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/MakeSequencer.cpp Wed Oct 10 05:34:43 2018 +0000
+++ b/MakeSequencer.cpp Thu Oct 11 11:07:31 2018 +0000
@@ -1,20 +1,28 @@
/*
-sample code
+sample
+
+#include "mbed.h"
+#include "MakeSequencer.h"
+
+//A row is from 1
LocalFileSystem local("local");
-int array[3] = {};
+int array[5] = {};
int main()
{
FILE *fp = fopen( "/local/out.txt", "r");
MakeSequencer code(fp);
-
- code.getGcode(1,array);
+ code.getGcode(3,sizeof(array)/sizeof(int),array); //getGcode(int row,int aSize, int* array)
+ //array will get Gcode of a "int row" line
+ for(int i = 0;i < sizeof(array)/sizeof(int);i++)
+ printf("%d,",array[i]);
+ printf("\n\r%d",code.getGcodeSize()); //getGcodeSize()
+ //return Gcode row
}
*/
-
#include "MakeSequencer.h"
@@ -24,12 +32,6 @@
FileOpen();
}
-bool MakeSequencer::inherit(int _rows,int _columns,int _data[][CODE_LENGTH])
-{
- _data[_rows][_columns] = (_columns == 0) ? 0 : _data[_rows][_columns-1];
- return false;
-}
-
bool MakeSequencer::FileOpen()
{
if ( _fp == NULL )
@@ -44,67 +46,96 @@
return true;
}
-void MakeSequencer::getGcode(int _seq,int* _array)
+void MakeSequencer::getGcode(int row,int aSize, int* array)
{
- for(int _i = 0;_i < ARRAY_EREMENT;_i++)
+ for(int i = 0;i < aSize;i++)
{
- _array[_i] = data[_i][_seq];
+ array[i] = _data[i][row-1];
}
}
int MakeSequencer::getGcodeSize()
{
- return codesize;
+ return _codesize+1;
}
bool MakeSequencer::ReadGcode()
{
- for(int i = 0;fgets(buf,sizeof(buf), _fp) != NULL;i++)
+ int _ele = 0;
+
+ for(int i = 0;fgets(_buf,sizeof(_buf), _fp) != NULL;i++)
{
- codesize = i+1;
+ _codesize = i;
+
if(i > CODE_LENGTH)
return false;
-
- for(int n = 0;buf[n] != '\0';n++)
- code[0][i] = code[0][i]+buf[n];
+ else
+ {
+ int _tempnum[ARRAY_EREMENT];
+ string _tempstr[ARRAY_EREMENT];
+ char _element[ARRAY_EREMENT][CODE_LENGTH];
+ char _char;
+ int _count = -1;
+ bool _check[ARRAY_EREMENT][CODE_LENGTH];
- 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:inherit(p,i,data);
-
- 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])
+ for(int n = 0;n < ARRAY_EREMENT;n++)
+ {
+ for(int p = 0;p < CODE_LENGTH;p++)
+ _check[n][p] = true;
+ }
+
+ for(int n = 0;_buf[n] != '\0';n++)
{
- 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;
+ _char = _buf[n];
+ if((_char >= 'a'&& _char <= 'z') || (_char >= 'A' && _char <= 'Z'))
+ {
+ _count++;
+ if(_char != _element[_count][0] && i != 0)
+ {
+ for(int p = 0;p < _ele;p++)
+ {
+ if(_char == _element[p][0])
+ {
+ _element[p][i] = _char;
+ _count = p;
+ _check[p][i] = false;
+ break;
+ }
+ }
+ }
+ _element[_count][i] = _char;
+ if(i == 0)
+ _ele++;
+ }
+ else if(_char >= '0'&& _char <= '9')
+ {
+ _tempstr[_count] = _tempstr[_count] + _char;
+ }
- 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;
+ else if('\n' || '\r')
+ {
+ }
+ else
+ return false;
+ }
+
+ for(int n = 0;n < _ele;n++)
+ {
+ _tempnum[n] = atoi(_tempstr[n].c_str());
- case 'z':
- data[2][i] = atoi(code[0][i].substr(pos[2]+1,code[0][i].size() - 1).c_str());
- break;
-
- default:
- break;
- }
+ if(i != 0 && _check[n][i] && _element[n][i] != _element[n][0])
+ {
+ //printf("{%d}-{%d},",n,i);
+ _data[n][i] = _data[n][i-1];
+ }
+ else
+ {
+ _data[n][i] = _tempnum[n];
+ }
+ printf("%c:%d ",_element[n][0],_data[n][i]);
+ }
+ printf("\n\r");
}
- printf("x=%d ,y=%d ,z=%d \n\r",data[0][i],data[1][i],data[2][i]);
}
return true;
}
\ No newline at end of file
--- a/MakeSequencer.h Wed Oct 10 05:34:43 2018 +0000
+++ b/MakeSequencer.h Thu Oct 11 11:07:31 2018 +0000
@@ -4,25 +4,24 @@
#include "mbed.h"
#include "string"
#define CODE_LENGTH 100
-#define ARRAY_EREMENT 3
+#define ARRAY_EREMENT 10
+
class MakeSequencer
{
public:
MakeSequencer(FILE *fp);
- bool inherit(int _rows,int _columns,int _data[][CODE_LENGTH]);
bool FileOpen();
- void getGcode(int _seq,int* _array);
+ void getGcode(int _row,int aSize,int* _array);
bool ReadGcode();
int getGcodeSize();
private:
- char buf[256];
- string code[1][CODE_LENGTH];
- int data[ARRAY_EREMENT][CODE_LENGTH];
- bool find[ARRAY_EREMENT];
- int codesize;
+ char _buf[256];
+ int _data[ARRAY_EREMENT][CODE_LENGTH];
+ int _codesize;
+
LocalFileSystem *_local;
FILE *_fp;
};