Skip to content
Snippets Groups Projects
darwin_dyn_manager.cpp 2.79 KiB
#include "darwin_dyn_manager.h"
#include "darwin_robot_exceptions.h"

CDarwinDynManager::CDarwinDynManager(const std::string &name,std::string &bus_id,int bus_speed, unsigned char id) : CDarwinRobotBase(name,bus_id,bus_speed,id)
{
  this->manager_period=this->get_base_period();
}

double CDarwinDynManager::get_base_period(void)
{
  unsigned char period;

  this->is_valid();
  this->robot_device->read_byte_register(MANAGER_PERIOD,&period);
  return ((double)period/1000.0);
}

void CDarwinDynManager::set_base_period(double period_s)
{
  unsigned char period;

  this->is_valid();
  period=(period_s*1000.0);
  this->robot_device->write_byte_register(MANAGER_PERIOD,period);
  this->manager_period=period_s;
}

unsigned int CDarwinDynManager::get_num_modules(void)
{
  unsigned char num;

  this->is_valid();
  this->robot_device->read_byte_register(MANAGER_NUM_MODULES,&num);
  return num;
}

unsigned int CDarwinDynManager::get_num_masters(void)
{
  unsigned char num;

  this->is_valid();
  this->robot_device->read_byte_register(MANAGER_NUM_MASTERS,&num);
  return num;
}

void CDarwinDynManager::start(void)
{
  this->is_valid();
  this->robot_device->write_byte_register(MANAGER_CONTROL,MANAGER_START);
}

void CDarwinDynManager::stop(void)
{
  this->is_valid();
  this->robot_device->write_byte_register(MANAGER_CONTROL,MANAGER_STOP);
}

bool CDarwinDynManager::is_running(void)
{
  unsigned char running;
  
  this->is_valid();
  this->robot_device->read_byte_register(MANAGER_CONTROL,&running);
  return running&MANAGER_RUNNING;
}

void CDarwinDynManager::start_scan(void)
{
  this->is_valid();
  this->robot_device->write_byte_register(MANAGER_CONTROL,MANAGER_START_SCAN);
}

bool CDarwinDynManager::is_scanning(void)
{
  unsigned char scanning;
  
  this->is_valid();
  this->robot_device->read_byte_register(MANAGER_CONTROL,&scanning);
  return scanning&MANAGER_SCANNING;
}

void CDarwinDynManager::enable_power(void)
{
  this->is_valid();
  this->robot_device->write_byte_register(MANAGER_CONTROL,MANAGER_ENABLE_POWER);
}

void CDarwinDynManager::disable_power(void)
{
  this->is_valid();
  this->robot_device->write_byte_register(MANAGER_CONTROL,MANAGER_DISABLE_POWER);
}

bool CDarwinDynManager::is_power_enabled(void)
{
  unsigned char powered;

  this->is_valid();
  this->robot_device->read_byte_register(MANAGER_CONTROL,&powered);
  return powered&MANAGER_POWERED;
}

unsigned char CDarwinDynManager::get_num_devices(void)
{
  unsigned char num;

  this->is_valid();
  this->robot_device->read_byte_register(MANAGER_NUM_DEVICES,&num);
  return num;
}

unsigned int CDarwinDynManager::get_present_devices(void)
{
  unsigned int present_devices;

  this->is_valid();
  this->robot_device->read_registers(MANAGER_PRESENT_DEVICES,(unsigned char *)&present_devices,4);
  return present_devices;
}

CDarwinDynManager::~CDarwinDynManager()
{
}