Reading Gcode in LocalFiileSystem and encodeing int array. but this program has bug.probably
Fork of MakeSequencer by
MakeSequencer.cpp@3:09ee560a3007, 2018-10-11 (annotated)
- Committer:
- satoyuki1111
- Date:
- Thu Oct 11 11:23:53 2018 +0000
- Revision:
- 3:09ee560a3007
- Parent:
- 2:4fc4593498d7
- Child:
- 4:1d7c50f17687
v1.3
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
satoyuki1111 | 0:359eba7592ca | 1 | /* |
satoyuki1111 | 2:4fc4593498d7 | 2 | sample |
satoyuki1111 | 2:4fc4593498d7 | 3 | |
satoyuki1111 | 2:4fc4593498d7 | 4 | #include "mbed.h" |
satoyuki1111 | 2:4fc4593498d7 | 5 | #include "MakeSequencer.h" |
satoyuki1111 | 2:4fc4593498d7 | 6 | |
satoyuki1111 | 2:4fc4593498d7 | 7 | //A row is from 1 |
satoyuki1111 | 0:359eba7592ca | 8 | |
satoyuki1111 | 0:359eba7592ca | 9 | LocalFileSystem local("local"); |
satoyuki1111 | 2:4fc4593498d7 | 10 | int array[5] = {}; |
satoyuki1111 | 0:359eba7592ca | 11 | |
satoyuki1111 | 0:359eba7592ca | 12 | int main() |
satoyuki1111 | 0:359eba7592ca | 13 | { |
satoyuki1111 | 0:359eba7592ca | 14 | FILE *fp = fopen( "/local/out.txt", "r"); |
satoyuki1111 | 0:359eba7592ca | 15 | MakeSequencer code(fp); |
satoyuki1111 | 2:4fc4593498d7 | 16 | code.getGcode(3,sizeof(array)/sizeof(int),array); //getGcode(int row,int aSize, int* array) |
satoyuki1111 | 2:4fc4593498d7 | 17 | //array will get Gcode of a "int row" line |
satoyuki1111 | 2:4fc4593498d7 | 18 | for(int i = 0;i < sizeof(array)/sizeof(int);i++) |
satoyuki1111 | 2:4fc4593498d7 | 19 | printf("%d,",array[i]); |
satoyuki1111 | 2:4fc4593498d7 | 20 | printf("\n\r%d",code.getGcodeSize()); //getGcodeSize() |
satoyuki1111 | 2:4fc4593498d7 | 21 | //return Gcode row |
satoyuki1111 | 0:359eba7592ca | 22 | } |
satoyuki1111 | 0:359eba7592ca | 23 | */ |
satoyuki1111 | 0:359eba7592ca | 24 | |
satoyuki1111 | 0:359eba7592ca | 25 | |
satoyuki1111 | 0:359eba7592ca | 26 | #include "MakeSequencer.h" |
satoyuki1111 | 0:359eba7592ca | 27 | |
satoyuki1111 | 0:359eba7592ca | 28 | |
satoyuki1111 | 0:359eba7592ca | 29 | MakeSequencer::MakeSequencer(FILE *fp) |
satoyuki1111 | 0:359eba7592ca | 30 | { |
satoyuki1111 | 0:359eba7592ca | 31 | _fp=fp; |
satoyuki1111 | 0:359eba7592ca | 32 | FileOpen(); |
satoyuki1111 | 0:359eba7592ca | 33 | } |
satoyuki1111 | 0:359eba7592ca | 34 | |
satoyuki1111 | 0:359eba7592ca | 35 | bool MakeSequencer::FileOpen() |
satoyuki1111 | 0:359eba7592ca | 36 | { |
satoyuki1111 | 0:359eba7592ca | 37 | if ( _fp == NULL ) |
satoyuki1111 | 0:359eba7592ca | 38 | { |
satoyuki1111 | 0:359eba7592ca | 39 | printf("Exception"); |
satoyuki1111 | 0:359eba7592ca | 40 | return false; |
satoyuki1111 | 0:359eba7592ca | 41 | } |
satoyuki1111 | 0:359eba7592ca | 42 | else |
satoyuki1111 | 0:359eba7592ca | 43 | ReadGcode(); |
satoyuki1111 | 0:359eba7592ca | 44 | |
satoyuki1111 | 0:359eba7592ca | 45 | fclose(_fp); |
satoyuki1111 | 0:359eba7592ca | 46 | return true; |
satoyuki1111 | 0:359eba7592ca | 47 | } |
satoyuki1111 | 0:359eba7592ca | 48 | |
satoyuki1111 | 2:4fc4593498d7 | 49 | void MakeSequencer::getGcode(int row,int aSize, int* array) |
satoyuki1111 | 0:359eba7592ca | 50 | { |
satoyuki1111 | 2:4fc4593498d7 | 51 | for(int i = 0;i < aSize;i++) |
satoyuki1111 | 0:359eba7592ca | 52 | { |
satoyuki1111 | 2:4fc4593498d7 | 53 | array[i] = _data[i][row-1]; |
satoyuki1111 | 0:359eba7592ca | 54 | } |
satoyuki1111 | 0:359eba7592ca | 55 | } |
satoyuki1111 | 0:359eba7592ca | 56 | |
satoyuki1111 | 1:4ebb30d54be7 | 57 | int MakeSequencer::getGcodeSize() |
satoyuki1111 | 1:4ebb30d54be7 | 58 | { |
satoyuki1111 | 2:4fc4593498d7 | 59 | return _codesize+1; |
satoyuki1111 | 1:4ebb30d54be7 | 60 | } |
satoyuki1111 | 1:4ebb30d54be7 | 61 | |
satoyuki1111 | 0:359eba7592ca | 62 | bool MakeSequencer::ReadGcode() |
satoyuki1111 | 0:359eba7592ca | 63 | { |
satoyuki1111 | 3:09ee560a3007 | 64 | _ele = 0; |
satoyuki1111 | 2:4fc4593498d7 | 65 | for(int i = 0;fgets(_buf,sizeof(_buf), _fp) != NULL;i++) |
satoyuki1111 | 0:359eba7592ca | 66 | { |
satoyuki1111 | 2:4fc4593498d7 | 67 | _codesize = i; |
satoyuki1111 | 2:4fc4593498d7 | 68 | |
satoyuki1111 | 0:359eba7592ca | 69 | if(i > CODE_LENGTH) |
satoyuki1111 | 0:359eba7592ca | 70 | return false; |
satoyuki1111 | 2:4fc4593498d7 | 71 | else |
satoyuki1111 | 2:4fc4593498d7 | 72 | { |
satoyuki1111 | 2:4fc4593498d7 | 73 | string _tempstr[ARRAY_EREMENT]; |
satoyuki1111 | 3:09ee560a3007 | 74 | _count = -1; |
satoyuki1111 | 0:359eba7592ca | 75 | |
satoyuki1111 | 2:4fc4593498d7 | 76 | for(int n = 0;n < ARRAY_EREMENT;n++) |
satoyuki1111 | 2:4fc4593498d7 | 77 | { |
satoyuki1111 | 2:4fc4593498d7 | 78 | for(int p = 0;p < CODE_LENGTH;p++) |
satoyuki1111 | 2:4fc4593498d7 | 79 | _check[n][p] = true; |
satoyuki1111 | 2:4fc4593498d7 | 80 | } |
satoyuki1111 | 2:4fc4593498d7 | 81 | |
satoyuki1111 | 2:4fc4593498d7 | 82 | for(int n = 0;_buf[n] != '\0';n++) |
satoyuki1111 | 0:359eba7592ca | 83 | { |
satoyuki1111 | 2:4fc4593498d7 | 84 | _char = _buf[n]; |
satoyuki1111 | 2:4fc4593498d7 | 85 | if((_char >= 'a'&& _char <= 'z') || (_char >= 'A' && _char <= 'Z')) |
satoyuki1111 | 2:4fc4593498d7 | 86 | { |
satoyuki1111 | 2:4fc4593498d7 | 87 | _count++; |
satoyuki1111 | 2:4fc4593498d7 | 88 | if(_char != _element[_count][0] && i != 0) |
satoyuki1111 | 2:4fc4593498d7 | 89 | { |
satoyuki1111 | 2:4fc4593498d7 | 90 | for(int p = 0;p < _ele;p++) |
satoyuki1111 | 2:4fc4593498d7 | 91 | { |
satoyuki1111 | 2:4fc4593498d7 | 92 | if(_char == _element[p][0]) |
satoyuki1111 | 2:4fc4593498d7 | 93 | { |
satoyuki1111 | 2:4fc4593498d7 | 94 | _element[p][i] = _char; |
satoyuki1111 | 2:4fc4593498d7 | 95 | _count = p; |
satoyuki1111 | 2:4fc4593498d7 | 96 | _check[p][i] = false; |
satoyuki1111 | 2:4fc4593498d7 | 97 | break; |
satoyuki1111 | 2:4fc4593498d7 | 98 | } |
satoyuki1111 | 2:4fc4593498d7 | 99 | } |
satoyuki1111 | 2:4fc4593498d7 | 100 | } |
satoyuki1111 | 2:4fc4593498d7 | 101 | _element[_count][i] = _char; |
satoyuki1111 | 2:4fc4593498d7 | 102 | if(i == 0) |
satoyuki1111 | 2:4fc4593498d7 | 103 | _ele++; |
satoyuki1111 | 2:4fc4593498d7 | 104 | } |
satoyuki1111 | 2:4fc4593498d7 | 105 | else if(_char >= '0'&& _char <= '9') |
satoyuki1111 | 2:4fc4593498d7 | 106 | { |
satoyuki1111 | 2:4fc4593498d7 | 107 | _tempstr[_count] = _tempstr[_count] + _char; |
satoyuki1111 | 2:4fc4593498d7 | 108 | } |
satoyuki1111 | 0:359eba7592ca | 109 | |
satoyuki1111 | 2:4fc4593498d7 | 110 | else if('\n' || '\r') |
satoyuki1111 | 2:4fc4593498d7 | 111 | { |
satoyuki1111 | 2:4fc4593498d7 | 112 | } |
satoyuki1111 | 2:4fc4593498d7 | 113 | else |
satoyuki1111 | 2:4fc4593498d7 | 114 | return false; |
satoyuki1111 | 2:4fc4593498d7 | 115 | } |
satoyuki1111 | 2:4fc4593498d7 | 116 | |
satoyuki1111 | 2:4fc4593498d7 | 117 | for(int n = 0;n < _ele;n++) |
satoyuki1111 | 2:4fc4593498d7 | 118 | { |
satoyuki1111 | 2:4fc4593498d7 | 119 | _tempnum[n] = atoi(_tempstr[n].c_str()); |
satoyuki1111 | 3:09ee560a3007 | 120 | _data[n][i] = (i != 0 && _check[n][i] && _element[n][i] != _element[n][0]) |
satoyuki1111 | 3:09ee560a3007 | 121 | ? _data[n][i-1] |
satoyuki1111 | 3:09ee560a3007 | 122 | : _tempnum[n]; |
satoyuki1111 | 2:4fc4593498d7 | 123 | } |
satoyuki1111 | 0:359eba7592ca | 124 | } |
satoyuki1111 | 0:359eba7592ca | 125 | } |
satoyuki1111 | 0:359eba7592ca | 126 | return true; |
satoyuki1111 | 0:359eba7592ca | 127 | } |