diff options
author | Barattero Laurent <laurent@larueluberlu.net> | 2014-01-18 10:24:55 +0100 |
---|---|---|
committer | Barattero Laurent <laurent@larueluberlu.net> | 2014-01-18 10:24:55 +0100 |
commit | 45ab288c8256f2787e7bf694c7a48888592be4cd (patch) | |
tree | 2e5541878cf4ec75a02e9b7b0846b522a2969371 /src/buffer.cpp | |
parent | 21f1a950c54e27044abcc35159cdcf5b8dc602d2 (diff) |
first commit release 0.2
Diffstat (limited to 'src/buffer.cpp')
-rw-r--r-- | src/buffer.cpp | 173 |
1 files changed, 173 insertions, 0 deletions
diff --git a/src/buffer.cpp b/src/buffer.cpp new file mode 100644 index 0000000..9c0ffec --- /dev/null +++ b/src/buffer.cpp @@ -0,0 +1,173 @@ +/* + Copyright (C) 2014 BARRATERO Laurent + + AeroUp is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + Aeroup is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +/* + * Filename: buffer.cpp + * + * Description: + * + * Version: 0.2 + * Created: 28/12/2013 07:06:20 + * Revision: none + * Compiler: gcc + * + * Author: BARATTERO Laurent, laurentba<at>larueluberlu.net + * Organization: La rue Luberlu + * + */ + +#include <buffer.hpp> + +using namespace std; + +Buffer::Buffer(): + size(0) +{ + //memset(buff, 0, sizeof(buff)); +} + +int Buffer::addChr(unsigned char val) +{ + verify_size(); + //buff[size++] = val; + //strcpy((char*)buff[size],(const char *)val); + buff[size] = val; + size++; + return 1; + +} + + string +Buffer::addDefsubToBuff() +{ + for(auto itr = sub_position.begin(); itr != sub_position.end(); ++itr) + { + while(((*itr).second.empty()) == false ) + { + auto it = defsub_position.find((*itr).first); + if(it != defsub_position.end()) + { + buff[(*itr).second.back()] = defsub_position[(*itr).first][0]; + buff[(*itr).second.back() + 1] = defsub_position[(*itr).first][1]; + (*itr).second.pop_back(); + } + else + { + return (*itr).first ; + } + } + } + return ""; +} + + int +Buffer::addDefsubPos(string defsubName) +{ + auto it = defsub_position.find(defsubName); + if(it == defsub_position.end()) + { + defsub_position[defsubName][0] = (uint8_t)(size & 0xff); + defsub_position[defsubName][1] = (uint8_t)(size >> 8); + return 0; + } + else + { + return 1; + } +} + + void +Buffer::addSubPos(string subName) +{ + sub_position[subName].push_back(size); +} + + void +Buffer::printDefsubPos() +{ + cout << endl + << "(Debug function) print map defsub_position :" << endl + << "============================================" << endl; + for(auto itr = defsub_position.begin(); itr != defsub_position.end(); ++itr) + { + cout << "Key : " << (*itr).first << endl + << "Lsb : " << dec << (int)(*itr).second[0] << endl + << "Msb : " << dec << (int)(*itr).second[1] << endl ; + } +} + + void +Buffer::printSubPos() +{ + cout << endl + << "(Debug function) print map sub_position :" << endl + << "=========================================" << endl; + for(auto itr = sub_position.begin(); itr != sub_position.end(); ++itr) + { + cout << "Key : " << (*itr).first << endl + << "Value : " ; + for (auto itr_vect = (*itr).second.begin(); + itr_vect != (*itr).second.end(); + ++itr_vect) + { + cout << (*itr_vect) << " "; + } + + cout << endl; + } +} + + void +Buffer::printBuff(void) const +{ + for (unsigned int i = 0; i < size ; i++) + { + printf("buff[%d] : %d\n", i, buff[i]); + + } + +} + + void +Buffer::verify_size(void) +{ + if (size > BUFF_SIZE_MAX) + { + printf ("Error glow file too big !"); + exit (EXIT_FAILURE); + } +} + + +/* + * where is sub map string vector int subnamekey, (byte,...) + * defsub defsubname, localisation subfunction + * + * if sub define 2 times error + * + * */ + unsigned char* +Buffer::getSizeUpCmd() +{ + lsb_msb[0]= 100; + lsb_msb[1]= (uint8_t)(size & 0xff); + lsb_msb[2]= (uint8_t)(size >> 8); + return lsb_msb; + + +} |