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.
Revision 4:1e606e2301f9, committed 2018-10-17
- Comitter:
- satoyuki1111
- Date:
- Wed Oct 17 08:39:42 2018 +0000
- Parent:
- 3:09ee560a3007
- Commit message:
- ok
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 Thu Oct 11 11:23:53 2018 +0000 +++ b/MakeSequencer.cpp Wed Oct 17 08:39:42 2018 +0000 @@ -1,31 +1,29 @@ /* -sample - +SAMPLE #include "mbed.h" #include "MakeSequencer.h" +#define SIZE 5 +#define ArraySize(array) (sizeof(array) / sizeof(array[0])) + //A row is from 1 LocalFileSystem local("local"); -int array[5] = {}; +int array[SIZE] = {}; int main() { 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) - //array will get Gcode of a "int row" line - for(int i = 0;i < sizeof(array)/sizeof(int);i++) + code.getGcode(2,ArraySize(array),array);//getGcode(int row,int aSize, int* array) + //array will get Gcode of a "int row" line + for(int i = 0;i < ArraySize(array);i++) printf("%d,",array[i]); - printf("\n\r%d",code.getGcodeSize()); //getGcodeSize() - //return Gcode row + printf("\n\r%d\n\r",code.getGcodeSize()); //getGcodeSize() + //return Gcode row } */ - - #include "MakeSequencer.h" - - MakeSequencer::MakeSequencer(FILE *fp) { _fp=fp; @@ -50,7 +48,7 @@ { for(int i = 0;i < aSize;i++) { - array[i] = _data[i][row-1]; + array[i] = _data[i][row]; } } @@ -61,27 +59,46 @@ bool MakeSequencer::ReadGcode() { + char * _buf = new char[BUF]; + int *_tempnum = new int[ARRAY_EREMENT]; + char **_element = new char*[ARRAY_EREMENT]; + bool **_check = new bool*[ARRAY_EREMENT]; + for (int y = 0; y < ARRAY_EREMENT; y++) + { + _element[y] = new char[CODE_LENGTH]; + _check[y] = new bool[CODE_LENGTH]; + } + + for(int b = 0;b < BUF;b++) + _buf[b] = 0; + + for(int x = 0;x < ARRAY_EREMENT;x++) + { + _tempnum[x] = 0; + for(int y = 0;y < CODE_LENGTH;y++) + { + _data [x][y] = 0; + _element[x][y] = ' '; + _check [x][y] = true; + } + } _ele = 0; - for(int i = 0;fgets(_buf,sizeof(_buf), _fp) != NULL;i++) + for(int i = 0;fgets(_buf,BUF, _fp) != NULL;i++) { _codesize = i; - if(i > CODE_LENGTH) return false; else { - string _tempstr[ARRAY_EREMENT]; + string *_tempstr = new string[ARRAY_EREMENT]; + for(int x = 0;x < ARRAY_EREMENT;x++) + _tempstr[x] = " "; + _count = -1; - 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++) { - _char = _buf[n]; + char _char = _buf[n]; if((_char >= 'a'&& _char <= 'z') || (_char >= 'A' && _char <= 'Z')) { _count++; @@ -98,30 +115,49 @@ } } } - _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; } - else if('\n' || '\r') + else if(_char == '\n' || _char == '\r') { } 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 y = 0; y < ARRAY_EREMENT;y++) + { + delete[] _check[y]; + delete[] _element[y]; + } + delete[] _tempnum; + delete[] _buf; + delete[] _check; + delete[] _element; + return true; } \ No newline at end of file
--- a/MakeSequencer.h Thu Oct 11 11:23:53 2018 +0000 +++ b/MakeSequencer.h Wed Oct 17 08:39:42 2018 +0000 @@ -3,32 +3,25 @@ #include "mbed.h" #include "string" -#define CODE_LENGTH 100 -#define ARRAY_EREMENT 10 +#define CODE_LENGTH 15 +#define ARRAY_EREMENT 5 +#define BUF 256 class MakeSequencer { public: MakeSequencer(FILE *fp); - bool FileOpen(); - void getGcode(int _row,int aSize,int* _array); + 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; };