53cb4257337430c7f0bc6dd2a96b3fab3fb891c9
[iot2.git] / benchmarks / Cpp / Lifxtest / Lifxtest.cpp
1 #include <iostream>
2 #include <chrono>
3 #include <thread>
4
5 #include "Lifxtest.hpp"
6 #include "LifxLightBulb.cpp"
7 #include "Iterator.hpp"
8
9
10 // External create, destroy, and init functions
11 extern "C" void* createLifxtest(void** params) {
12         // Arguments: IoTSet<void*>* lifx_light_bulb
13         return new Lifxtest((IoTSet<void*>*) params[0]);
14 }
15
16
17 extern "C" void destroyLifxtest(void* t) {
18         Lifxtest* lt = (Lifxtest*) t;
19         delete lt;
20 }
21
22
23 extern "C" void initLifxtest(void* t) {
24         Lifxtest* lt = (Lifxtest*) t;
25         lt->init();
26 }
27
28 Lifxtest::Lifxtest() {
29         log.open("Lifxtest_object_cpp.log");
30         log << "lifx_light_bulb initialized!" << endl;
31 }
32
33 Lifxtest::Lifxtest(IoTSet<void*>* _lifx_light_bulb) {
34
35         log.open("Lifxtest_object_cpp.log");
36         lifx_light_bulb = _lifx_light_bulb;
37         log << "lifx_light_bulb initialized!" << endl;
38 }
39
40 Lifxtest::Lifxtest(void** args) {
41
42         log.open("Lifxtest_object_cpp.log");
43         lifx_light_bulb = (IoTSet<void*>*) args[0];
44         log << "lifx_light_bulb initialized!" << endl;
45 }
46
47
48 Lifxtest::~Lifxtest() {
49 }
50
51
52 void Lifxtest::init() {
53
54         unordered_set<void*>* bulbSet = lifx_light_bulb->values();
55         //for (unordered_set<void*>::const_iterator itr = bulbSet->begin(); itr != bulbSet->end(); ++itr) {
56         log << "Get into Lifxtest init()!" << endl;
57         for (auto itr = bulbSet->begin(); itr != bulbSet->end(); ++itr) {
58                 log << "Iteration init()!" << endl;
59                 //LightBulb* lifx = (LightBulb*) *itr;
60                 LightBulbTest* lifx = (LightBulbTest*) *itr;
61                 log << "Getting object!" << endl;
62                 lifx->init();
63                 log << "Executing init!" << endl;
64                 this_thread::sleep_for (chrono::milliseconds(1000));
65
66                 for (int i = 0; i < 5; i++) {
67                         lifx->turnOff();
68                         //cout << "Turning off!" << endl;
69                         log << "Turning off!" << endl;
70                         this_thread::sleep_for (chrono::milliseconds(1000));
71                         lifx->turnOn();
72                         //cout << "Turning on!" << endl;
73                         log << "Turning on!" << i << endl;
74                         this_thread::sleep_for (chrono::milliseconds(1000));
75                 }
76                 
77
78                 for (int i = 2500; i < 9000; i += 100) {
79                         //cout << "Adjusting Temp: " << i << endl;
80                         log << "Adjusting Temp: " << i << endl;
81                         lifx->setTemperature(i);
82                         this_thread::sleep_for (chrono::milliseconds(100));
83                 }
84
85                 for (int i = 9000; i > 2500; i -= 100) {
86                         //cout << "Adjusting Temp: " << i << endl;
87                         log << "Adjusting Temp: " << i << endl;
88                         lifx->setTemperature(i);
89                         this_thread::sleep_for (chrono::milliseconds(100));
90                 }
91
92                 for (int i = 100; i > 0; i -= 10) {
93                         //cout << "Adjusting Brightness: " << i << endl;
94                         log << "Adjusting Brightness: " << i << endl;
95                         lifx->setColor(lifx->getHue(), lifx->getSaturation(), i);
96                         this_thread::sleep_for (chrono::milliseconds(500));
97                 }
98
99                 for (int i = 0; i < 100; i += 10) {
100                         //cout << "Adjusting Brightness: " << i << endl;
101                         log << "Adjusting Brightness: " << i << endl;
102                         lifx->setColor(lifx->getHue(), lifx->getSaturation(), i);
103                         this_thread::sleep_for (chrono::milliseconds(500));
104                 }
105                 lifx->turnOff();
106         }
107
108         log << "End of iteration.. closing!" << endl;
109         log.close();
110         while(true) { } // Testing infinite loop - will need to do "pkill IoTSlave"
111 }
112
113
114 /*int main(int argc, char *argv[])
115 {
116         // LightBulb #1
117         string macAddress1 = "D073D5128E300000";
118         string devIPAddress1 = "192.168.2.126";
119         IoTDeviceAddress* devAddress1 = new IoTDeviceAddress(devIPAddress1, 12345, 56700, false, false);
120         unordered_set<void*>* myset1 = new unordered_set<void*>();
121         myset1->insert(devAddress1);
122         IoTSet<void*>* setDevAddress1 = new IoTSet<void*>(myset1);
123         LifxLightBulb *llb1 = new LifxLightBulb(setDevAddress1, macAddress1);
124         //cout << "Generated LifxLightBulb object!" << endl;
125
126         // LightBulb #2
127         string macAddress2 = "D073D50241DA0000";
128         string devIPAddress2 = "192.168.2.232";
129         IoTDeviceAddress* devAddress2 = new IoTDeviceAddress(devIPAddress2, 12346, 56700, false, false);
130         unordered_set<void*>* myset2 = new unordered_set<void*>();
131         myset2->insert(devAddress2);
132         IoTSet<void*>* setDevAddress2 = new IoTSet<void*>(myset2);
133         LifxLightBulb *llb2 = new LifxLightBulb(setDevAddress2, macAddress2);
134
135         // Set of lightbulbs
136         unordered_set<void*>* setLb = new unordered_set<void*>();
137         setLb->insert(llb1);
138         setLb->insert(llb2);
139         IoTSet<void*>* lbSet = new IoTSet<void*>(setLb);
140
141         //void* args[1];
142         //args[0] = (void*) lbSet;
143         //Lifxtest *lt = new Lifxtest(args);
144         Lifxtest *lt = new Lifxtest(lbSet);
145         lt->init();
146
147         //delete llb1;
148         //delete llb2;
149         delete devAddress1;
150         delete devAddress2;
151         delete myset1;
152         delete myset2;
153         delete setDevAddress1;
154         delete setDevAddress2;
155         delete setLb;
156         delete lbSet;
157
158         return 0;
159 }
160 */
161