Cleaning up the Makefile for compiler related commands; cleaning up C++ stubs and...
[iot2.git] / benchmarks / drivers / Cpp / LifxLightBulb / LifxLightBulb.cpp
index 07076db9f9002d0711505b89e8ade62f17c12c21..7b7ce1d97419a7b3ec658dcd5892ffc5fbe9a4a5 100644 (file)
@@ -33,9 +33,9 @@ extern "C" void initLifxLightBulb(void* t) {
 // Constructor
 LifxLightBulb::LifxLightBulb() { 
        // LB1 macAddress: d0:73:d5:12:8e:30
-       // LB1 macAddress: d0:73:d5:02:41:da
-       string macAddress = "D073D5128E300000"; // bulbMacAddress: [-48, 115, -43, 18, -114, 48, 0, 0]
-       //string macAddress = "D073D50241DA0000"; // bulbMacAddress: [-48, 115, -43, 2, 65, -38, 0, 0]
+       // LB2 macAddress: d0:73:d5:02:41:da
+       string macAddress = "D073D5128E300000";
+       //string macAddress = "D073D50241DA0000";
        /*bulbMacAddress[0] = 0xD0;
        bulbMacAddress[1] = 0x73;
        bulbMacAddress[2] = 0xD5;
@@ -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,10 +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
-       log.open("LifxLightBulb_cpp.log");
-       log << "MAC address is " << macAddress << endl;
 
        // Initialize device address
        lb_addresses = _devAddress;
@@ -116,7 +110,6 @@ void LifxLightBulb::init() {
        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);
@@ -124,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
@@ -136,8 +126,6 @@ void LifxLightBulb::init() {
        th1.detach();
 
        //cout << "Initialized LifxLightBulb!" << endl;
-       log << "Initialized LifxLightBulb!" << endl;
-       log.close();
 }
 
 
@@ -332,7 +320,6 @@ void LifxLightBulb::receivedPacket(char* packetData) {
        recHeader.setFromBytes(headerBytes);
 
        // load the payload bytes (strip away the header)
-       //char payloadBytes[recHeader.getSize()];
        char* payloadBytes = new char[recHeader.getSize()];
        for (int i = 36; i < recHeader.getSize(); i++) {
                payloadBytes[i - 36] = packetData[i];
@@ -390,7 +377,6 @@ 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
@@ -803,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);
@@ -1162,76 +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 macAddress = "D073D5128E300000";
-       //string macAddress = "D073D50241DA0000";
-       string devIPAddress = "192.168.2.126";
-       //string devIPAddress = "192.168.2.232";
-       //IoTDeviceAddress devAddress(devIPAddress, 12345, 56700, false, false);
-       IoTDeviceAddress* devAddress = new IoTDeviceAddress(devIPAddress, 12345, 56700, false, false);
-       unordered_set<IoTDeviceAddress*> myset = { devAddress };
-
-       IoTSet<IoTDeviceAddress*> setDevAddress(myset);
-       LifxLightBulb *llb = new LifxLightBulb(setDevAddress, macAddress);
-       cout << "Generated LifxLightBulb object!" << endl;
-       llb->init();
-       llb->turnOn();
-       onOff(llb);
-       adjustTemp(llb);
-       adjustBright(llb);
-//     llb->turnOff();
-
-       delete devAddress;
-       delete llb;
-
-       return 0;
-}*/