<commit_before>/*
 *  This program 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 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program 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 Library 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 * UsbProWidget.cpp
 * UsbPro Widget
 * Copyright (C) 2006-2008 <NAME>
 *
 * The device represents the widget.
 */

#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <termios.h>
#include <unistd.h>
#include <string>

#include <algorithm>
#include "ola/Logging.h"
#include "plugins/usbpro/UsbProWidget.h"

namespace ola {
namespace plugin {
namespace usbpro {

using std::string;

const char UsbProWidget::REPLY_SUCCESS[] = "TRUE";

typedef enum {
  ID_PROGRAM_FIRMWARE = 0x01,
  ID_FLASH_PAGE = 0x02,
  ID_PRMREQ = 0x03,
  ID_PRMREP = 0x03,
  ID_PRMSET = 0x04,
  ID_RDMX = 0x05,
  ID_SDMX = 0x06,
  ID_RDM =  0x07,
  ID_RCMODE = 0x08,
  ID_COS = 0x09,
  ID_SNOREQ = 0x0A,
  ID_SNOREP = 0x0A
} usbpro_packet_type;

/*
 * Connect to the widget
 * @returns true if the connect succeeded, false otherwise
 */
bool UsbProWidget::Connect(const string &path) {
  if (m_enabled)
    return false;

  if (m_socket) {
    m_socket->Close();
    delete m_socket;
  }

  struct termios newtio;
  int fd = open(path.data(), O_RDWR | O_NONBLOCK | O_NOCTTY);

  if (fd == -1) {
    OLA_WARN << "Failed to open " << path << " " << strerror(errno);
    return false;
  }

  bzero(&newtio, sizeof(newtio));  // clear struct for new port settings
  tcsetattr(fd, TCSANOW, &newtio);
  m_socket = new ola::network::DeviceSocket(fd);
  m_socket->SetOnData(NewClosure(this, &UsbProWidget::SocketReady));

  // fire off a get request
  if (!GetParameters()) {
    OLA_WARN << "Failed to send a GetParameters message";
    delete m_socket;
    return false;<commit_msg> * add support for the Arduino RGB<commit_after>/*
 *  This program 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 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program 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 Library 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 * UsbProWidget.cpp
 * UsbPro Widget
 * Copyright (C) 2006-2008 <NAME>
 *
 * The device represents the widget.
 */

#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <termios.h>
#include <unistd.h>
#include <string>

#include <algorithm>
#include "ola/Logging.h"
#include "plugins/usbpro/UsbProWidget.h"

namespace ola {
namespace plugin {
namespace usbpro {

using std::string;

const char UsbProWidget::REPLY_SUCCESS[] = "TRUE";

typedef enum {
  ID_PROGRAM_FIRMWARE = 0x01,
  ID_FLASH_PAGE = 0x02,
  ID_PRMREQ = 0x03,
  ID_PRMREP = 0x03,
  ID_PRMSET = 0x04,
  ID_RDMX = 0x05,
  ID_SDMX = 0x06,
  ID_RDM =  0x07,
  ID_RCMODE = 0x08,
  ID_COS = 0x09,
  ID_SNOREQ = 0x0A,
  ID_SNOREP = 0x0A
} usbpro_packet_type;

/*
 * Connect to the widget
 * @returns true if the connect succeeded, false otherwise
 */
bool UsbProWidget::Connect(const string &path) {
  if (m_enabled)
    return false;

  if (m_socket) {
    m_socket->Close();
    delete m_socket;
  }

  struct termios newtio;
  int fd = open(path.data(), O_RDWR | O_NONBLOCK | O_NOCTTY);

  if (fd == -1) {
    OLA_WARN << "Failed to open " << path << " " << strerror(errno);
    return false;
  }

  bzero(&newtio, sizeof(newtio));  // clear struct for new port settings
  cfsetispeed(&newtio, B115200);
  cfsetospeed(&newtio, B115200);

  tcsetattr(fd, TCSANOW, &newtio);
  m_socket = new ola::network::DeviceSocket(fd);
  m_socket->SetOnData(NewClosure(this, &UsbProWidget::SocketReady));

  // fire off a get request
  if (!GetParameters()) {
    OLA_WARN << "Failed to send a GetParameters message";
    delete m_socket;
    return false;
{'fraction_non_alphanumeric': 0.10969180859691809, 'fraction_numerical': 0.025952960259529603, 'mean_word_length': 3.77541142303969, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6251645', 'n_tokens_mistral': 1837, 'n_tokens_neox': 1734, 'n_words': 555}