Reading Gcode in LocalFiileSystem and encodeing int array. but this program has bug.probably
Fork of MakeSequencer by
Revision 4:1d7c50f17687, committed 2018-10-17
- Comitter:
- satoyuki1111
- Date:
- Wed Oct 17 01:09:47 2018 +0000
- Parent:
- 3:09ee560a3007
- Commit message:
- v3
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 |
diff -r 09ee560a3007 -r 1d7c50f17687 MakeSequencer.cpp --- a/MakeSequencer.cpp Thu Oct 11 11:23:53 2018 +0000 +++ b/MakeSequencer.cpp Wed Oct 17 01:09:47 2018 +0000 @@ -13,7 +13,7 @@ { FILE *fp = fopen( "/local/out.txt", "r"); MakeSequencer code(fp); - code.getGcode(3,sizeof(array)/sizeof(int),array); //getGcode(int row,int aSize, int* array) + code.getGcode(1,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]); @@ -30,6 +30,7 @@ { _fp=fp; FileOpen(); + } bool MakeSequencer::FileOpen() @@ -61,6 +62,16 @@ bool MakeSequencer::ReadGcode() { + //char * _buf = new char[BUF]; + char _buf[BUF]; + int *_tempnum = new int[ARRAY_EREMENT]; + char **_element = new char*[ARRAY_EREMENT]; + bool **_check = new bool*[ARRAY_EREMENT]; + for (int a = 0; a < ARRAY_EREMENT; a++) + { + _element[a] = new char[CODE_LENGTH]; + _check[a] = new bool[CODE_LENGTH]; + } _ele = 0; for(int i = 0;fgets(_buf,sizeof(_buf), _fp) != NULL;i++) { @@ -70,10 +81,10 @@ return false; else { - string _tempstr[ARRAY_EREMENT]; + string *_tempstr = new string[ARRAY_EREMENT]; _count = -1; - for(int n = 0;n < ARRAY_EREMENT;n++) + for(int n = 0;n < ARRAY_EREMENT;n++)//bool array Initialize { for(int p = 0;p < CODE_LENGTH;p++) _check[n][p] = true; @@ -98,11 +109,12 @@ } } } - _element[_count][i] = _char; + else + _element[_count][i] = _char; if(i == 0) _ele++; } - else if(_char >= '0'&& _char <= '9') + else if(_char >= '0'&& _char <= '9' || _char <= '-') { _tempstr[_count] = _tempstr[_count] + _char; } @@ -113,15 +125,34 @@ else return false; } - + printf("#(%d) ",i); for(int n = 0;n < _ele;n++) { _tempnum[n] = atoi(_tempstr[n].c_str()); _data[n][i] = (i != 0 && _check[n][i] && _element[n][i] != _element[n][0]) ? _data[n][i-1] : _tempnum[n]; + + _element[n][i] = (i != 0 && _check[n][i] && _element[n][i] != _element[n][0]) + ? _element[n][0] + : _element[n][i]; + printf("%c:%d",_element[n][i],_data[n][i]); } + printf("\n\r"); + //delete[] _tempstr; } + } + for (int a = 0; a < ARRAY_EREMENT; a++) + { + delete[] _data[a]; + delete[] _check[a]; + delete[] _element[a]; + } + //delete[] _buf; + //delete[] _data; + delete[] _element; + delete[] _check; + delete[] _tempnum; return true; } \ No newline at end of file
diff -r 09ee560a3007 -r 1d7c50f17687 MakeSequencer.h --- a/MakeSequencer.h Thu Oct 11 11:23:53 2018 +0000 +++ b/MakeSequencer.h Wed Oct 17 01:09:47 2018 +0000 @@ -3,8 +3,9 @@ #include "mbed.h" #include "string" -#define CODE_LENGTH 100 -#define ARRAY_EREMENT 10 +#define CODE_LENGTH 30 +#define ARRAY_EREMENT 5 +#define BUF 256 class MakeSequencer @@ -14,20 +15,15 @@ bool FileOpen(); void getGcode(int _row,int aSize,int* _array); + int getGcodeSize(); bool ReadGcode(); - int getGcodeSize(); - private: - char _buf[256]; + private: int _data[ARRAY_EREMENT][CODE_LENGTH]; int _codesize; - - int _tempnum[ARRAY_EREMENT]; int _ele; - char _element[ARRAY_EREMENT][CODE_LENGTH]; char _char; int _count; - bool _check[ARRAY_EREMENT][CODE_LENGTH]; LocalFileSystem *_local; FILE *_fp;