aboutsummaryrefslogtreecommitdiff
path: root/src/optmanager.hpp
blob: ee8142818738dfbb8101cae55f55264fd0854971 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
    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.3.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"
#include "symlink.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
#define FLAG_SYMLINK  0x20

/*
 *        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 addItemSymlink(std::string port_name)
                {symlinkList.push_back(port_name);}

    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 sendSymlink(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;
    std::vector<std::string> symlinkList;
    // end of Structures and variables for opts containers 

}; /* -----  end of class OptManager  ----- */

#endif   /* ----- #ifndef optmanager_INC  ----- */