Ejemplo n.º 1
0
int main(int argc, char* argv[])
{    
    Controller c;

    if (!c.connectDevice(1)) {
        std::cerr << "Connection established" << std::endl;
        return EXIT_FAILURE;
    }
    
    Device *dc = c.getConnectedDevice();
    dc->on(4,4,4);
    dc->on(3,4,4);
    dc->on(4,3,4);
    dc->on(5,4,4);
    dc->on(4,5,4);
    dc->on(3,3,4);
    dc->on(5,5,4);

    std::cout << "DeviceShape on (4,4,4)" << std::endl;
    
    c.display();
    std::cout << "DeviceShape displayed" << std::endl;

    c.disconnectDevice();
    return 0;
}
Ejemplo n.º 2
0
/*!
 * \brief Sends a message to a device
 * \param c controller
 * \return true if the message was sent properly
 */
bool OutgoingMessage::send(Controller &c)
{
    std::cout << "Outgoing message send \n";
    if (c.getConnectedDevice() == NULL)
        return false;

    LOG(2, "[SEND] Send a message :\n" + this->toStringDebug());

    int n = this->NbBuffers();

    for (int i = 0; i < n; i++) {
        LOG(5, "[SEND] Buffer N° " + std::to_string(i));

        // Convert the buffer i into an array
        uint8_t *bufferArray = new uint8_t[sizeBuffer];
        listBuffer[i].toArray(bufferArray);

        int nbTry = 0;

        do {
            // Send the message to the device
            if (!(c.getConnectedDevice()->writeToFileDescriptor(bufferArray,
                                                                sizeBuffer))) {
                throw ErrorException("Error while sending a message : "
                                     "Number of tries to send "
                                     "the message exceeded");
                c.disconnectDevice();
            } /* Buffer sent */
            LOG(5, "Buffer sent");
            
            // ack, response ?
            if (!c.secure)
                break;
            
        } while (++nbTry < MAX_TRY);

        //If number of tries exceeded
        if (nbTry == MAX_TRY) {
            LOG(2, "[HANDLER] NB TRY EXCEDEED");

            throw ErrorException("Error while receiving a ack: "
                                 "Number of tries to receive "
                                 "the ack exceeded");
        }

        delete [] bufferArray;
    }
    LOG(1, "[SEND] Message sent");
    return true;
}
Ejemplo n.º 3
0
int main(int argc, char** argv) {
    
    Controller c;
    c.connectDevice(1);
    
    Ball b;
    
    c.getConnectedDevice()->setLedStatus(b);

    for (int i = 0; i < 100; i++) {
        b.action();
        c.getConnectedDevice()->setLedStatus(b);
        
        c.display();
        //nanosleep(TIME, NULL);
        sleep(2);
    }
    c.disconnectDevice();
    return 0;
}