aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBarattero Laurent <laurent@larueluberlu.net>2014-01-18 10:24:55 +0100
committerBarattero Laurent <laurent@larueluberlu.net>2014-01-18 10:24:55 +0100
commit45ab288c8256f2787e7bf694c7a48888592be4cd (patch)
tree2e5541878cf4ec75a02e9b7b0846b522a2969371 /src
parent21f1a950c54e27044abcc35159cdcf5b8dc602d2 (diff)
first commit release 0.2
Diffstat (limited to '')
-rw-r--r--src/Makefile.am28
-rw-r--r--src/buffer.cpp173
-rw-r--r--src/buffer.hpp74
-rw-r--r--src/buffermanager.cpp384
-rw-r--r--src/buffermanager.hpp105
-rw-r--r--src/config.h.in91
-rw-r--r--src/define_ultimate_fct.h50
-rw-r--r--src/gloInterface.hpp63
-rw-r--r--src/global.hpp42
-rw-r--r--src/gloseq.cpp238
-rw-r--r--src/gloseq.hpp99
-rw-r--r--src/main.cpp269
-rw-r--r--src/main.hpp50
-rw-r--r--src/optmanager.cpp438
-rw-r--r--src/optmanager.hpp141
-rw-r--r--src/regboost.cpp62
-rw-r--r--src/regboost.hpp72
-rw-r--r--src/reglinux.cpp97
-rw-r--r--src/reglinux.hpp80
-rw-r--r--src/rules.cpp198
-rw-r--r--src/rules.hpp94
-rw-r--r--src/ruleserror.hpp81
-rw-r--r--src/serialboost.cpp200
-rw-r--r--src/serialboost.hpp69
-rw-r--r--src/seriallinux.cpp136
-rw-r--r--src/seriallinux.hpp66
-rw-r--r--src/serialprop.cpp70
-rw-r--r--src/serialprop.hpp77
-rw-r--r--src/ultimate.cpp137
-rw-r--r--src/ultimate.hpp66
30 files changed, 3750 insertions, 0 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
new file mode 100644
index 0000000..bf11705
--- /dev/null
+++ b/src/Makefile.am
@@ -0,0 +1,28 @@
+bin_PROGRAMS = aeroup
+
+ext_src =
+if BOOST
+ext_src += serialboost.cpp
+ext_src += regboost.cpp
+#echo have boost
+else
+ext_src += reglinux.cpp
+ext_src += seriallinux.cpp
+#echo have not boost
+endif
+
+aeroup_SOURCES = \
+ main.cpp \
+ ultimate.cpp \
+ serialprop.cpp \
+ optmanager.cpp \
+ gloseq.cpp \
+ buffer.cpp \
+ buffermanager.cpp \
+ rules.cpp \
+ ${ext_src}
+
+aeroup_CPPFLAGS = -W -Wall -std=c++11
+aeroup_LDFLAGS =
+#LIBS +=
+#-DSERIAL_BOOST_LIB
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;
+
+
+}
diff --git a/src/buffer.hpp b/src/buffer.hpp
new file mode 100644
index 0000000..eae7080
--- /dev/null
+++ b/src/buffer.hpp
@@ -0,0 +1,74 @@
+/*
+ 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.hpp
+ *
+ * Description:
+ *
+ * Version: 0.2
+ * Created: 28/12/2013 07:01:58
+ * Revision: none
+ * Compiler: gcc
+ *
+ * Author: BARATTERO Laurent, laurentba<at>larueluberlu.net
+ * Organization: La rue Luberlu
+ */
+
+#ifndef buffer_INC
+#define buffer_INC
+
+#define BUFF_SIZE_MAX 8959
+//#define SIZE_MAX_OVER 20000
+
+
+#include "global.hpp"
+#include <map>
+#include <vector>
+
+class Buffer
+{
+public:
+ Buffer();
+ int addChr(unsigned char val);
+ void addSubPos(std::string subName);
+ int addDefsubPos(std::string defsubName);
+ std::string addDefsubToBuff();
+ void printSubPos();
+ void printDefsubPos();
+ void printBuff(void) const;
+ // SIZE
+ unsigned short int getSize(void) const { return size;}
+ unsigned char * pointToBuff(){return buff;}
+ unsigned char* getSizeUpCmd();
+
+
+private:
+ void setSize(unsigned short int val) {size = val ;}
+ void verify_size(void);
+ unsigned short int size;
+ uint8_t lsb_msb[3];
+
+ // metre une variable pour 80
+ uint8_t buff[BUFF_SIZE_MAX];
+ std::map <std::string, std::vector<int> > sub_position;
+ std::map <std::string, uint8_t[2]> defsub_position;
+};
+
+
+#endif /* ----- #ifndef buffer_INC ----- */
diff --git a/src/buffermanager.cpp b/src/buffermanager.cpp
new file mode 100644
index 0000000..72ae576
--- /dev/null
+++ b/src/buffermanager.cpp
@@ -0,0 +1,384 @@
+/*
+ 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: buffermanager.cpp
+ *
+ * Description: take the parsed, tokenized lines and manage them.
+ * send also some rules test
+ *
+ * Version: 0.2
+ * Created: 30/12/2013 12:12:46
+ * Revision: none
+ * Compiler: gcc
+ *
+ * Author: BARATTERO Laurent, laurentba<at>larueluberlu.net
+ * Organization: La rue Luberlu
+ */
+
+#include "buffermanager.hpp"
+
+using namespace std;
+
+
+/*
+ * Class: BufferManager
+ * Method: BufferManager
+ * Description: constructor
+ */
+
+BufferManager::BufferManager (Buffer* theBuff, Rules* theRules):
+ buff(theBuff),
+ rules(theRules)
+{
+}
+
+/*
+ * Class: BufferManager
+ * Method: completesCreateCommand
+ * Description: Second pass to buff, Completes createCommand work
+ */
+ void
+BufferManager::completesCreateCommand()
+{
+ verifyEndFileError();
+ addDefsubToBuff();
+}
+
+/*
+ * Class: BufferManager
+ * Method: BufferManager :: verifyEndFileError
+ * Description: Verification which require that EOF is reached
+ * executed after the multiple call
+ * to the createCommand function by GloSeq instance.
+ */
+ void
+BufferManager::verifyEndFileError()
+{
+ /* verify there is no DEFSUB without ENDSUB before EOF */
+ rules->endTestDefsub();
+
+}
+
+/*
+ * Class: BufferManager
+ * Method: BufferManager :: addDefsubToBuff
+ * Description: adds the defsub adress to every sub of the buffer
+ */
+ void
+BufferManager::addDefsubToBuff()
+{
+ string sub_name = buff->addDefsubToBuff();
+ /* If a sub is not defined, we throw an error */
+ if(!sub_name.empty())
+ {
+ rules->noDefsubError(sub_name);
+ }
+}
+
+/*
+ * Class: BufferManager
+ * Method: BufferManager :: createCommand
+ * Description: fills the buffer with a token line
+ */
+
+ void
+BufferManager::createCommand (vector <string> tokens, int cmd_type, int nb_line)
+{
+
+ switch (cmd_type) {
+
+ case C_FCT:
+ rules->isStandardCmdPossible(nb_line, C_FCT);
+ colorsFillBuff(tokens);
+ break;
+
+ case D_FCT:
+ rules->isStandardCmdPossible(nb_line, D_FCT);
+ delayFillBuff(tokens);
+ break;
+
+ case RAMP_FCT:
+ rules->isStandardCmdPossible(nb_line, RAMP_FCT);
+ rampFillBuff(tokens);
+ break;
+
+ case L_FCT:
+ rules->setloop(nb_line);
+ loopFillBuff(tokens);
+ break;
+
+ case E_FCT:
+ rules->unsetloop(nb_line);
+ oneByteFillBuff(E_CMD);
+ break;
+
+ case R_FCT:
+ rules->isStandardCmdPossible(nb_line, R_FCT);
+ oneColorFillBuff(tokens, R_CMD);
+ break;
+
+ case G_FCT:
+ rules->isStandardCmdPossible(nb_line, G_FCT);
+ oneColorFillBuff(tokens, G_CMD);
+ break;
+
+ case B_FCT:
+ rules->isStandardCmdPossible(nb_line, B_FCT);
+ oneColorFillBuff(tokens, B_CMD);
+ break;
+
+ case SUB_FCT:
+ rules->isStandardCmdPossible(nb_line, SUB_FCT);
+ subFillBuff(tokens);
+ break;
+
+ case DEFSUB_FCT:
+ rules->setDefsub(nb_line);
+ defsubFillBuff(tokens, nb_line);
+ break;
+
+ case ENDSUB_FCT:
+ rules->unsetDefsub(nb_line);
+ oneByteFillBuff(ENDSUB_CMD);
+ break;
+
+ case END_FCT:
+ rules->setEnd(nb_line);
+ oneByteFillBuff(END_CMD);
+ break;
+ } /* ----- end switch ----- */
+ return ;
+} /* ----- end of method BufferManager::createCommand ----- */
+
+
+
+/*
+ * Class: BufferManager
+ * Method: BufferManager :: oneColorFillBuff
+ * Description: ( *FillBuff function ) generic method for R, G, B commands
+ */
+
+ void
+BufferManager::oneColorFillBuff(vector <string> tokens, int col)
+{
+ buff->addChr(col);
+ buffAddOneColor(tokens[1]);
+}
+
+
+/*
+ * Class: BufferManager
+ * Method: BufferManager :: ColorFillBuff
+ * Description: ( *FillBuff function ) Color C
+ */
+ void
+BufferManager::colorsFillBuff (vector <string> tokens)
+{
+ buff->addChr(C_CMD);
+ buffAddTriColors(tokens);
+}
+
+
+/*
+ * Class: BufferManager
+ * Method: BufferManager :: delayFillBuff
+ * Description: ( *FillBuff function ) Delay D
+ */
+
+ void
+BufferManager::delayFillBuff (vector <string> tokens)
+{
+ int tmp_byte;
+ tmp_byte = stoi(tokens[1]);
+ if (verifyByteOverflow(tmp_byte) != -1)
+ {
+ buff->addChr(D_LOW_CMD);
+ buff->addChr((uint8_t)tmp_byte);
+ return;
+ }
+ else if(verify2BytesOverflow(tmp_byte) != -1)
+ {
+ buff->addChr(D_HIGH_CMD);
+ buff->addChr((uint8_t)(tmp_byte & 0xff));
+ buff->addChr((uint8_t)(tmp_byte >> 8));
+ return;
+ }
+ else
+ exit(EXIT_FAILURE);
+} /* ----- end of method BufferManager::delayFillBuff ----- */
+
+/*
+ * Class: BufferManager
+ * Method: BufferManager :: loopFillBuff
+ * Description: ( *FillBuff function ) Loop L
+ */
+ void
+BufferManager::loopFillBuff (vector <string> tokens)
+{
+ buff->addChr(L_CMD);
+ int tmp_byte;
+ tmp_byte = stoi(tokens[1]);
+ if(verifyByteOverflow(tmp_byte)!= -1)
+ {
+ buff->addChr((uint8_t)tmp_byte);
+ }
+ else
+ {
+ exit(EXIT_FAILURE);
+ }
+} /* ----- end of method BufferManager::loopFillBuff ----- */
+
+/*
+ * Class: BufferManager
+ * Method: BufferManager :: oneByteFillBuff
+ * Description: ( *FillBuff function ) Generic for E, END, ENDSUB
+ */
+ void
+BufferManager::oneByteFillBuff(int cmd)
+{
+ buff->addChr(cmd);
+} /* ----- end of method BufferManager::endLoopFillBuff ----- */
+
+/*
+ * Class: BufferManager
+ * Method: BufferManager :: rampFillBuff
+ * Description: ( *FillBuff function ) RAMP
+ */
+ void
+BufferManager::rampFillBuff(std::vector<std::string> tokens)
+{
+ int tmp_byte;
+ tmp_byte = stoi(tokens[4]);
+ if (verifyByteOverflow(tmp_byte) != -1)
+ {
+ buff->addChr(RAMP_LOW_CMD);
+ buffAddTriColors(tokens);
+ buff->addChr(tmp_byte);
+ }
+ else if(verify2BytesOverflow(tmp_byte) != -1)
+ {
+ buff->addChr(RAMP_HIGH_CMD);
+ buffAddTriColors(tokens);
+ buff->addChr((uint8_t)(tmp_byte & 0xff));
+ buff->addChr((uint8_t)(tmp_byte >> 8));
+ return;
+ }
+ else
+ exit(EXIT_FAILURE);
+} /* ----- end of method BufferManager::rampFillBuff ----- */
+
+
+/*
+ * Class: BufferManager
+ * Method: BufferManager :: subFillBuff
+ * Description: ( *FillBuff function ) SUB
+ * - Add SUB_CMD to buff
+ * - Stores the buffer position of the SUB LSB value in a map
+ * - And add two tempory '\0' value to buff for LSB & MSB
+ */
+ void
+BufferManager::subFillBuff(std::vector<std::string> tokens)
+{
+ buff->addChr(SUB_CMD);
+ buff->addSubPos(tokens[1]);
+ buff->addChr(0);
+ buff->addChr(0);
+} /* ----- end of method BufferManager::subFillBuff ----- */
+
+/*
+ * Class: BufferManager
+ * Method: BufferManager :: defsubFillBuff
+ * Description: ( *FillBuff function ) DEFSUB
+ * - Add the beginning position of the DEFSUB
+ * function in the buffer to a map.
+ * - throws an error if the same function is defined twice
+ */
+ void
+BufferManager::defsubFillBuff(std::vector<std::string> tokens, int nb_line)
+{
+ if(buff->addDefsubPos(tokens[1]))
+ {
+ rules->twiceDefsubError(nb_line);
+ }
+
+} /* ----- end of method BufferManager::defsubFillBuff function ----- */
+
+
+
+/*
+ * Class: BufferManager
+ * Method: BufferManager :: verifyByteOverflow
+ */
+ int
+BufferManager::verifyByteOverflow(int value)
+{
+ if (value < 256 && value > -1)
+ {
+ return value;
+ }
+ else
+ return -1;
+} /* ----- end of method BufferManager::verifyByteOverflow function ----- */
+
+/*
+ * Class: BufferManager
+ * Method: BufferManager :: verify2BytesOverflow
+ */
+ int
+BufferManager::verify2BytesOverflow(int value)
+{
+ if (value < 65536 && value > 255)
+ {
+ return value;
+ }
+ else
+ return -1;
+} /* ----- end of method BufferManager::verify2BytesOverflow function ----- */
+
+/*
+ * Class: BufferManager
+ * Method: BufferManager :: buffAddTriColors
+ */
+ void
+BufferManager::buffAddTriColors(vector<string>& tokens)
+{
+ for(int i = 1; i < 4; i++)
+ {
+ buffAddOneColor(tokens[i]);
+ }
+} /* ----- end of method BufferManager::buffAddTriColors function ----- */
+
+/*
+ * Class: BufferManager
+ * Method: BufferManager :: buffAddOneColor
+ */
+ void
+BufferManager::buffAddOneColor(string& tok)
+{
+ int tmp_byte;
+ tmp_byte = stoi(tok);
+ if(verifyByteOverflow(tmp_byte)!= -1)
+ {
+ buff->addChr((uint8_t)tmp_byte);
+ }
+ else {
+ exit(EXIT_FAILURE);
+ }
+} /* ----- end of method BufferManager::buffAddOneColor function ----- */
+
diff --git a/src/buffermanager.hpp b/src/buffermanager.hpp
new file mode 100644
index 0000000..0b14781
--- /dev/null
+++ b/src/buffermanager.hpp
@@ -0,0 +1,105 @@
+/*
+ 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: buffermanager.hpp
+ *
+ * Description:
+ *
+ * Version: 0.2
+ * Created: 30/12/2013 12:07:43
+ * Revision: none
+ * Compiler: gcc
+ *
+ * Author: BARATTERO Laurent, laurentba<at>larueluberlu.net
+ * Organization: La rue Luberlu
+ */
+
+#ifndef commandfactory_INC
+#define commandfactory_INC
+
+#include <string>
+#include <vector>
+
+#include "buffer.hpp"
+#include "global.hpp"
+#include "rules.hpp"
+#include "define_ultimate_fct.h"
+
+/* -- commands byte values -- */
+const uint8_t C_CMD = 1;
+const uint8_t D_LOW_CMD = 2;
+const uint8_t L_CMD = 3;
+const uint8_t D_HIGH_CMD = 4;
+const uint8_t E_CMD = 5;
+const uint8_t R_CMD = 7;
+const uint8_t G_CMD = 8;
+const uint8_t B_CMD = 9;
+const uint8_t RAMP_LOW_CMD = 12;
+const uint8_t RAMP_HIGH_CMD = 13;
+const uint8_t SUB_CMD = 10;
+const uint8_t ENDSUB_CMD = 11;
+const uint8_t END_CMD = 255;
+
+/*
+ * Class: BufferManager
+ * Description:
+ */
+class BufferManager
+{
+ public:
+ BufferManager (Buffer* theBuff, Rules* theRules); /* constructor */
+
+ void createCommand ( std::vector <std::string> tokens,
+ int cmd_type,
+ int nb_line );
+ void completesCreateCommand ();
+
+ private:
+ /* ...FillBuff function */
+ void delayFillBuff(std::vector<std::string> tokens);
+ void oneByteFillBuff(int fct);
+ void oneColorFillBuff(std::vector <std::string> tokens, int col);
+ void colorsFillBuff(std::vector<std::string> tokens);
+ void rampFillBuff(std::vector<std::string> tokens);
+ void loopFillBuff(std::vector<std::string> tokens);
+ void subFillBuff(std::vector<std::string> tokens);
+ void defsubFillBuff(std::vector<std::string> tokens, int nb_line);
+
+ /* Second pass to buff, Completes createCommand work */
+ void addDefsubToBuff();
+ void verifyEndFileError();
+
+ /* Byte verification */
+ int verifyByteOverflow(int Value);
+ int verify2BytesOverflow(int Value);
+
+ /* Colors utility */
+ void buffAddTriColors(std::vector<std::string>& tokens);
+ void buffAddOneColor(std::string& tok);
+
+ /* aggregation */
+ Buffer* buff;
+ Rules* rules;
+
+ /* data */
+ std::string fileName;
+
+};
+
+#endif /* ----- #ifndef command_factory_INC ----- */
diff --git a/src/config.h.in b/src/config.h.in
new file mode 100644
index 0000000..aaedc55
--- /dev/null
+++ b/src/config.h.in
@@ -0,0 +1,91 @@
+/* src/config.h.in. Generated from configure.ac by autoheader. */
+
+/* Define debug mod */
+#undef DEBUG
+
+/* Define to 1 if you have the `bzero' function. */
+#undef HAVE_BZERO
+
+/* Define to 1 if you have the <fcntl.h> header file. */
+#undef HAVE_FCNTL_H
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#undef HAVE_INTTYPES_H
+
+/* Define to 1 if you have the 'boost_regex' library (-lboost_regex) */
+#undef HAVE_LIBBOOST_REGEX
+
+/* Define to 1 if you have the `boost_system' library (-lboost_system). */
+#undef HAVE_LIBBOOST_SYSTEM
+
+/* Define to 1 if you have the `boost_thread' library (-lboost_thread). */
+#undef HAVE_LIBBOOST_THREAD
+
+/* Define to 1 if you have the <memory.h> header file. */
+#undef HAVE_MEMORY_H
+
+/* Define to 1 if you have the `memset' function. */
+#undef HAVE_MEMSET
+
+/* Define to 1 if you have the `regcomp' function. */
+#undef HAVE_REGCOMP
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#undef HAVE_STDINT_H
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#undef HAVE_STDLIB_H
+
+/* Define to 1 if you have the <strings.h> header file. */
+#undef HAVE_STRINGS_H
+
+/* Define to 1 if you have the <string.h> header file. */
+#undef HAVE_STRING_H
+
+/* Define to 1 if you have the `strtol' function. */
+#undef HAVE_STRTOL
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#undef HAVE_SYS_STAT_H
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#undef HAVE_SYS_TYPES_H
+
+/* Define to 1 if you have the <termios.h> header file. */
+#undef HAVE_TERMIOS_H
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#undef HAVE_UNISTD_H
+
+/* Define to 1 if the system has the type `_Bool'. */
+#undef HAVE__BOOL
+
+/* Name of package */
+#undef PACKAGE
+
+/* Define to the address where bug reports for this package should be sent. */
+#undef PACKAGE_BUGREPORT
+
+/* Define to the full name of this package. */
+#undef PACKAGE_NAME
+
+/* Define to the full name and version of this package. */
+#undef PACKAGE_STRING
+
+/* Define to the one symbol short name of this package. */
+#undef PACKAGE_TARNAME
+
+/* Define to the home page for this package. */
+#undef PACKAGE_URL
+
+/* Define to the version of this package. */
+#undef PACKAGE_VERSION
+
+/* Define to 1 if you have the ANSI C header files. */
+#undef STDC_HEADERS
+
+/* Version number of package */
+#undef VERSION
+
+/* Define to `unsigned int' if <sys/types.h> does not define. */
+#undef size_t
diff --git a/src/define_ultimate_fct.h b/src/define_ultimate_fct.h
new file mode 100644
index 0000000..36fe030
--- /dev/null
+++ b/src/define_ultimate_fct.h
@@ -0,0 +1,50 @@
+/*
+ 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: define_ultimate_fct.h
+ *
+ * Description:
+ *
+ * Version: 0.2
+ * Created: 30/12/2013 12:50:40
+ * Revision: none
+ * Compiler: gcc
+ *
+ * Author: BARATTERO Laurent, laurentba<at>larueluberlu.net
+ * Organization: La rue Luberlu
+ */
+
+#ifndef define_ultimate_fct_INC
+#define define_ultimate_fct_INC
+
+#define C_FCT 0
+#define D_FCT 1
+#define RAMP_FCT 2
+#define L_FCT 3
+#define E_FCT 4
+#define R_FCT 5
+#define G_FCT 6
+#define B_FCT 7
+#define SUB_FCT 8
+#define DEFSUB_FCT 9
+#define ENDSUB_FCT 10
+#define END_FCT 11
+#define REG_TAB_LEN (END_FCT + 1)
+
+#endif /* ----- #ifndef define_ultimate_fct_INC ----- */
diff --git a/src/gloInterface.hpp b/src/gloInterface.hpp
new file mode 100644
index 0000000..f31658a
--- /dev/null
+++ b/src/gloInterface.hpp
@@ -0,0 +1,63 @@
+/*
+ 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: gloInterface.hpp
+ *
+ * Description:
+ *
+ * Version:
+ * Created: 11/01/2014 14:03:43
+ * Revision: none
+ * Compiler: gcc
+ *
+ * Author: BARATTERO Laurent, laurentba<at>larueluberlu.net
+ * Organization: La rue Luberlu
+ */
+
+#ifndef gloInterface_INC
+#define gloInterface_INC
+
+
+
+#include "global.hpp"
+#include "gloseq.hpp"
+
+
+/*
+ * Class: GloInterface
+ * Description:
+ */
+class GloInterface
+{
+ public:
+ GloInterface(){;} /* constructor */
+
+ int verifyFile( std::string fileName)
+ {
+ GloSeq file(fileName);
+ file.verify();
+ return (1); // tempory implementaion return
+ }
+
+
+ private:
+
+}; /* ----- end of class Editor ----- */
+
+#endif
diff --git a/src/global.hpp b/src/global.hpp
new file mode 100644
index 0000000..be20d98
--- /dev/null
+++ b/src/global.hpp
@@ -0,0 +1,42 @@
+/*
+ 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: global.hpp
+ *
+ * Description:
+ *
+ * Version: 0.2
+ * Created: 20/12/2013 00:09:35
+ * Revision: none
+ * Compiler: gcc
+ *
+ * Author: BARATTERO Laurent, laurentba<at>larueluberlu.net
+ * Organization: La rue Luberlu
+ */
+
+#ifndef global_INC
+#define global_INC
+
+#include <stdlib.h>
+#include <string>
+#include <iostream>
+
+typedef unsigned char uint8_t;
+
+#endif /* ----- #ifndef global_INC ----- */
diff --git a/src/gloseq.cpp b/src/gloseq.cpp
new file mode 100644
index 0000000..370b522
--- /dev/null
+++ b/src/gloseq.cpp
@@ -0,0 +1,238 @@
+/*
+ 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: gloseq.cpp
+ *
+ * Description:
+ *
+ * Version: 0.2
+ * Created: 27/12/2013 10:38:49
+ * Revision: none
+ * Compiler: gcc
+ *
+ * Author: BARATTERO Laurent, laurentba<at>larueluberlu.net
+ * Organization: La rue Luberlu
+ */
+
+#include <sstream>
+#include "gloseq.hpp"
+
+using namespace std;
+
+
+/*
+ * Class: GloSeq
+ * Method: GloSeq :: GloSeq
+ * Description: Constructor, open glo file in read mode
+ */
+GloSeq::GloSeq (string fileName):
+ file_name(fileName),
+ buff(),
+ rules(file_name),
+ buffManager(&buff, &rules)
+{
+ try
+ {
+ glofile.open(fileName);
+ if (!glofile)
+ {
+ throw "Error : can't opening glo file : ";
+ }
+ }
+ catch(const char* cstr)
+ {
+ cerr << cstr << fileName << endl;
+ throw;
+ }
+} /* ----- end of constructor ----- */
+
+/*
+ * Class: GloSeq
+ * Method: GloSeq :: verify
+ * Description: Verify that the glo file is valid.
+ * At the end of process, if no error happened the buffer is filled
+ * and ready to be upload.
+ */
+ void
+GloSeq::verify ()
+{
+ /* step 1 */
+ #ifdef DEBUG
+ cout << endl
+ << "1) Clean lines and keep what is needed :" << endl
+ << "========================================" << endl;
+ int j = 0;
+ #endif
+
+ string line;
+ for(int nb_line = 1; getline(glofile, line) != 0; nb_line++)
+ {
+ // cleaning each line
+ cleanLine(line);
+ if (line.length() != 0)
+ {
+ // put it in a vector
+ cmdTab.push_back({line, -1, nb_line});
+#ifdef DEBUG
+ cout << cmdTab[j].nb_line <<"| "<< cmdTab[j].line << endl;
+ ++j;
+#endif
+ }
+ }
+
+ /* step 2 */
+ #ifdef DEBUG
+ cout << endl
+ << "2) Regex validation :" << endl
+ << "=====================" << endl;
+ #endif
+
+#if HAVE_LIBBOOST_REGEX
+ RegBoost* reg = new RegBoost;
+#else
+ RegLinux* reg = new RegLinux;
+#endif
+ auto iterlist = cmdTab.begin();
+ int cmd;
+ int nb_error = 0;
+
+ while (iterlist != cmdTab.end())
+ {
+ cmd = reg->isValidSyntax( (*iterlist).line );
+ if (cmd == NOT_VALID)
+ {
+ if (!nb_error)
+ cout << "Syntax error in file " << file_name << " :" << endl;
+
+ cout << "Error line " << (*iterlist).nb_line
+ << ", " << (*iterlist).line << endl;
+ ++nb_error;
+ }
+ else
+ (*iterlist).cmd_type = cmd;
+ ++iterlist;
+ }
+ delete reg;
+
+ try
+ {
+ if (nb_error != 0)
+ throw(nb_error);
+ }
+ catch (int nb_error )
+ {
+ if (nb_error == 1)
+ cerr << "Error : "<< nb_error <<" syntax error in " << file_name << endl;
+ else
+ cerr << "Error : "<< nb_error <<" syntax errors in " << file_name << endl;
+ throw;
+ }
+
+ /* step 3 */
+ #ifdef DEBUG
+ cout << endl
+ << "3) Tokenize and send to buffManager:" << endl
+ << "========================================" << endl;
+ #endif
+ iterlist = cmdTab.begin();
+ vector <string> tokens;
+ //vector<string>::iterator it_string;
+
+ while (iterlist != cmdTab.end())
+ {
+ istringstream iss((*iterlist).line);
+ tokens.clear();
+ for (string each; (getline(iss, each, ',')); tokens.push_back(each));
+ try
+ {
+ buffManager.createCommand(tokens, (*iterlist).cmd_type, (*iterlist).nb_line);
+ }
+ catch( const std::exception & e )
+ {
+ cerr << e.what() << "\n";
+ throw;
+ }
+
+ ++iterlist;
+ }
+
+ #ifdef DEBUG
+ buff.printBuff();
+ buff.printSubPos();
+ buff.printDefsubPos();
+ #endif
+
+ try
+ {
+ /*
+ * createCommand second pass:
+ * makes some works haven't been at the first pass
+ * 1) error detection, we can't see during the createCommand function
+ * 2) fill buffer with the adress of beginning of defsub
+ **/
+ buffManager.completesCreateCommand();
+ }
+ catch( const std::exception & e )
+ {
+ cerr << e.what() << "\n";
+ throw;
+ }
+
+ #ifdef DEBUG
+ cout << "(debug) print buff second pass :" << endl
+ << "================================" << endl;
+ buff.printBuff();
+ #endif
+} /* ----- end of method GloSeq::verify ----- */
+
+/*
+ * Class: GloSeq
+ * Method: GloSeq :: cleanLine
+ * Description:
+ */
+ void
+GloSeq::cleanLine ( string &rline )
+{
+ size_t i;
+ // parsing a line
+ for (i = 0 ; i < rline.length(); ++ i )
+ {
+ if (rline[i] == ';')
+ rline.erase(i, rline.length());
+
+ else if (rline[i] == SP || rline[i] == TAB || rline[i] == CR || rline[i] == LF)
+ rline.erase(rline.begin() + i--);
+ }
+} /* ----- end of method GloSeq::cleanLine ----- */
+
+
+/*
+ * Class: GloSeq
+ * Method: GloSeq :: upload
+ * Description:
+ */
+ void
+GloSeq::upload(SerialProp & ser)
+{
+ ser.sendString(buff.getSizeUpCmd(), 3);
+ ser.sendString(buff.pointToBuff(), buff.getSize());
+
+} /* ----- end of method GloSeq::upload ----- */
+
+
diff --git a/src/gloseq.hpp b/src/gloseq.hpp
new file mode 100644
index 0000000..3487f6b
--- /dev/null
+++ b/src/gloseq.hpp
@@ -0,0 +1,99 @@
+/*
+ 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: gloseq.hpp
+ *
+ * Description:
+ *
+ * Version: 0.2
+ * Created: 27/12/2013 10:40:44
+ * Revision: none
+ * Compiler: gcc
+ *
+ * Author: BARATTERO Laurent, laurentba<at>larueluberlu.net
+ * Organization: La rue Luberlu
+ */
+
+#ifndef gloseq_INC
+#define gloseq_INC
+
+#include <string>
+#include <vector>
+#include <fstream>
+#include <iterator>
+#include <algorithm>
+
+#include "global.hpp"
+#include "buffer.hpp"
+#include "buffermanager.hpp"
+#include "rules.hpp"
+#include "serialprop.hpp"
+#include "config.h"
+
+#if HAVE_LIBBOOST_REGEX
+ #include "regboost.hpp"
+#else
+ #include "reglinux.hpp"
+#endif
+
+
+/*
+ * Class: GloSeq
+ * Description: Contains all the processing related to the glo file.
+ */
+class GloSeq
+{
+ public:
+ void verify();
+ void upload(SerialProp & ser);
+
+ GloSeq (std::string fileName); /* constructor */
+
+
+
+ private:
+ void cleanLine(std::string& rline);
+
+ const char SP = 0x20;
+ const char TAB = 0x09;
+ const char CR = 0x0d;
+ const char LF = 0x0a;
+ const int NOT_VALID = -1;
+
+ std::string file_name;
+ std::ifstream glofile;
+
+ struct command
+ {
+ std::string line;
+ int cmd_type;
+ int nb_line;
+ };
+ std::vector <command> cmdTab;
+
+
+ Buffer buff;
+ Rules rules;
+ BufferManager buffManager;
+
+
+}; /* ----- end of class GloSeq ----- */
+
+
+#endif /* ----- #ifndef gloseq_INC ----- */
diff --git a/src/main.cpp b/src/main.cpp
new file mode 100644
index 0000000..920a89b
--- /dev/null
+++ b/src/main.cpp
@@ -0,0 +1,269 @@
+/*
+ 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: main.cpp
+ *
+ * Description: command line entry point.
+ * lib getopt needed this is for unix users
+ *
+ *
+ * Version: 0.2
+ * Created: 20/12/2013 00:57:44
+ * Revision: none
+ * Compiler: gcc
+ *
+ * Author: BARATTERO Laurent, laurentba<at>larueluberlu.net
+ * Organization: La rue Luberlu
+ */
+
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <vector>
+#include <string>
+
+#include <getopt.h>
+#include "global.hpp"
+#include "main.hpp"
+#include "optmanager.hpp"
+#include "config.h"
+
+
+
+using namespace std;
+
+
+bool VERBOSE_AERO;
+
+/*
+ * Name: main
+ * Description: get cmd args... gives the job to OptManager.
+ * and finally said to OptManager to start launch
+ * of what is expected.
+ */
+ int
+main ( int argc, char *argv[] )
+{
+
+ int version = 0;
+ int help = 0;
+ VERBOSE_AERO = false;
+ int c;
+ OptManager manager;
+
+ while (1)
+ {
+ static struct option long_options[] =
+ {
+ {"start", required_argument, NULL, 'o'},
+ {"test", required_argument, NULL, 't'},
+ {"color", required_argument, NULL, 'c'},
+ {"getSerial", required_argument, NULL, 'G'},
+ {"setSerial", required_argument, NULL, 'S'},
+ {"verify", required_argument, NULL, 'i'},
+ {"uploadGlo", required_argument, NULL, 'u'},
+ {"uploadGloc", no_argument, NULL, 'U'},
+ {"verbose", no_argument, NULL, 'v'},
+ {"thread", no_argument, NULL, 1 },
+ {"version", no_argument, &version, 1 },
+ {"help", no_argument, NULL, 'h'},
+ {0, 0, 0, 0}
+ };
+ /* getopt_long stores the option index here. */
+ int option_index = 0;
+ c = getopt_long (argc, argv, "o:t:c:G:S:u:U:i:vh",
+ long_options, &option_index);
+
+ /* Detect the end of the options. */
+ if (c == -1)
+ break;
+
+ switch (c)
+ {
+ case 'o':
+ manager.addItemStart(optarg);
+ break;
+
+ case 't':
+ manager.addItemTest(optarg);
+ break;
+
+ case 'c':
+ try
+ {
+ manager.subRoutine(FLAG_COLOR);
+ }
+ catch ( const string & Msg )
+ {
+ cerr << "Error : " << Msg << endl;
+ return(EXIT_FAILURE);
+ }
+ break;
+
+ case 'G':
+ manager.addItemGetSerial(optarg);
+ break;
+
+ case 'S':
+ try
+ {
+ manager.subRoutine(FLAG_SET_SER);
+ }
+ catch ( const string & Msg )
+ {
+ cerr << "Error : " << Msg << endl;
+ return(EXIT_FAILURE);
+ }
+ break;
+
+ case 'i':
+ manager.addItemVerify(optarg);
+ break;
+
+ case 'u':
+ manager.subRoutine(FLAG_UP_GLO);
+ break;
+
+ case 'U':
+ manager.subRoutine(FLAG_UP_GLOC);
+ break;
+
+ case 'v':
+ VERBOSE_AERO = true;
+ break;
+
+ case 'h':
+ help = 1;
+ break;
+
+ case '?':
+ /* getopt_long already printed an error message. */
+ puts("To get help : 'aeroup --help' or 'man aeroup'");
+ return EXIT_FAILURE;
+ break;
+
+ default:
+ abort ();
+ }
+ }
+
+ /* Print any remaining command line arguments (not options). */
+ if (optind < argc)
+ {
+ printf ("non-option ARGV-elements: ");
+ while (optind < argc)
+ printf ("%s ", argv[optind++]);
+ putchar ('\n');
+ puts("To get help : 'aeroup --help' or 'man aeroup'");
+ return(EXIT_FAILURE);
+ }
+
+
+ if(version)
+ {
+ aeroVersion();
+ return(EXIT_SUCCESS);
+ }
+
+ if(help || argc == 1)
+ {
+ aeroHelp();
+ return(EXIT_SUCCESS);
+ }
+
+ try
+ {
+ manager.start();
+ }
+ catch( const exception & e )
+ {
+ return(EXIT_FAILURE);
+ }
+ catch(...)
+ {
+ //return(EXIT_FAILURE);
+ puts("UNKNOWN ERROR, CATCHED IN MAIN");
+ return(EXIT_FAILURE);
+ }
+
+ return(EXIT_SUCCESS);
+}
+
+
+/*
+ * Name: aeroHelp
+ * Description: --help
+ */
+ void
+aeroHelp()
+{
+ cout << "Usage : " << PACKAGE <<" [OPTION [SUB_OPTION]]...\n"
+ << "AeroUp is an open source command line tool to control Ultimate juggling props sold by Aerotech Projects.\n\n"
+ << " -t, --test=serialPort Send a test command on dev serialPort.\n"
+ << " -o, --start=serialPort Send a start sequence command on dev serialPort.\n"
+ << " -c, --color=R,G,B,serialPort Send a color command on dev serialPort.\n"
+ << " R,G,B can be hex (0x#), dec (#) value,\n"
+ << " in range of [0-255] (8bit).\n"
+ << " -G, --getSerial=serialPort get serial number on dev serialPort, and print it to standard output.\n"
+ << " -S, --setSerial=serialNumber,serialPort Set serialNumber on dev serialPort. the 32 bits serialNumber value\n"
+ << " can be writen in hex (0x#) or dec (#).\n"
+ << " -i, --verify=gloFile Verify that syntax glo file is valid.\n"
+ << " -u, --uploadGloc=gloFile,serialPort Verify that syntax glo file is valid, and if this is the case\n"
+ << " upload it on dev serialPort.\n"
+ << " -P, --thread Multithread mode, not implemented yet...\n"
+ << " -U, --uploadGloc=glocFile,serialPort not implemented yet...\n"
+ << " -v Verbose mode.\n"
+ << " -h, --help Print help.\n"
+ << " --version Print version.\n\n"
+ << "Each sub options have to be separate with a comma without blank.\n"
+ << "you 'll find more info in the man of aeroup.\n\n"
+ << "Examples\n"
+ << " aeroup -t /dev/ttyACM0\n"
+ << " aeroup -o /dev/ttyACM0 -o /dev/ttyACM1 -t /dev/ttyACM3\n"
+ << " aeroup -c 255,69,255,/dev/ttyACM0 27,3,7,/dev/ttyACM1\n"
+ << " aeroup -S 0x0b01/dev/ttyACM0\n"
+ << " aeroup -G /dev/ttyACM0\n\n"
+ << "AeroUp project page : " PACKAGE_URL << "\n"
+ << "You can also take a look at the AeroWrite project page https://github.com/LaurentBa/AeroWrite\n"
+ << "Report bugs to " << PACKAGE_BUGREPORT << "\n"
+ << endl;
+
+}
+
+
+/*
+ * Name: aeroVersion
+ * Description: --version
+ */
+ void
+aeroVersion()
+{
+ cout << PACKAGE_STRING << "\n"
+ "Copyright © 2014 BARATTERO Laurent\n"
+ "License GPLv3+: GNU GPL version 3 or later\n"
+ "<http://gnu.org/licenses/gpl.html>\n"
+ "This is free software: you are free to change and redistribute it.\n"
+ "There is NO WARRANTY, to the extent permitted by law\n";
+}
+
+
+
+
+
diff --git a/src/main.hpp b/src/main.hpp
new file mode 100644
index 0000000..d66dfff
--- /dev/null
+++ b/src/main.hpp
@@ -0,0 +1,50 @@
+/*
+ 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: main.hpp
+ *
+ * Description:
+ *
+ * Version: 0.2
+ * Created: 21/12/2013 03:56:20
+ * Revision: none
+ * Compiler: gcc
+ *
+ * Author: BARATTERO Laurent, laurentba<at>larueluberlu.net
+ * Organization: La rue Luberlu
+ */
+
+#ifndef main_INC
+#define main_INC
+
+#define TEST_FLAG 0x1
+#define START_FLAG 0x2
+#define GET_SERIAL_FLAG 0x4
+#define SET_SERIAL_FLAG 0x8
+#define UPLOAD_GLO_FLAG 0x10
+#define UPLOAD_GLOC_FLAG 0x20
+#define VERBOSSE_FLAG 0x40
+#define VERIFY_FLAG 0x80
+#define MAKE_GLOC_FLAG 0x100
+#define FLAG1 0x100
+
+void aeroHelp();
+void aeroVersion();
+
+#endif /* ----- #ifndef main_INC ----- */
diff --git a/src/optmanager.cpp b/src/optmanager.cpp
new file mode 100644
index 0000000..a8cc039
--- /dev/null
+++ b/src/optmanager.cpp
@@ -0,0 +1,438 @@
+/*
+ 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: optmanager.cpp
+ *
+ * Description: Manages command line options & sub options
+ * To do : make space possible on command line
+ * for sub option would be cool more cool
+ *
+ * ToDo : Verify that the value for setSerial is not out of range
+ * for the time being, the value is set to max.
+ * we could test string before conversion.
+ *
+ * Version: 0.2
+ * Created: 23/12/2013 23:31:46
+ * Revision: none
+ * Compiler: gcc
+ *
+ * Author: BARATTERO Laurent, laurentba<at>larueluberlu.net
+ * Organization: La rue Luberlu
+ */
+
+#include "optmanager.hpp"
+
+extern bool VERBOSE_AERO;
+
+using namespace std;
+
+
+/*
+ * Class: OptManager
+ * Method: OptManager :: start
+ * Description: Order Processing
+ */
+ void
+OptManager::start()
+{
+ // Start command
+ for (vector<string>::iterator iter = startList.begin();
+ iter != startList.end(); ++iter)
+ {
+ sendStart(*iter);
+ if (VERBOSE_AERO)
+ cout << "Start command sent on : " << *iter << endl;
+ }
+
+ // Color Command
+ for (vector<optCol>::iterator iter = colorList.begin();
+ iter != colorList.end(); ++iter)
+ {
+ if ( (*iter).port != "\0")
+ {
+ sendColor( (*iter).rgb[RED],
+ (*iter).rgb[GREEN],
+ (*iter).rgb[BLUE],
+ (*iter).port);
+ }
+ else
+ {
+ cout << "missing port name argument in color command" << endl;
+ exit (EXIT_FAILURE);
+ }
+
+ if(VERBOSE_AERO)
+ {
+ cout << "Color command (c" << dec
+ << "," << static_cast<int>((*iter).rgb[RED])
+ << "," << static_cast<int>((*iter).rgb[GREEN])
+ << "," << static_cast<int>((*iter).rgb[BLUE])
+ << ") sent on port \"" << (*iter).port << "\""
+ << endl;
+
+ }
+ }
+
+ // Test command
+ for ( vector<string>::iterator iter = testList.begin();
+ iter != testList.end(); ++iter)
+ {
+ sendTest(*iter);
+ if (VERBOSE_AERO)
+ cout << "Test command sent on : " << *iter << endl;
+ }
+
+ // Upload Glo file
+ for (vector<optUp>::iterator iter = upGloList.begin();
+ iter != upGloList.end(); ++iter)
+ {
+ sendUpGlo((*iter).fileName, (*iter).port);
+ }
+
+ // Get serial number
+ for (vector<string>::iterator iter = getSerialList.begin();
+ iter != getSerialList.end(); ++iter)
+ {
+ sendGetSerial(*iter);
+ }
+
+ // Set serial number
+ for (vector<optSerial>::iterator iter = setSerialList.begin();
+ iter != setSerialList.end(); ++iter)
+ {
+ sendSetSerial((*iter).i_serialNumber,(*iter).port);
+ }
+
+ // Verify Glo file
+ for ( vector<string>::iterator iter = verifyList.begin();
+ iter != verifyList.end(); ++iter)
+ {
+ sendVerify(*iter);
+ if (VERBOSE_AERO)
+ cout << "Process verification on file " << *iter << endl;
+ }
+
+} /* ----- end of method OptManager::start ----- */
+
+
+/*
+ * .::SEND COMMAND::.
+ * all the functionalities functionality proposed by the command line interface
+ */
+
+/*
+ * Method: OptManager :: sendTest
+ */
+ void
+OptManager::sendTest( std::string port_name )
+{
+ Ultimate prop( port_name );
+ prop.test();
+
+}
+
+/*
+ * Method: OptManager :: sendStart
+ */
+ void
+OptManager::sendStart(string port_name)
+{
+ Ultimate prop(port_name);
+ prop.start();
+}
+
+/*
+ * Method: OptManager :: sendColor
+ */
+ void
+OptManager::sendColor( uint8_t red, uint8_t green, uint8_t blue, string port_name)
+{
+ Ultimate prop(port_name);
+ prop.color(red, green, blue);
+}
+
+/*
+ * Method: OptManager :: sendGetSerial
+ */
+ void
+OptManager::sendGetSerial( std::string port_name)
+{
+ Ultimate prop(port_name);
+ cout << "Serial number is : 0x" << prop.getSerial() << endl;
+
+}
+
+/*
+ * Method: OptManager :: sendSetSerial
+ */
+ void
+OptManager::sendSetSerial(uint32_t i_serialNumber, string port)
+{
+ Ultimate prop(port);
+ prop.setSerialUlt( i_serialNumber);
+}
+
+/*
+ * Method: OptManager :: sendVerify
+ */
+ void
+OptManager::sendVerify(string fileName)
+{
+ GloInterface gloInt;
+ gloInt.verifyFile(fileName);
+}
+/*
+ * Method: OptManager :: sendUpGlo
+ */
+ void
+OptManager::sendUpGlo(string fileName, string port_name)
+{
+ Ultimate prop(port_name);
+ if( prop.uploadGlo(fileName))
+ {
+ cout << "Upload " << fileName << " OK" << endl;
+ }
+}
+
+/* ---- End of SEND COMMAND ---- */
+
+
+/*
+ * .::SUB COMMAND::.
+ */
+
+/*
+ * Class: OptManager
+ * Method: OptManager :: subRoutine
+ * Description: Getopt sub routine switch
+ */
+ void
+OptManager::subRoutine(const short int FLAG )
+{
+ switch(FLAG)
+ {
+ case FLAG_COLOR:
+ subRoutineColor();
+ break;
+
+ case FLAG_UP_GLOC:
+ case FLAG_UP_GLO:
+ subRoutineUp(FLAG);
+ break;
+
+ case FLAG_SET_SER:
+ subRoutineSetSerial();
+ break;
+ }
+}
+
+/*
+ * Class: OptManager
+ * Method: OptManager :: subRoutineSetSerial
+ * Description: Getopt sub routine for Set Serial
+ */
+ void
+OptManager::subRoutineSetSerial()
+{
+ optSerial tmpSerialNb;
+ subopts = optarg;
+ tmpSerialNb.i_serialNumber = 0;
+ uint32_t tmp_int;
+ for (int i = 0; *subopts !='\0'; i++)
+ {
+ getsubopt(&subopts, token, &value);
+ switch (i)
+ {
+ case 0:
+ tmp_int =isValidSerialNumber(value);
+ if (tmp_int != 1)
+ tmpSerialNb.i_serialNumber = tmp_int;
+ else
+ cerr << "error without throw" << endl;
+ break;
+
+ case 1:
+ tmpSerialNb.port = value;
+ break;
+
+ default:
+ cout << "too many args in set serial command" << endl;
+ break;
+ }
+ }
+ setSerialList.push_back(tmpSerialNb);
+}
+
+
+/*
+ * Class: OptManager
+ * Method: OptManager :: subRoutineUp
+ * Description: Getopt sub routine for Upload Glo & GloC
+ */
+ void
+OptManager::subRoutineUp(const short int FLAG )
+{
+ optUp tmpOpt;
+
+ subopts = optarg;
+ for (int i = 0; *subopts !='\0'; i++)
+ {
+ getsubopt(&subopts, token, &value);
+ switch (i)
+ {
+ case 0:
+ tmpOpt.fileName = value;
+ break;
+
+ case 1:
+ tmpOpt.port = value;
+ break;
+
+ default:
+ cout << "too many args in upload command" << endl;
+ break;
+ }
+ }
+
+ switch (FLAG)
+ {
+ case FLAG_UP_GLO:
+ upGloList.push_back(tmpOpt);
+ case FLAG_UP_GLOC:
+ upGloCList.push_back(tmpOpt);
+ break;
+ }
+}
+
+/*
+ * Class: OptManager
+ * Method: OptManager :: subRoutineColor
+ * Description: Getopt sub routine for color command
+ */
+ void
+OptManager::subRoutineColor()
+{
+ optCol tmpcol;
+ uint8_t intensity[3] = {0} ;
+ int tmp_int;
+ subopts = optarg;
+ for (int i = 0; *subopts !='\0'; i++)
+ {
+ getsubopt(&subopts, token, &value);
+ switch (i)
+ {
+
+ // for all color verify the validity of values
+ case RED: case GREEN: case BLUE:
+ tmp_int = isValid0xFF(value);
+ if (tmp_int == -1)
+ {
+ cerr << "ERROR : non valid color for color command c "
+ << value << endl;
+ exit (EXIT_FAILURE);
+ }
+ intensity[i] = ( char)tmp_int;
+ break;
+
+ case PORT_NAME:
+ for (int index = 0 ; index<3; index++)
+ tmpcol.rgb[index] = intensity[index];
+ tmpcol.port = value;
+ colorList.push_back(tmpcol);
+ break;
+
+ default:
+ cerr << "Error, too many args for -c" << endl;
+ exit (EXIT_FAILURE);
+ break;
+ }
+ }
+} /* ----- end of method OptManager::subRoutineColor ----- */
+
+
+/*
+ * Class: OptManager
+ * Method: OptManager :: isValid0xFF
+ * Description: verify if value can become 1 byte(0-255)
+ */
+ int
+OptManager::isValid0xFF(char * value)
+{
+ int hexval = strtol(value,(char**)NULL,0);
+ if (hexval < 256 && hexval > -1)
+ return hexval;
+ return -1;
+}
+
+/*
+ * Class: OptManager
+ * Method: OptManager :: isValidSerialNumber
+ * Description: test with dec, hex & bin notation
+ */
+ uint32_t
+OptManager::isValidSerialNumber(string strNb)
+{
+ uint32_t i_ser_nb;
+
+ if (isDecNotation( strNb))
+ {
+ std::stringstream ss( strNb);
+ ss >> dec >> i_ser_nb;
+ cout << i_ser_nb << endl;
+ }
+ else if(isHexNotation( strNb))
+ {
+ std::stringstream ss( strNb.substr(2));
+ ss >> hex >> i_ser_nb;
+ cout << i_ser_nb << endl;
+ }
+ else
+ {
+ throw std::string( "Bad serial number" );
+ }
+
+ return i_ser_nb;
+}
+
+/*
+ * Class: OptManager
+ * Method: OptManager :: isHexNotation
+ * Description: is hex notation
+ */
+ bool
+OptManager::isHexNotation(std::string const& s)
+{
+ return s.compare(0, 2, "0x") == 0
+ && s.size() > 2
+ && s.find_first_not_of("0123456789abcdefABCDEF", 2) == std::string::npos;
+}
+
+
+/*
+ * Class: OptManager
+ * Method: OptManager :: isDecNotation
+ * Description: is dec notation
+ */
+ bool
+OptManager::isDecNotation(const std::string& s)
+{
+ std::string::const_iterator it = s.begin();
+ while (it != s.end() && std::isdigit(*it)) ++it;
+ return !s.empty() && it == s.end();
+}
diff --git a/src/optmanager.hpp b/src/optmanager.hpp
new file mode 100644
index 0000000..3252a91
--- /dev/null
+++ b/src/optmanager.hpp
@@ -0,0 +1,141 @@
+/*
+ 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: optmanager.hpp
+ *
+ * Description:
+ *
+ * Version: 0.2
+ * Created: 23/12/2013 22:59:22
+ * Revision: none
+ * Compiler: gcc
+ *
+ * Author: BARATTERO Laurent, laurentba<at>larueluberlu.net
+ * Organization: La rue Luberlu
+ */
+
+#ifndef optmanager_INC
+#define optmanager_INC
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <getopt.h>
+#include <string>
+#include <vector>
+#include "global.hpp"
+#include "ultimate.hpp"
+#include "gloInterface.hpp"
+
+#define MAX_LEN_OPT 2
+
+#define FLAG_SET_SER 0x1
+#define FLAG_UP_GLO 0x2
+#define FLAG_UP_GLOC 0x4
+#define FLAG_COLOR 0x8
+#define FLAG_VERIFY 0x10
+
+/*
+ * Class: OptManager
+ * Description: Manages command line options & sub options
+ */
+class OptManager
+{
+ public:
+ OptManager (){;} /* constructor */
+
+ void start();
+
+ void addItemStart(std::string port_name)
+ {startList.push_back(port_name);}
+
+ void addItemTest(std::string port_name)
+ {testList.push_back(port_name);}
+
+ void addItemGetSerial(std::string port_name)
+ {getSerialList.push_back(port_name);}
+
+ void addItemVerify(std::string glo_file)
+ {verifyList.push_back(glo_file);}
+
+ void subRoutine(const short int FLAG);
+
+ private:
+ // Send functions
+ void sendTest(std::string port_name);
+ void sendStart(std::string port_name);
+ void sendColor(uint8_t red, uint8_t green, uint8_t blue, std::string port_name);
+ void sendGetSerial(std::string port_name);
+ void sendSetSerial(uint32_t i_serialNumber, std::string port);
+ void sendVerify(std::string fileName);
+ void sendUpGlo(std::string fileName, std::string port);
+ // void sendUpGloC(std::string fileName, std::string port);
+
+ // Sub functions
+ void subRoutineColor();
+ void subRoutineUp(const short FLAG);
+ void subRoutineSetSerial();
+
+ // Tool functions
+ uint32_t isValidSerialNumber(std::string strNb);
+ int isValid0xFF(char* value);
+ bool isHexNotation(std::string const& s);
+ bool isDecNotation(std::string const& s);
+
+ // GetSubOpt data
+ char * token[MAX_LEN_OPT]={0};
+ char *subopts;
+ char *value;
+ enum { RED = 0, GREEN, BLUE, PORT_NAME };
+
+
+ // Structures and variables for opts containers
+ // struct
+ struct optCol
+ {
+ unsigned char rgb[3];
+ std::string port;
+ };
+
+ struct optUp
+ {
+ std::string fileName;
+ std::string port;
+ };
+
+ struct optSerial
+ {
+ uint32_t i_serialNumber;
+ std::string serialNumber;
+ std::string port;
+ };
+ // Var
+ std::vector<std::string> startList;
+ std::vector<std::string> testList;
+ std::vector<optCol> colorList;
+ std::vector<optUp> upGloList;
+ std::vector<optUp> upGloCList;
+ std::vector<std::string> verifyList;
+ std::vector<optSerial> setSerialList;
+ std::vector<std::string> getSerialList;
+ // end of Structures and variables for opts containers
+
+}; /* ----- end of class OptManager ----- */
+
+#endif /* ----- #ifndef optmanager_INC ----- */
diff --git a/src/regboost.cpp b/src/regboost.cpp
new file mode 100644
index 0000000..bf3cf87
--- /dev/null
+++ b/src/regboost.cpp
@@ -0,0 +1,62 @@
+/*
+ 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: regboost.cpp
+ *
+ * Description:
+ *
+ * Version: 0.2
+ * Created: 19/12/2013 05:22:37
+ * Revision: none
+ * Compiler: gcc
+ *
+ * Author: BARATTERO Laurent, laurentba<at>larueluberlu.net
+ * Organization: La rue Luberlu
+ *
+ */
+#include "regboost.hpp"
+
+
+using namespace std;
+using namespace boost;
+
+RegBoost::RegBoost ( )
+{
+} /* ----- end of method RegBoost::RegBoost ----- */
+
+
+
+ int
+RegBoost::isValidSyntax ( string &rline )
+{
+ for (int i = 0; i < REG_TAB_LEN; i++)
+ {
+ if ( regex_match(rline.begin(), rline.end(), reg_tab[i]) )
+ {
+ #ifdef DEBUG
+ cout << rline << " -> ok" << endl;
+ #endif
+ return i;
+ }
+ }
+ return -1;
+
+} /* ----- end of method RegBoost::isValidSyntax ----- */
+
+
diff --git a/src/regboost.hpp b/src/regboost.hpp
new file mode 100644
index 0000000..956be25
--- /dev/null
+++ b/src/regboost.hpp
@@ -0,0 +1,72 @@
+/*
+ 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: regboost.hpp
+ *
+ * Description:
+ *
+ * Version: 0.2
+ * Created: 19/12/2013 05:23:16
+ * Revision: none
+ * Compiler: gcc
+ *
+ * Author: BARATTERO Laurent, laurentba<at>larueluberlu.net
+ * Organization: La rue Luberlu
+ */
+
+
+#ifndef regboost_INC
+#define regboost_INC
+
+
+#include <boost/regex.hpp>
+#include <iostream>
+#include "define_ultimate_fct.h"
+#include "global.hpp"
+
+// BOOST REGEX TAB
+static const boost::regex reg_tab[] = {
+ boost::regex("^C,[[:digit:]]{1,3},[[:digit:]]{1,3},[[:digit:]]{1,3}$"), // C_FCT
+ boost::regex("^D,[[:digit:]]{1,5}$"), // D_FCT
+ boost::regex("^RAMP,[[:digit:]]{1,3},[[:digit:]]{1,3},[[:digit:]]{1,3},[[:digit:]]{1,5}$"), // RAMP_FCT
+ boost::regex("^L,[[:digit:]]{1,3}$"), // L_FCT
+ boost::regex("^E$"), // E_FCT
+ boost::regex("^R,[[:digit:]]{1,3}$"), // R_FCT
+ boost::regex("^G,[[:digit:]]{1,3}$"), // G_FCT
+ boost::regex("^B,[[:digit:]]{1,3}$"), // B_FCT
+ boost::regex("^SUB,[-_[:alnum:]]+$"), // SUB_FCT
+ boost::regex("^DEFSUB,[-_[:alnum:]]+$"), // DEFSUB_FCT
+ boost::regex("^ENDSUB$"), // ENDSUB_FCT
+ boost::regex("^END$")}; // END_FCT
+
+
+/*
+ * Class: RegBoost
+ * Description:
+ */
+class RegBoost
+{
+ public:
+ RegBoost (); /* constructor */
+
+ int isValidSyntax( std::string &rline);
+
+}; /* ----- end of class RegBoost ----- */
+
+#endif /* ----- #ifndef regboost_INC ----- */
diff --git a/src/reglinux.cpp b/src/reglinux.cpp
new file mode 100644
index 0000000..854d1b4
--- /dev/null
+++ b/src/reglinux.cpp
@@ -0,0 +1,97 @@
+/*
+ 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: reglinux.cpp
+ *
+ * Description: Regex lib (linux version)
+ *
+ * Version: 0.2
+ * Created: 18/01/2014 01:16:04
+ * Revision: none
+ * Compiler: gcc
+ *
+ * Author: BARATTERO Laurent, laurentba<at>larueluberlu.net
+ * Organization: La rue Luberlu
+ */
+#include <stdlib.h>
+#include "reglinux.hpp"
+
+/*
+ * Class: RegLinux
+ * Method: RegLinux :: RegLinux
+ * Description: Constructor
+ */
+RegLinux::RegLinux()
+{
+ comp();
+}
+
+
+/*
+ *--------------------------------------------------------------------------------------
+ * Class: RegLinux
+ * Method: RegLinux :: comp
+ * Description: Compile Regex
+ *--------------------------------------------------------------------------------------
+ */
+ void
+RegLinux::comp(void)
+{
+ int err = regcomp (reg, str_regex[0], REG_NOSUB | REG_EXTENDED);
+ if (err != 0)
+ {
+ printf("ERROR");
+ exit (EXIT_FAILURE);
+ }
+
+ for (int i = 0; i < REG_TAB_LEN ; i++, preg++)
+ {
+
+ err = regcomp (preg, str_regex[i], REG_NOSUB | REG_EXTENDED);
+ if (err != 0)
+ {
+ printf("ERROR");
+ exit (EXIT_FAILURE);
+ }
+ }
+}
+
+
+/*
+ *--------------------------------------------------------------------------------------
+ * Class: RegLinux
+ * Method: RegLinux :: isValidSyntax
+ * Description: Compile Regex
+ *--------------------------------------------------------------------------------------
+ */
+ int
+RegLinux::isValidSyntax ( std::string &rline )
+{
+ preg = &reg[0];
+ int match;
+ for (int i = 0; i < REG_TAB_LEN; i++, preg++)
+ {
+ match = regexec (preg, rline.c_str(), 0, NULL, 0);
+ if (match == 0)
+ return i;
+ }
+ return -1;
+} /* ----- end of method RegLinux::isValidSyntax ----- */
+
+
diff --git a/src/reglinux.hpp b/src/reglinux.hpp
new file mode 100644
index 0000000..16ffd43
--- /dev/null
+++ b/src/reglinux.hpp
@@ -0,0 +1,80 @@
+/*
+ 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: reglinux.hpp
+ *
+ * Description: Regex lib (linux version)
+ *
+ * Version: 0.2
+ * Created: 18/01/2014 01:16:31
+ * Revision: none
+ * Compiler: gcc
+ *
+ * Author: BARATTERO Laurent, laurentba<at>larueluberlu.net
+ * Organization: La rue Luberlu
+ */
+
+#ifndef reglinux_INC
+#define reglinux_INC
+
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <regex.h>
+#include <string.h>
+#include "define_ultimate_fct.h"
+#include "global.hpp"
+
+
+/*
+ * Class: RegLinux
+ * Description: Linux regex lib version
+ */
+
+class RegLinux
+{
+public:
+ RegLinux();
+ int isValidSyntax(std::string &rline);
+
+
+private:
+ void comp(void);
+
+ regex_t reg[REG_TAB_LEN];
+ regex_t *preg = &reg[0];
+
+ const char *str_regex[REG_TAB_LEN] ={
+ "^C,[[:digit:]]{1,3},[[:digit:]]{1,3},[[:digit:]]{1,3}$", // C_FCT
+ "^D,[[:digit:]]{1,5}$", // D_FCT
+ "^RAMP,[[:digit:]]{1,3},[[:digit:]]{1,3},[[:digit:]]{1,3},[[:digit:]]{1,5}$", // RAMP_FCT
+ "^L,[[:digit:]]{1,3}$", // L_FCT
+ "^E$", // E_FCT
+ "^R,[[:digit:]]{1,3}$", // R_FCT
+ "^G,[[:digit:]]{1,3}$", // G_FCT
+ "^B,[[:digit:]]{1,3}$", // B_FCT
+ "^SUB,[-_[:alnum:]]+$", // SUB_FCT
+ "^DEFSUB,[-_[:alnum:]]+$", // DEFSUB_FCT
+ "^ENDSUB$", // ENDSUB_FCT
+ "^END$"}; // END_FCT
+};
+
+
+
+#endif /* ----- #ifndef reglinux_INC ----- */
diff --git a/src/rules.cpp b/src/rules.cpp
new file mode 100644
index 0000000..741a2cd
--- /dev/null
+++ b/src/rules.cpp
@@ -0,0 +1,198 @@
+/*
+ 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: rules.cpp
+ *
+ * Description:
+ *
+ * Version: 0.2
+ * Created: 31/12/2013 18:33:14
+ * Revision: none
+ * Compiler: gcc
+ *
+ * Author: BARATTERO Laurent, laurentba<at>larueluberlu.net
+ * Organization: La rue Luberlu
+ *
+ */
+#include "rules.hpp"
+
+using namespace std;
+
+/*
+ * Class: Rules
+ * Method: Rules
+ * Description: constructor
+ */
+Rules::Rules (string gloFileName):
+ fileName(gloFileName)
+{
+} /* ----- end of method Rules::Rules (constructor) ----- */
+
+ bool
+Rules::isStandardCmdPossible(int nb_line, int fct)
+{
+ if(!end || defsub_cout )
+ return true;
+ else
+ {
+ string error = "invalid " + FctVectStr[fct] + " not in main sequence or sub-sequence";
+ throw RulesError( error.c_str() , fileName, nb_line );
+ return false;
+ }
+}
+ bool
+Rules::isDefsubCmdPossible()
+{
+
+ return true;
+}
+ bool
+Rules::isEndPossible()
+{
+
+ return true;
+}
+
+ bool
+Rules::isSeqOk()
+{
+ return true;
+
+}
+
+
+ void
+Rules::setEnd(int nb_line)
+{
+ if(!end && !loop_count)
+ end = true;
+ else
+ {
+ if(end)
+ {
+ string error = "Attempt to define more than one 'END command'";
+ throw RulesError(error.c_str(), fileName, nb_line );
+ }
+ else
+ {
+ string error = "Reached end of main sequence with unterminated loop";
+ throw RulesError(error.c_str(), fileName, nb_line );
+ }
+ }
+}
+
+ void
+Rules::setDefsub(int nb_line)
+{
+ if(!defsub_cout && end)
+ {
+ defsub_cout = nb_line;
+ }
+ else
+ {
+ if(!end)
+ {
+ string error = "Attempt to define subsequence before the main sequence is complete ";
+ throw RulesError(error.c_str(), fileName, nb_line );
+ }
+ else
+ {
+ string error = "Attempting to define a subroutine inside another subroutine' ";
+ throw RulesError(error.c_str(), fileName, nb_line );
+ }
+ }
+}
+
+ void
+Rules::unsetDefsub(int nb_line)
+{
+ if(defsub_cout && !loop_count)
+ {
+ defsub_cout = 0;
+ }
+ else
+ {
+ if (!defsub_cout)
+ {
+ string error = "ENDSUB without corresponding DEFSUB command";
+ throw RulesError(error.c_str(), fileName, nb_line );
+ }
+ else
+ {
+ string error = "'ENDSUB command' found with unterminated 'Loop command'";
+ throw RulesError(error.c_str(), fileName, nb_line );
+ }
+ }
+}
+
+ void
+Rules::endTestDefsub()
+{
+ if (defsub_cout)
+ {
+ string error = "Reached EOF with unterminated 'DEFSUB command'";
+ throw RulesError(error.c_str(), fileName, defsub_cout);
+ }
+}
+
+
+
+ void
+Rules::setloop(int nb_line)
+{
+ isStandardCmdPossible(nb_line, L_FCT);
+ loop_count +=1;
+}
+
+ void
+Rules::unsetloop(int nb_line)
+{
+ isStandardCmdPossible(nb_line, E_FCT);
+ if (loop_count > 0)
+ loop_count -=1;
+ else
+ {
+ string error = "End Loop command with no Loop Command";
+ throw RulesError(error.c_str(), fileName, nb_line );
+ }
+}
+
+
+
+/*
+ * Class: Rules
+ * Method: Rules :: twiceDefsubError
+ * Description:
+ */
+ void
+Rules::twiceDefsubError(int nb_line)
+{
+ // to do : add class warning
+ throw RulesError("Error, more than one definition for a sub function !", fileName, nb_line );
+
+} /* ----- end of method Rules::twiceDefsubError ----- */
+
+ void
+Rules::noDefsubError(string sub_name)
+{
+ string error = "No definition for SUB," + sub_name ;
+ throw RulesError(error.c_str(), fileName);
+
+}
+
diff --git a/src/rules.hpp b/src/rules.hpp
new file mode 100644
index 0000000..a658fce
--- /dev/null
+++ b/src/rules.hpp
@@ -0,0 +1,94 @@
+/*
+ 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: rules.hpp
+ *
+ * Description:
+ *
+ * Version: 0.2
+ * Created: 31/12/2013 18:32:35
+ * Revision: none
+ * Compiler: gcc
+ *
+ * Author: BARATTERO Laurent, laurentba<at>larueluberlu.net
+ * Organization: La rue Luberlu
+ */
+
+#ifndef rules_INC
+#define rules_INC
+#include "ruleserror.hpp"
+#include "define_ultimate_fct.h"
+#include <vector>
+#include "global.hpp"
+/*
+ * Class: Rules
+ * Description:
+ */
+class Rules
+{
+ public:
+ Rules (std::string gloFileName); /* constructor */
+ void twiceDefsubError(int nb_line);
+ void noDefsubError(std::string sub_name);
+
+ bool isStandardCmdPossible(int nb_line, int fct=0);
+ bool isDefsubCmdPossible();
+ bool isEndPossible();
+ bool isSeqOk();
+
+ /* END */
+ void setEnd(int nb_line);
+
+ /* DEFSUB */
+ void setDefsub(int nb_line);
+ void unsetDefsub(int nb_line);
+ void endTestDefsub();
+
+ /* LOOP */
+ void setloop(int nb_line);
+ void unsetloop(int nb_line);
+
+ private:
+ struct defsub
+ {
+ bool on = false;
+ int line = 0;
+ } ;
+
+ int defsub_cout = 0;
+ int loop_count = 0;
+ bool end = false;
+ std::string fileName;
+ std::vector<std::string> FctVectStr = {
+ "'C command'",
+ "'D command'",
+ "'RAMP command'",
+ "'L command'",
+ "'E command'",
+ "'R command'",
+ "'G command'",
+ "'B command'",
+ "'SUB command'",
+ "'DEFSUB command'",
+ "'ENDSUB command'",
+ "'END command'"
+ };
+}; /* ----- end of class Rules ----- */
+
+#endif /* ----- #ifndef rules_INC ----- */
diff --git a/src/ruleserror.hpp b/src/ruleserror.hpp
new file mode 100644
index 0000000..d84192d
--- /dev/null
+++ b/src/ruleserror.hpp
@@ -0,0 +1,81 @@
+/*
+ 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: rulesError.hpp
+ *
+ * Description:
+ *
+ * Version: 0.2
+ * Created: 06/01/2014 10:04:32
+ * Revision: none
+ * Compiler: gcc
+ *
+ * Author: BARATTERO Laurent, laurentba<at>larueluberlu.net
+ * Organization: La rue Luberlu
+ */
+
+
+#ifndef ruleserror_INC
+#define ruleserror_INC
+
+#include <iostream>
+#include <sstream>
+#include <exception>
+
+
+/*
+ * Class: RulesError
+ * Description:
+ */
+class RulesError : public std::exception
+{
+ public:
+ RulesError (const char * Msg, std::string fileName, int line)
+ {
+ std::ostringstream oss;
+ oss << "In File \"" << fileName << "\""
+ << ", Error line " << line << " : "
+ << Msg;
+ this->msg = oss.str();
+ } /* constructor 1 */
+
+ RulesError (const char * Msg, std::string fileName)
+ {
+ std::ostringstream oss;
+ oss << "In File \"" << fileName << "\""
+ << ", Error" << " : "
+ << Msg;
+ this->msg = oss.str();
+ } /* constructor 2 */
+
+ virtual ~RulesError() throw()
+ {
+ }
+
+ virtual const char* what() const throw()
+ {
+ return this->msg.c_str();
+ }
+
+ private:
+ std::string msg;
+
+}; /* ----- end of class RulesError ----- */
+
+#endif /* ----- #ifndef ruleserror_INC ----- */
diff --git a/src/serialboost.cpp b/src/serialboost.cpp
new file mode 100644
index 0000000..821fed8
--- /dev/null
+++ b/src/serialboost.cpp
@@ -0,0 +1,200 @@
+/*
+ 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: serialboost.cpp
+ *
+ * Description:
+ *
+ * Version: 0.2
+ * Created: 20/12/2013 00:06:15
+ * Revision: none
+ * Compiler: gcc
+ *
+ * Author: BARATTERO Laurent, laurentba<at>larueluberlu.net
+ * Organization: La rue Luberlu
+ */
+#include <serialboost.hpp>
+
+using namespace std;
+using namespace boost;
+
+
+/*
+ * Class: SerialBoost
+ * Method: SerialBoost :: SerialBoost
+ * Description: Constructor
+ */
+SerialBoost::SerialBoost ( std::string port_name ):
+ port(port_io)
+{
+ try
+ {
+ port.open( port_name );
+ }
+ catch(boost::system::system_error& e)
+ {
+ cout<<"Serial Error ("<<e.what()<< ")" << endl;
+ throw;
+ }
+
+ typedef asio::serial_port_base asio_serial;
+ port.set_option(asio_serial::baud_rate(19200));
+ port.set_option(asio_serial::flow_control(asio_serial::flow_control::none));
+ port.set_option(asio_serial::parity( asio_serial::parity::none));
+ port.set_option(asio_serial::stop_bits( asio_serial::stop_bits::one));
+ port.set_option(asio_serial::character_size(8));
+
+} /* ----- end of Constructor ----- */
+
+
+/*
+ * Class: SerialBoost
+ * Method: SerialBoost :: ~SerialBoost
+ * Description: Destructor
+ */
+SerialBoost::~SerialBoost ( )
+{
+ port.close();
+
+} /* ----- end of Destructor ----- */
+
+
+/**
+ * SEND A CHAR METHODS...
+ **/
+
+/*
+ * Class: SerialBoost
+ * Method: SerialBoost :: sendChar
+ * Description: Write on serial port
+ * char version
+ */
+ void
+SerialBoost::sendChar(char c)
+{
+ port.write_some(asio::buffer(&c, 1));
+}
+
+/*
+ * Class: SerialBoost
+ * Method: SerialBoost :: sendChar
+ * Description: Write on serial port
+ * unsigned Char version
+ */
+ void
+SerialBoost::sendChar(unsigned char c)
+{
+ port.write_some(asio::buffer(&c, 1));
+
+}
+
+/**
+ * SEND A STRING METHODS...
+ **/
+
+/*
+ * Class: SerialBoost
+ * Method: SerialBoost :: sendString
+ * Description: Write on serial port
+ * (char* + nb) version
+ */
+ void
+SerialBoost::sendString(char* s, int nb_char)
+{
+ port.write_some(asio::buffer(s, nb_char));
+}
+
+/*
+ * Class: SerialBoost
+ * Method: SerialBoost :: sendString
+ * Description: Write on serial port
+ * (unsigned char* + nb) version
+ */
+ void
+SerialBoost::sendString(unsigned char* s, int nb_char)
+{
+ port.write_some(asio::buffer(s, nb_char));
+}
+
+/*
+ * Class: SerialBoost
+ * Method: SerialBoost :: sendString
+ * Description: Write on serial port
+ * (const char* + nb) version
+ */
+ void
+SerialBoost::sendString(const char* s, int nb_char)
+{
+ port.write_some(asio::buffer(s, nb_char));
+}
+
+/*
+ * Class: SerialBoost
+ * Method: SerialBoost :: sendString
+ * Description: Write on serial port
+ * String version
+ */
+ void
+SerialBoost::sendString(string s)
+{
+ port.write_some(asio::buffer(s.c_str(),s.size()));
+}
+
+/**
+ * READ METHODS...
+ **/
+
+/*
+ * Class: SerialBoost
+ * Method: SerialBoost ::readLine
+ * Description: Read on serial port
+ * Readline version
+ */
+ string
+SerialBoost::readLine()
+{
+ char c;
+ string result;
+ for(;;)
+ {
+ asio::read(port, asio::buffer(&c,1));
+ switch(c)
+ {
+ case '\r':
+ break;
+ case '\n':
+ return result;
+ default:
+ result+=c;
+ }
+ }
+}
+
+/*
+ * Class: SerialBoost
+ * Method: SerialBoost :: getString
+ * Description: Read on serial port
+ * (char* + nb-read) version
+ */
+void SerialBoost::getString(char* s, int nb_char)
+{
+ asio::read(port, asio::buffer(s, nb_char));
+}
+
+
diff --git a/src/serialboost.hpp b/src/serialboost.hpp
new file mode 100644
index 0000000..0b5dd9d
--- /dev/null
+++ b/src/serialboost.hpp
@@ -0,0 +1,69 @@
+/*
+ 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: serialboost.hpp
+ *
+ * Description:
+ *
+ * Version: 0.2
+ * Created: 20/12/2013 00:06:28
+ * Revision: none
+ * Compiler: gcc
+ *
+ * Author: BARATTERO Laurent, laurentba<at>larueluberlu.net
+ * Organization: La rue Luberlu
+ */
+
+#ifndef serialboost_INC
+#define serialboost_INC
+
+#include <boost/asio.hpp>
+#include <boost/asio/serial_port.hpp>
+#include <boost/asio/read.hpp>
+#include <boost/asio/deadline_timer.hpp>
+#include <boost/ref.hpp>
+#include "global.hpp"
+
+/*
+ * Class: SerialBoost
+ * Description:
+ */
+class SerialBoost
+{
+ public:
+ SerialBoost (std::string port_name); /* constructor */
+ ~SerialBoost (); /* destructor */
+
+ void sendChar(char c);
+ void sendChar(unsigned char c);
+ void sendString(unsigned char* s, int nb_char);
+ void sendString(char* s, int nb_char);
+ void sendString(const char* s, int nb_char);
+ void sendString(std::string s);
+ void getString();
+ void getString(char* s, int nb_char);
+ std::string readLine();
+
+ protected:
+ boost::asio::io_service port_io;
+ boost::asio::serial_port port;
+
+}; /* ----- end of class SerialBoost ----- */
+
+#endif /* ----- #ifndef serialboost_INC ----- */
diff --git a/src/seriallinux.cpp b/src/seriallinux.cpp
new file mode 100644
index 0000000..27ba784
--- /dev/null
+++ b/src/seriallinux.cpp
@@ -0,0 +1,136 @@
+/*
+ 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: seriallinux.cpp
+ *
+ * Description: Serial lib linux (termios version)
+ * used if haven't boost
+ *
+ * Version: 0.2
+ * Created: 17/01/2014 03:31:32
+ * Revision: none
+ * Compiler: gcc
+ *
+ * Author: BARATTERO Laurent, laurentba<at>larueluberlu.net
+ * Organization: La rue Luberlu
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <iostream>
+#include <pthread.h>
+
+#include "seriallinux.hpp"
+
+
+using namespace std;
+
+/*
+ * Class: SerialLinux
+ * Description: open/write to serial port
+ */
+SerialLinux::SerialLinux(std::string dev)
+ {
+ memset(&tio,0,sizeof(tio));
+ tio.c_iflag= IGNPAR ;
+ tio.c_oflag=0;
+ tio.c_cflag= CS8|CREAD|CLOCAL ;
+ tio.c_lflag=0;
+ tio.c_cc[VMIN]=1;
+ tio.c_cc[VTIME]=0;
+
+ fd = open( dev.c_str(), O_RDWR | O_NOCTTY);
+ if(fd < 0)
+ {
+ perror("open");
+ printf("file => %s\n", dev.c_str());
+ exit(EXIT_FAILURE);
+ }
+
+ tcgetattr(fd,&old_tio);
+ tcflush(fd, TCIFLUSH);
+ cfsetospeed(&tio, B19200);
+ cfsetispeed(&tio, B19200);
+ tcsetattr(fd,TCSANOW,&tio);
+
+ }
+
+SerialLinux::~SerialLinux()
+{
+ tcsetattr(fd,TCSANOW,&old_tio);
+ fclose();
+}
+
+ void
+SerialLinux::sendChar(char c)
+{
+ write(fd,&c,1);
+}
+
+ void
+SerialLinux::sendString(uint8_t *c, int n)
+{
+ write(fd, c, n);
+}
+
+ string
+SerialLinux::readLine()
+{
+ char c[] = {0,0};
+ string result;
+ for(;;)
+ {
+ nb_read = read(fd, c, 1);
+ switch(c[0])
+ {
+ case '\r':
+ break;
+ case '\n':
+ return result;
+ default:
+ result+=c[0];
+ }
+ }
+}
+
+ void
+SerialLinux::fclose()
+{
+ if (close(fd)<0)
+ {
+ perror("close");
+ exit(EXIT_FAILURE);
+ }
+}
+
+
+ void
+SerialLinux::setspeed(speed_t vitesse)
+{
+ cfsetospeed(&tio, vitesse);
+ cfsetispeed(&tio, vitesse);
+ tcsetattr(fd,TCSANOW,&tio);
+}
+
+
+
+
diff --git a/src/seriallinux.hpp b/src/seriallinux.hpp
new file mode 100644
index 0000000..82b7475
--- /dev/null
+++ b/src/seriallinux.hpp
@@ -0,0 +1,66 @@
+/*
+ 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: seriallinux.hpp
+ *
+ * Description: Serial lib linux (termios version)
+ * used if haven't boost
+ *
+ * Version: 0.2
+ * Created: 17/01/2014 03:31:35
+ * Revision: none
+ * Compiler: gcc
+ *
+ * Author: BARATTERO Laurent, laurentba<at>larueluberlu.net
+ * Organization: La rue Luberlu
+ */
+
+
+#ifndef seriallinux_INC
+#define seriallinux_INC
+
+#ifndef DEF_SERIAL
+#define DEF_SERIAL
+
+#include <termios.h>
+#include <unistd.h>
+#include "global.hpp"
+
+
+class SerialLinux
+{
+ public:
+ SerialLinux(std::string dev);
+ ~SerialLinux();
+ void sendChar(char c);
+ void sendString(uint8_t *c, int n);
+ std::string readLine();
+ void fclose();
+
+ private:
+ void setspeed(speed_t vitesse);
+ int nb_read;
+ struct termios tio, old_tio;
+ int fd;
+
+};
+#endif
+
+
+#endif /* ----- #ifndef seriallinux_INC ----- */
diff --git a/src/serialprop.cpp b/src/serialprop.cpp
new file mode 100644
index 0000000..309a75c
--- /dev/null
+++ b/src/serialprop.cpp
@@ -0,0 +1,70 @@
+/*
+ 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: serialprop.cpp
+ *
+ * Description:
+ *
+ * Version: 0.2
+ * Created: 21/12/2013 01:39:53
+ * Revision: none
+ * Compiler: gcc
+ *
+ * Author: BARATTERO Laurent, laurentba<at>larueluberlu.net
+ * Organization: La rue Luberlu
+ */
+
+#include "serialprop.hpp"
+
+using namespace std;
+
+
+ void
+SerialProp::start()
+{
+ sendChar('o');
+}
+
+ void
+SerialProp::test()
+{
+ sendChar('t');
+}
+
+ void
+SerialProp::color(unsigned char red, unsigned char green, unsigned char blue )
+{
+ unsigned char rgb[5] = { 'c', red, green, blue, '\0'};
+ sendString(rgb, 4);
+}
+
+ void
+SerialProp::serialNumber(uint8_t * five)
+{
+ sendString(five, 5);
+}
+
+ string
+SerialProp::getSerial()
+{
+ string line;
+ sendChar('G');
+ line = readLine();
+ return line.erase(0,13);
+}
diff --git a/src/serialprop.hpp b/src/serialprop.hpp
new file mode 100644
index 0000000..d335c46
--- /dev/null
+++ b/src/serialprop.hpp
@@ -0,0 +1,77 @@
+/*
+ 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: serialprop.hpp
+ *
+ * Description:
+ *
+ * Version: 0.2
+ * Created: 19/12/2013 23:25:14
+ * Revision: none
+ * Compiler: gcc
+ *
+ * Author: BARATTERO Laurent, laurentba<at>larueluberlu.net
+ * Organization: La rue Luberlu
+ */
+
+
+#ifndef serialprop_INC
+#define serialprop_INC
+#include "global.hpp"
+#include "config.h"
+
+#if HAVE_TERMIOS_H==1
+#include "seriallinux.hpp"
+/*
+ * Class: SerialProp
+ * Description:
+ */
+class SerialProp : public SerialLinux
+{
+ public:
+ SerialProp (std::string port_name) : SerialLinux(port_name){}; /* constructor */
+
+ void test();
+ void start();
+ void color(unsigned char red, unsigned char green, unsigned char blue);
+ void serialNumber(uint8_t * five);
+ std::string getSerial();
+}; /* ----- end of class SerialAbs ----- */
+
+
+#else /* ----- not HAVE_TERMIOS_H ----- */
+ #include "serialboost.hpp"
+/*
+ * Class: SerialProp
+ * Description:
+ */
+class SerialProp : public SerialBoost
+{
+ public:
+ SerialProp (std::string port_name) : SerialBoost(port_name){}; /* constructor */
+
+ void test();
+ void start();
+ void color(unsigned char red, unsigned char green, unsigned char blue);
+ void serialNumber(uint8_t * five);
+ std::string getSerial();
+}; /* ----- end of class SerialAbs ----- */
+#endif /* ----- not HAVE_TERMIOS_H ----- */
+
+#endif /* ----- #ifndef serialabs_INC ----- */
diff --git a/src/ultimate.cpp b/src/ultimate.cpp
new file mode 100644
index 0000000..5efa0f9
--- /dev/null
+++ b/src/ultimate.cpp
@@ -0,0 +1,137 @@
+/*
+ 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: ultimatecmd.cpp
+ *
+ * Description: Interface for Ultimate props
+ *
+ * Version: 0.2
+ * Created: 19/12/2013 20:28:22
+ * Revision: none
+ * Compiler: gcc
+ *
+ * Author: BARATTERO Laurent, laurentba<at>larueluberlu.net
+ * Organization: La rue Luberlu
+ */
+#include <stdlib.h>
+#include "ultimate.hpp"
+
+using namespace std;
+
+Ultimate::Ultimate ( string serial_name ):
+ ser(serial_name)
+{
+} /* ----- end of constructor ----- */
+
+
+/*
+ * Class: Ultimate
+ * Method: Ultimate :: test
+ * Description:
+ */
+void Ultimate::test ()
+{
+ ser.test();
+}
+
+/*
+ * Class: Ultimate
+ * Method: Ultimate :: start
+ * Description:
+ */
+ void
+Ultimate::start ()
+{
+ ser.start();
+}
+
+/*
+ * Class: Ultimate
+ * Method: Ultimate :: color
+ * Description:
+ */
+ void
+Ultimate::color (unsigned char red, unsigned char green, unsigned char blue)
+{
+ ser.color(red, green, blue);
+}
+
+/*
+ * Class: Ultimate
+ * Method: Ultimate :: getSerial
+ * Description:
+ */
+ string
+Ultimate::getSerial ()
+{
+ string nb = ser.getSerial();
+ return nb;
+}
+
+/*
+ * Class: Ultimate
+ * Method: Ultimate :: uploadGloc
+ * Description:
+ */
+ int
+Ultimate::uploadGloc ( string filename)
+{
+ return sizeof(filename);
+}
+
+/*
+ * Class: Ultimate
+ * Method: Ultimate :: uploadGlo
+ * Description:
+ */
+ int
+Ultimate::uploadGlo ( string fileName)
+{
+ GloSeq file(fileName);
+ file.verify();
+ // to do add security
+ file.upload(ser);
+ return sizeof(fileName);
+}
+
+/*
+ * Class: Ultimate
+ * Method: Ultimate :: setSerialUlt
+ * Description:
+ */
+ void
+Ultimate::setSerialUlt(uint32_t serialNumber)
+{
+ cout << serialNumber << endl;
+ uint8_t ser_nb[6] = {83,0,0,0,0,0};
+
+ ser_nb[4] = (uint8_t)((serialNumber & 0xff000000UL) >> 24);
+ ser_nb[3] = (uint8_t)((serialNumber & 0x00ff0000UL) >> 16);
+ ser_nb[2] = (uint8_t)((serialNumber & 0x0000ff00UL) >> 8);
+ ser_nb[1] = (uint8_t)((serialNumber & 0x000000ffUL) );
+
+ for (int i = 0; i < 6; i++)
+ {
+ cout << (int)ser_nb[i] << endl;
+ }
+ ser.serialNumber(ser_nb) ;
+
+ exit (EXIT_FAILURE);
+
+}
diff --git a/src/ultimate.hpp b/src/ultimate.hpp
new file mode 100644
index 0000000..0375781
--- /dev/null
+++ b/src/ultimate.hpp
@@ -0,0 +1,66 @@
+/*
+ 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: ultimatecmd.hpp
+ *
+ * Description:
+ *
+ * Version: 0.2
+ * Created: 19/12/2013 20:28:34
+ * Revision: none
+ * Compiler: gcc
+ *
+ * Author: BARATTERO Laurent, laurentba<at>larueluberlu.net
+ * Organization: La rue Luberlu
+ */
+
+#ifndef ultimate_INC
+#define ultimate_INC
+
+#include <string>
+#include "global.hpp"
+#include "serialprop.hpp"
+#include "gloseq.hpp"
+
+
+/*
+ * Class: Ultimate
+ * Description: Ultimate interface, access to all commands used by your props
+ */
+class Ultimate
+{
+ public:
+ Ultimate (std::string serial_name); /* constructor */
+
+ void start();
+ void test();
+ void color(unsigned char red,
+ unsigned char green,
+ unsigned char blue);
+ std::string getSerial();
+ int uploadGlo(std::string file_name);
+ int uploadGloc(std::string file_name);
+ void setSerialUlt(uint32_t serialNumber);
+
+ private:
+ SerialProp ser;
+
+}; /* ----- end of class UltimateCmd ----- */
+
+#endif /* ----- #ifndef ultimatecmd_INC ----- */