OrderedTaskPoint* AbstractTaskFactory::createPoint(const LegalPointType_t type, const Waypoint &wp, const fixed _start_radius, const fixed _turnpoint_radius, const fixed _finish_radius) const { fixed start_radius = _start_radius; fixed turnpoint_radius = _turnpoint_radius; fixed finish_radius = _finish_radius; getPointDefaultSizes(type, start_radius, turnpoint_radius, finish_radius); switch (type) { case START_SECTOR: return createStart(new FAISectorZone(wp.location, false), wp); case START_LINE: return createStart(new LineSectorZone(wp.location, start_radius), wp); case START_CYLINDER: return createStart(new CylinderZone(wp.location, start_radius), wp); case START_BGA: return createStart(new BGAStartSectorZone(wp.location), wp); case FAI_SECTOR: return createAST(new FAISectorZone(wp.location, true), wp); case KEYHOLE_SECTOR: return createAST(new KeyholeZone(wp.location), wp); case BGAFIXEDCOURSE_SECTOR: return createAST(new BGAFixedCourseZone(wp.location), wp); case BGAENHANCEDOPTION_SECTOR: return createAST(new BGAEnhancedOptionZone(wp.location), wp); case AST_CYLINDER: return createAST(new CylinderZone(wp.location, turnpoint_radius), wp); case AAT_CYLINDER: return createAAT(new CylinderZone(wp.location, turnpoint_radius), wp); case AAT_SEGMENT: return createAAT(new SectorZone(wp.location, turnpoint_radius), wp); case AAT_ANNULAR_SECTOR: return createAAT(new AnnularSectorZone(wp.location, turnpoint_radius), wp); case FINISH_SECTOR: return createFinish(new FAISectorZone(wp.location, false), wp); case FINISH_LINE: return createFinish(new LineSectorZone(wp.location, finish_radius), wp); case FINISH_CYLINDER: return createFinish(new CylinderZone(wp.location, finish_radius), wp); } assert(1); return NULL; }
bool AbstractTaskFactory::remove(const unsigned position, const bool auto_mutate) { if (position >= m_task.TaskSize()) return false; if (auto_mutate) { if (position == 0) { // special case, remove start point.. if (m_task.TaskSize() == 1) { return m_task.remove(0); } else { // create new start point from next point StartPoint* sp = createStart(m_task.getTaskPoint(1)->GetWaypoint()); bool success = m_task.remove(0) && m_task.replace(*sp, 0); delete sp; return success; } } else if (is_position_finish(position - 1) && (position + 1 == m_task.TaskSize())) { // create new finish from previous point FinishPoint* sp = createFinish( m_task.getTaskPoint(position - 1)->GetWaypoint()); bool success = m_task.remove(position) && m_task.replace(*sp, position - 1); delete sp; return success; } else { // intermediate point deleted, nothing special to do return m_task.remove(position); } } return m_task.remove(position); }
bool AbstractTaskFactory::replace(const OrderedTaskPoint &new_tp, const unsigned position, const bool auto_mutate) { if (auto_mutate) { if (validType(new_tp, position)) // ok to replace directly return m_task.replace(new_tp, position); // will need to convert type of candidate OrderedTaskPoint *tp; if (position == 0) { // candidate must be transformed into a startpoint tp = createStart(new_tp.GetWaypoint()); } else if (is_position_finish(position) && position + 1 == m_task.TaskSize()) { // this point must be mutated into a finish tp = createFinish(new_tp.GetWaypoint()); } else { // this point must be mutated into an intermediate tp = createIntermediate(new_tp.GetWaypoint()); } bool success = m_task.replace(*tp, position); delete tp; return success; } return m_task.replace(new_tp, position); }
StartPoint* AbstractTaskFactory::createStart(const Waypoint &wp) const { LegalPointType_t type = m_behaviour.sector_defaults.start_type; if (!validStartType(type)) type = *m_start_types.begin(); return createStart(type, wp); }
bool AbstractTaskFactory::append_optional_start(const OrderedTaskPoint &new_tp, const bool auto_mutate) { if (auto_mutate && !validType(new_tp, 0)) { // candidate must be transformed into a startpoint of appropriate type StartPoint* sp = createStart(new_tp.GetWaypoint()); bool success = m_task.append_optional_start(*sp); delete sp; return success; } // ok to add directly return m_task.append_optional_start(new_tp); }
static int createCode(struct JsonNode *code) { int id = -1; int unit = -1; int state = -1; int all = 0; int learn = -1; double itmp = -1; if(json_find_number(code, "id", &itmp) == 0) id = (int)round(itmp); if(json_find_number(code, "unit", &itmp) == 0) unit = (int)round(itmp); if(json_find_number(code, "all", &itmp) == 0) all = (int)round(itmp); if(json_find_number(code, "off", &itmp) == 0) state=0; else if(json_find_number(code, "on", &itmp) == 0) state=1; if(json_find_number(code, "learn", &itmp) == 0) learn = 1; if(all > 0 && learn > -1) { logprintf(LOG_ERR, "arctech_switch: all and learn cannot be combined"); return EXIT_FAILURE; } else if(id == -1 || (unit == -1 && all == 0) || state == -1) { logprintf(LOG_ERR, "arctech_switch: insufficient number of arguments"); return EXIT_FAILURE; } else if(id > 67108863 || id < 1) { logprintf(LOG_ERR, "arctech_switch: invalid id range"); return EXIT_FAILURE; } else if((unit > 15 || unit < 0) && all == 0) { logprintf(LOG_ERR, "arctech_switch: invalid unit range"); return EXIT_FAILURE; } else { if(unit == -1 && all == 1) { unit = 0; } createMessage(id, unit, state, all, learn); createStart(); clearCode(); createId(id); createAll(all); createState(state); createUnit(unit); createFooter(); arctech_switch->rawlen = RAW_LENGTH; } return EXIT_SUCCESS; }
bool AbstractTaskFactory::append_optional_start(const Waypoint& wp) { OrderedTaskPoint* tp = NULL; if (m_task.TaskSize()) tp = m_task.get_tp(0)->clone(m_behaviour, m_task.get_ordered_task_behaviour(), &wp); else tp = createStart(wp); if (!tp) return false; // should never happen bool success = m_task.append_optional_start(*tp); delete tp; return success; }
bool AbstractTaskFactory::append(const OrderedTaskPoint &new_tp, const bool auto_mutate) { if (m_task.is_max_size()) return false; if (auto_mutate) { if (!m_task.TaskSize()) { // empty task, so add as a start point if (validType(new_tp, m_task.TaskSize())) { // candidate is ok, so add it return m_task.append(new_tp); } else { // candidate must be transformed into a startpoint StartPoint* sp = createStart(new_tp.GetWaypoint()); bool success = m_task.append(*sp); delete sp; return success; } } // non-empty task if (m_task.has_finish()) { // old finish must be mutated into an intermediate point IntermediateTaskPoint* sp = createIntermediate(m_task.getTaskPoint( m_task.TaskSize() - 1)->GetWaypoint()); m_task.replace(*sp, m_task.TaskSize()-1); delete sp; } if (validType(new_tp, m_task.TaskSize())) // ok to append directly return m_task.append(new_tp); // this point must be mutated into a finish FinishPoint* sp = createFinish(new_tp.GetWaypoint()); bool success = m_task.append(*sp); delete sp; return success; } return m_task.append(new_tp); }
bool AbstractTaskFactory::insert(const OrderedTaskPoint &new_tp, const unsigned position, const bool auto_mutate) { if (position >= m_task.TaskSize()) return append(new_tp, auto_mutate); if (auto_mutate) { if (position == 0) { if (m_task.has_start()) { // old start must be mutated into an intermediate point IntermediateTaskPoint* sp = createIntermediate(m_task.getTaskPoint(0)->GetWaypoint()); m_task.replace(*sp, 0); delete sp; } if (validType(new_tp, 0)) { return m_task.insert(new_tp, 0); } else { // candidate must be transformed into a startpoint StartPoint* sp = createStart(new_tp.GetWaypoint()); bool success = m_task.insert(*sp, 0); delete sp; return success; } } else { if (new_tp.IsIntermediatePoint()) { // candidate ok for direct insertion return m_task.insert(new_tp, position); } else { // candidate must be transformed into a intermediatepoint IntermediateTaskPoint* sp = createIntermediate(new_tp.GetWaypoint()); bool success = m_task.insert(*sp, position); delete sp; return success; } } } return m_task.insert(new_tp, position); }
static int createCode(struct JsonNode *code) { int id = -1; int unit = -1; int state = -1; int all = 0; int dimlevel = -1; int learn = -1; int max = 15; int min = 0; double itmp = -1; if(json_find_number(code, "dimlevel-maximum", &itmp) == 0) max = (int)round(itmp); if(json_find_number(code, "dimlevel-minimum", &itmp) == 0) min = (int)round(itmp); if(json_find_number(code, "id", &itmp) == 0) id = (int)round(itmp); if(json_find_number(code, "unit", &itmp) == 0) unit = (int)round(itmp); if(json_find_number(code, "dimlevel", &itmp) == 0) dimlevel = (int)round(itmp); if(json_find_number(code, "all", &itmp) == 0) all = (int)round(itmp); if(json_find_number(code, "learn", &itmp) == 0) learn = 1; if(json_find_number(code, "off", &itmp) == 0) state=0; else if(json_find_number(code, "on", &itmp) == 0) state=1; if(all > 0 && learn > -1) { logprintf(LOG_ERR, "arctech_dimmer: all and learn cannot be combined"); return EXIT_FAILURE; } else if(id == -1 || (unit == -1 && all == 0) || (dimlevel == -1 && state == -1)) { logprintf(LOG_ERR, "arctech_dimmer: insufficient number of arguments"); return EXIT_FAILURE; } else if(id > 67108863 || id < 1) { logprintf(LOG_ERR, "arctech_dimmer: invalid id range"); return EXIT_FAILURE; } else if((unit > 15 || unit < 0) && all == 0) { logprintf(LOG_ERR, "arctech_dimmer: invalid unit range"); return EXIT_FAILURE; } else if(dimlevel != -1 && (dimlevel > max || dimlevel < min) ) { logprintf(LOG_ERR, "arctech_dimmer: invalid dimlevel range"); return EXIT_FAILURE; } else if(dimlevel >= 0 && state == 0) { logprintf(LOG_ERR, "arctech_dimmer: dimlevel and off state cannot be combined"); return EXIT_FAILURE; } else { if(unit == -1 && all == 1) { unit = 0; } if(dimlevel >= 0) { state = -1; } createMessage(id, unit, state, all, dimlevel, learn); createStart(); clearCode(); createId(id); createAll(all); createState(state); createUnit(unit); if(dimlevel > -1) { createDimlevel(dimlevel); } createFooter(); arctech_dimmer->rawlen = RAW_LENGTH; } return EXIT_SUCCESS; }