Cleaning up drivers/Cpp, Cpp/Lifxtest, virtuals, and iotrmi/C++ (revisiting the C...
[iot2.git] / benchmarks / drivers / Cpp / LifxLightBulb / LifxLightBulb.cpp
index 976ec547216f0d6c8865ce9ccf67e0f9ebafa30c..667d765bf27d2a44e725d39dc49259b0b41085f5 100644 (file)
@@ -47,7 +47,6 @@ LifxLightBulb::LifxLightBulb() {
 
        char tmpMacAddress[16];
        strcpy(tmpMacAddress, macAddress.c_str());
-       //test[0] = (char) strtol(strTest.c_str(), NULL, 16);
        for(int i=0; i<16; i=i+2) {
                // Take 2 digits and then convert
                char tmpMacByte[2];
@@ -55,7 +54,6 @@ LifxLightBulb::LifxLightBulb() {
                tmpMacByte[1] = tmpMacAddress[i+1];
                bulbMacAddress[i/2] = (char) strtol(tmpMacByte, NULL, 16);
        }
-       //IoTRMIUtil::printBytes(bulbMacAddress, 8, false);
 }
 
 
@@ -74,16 +72,6 @@ LifxLightBulb::LifxLightBulb(IoTSet<void*>* _devAddress, string macAddress) {
                bulbMacAddress[i/2] = (char) strtol(tmpMacByte, NULL, 16);
        }
        //cout << "MAC address is set. Value: ";
-       IoTRMIUtil::printBytes(bulbMacAddress, 8, false);
-       // Logging
-       int i=0;
-       string file = "LifxLightBulb_cpp" + to_string(i) + ".log";
-       while (ifstream(file.c_str())) {
-               i++;
-               file = "LifxLightBulb_cpp" + to_string(i) + ".log";
-       }
-       log.open(file);
-       log << "MAC address is " << macAddress << endl;
 
        // Initialize device address
        lb_addresses = _devAddress;
@@ -119,11 +107,9 @@ void LifxLightBulb::init() {
        if (didAlreadyInit.exchange(true))
                return;
 
-       log << "lb_addresses has: " << lb_addresses->size() << endl;
        unordered_set<void*>::const_iterator itr = lb_addresses->begin();
        IoTDeviceAddress* deviceAddress = (IoTDeviceAddress*) *itr;
        //cout << "Address: " << deviceAddress->getAddress() << endl;
-       log << "Address: " << deviceAddress->getAddress() << endl;
 
        // Create IoTUDP socket
        communicationSocket = new IoTUDP(deviceAddress);
@@ -131,9 +117,6 @@ void LifxLightBulb::init() {
        //cout << "Host address: " << communicationSocket->getHostAddress() << endl;
        //cout << "Source port: " << communicationSocket->getSourcePort() << endl;
        //cout << "Destination port: " << communicationSocket->getDestinationPort() << endl << endl;
-       log << "Host address: " << communicationSocket->getHostAddress() << endl;
-       log << "Source port: " << communicationSocket->getSourcePort() << endl;
-       log << "Destination port: " << communicationSocket->getDestinationPort() << endl << endl;
 
        // Launch the worker function in a separate thread.
        //              NOTE: "this" pointer is passed into the detached thread because it does not belong
@@ -143,8 +126,6 @@ void LifxLightBulb::init() {
        th1.detach();
 
        //cout << "Initialized LifxLightBulb!" << endl;
-       log << "Initialized LifxLightBulb!" << endl;
-       log.close();
 }
 
 
@@ -346,7 +327,6 @@ void LifxLightBulb::receivedPacket(char* packetData) {
 
        int type = recHeader.getType();
        //cout << "Received: " << type << endl;
-       log << "Received: " << type << endl;
 
        DeviceStateService* dat = NULL;
        switch (type) {
@@ -397,14 +377,11 @@ void LifxLightBulb::workerFunction(LifxLightBulb* llb) {
        // Need timeout on receives since we are not sure if a packet will be available
        // for processing so don't block waiting
        llb->communicationSocket->setTimeOut(50000);    // In milliseconds
-
        llb->turnOff();
 
        int64_t lastSentGetBulbVersionRequest = 0;      // time last request sent
        char dat[1024];
 
-       llb->log << "Turning off and entering while loop!" << endl;
-
        while (true) {
                // Check if we got the bulb version yet
                // could have requested it but message could have gotten lost (UDP)
@@ -812,10 +789,8 @@ void LifxLightBulb::sendSetLightPowerPacket(int level, long duration) {
                cerr << "Invalid parameter values" << endl;
                exit(1);
        }
-
        char packetBytes[42];
 
-
        LifxHeader header;
        header.setSize(42);
        header.setTagged(false);
@@ -1171,78 +1146,3 @@ void LifxLightBulb::handleLightStateMessageReceived(char* payloadData) {
        delete color;
 }
 
-
-// Functions for the main function
-void onOff(LifxLightBulb *llb) {
-
-       for (int i = 0; i < 2; i++) {
-               llb->turnOff();
-               //cout << "Turning off!" << endl;
-               this_thread::sleep_for (chrono::milliseconds(1000));
-               llb->turnOn();
-               //cout << "Turning on!" << endl;
-               this_thread::sleep_for (chrono::milliseconds(1000));
-       }
-}
-
-
-void adjustTemp(LifxLightBulb *llb) {
-
-       for (int i = 2500; i < 9000; i += 100) {
-               //cout << "Adjusting Temp: " << i << endl;
-               llb->setTemperature(i);
-               this_thread::sleep_for (chrono::milliseconds(100));
-       }
-       //cout << "Adjusted temperature to 9000!" << endl;
-       for (int i = 9000; i > 2500; i -= 100) {
-               //cout << "Adjusting Temp: " << i << endl;
-               llb->setTemperature(i);
-               this_thread::sleep_for (chrono::milliseconds(100));
-       }
-       //cout << "Adjusted temperature to 2500!" << endl;
-}
-
-
-void adjustBright(LifxLightBulb *llb) {
-       for (int i = 100; i > 0; i -= 10) {
-               //cout << "Adjusting Brightness: " << i << endl;
-               llb->setColor(llb->getHue(), llb->getSaturation(), i);
-               this_thread::sleep_for (chrono::milliseconds(100));
-       }
-       //cout << "Adjusted brightness to 0!" << endl;
-       for (int i = 0; i < 100; i += 10) {
-               //cout << "Adjusting Brightness: " << i << endl;
-               llb->setColor(llb->getHue(), llb->getSaturation(), i);
-               this_thread::sleep_for (chrono::milliseconds(100));
-       }
-       //cout << "Adjusting brightness to 100!" << endl;
-}
-
-
-/*int main(int argc, char *argv[])
-{
-       string macAddress1 = "D073D5128E300000";
-       //string macAddress = "D073D50241DA0000";
-       string devIPAddress1 = "192.168.1.126";
-       //string devIPAddress = "192.168.1.232";
-       IoTDeviceAddress* devAddress1 = new IoTDeviceAddress(devIPAddress1, 12345, 56700, false, false);
-       unordered_set<void*>* myset1 = new unordered_set<void*>();
-       myset1->insert(devAddress1);
-
-       IoTSet<void*>* setDevAddress1 = new IoTSet<void*>(myset1);
-       LifxLightBulb *llb1 = new LifxLightBulb(setDevAddress1, macAddress1);
-       cout << "Generated LifxLightBulb object!" << endl;
-       llb1->init();
-       cout << "Initialized!" << endl;
-       llb1->turnOn();
-       cout << "Turning on!" << endl;
-       onOff(llb1);
-//     adjustTemp(llb1);
-//     adjustBright(llb1);
-       llb1->turnOff();
-
-//     delete devAddress1;
-//     delete llb1;
-
-       return 0;
-}*/