//! Initialize resources. void onResourceInitialization(void) { if (!getConstantParameters()) throw RestartNeeded(DTR("failed to get constant parameters"), c_restart_delay); setConfig(); std::map<std::string, LED*>::iterator itr = m_led_by_name.begin(); for (unsigned i = 0; i < c_led_count; ++i) setBrightness(itr->second, 0); if (!m_args.led_patterns.empty()) { uint8_t count = m_args.led_patterns.size(); UCTK::Frame frame; frame.setId(PKT_ID_LED_PATTERN); frame.setPayloadSize(1 + (count * 2)); frame.set(count, 0); for (size_t i = 0; i < count; ++i) frame.set<uint16_t>(m_args.led_patterns[i], 1 + i * 2); if (!m_ctl->sendFrame(frame)) throw RestartNeeded(DTR("failed to set LED patterns"), c_restart_delay); } m_wdog.reset(); setEntityState(IMC::EntityState::ESTA_NORMAL, Status::CODE_ACTIVE); }
bool setPatternPulseWidth(uint16_t pwidth) { UCTK::Frame frame; frame.setId(PKT_ID_LED_PATTERN_PW); frame.setPayloadSize(2); frame.set(pwidth, 0); return m_ctl->sendFrame(frame); }
void Interface::resetDevice(void) { UCTK::Frame frame; frame.setId(PKT_ID_RESET); frame.setPayloadSize(0); if (!sendFrame(frame)) throw std::runtime_error(DTR("failed to reset device")); }
bool setExternalTrigger(bool enabled) { uint8_t v = enabled ? 1 : 0; UCTK::Frame frame; frame.setId(PKT_ID_LED_EXT_TRG); frame.setPayloadSize(1); frame.set(v, 0); return m_ctl->sendFrame(frame); }
void Interface::setBootStop(bool value) { UCTK::Frame frame; frame.setId(PKT_ID_BOOT); frame.setPayloadSize(1); frame.set<uint8_t>(value, 0); if (!sendFrame(frame)) throw std::runtime_error(DTR("failed to set bootloader parameters")); }
void Interface::getFirmwareName(FirmwareInfo& info) { UCTK::Frame frame; frame.setId(PKT_ID_NAME); frame.setPayloadSize(0); if (!sendFrame(frame)) throw std::runtime_error(DTR("failed to get firmware name")); info.name.assign((const char*)frame.getPayload(), frame.getPayloadSize()); }
void setBrightness(LED* led, uint8_t value) { uint8_t id = led->id; uint16_t ticks = ((value * m_dif_dur) / 255) + m_min_dur; UCTK::Frame frame; frame.setId(PKT_ID_LED_PW); frame.setPayloadSize(3); frame.set(id, 0); frame.set(ticks, 1); if (m_ctl->sendFrame(frame)) { led->brightness.value = value; m_wdog.reset(); } }
bool getConstantParameters(void) { UCTK::Frame frame; frame.setId(PKT_ID_PARAMS); if (!m_ctl->sendFrame(frame)) return false; if (frame.getPayloadSize() != 4) return false; frame.get(m_min_dur, 0); frame.get(m_max_dur, 2); m_dif_dur = m_max_dur - m_min_dur; return true; }
bool getMonitors(void) { UCTK::Frame frame; frame.setId(PKT_ID_STATE); if (!m_ctl->sendFrame(frame)) return false; if (frame.getPayloadSize() != 6) return false; // MCU Voltage. uint16_t tmp_u16 = 0; frame.get(tmp_u16, 0); IMC::Voltage v; v.value = tmp_u16 / 1000.0; m_mcu_ent->dispatch(v); // Voltage. frame.get(tmp_u16, 2); m_voltage.value = tmp_u16 / 1000.0; dispatch(m_voltage); // Current. frame.get(tmp_u16, 4); m_current.value = tmp_u16 / 1000.0; dispatch(m_current); m_wdog.reset(); return true; }
void Interface::getFirmwareVersion(FirmwareInfo& info) { UCTK::Frame frame; frame.setId(PKT_ID_VERSION); frame.setPayloadSize(0); if (!sendFrame(frame)) throw std::runtime_error(DTR("failed to get firmware version")); if (frame.getPayloadSize() != 3) throw std::runtime_error(DTR("invalid firmware version")); frame.get(info.major, 0); frame.get(info.minor, 1); frame.get(info.patch, 2); }