int runtime::app::onCommand(const Glib::RefPtr<Gio::ApplicationCommandLine> &appCmdLine) { auto optDict = appCmdLine->get_options_dict(); auto cmdOptions = getCmdOptions(); for (auto &o : *(cmdOptions->getEntries())) { if (o.second.value.type == dataTypes::OptionArgumentText || o.second.value.type == dataTypes::OptionArgumentFilename) { Glib::ustring tmp; if (!optDict->lookup_value(o.second.longName.c_str(), tmp)) continue; o.second.value.textValue = tmp.c_str(); } else if (o.second.value.type == dataTypes::OptionArgumentLogical) { bool tmp; if (!optDict->lookup_value(o.second.longName.c_str(), tmp)) continue; o.second.value.logicalValue = tmp; } else if (o.second.value.type == dataTypes::OptionArgumentNumeric) { int tmp; if (!optDict->lookup_value(o.second.longName.c_str(), tmp)) continue; o.second.value.numericValue = tmp; } if (o.second.callback) { int retval = -1; // continue if (!o.second.callback(o.second, &retval)) return retval; } } optDict->lookup_value(G_OPTION_REMAINING, cmdOptions->pathArgs); _app->activate(); return EXIT_SUCCESS; }
int Application::on_command_line(Glib::RefPtr<Gio::ApplicationCommandLine> const & command_line) { auto const options = command_line->get_options_dict(); bool version = false; options->lookup_value("version", version); if (version) { std::cout << VERSION << std::endl; return 0; } std::vector<std::string> remaining; options->lookup_value(G_OPTION_REMAINING, remaining); if (remaining.size() == 0) { FontCatalogue::initialize(); } else { FontCatalogue::initialize(remaining); } activate(); return 0; }
int main(int argc, char **argv) { int sock; int protocol; if (argc != 2) { fprintf(stderr, "usage: %s protocol\n", argv[0]); exit(1); } protocol = lookup_value(argv[1], protocols); if (protocol < 0) { fprintf(stderr, "%s: unknown protocol %s\n", argv[0], argv[1]); exit(1); } sock = socket(AF_NETLINK, SOCK_DGRAM, protocol); if (sock < 0) { fprintf(stderr, "%s: socket(AF_NETLINK, SOCK_DGRAM, %s/%d): %s\n", argv[0], argv[1], protocol, strerror(errno)); exit(1); } close(sock); exit(0); }
/* * [g|s]etsockopt's level argument can either be SOL_SOCKET or a * protocol-specific value. */ const char * sysdecode_sockopt_level(int level) { const char *str; if (level == SOL_SOCKET) return ("SOL_SOCKET"); /* SOL_* constants for Bluetooth sockets. */ str = lookup_value(ngbtsolevel, level); if (str != NULL) return (str); /* * IP and Infiniband sockets use IP protocols as levels. Not all * protocols are valid but it is simpler to just allow all of them. * * XXX: IPPROTO_IP == 0, but UNIX domain sockets use a level of 0 * for private options. */ str = sysdecode_ipproto(level); if (str != NULL) return (str); return (NULL); }
static bool print_value(FILE *fp, struct name_table *table, uintmax_t val) { const char *str; str = lookup_value(table, val); if (str != NULL) { fputs(str, fp); return (true); } return (false); }
bool sysdecode_socket_type(FILE *fp, int type, int *rem) { const char *str; uintmax_t val; bool printed; str = lookup_value(socktype, type & ~(SOCK_CLOEXEC | SOCK_NONBLOCK)); if (str != NULL) { fputs(str, fp); *rem = 0; printed = true; } else { *rem = type & ~(SOCK_CLOEXEC | SOCK_NONBLOCK); printed = false; } val = type & (SOCK_CLOEXEC | SOCK_NONBLOCK); print_mask_part(fp, sockflags, &val, &printed); return (printed); }
static int instinctq_battery_probe(struct platform_device *pdev) { struct s3c_adc_client *client; struct instinctq_battery_pdata *pdata = pdev->dev.platform_data; struct instinctq_battery *bat; int ret, i, irq; /* Platform data is required */ if (!pdata) { dev_err(&pdev->dev, "no platform data supplied\n"); return -ENODEV; } /* Check GPIOs */ if (!gpio_is_valid(pdata->gpio_pok)) { dev_err(&pdev->dev, "Invalid gpio pin for POK line\n"); return -EINVAL; } if (!gpio_is_valid(pdata->gpio_chg)) { dev_err(&pdev->dev, "Invalid gpio pin for CHG line\n"); return -EINVAL; } if (!gpio_is_valid(pdata->gpio_en)) { dev_err(&pdev->dev, "Invalid gpio pin for EN line\n"); return -EINVAL; } if (!pdata->supply_detect_init) { dev_err(&pdev->dev, "Supply detection is required\n"); return -EINVAL; } /* Register ADC client */ client = s3c_adc_register(pdev, NULL, NULL, 0); if (IS_ERR(client)) { dev_err(&pdev->dev, "could not register adc\n"); return PTR_ERR(client); } /* Allocate driver data */ bat = kzalloc(sizeof(struct instinctq_battery), GFP_KERNEL); if (!bat) { dev_err(&pdev->dev, "could not allocate driver data\n"); ret = -ENOMEM; goto err_free_adc; } /* Claim and setup GPIOs */ ret = gpio_request(pdata->gpio_pok, dev_name(&pdev->dev)); if (ret) { dev_err(&pdev->dev, "Failed to request POK pin: %d\n", ret); goto err_free; } ret = gpio_direction_input(pdata->gpio_pok); if (ret) { dev_err(&pdev->dev, "Failed to set POK to input: %d\n", ret); goto err_gpio_pok_free; } ret = gpio_request(pdata->gpio_chg, dev_name(&pdev->dev)); if (ret) { dev_err(&pdev->dev, "Failed to request CHG pin: %d\n", ret); goto err_gpio_pok_free; } ret = gpio_direction_input(pdata->gpio_chg); if (ret) { dev_err(&pdev->dev, "Failed to set CHG to input: %d\n", ret); goto err_gpio_chg_free; } ret = gpio_request(pdata->gpio_en, dev_name(&pdev->dev)); if (ret) { dev_err(&pdev->dev, "Failed to request EN pin: %d\n", ret); goto err_gpio_chg_free; } ret = gpio_direction_output(pdata->gpio_en, pdata->gpio_en_inverted); if (ret) { dev_err(&pdev->dev, "Failed to set EN to output: %d\n", ret); goto err_gpio_en_free; } platform_set_drvdata(pdev, bat); bat->dev = &pdev->dev; bat->client = client; bat->pdata = pdata; bat->status = POWER_SUPPLY_STATUS_DISCHARGING; bat->health = POWER_SUPPLY_HEALTH_GOOD; bat->supply = instinctq_BATTERY_NONE; bat->interval = BAT_POLL_INTERVAL; bat->calibration = pdata->calibration; ret = create_lookup_table(pdata->percent_lut, pdata->percent_lut_cnt, &bat->percent_lookup); if (ret) { dev_err(&pdev->dev, "could not get create percentage lookup table"); goto err_gpio_en_free; } ret = create_lookup_table(pdata->volt_lut, pdata->volt_lut_cnt, &bat->volt_lookup); if (ret) { dev_err(&pdev->dev, "could not get create voltage lookup table"); goto err_percent_free; } ret = create_lookup_table(pdata->temp_lut, pdata->temp_lut_cnt, &bat->temp_lookup); if (ret) { dev_err(&pdev->dev, "could not get create temperature lookup table"); goto err_volt_free; } INIT_WORK(&bat->work, instinctq_battery_work); INIT_DELAYED_WORK(&bat->poll_work, instinctq_battery_poll); mutex_init(&bat->mutex); #ifdef CONFIG_HAS_WAKELOCK wake_lock_init(&bat->wakelock, WAKE_LOCK_SUSPEND, "battery"); wake_lock_init(&bat->chg_wakelock, WAKE_LOCK_SUSPEND, "charger"); wake_lock_init(&bat->fault_wakelock, WAKE_LOCK_SUSPEND, "battery fault"); wake_lock_init(&bat->suspend_lock, WAKE_LOCK_SUSPEND, "suspend_lock"); #endif #ifdef CONFIG_RTC_INTF_ALARM alarm_init(&bat->alarm, ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP, instinctq_battery_alarm); #endif /* Get some initial data for averaging */ for (i = 0; i < NUM_SAMPLES; ++i) { int sample; /* Get a voltage sample from the ADC */ sample = instinctq_battery_adc_read(bat->client, bat->pdata->volt_channel); if (sample < 0) { dev_warn(&pdev->dev, "Failed to get ADC sample.\n"); continue; } sample += bat->compensation; bat->vol_adc = sample; /* Put the sample and get the new average */ bat->volt_value = put_sample_get_avg(&bat->volt_avg, sample); /* Get a temperature sample from the ADC */ sample = instinctq_battery_adc_read(bat->client, bat->pdata->temp_channel); if (sample < 0) { dev_warn(&pdev->dev, "Failed to get ADC sample.\n"); continue; } bat->temp_adc = sample; /* Put the sample and get the new average */ bat->temp_value = put_sample_get_avg(&bat->temp_avg, sample); } bat->percent_value = lookup_value(&bat->percent_lookup, bat->volt_value); bat->volt_value = lookup_value(&bat->volt_lookup, bat->volt_value); bat->temp_value = lookup_value(&bat->temp_lookup, bat->temp_value); bat->last_sample = ktime_get_boottime(); /* Register the power supplies */ for (i = 0; i < instinctq_BATTERY_NUM; ++i) { bat->psy[i] = instinctq_chg_templates[i]; ret = power_supply_register(&pdev->dev, &bat->psy[i]); if (ret < 0) { dev_err(&pdev->dev, "Failed to register power supply %s (%d)\n", bat->psy[i].name, ret); break; } } /* Undo the loop on error */ if (i-- != instinctq_BATTERY_NUM) { for (; i >= 0; --i) power_supply_unregister(&bat->psy[i]); goto err_temp_free; } #ifdef CONFIG_HAS_WAKELOCK ret = device_create_file(bat->psy[instinctq_BATTERY_AC].dev, &dev_attr_suspend_lock); if (ret < 0) { dev_err(&pdev->dev, "Failed to register device attribute.\n"); goto err_psy_unreg; } #endif /* Register the battery */ bat->bat = instinctq_bat_template; ret = power_supply_register(&pdev->dev, &bat->bat); if (ret < 0) { dev_err(&pdev->dev, "Failed to register battery power supply: %d\n", ret); goto err_attr_unreg; } for (i = 0; i < ARRAY_SIZE(battery_attrs); ++i) { ret = device_create_file(bat->bat.dev, battery_attrs[i]); if (ret < 0) break; } if (ret < 0) { for (; i >= 0; --i) device_remove_file(bat->bat.dev, battery_attrs[i]); goto err_bat_unreg; } bat->workqueue = create_freezable_workqueue(dev_name(&pdev->dev)); if (!bat->workqueue) { dev_err(&pdev->dev, "Failed to create freezeable workqueue\n"); ret = -ENOMEM; goto err_remove_bat_attr; } /* Claim IRQs */ irq = gpio_to_irq(pdata->gpio_pok); if (irq <= 0) { dev_err(&pdev->dev, "POK irq invalid.\n"); goto err_destroy_workqueue; } bat->irq_pok = irq; ret = request_irq(irq, instinctq_charger_irq, IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, dev_name(&pdev->dev), bat); if (ret) { dev_err(&pdev->dev, "Failed to request POK irq (%d)\n", ret); goto err_destroy_workqueue; } ret = request_irq(IRQ_BATF, instinctq_battery_fault_irq, 0, dev_name(&pdev->dev), bat); if (ret) { dev_err(&pdev->dev, "Failed to request battery fault irq (%d)\n", ret); goto err_pok_irq_free; } enable_irq_wake(bat->irq_pok); instinctq_battery_set_fault_enable(1); /* Finish */ dev_info(&pdev->dev, "successfully loaded\n"); device_init_wakeup(&pdev->dev, 1); pdata->supply_detect_init(instinctq_battery_supply_notify); /* Schedule work to check current status */ #ifdef CONFIG_HAS_WAKELOCK wake_lock(&bat->wakelock); #endif queue_work(bat->workqueue, &bat->work); return 0; err_pok_irq_free: free_irq(bat->irq_pok, bat); err_destroy_workqueue: destroy_workqueue(bat->workqueue); err_remove_bat_attr: for (i = 0; i < ARRAY_SIZE(battery_attrs); ++i) device_remove_file(bat->bat.dev, battery_attrs[i]); err_bat_unreg: power_supply_unregister(&bat->bat); err_attr_unreg: #ifdef CONFIG_HAS_WAKELOCK device_remove_file(bat->psy[instinctq_BATTERY_AC].dev, &dev_attr_suspend_lock); err_psy_unreg: #endif for (i = 0; i < instinctq_BATTERY_NUM; ++i) power_supply_unregister(&bat->psy[i]); err_temp_free: #ifdef CONFIG_HAS_WAKELOCK wake_lock_destroy(&bat->wakelock); wake_lock_destroy(&bat->chg_wakelock); wake_lock_destroy(&bat->fault_wakelock); wake_lock_destroy(&bat->suspend_lock); #endif kfree(bat->temp_lookup.table); err_volt_free: kfree(bat->volt_lookup.table); err_percent_free: kfree(bat->percent_lookup.table); err_gpio_en_free: gpio_free(pdata->gpio_en); err_gpio_chg_free: gpio_free(pdata->gpio_chg); err_gpio_pok_free: gpio_free(pdata->gpio_pok); err_free: kfree(bat); err_free_adc: s3c_adc_release(client); return ret; }
static void instinctq_battery_poll(struct work_struct *work) { struct delayed_work *dwrk = to_delayed_work(work); struct instinctq_battery *bat = container_of(dwrk, struct instinctq_battery, poll_work); struct instinctq_battery_pdata *pdata = bat->pdata; int volt_sample, volt_value, temp_sample, temp_value, percent_value; int health, update = 0; mutex_lock(&bat->mutex); /* Get a voltage sample from the ADC */ volt_sample = instinctq_battery_adc_read(bat->client, bat->pdata->volt_channel); if (volt_sample < 0) { dev_warn(bat->dev, "Failed to get ADC sample.\n"); bat->health = POWER_SUPPLY_HEALTH_UNKNOWN; goto error; } volt_sample += bat->compensation; bat->vol_adc = volt_sample; volt_sample = put_sample_get_avg(&bat->volt_avg, volt_sample); volt_value = lookup_value(&bat->volt_lookup, volt_sample); percent_value = lookup_value(&bat->percent_lookup, volt_sample); /* Get a temperature sample from the ADC */ temp_sample = instinctq_battery_adc_read(bat->client, bat->pdata->temp_channel); if (temp_sample < 0) { dev_warn(bat->dev, "Failed to get ADC sample.\n"); bat->health = POWER_SUPPLY_HEALTH_UNKNOWN; goto error; } bat->temp_adc = temp_sample; temp_sample = put_sample_get_avg(&bat->temp_avg, temp_sample); temp_value = lookup_value(&bat->temp_lookup, temp_sample); if (bat->health == POWER_SUPPLY_HEALTH_UNKNOWN) bat->health = POWER_SUPPLY_HEALTH_GOOD; bat->volt_value = volt_value; if (bat->percent_value >= percent_value || bat->status != POWER_SUPPLY_STATUS_DISCHARGING) bat->percent_value = percent_value; bat->temp_value = temp_value; bat->last_sample = ktime_get_boottime(); health = bat->health; if (temp_value <= pdata->low_temp_enter) health = POWER_SUPPLY_HEALTH_COLD; if (temp_value >= pdata->high_temp_enter) health = POWER_SUPPLY_HEALTH_OVERHEAT; if (temp_value >= pdata->low_temp_exit && temp_value <= pdata->high_temp_exit) health = POWER_SUPPLY_HEALTH_GOOD; if (bat->health != health) { bat->health = health; update = 1; } if (bat->chg_enable) { if (gpio_get_value(pdata->gpio_chg) ^ pdata->gpio_chg_inverted) bat->status = POWER_SUPPLY_STATUS_CHARGING; else bat->status = POWER_SUPPLY_STATUS_FULL; } error: mutex_unlock(&bat->mutex); /* Schedule next poll */ if (update) { queue_work(bat->workqueue, &bat->work); } else { queue_delayed_work(bat->workqueue, &bat->poll_work, msecs_to_jiffies(bat->interval)); power_supply_changed(&bat->bat); } }
/* XXX: 'type' is really an acl_type_t. */ const char * sysdecode_acltype(int type) { return (lookup_value(acltype, type)); }
/* XXX: idtype is really an idtype_t */ const char * sysdecode_idtype(int idtype) { return (lookup_value(idtypes, idtype)); }
const char * sysdecode_shmctl_cmd(int cmd) { return (lookup_value(shmctlops, cmd)); }
void RaycastCar::update_engine(btScalar step) { const btTransform & chassis_t = getChassisWorldTransform(); btVector3 fwd(chassis_t.getBasis()[0][m_indexForwardAxis], chassis_t.getBasis()[1][m_indexForwardAxis], chassis_t.getBasis()[2][m_indexForwardAxis]); WheelInfo & wheelInfo0 = m_wheelInfo[0]; wheelInfo0.m_last_linear_velocity = wheelInfo0.m_linear_velocity; btVector3 relpos0 = wheelInfo0.m_raycastInfo.m_hardPointWS - getRigidBody()->getCenterOfMassPosition(); btVector3 vel0 = getRigidBody()->getVelocityInLocalPoint(relpos0); btScalar proj0 = fwd.dot(wheelInfo0.m_raycastInfo.m_contactNormalWS); btVector3 fwd_w0 = fwd - wheelInfo0.m_raycastInfo.m_contactNormalWS * proj0; btScalar lin_vel0 = fwd_w0.dot(vel0); btScalar w0_rpm = fabs(rads2rpm(lin_vel0/wheelInfo0.m_wheelsRadius)); btScalar delta0 = (lin_vel0/wheelInfo0.m_wheelsRadius)*step; wheelInfo0.m_linear_velocity = lin_vel0; wheelInfo0.m_angular_velocity = lin_vel0/wheelInfo0.m_wheelsRadius; WheelInfo & wheelInfo1 = m_wheelInfo[1]; wheelInfo1.m_last_linear_velocity = wheelInfo1.m_linear_velocity; btVector3 relpos1 = wheelInfo1.m_raycastInfo.m_hardPointWS - getRigidBody()->getCenterOfMassPosition(); btVector3 vel1 = getRigidBody()->getVelocityInLocalPoint(relpos1); btScalar proj1 = fwd.dot(wheelInfo1.m_raycastInfo.m_contactNormalWS); btVector3 fwd_w1 = fwd - wheelInfo1.m_raycastInfo.m_contactNormalWS * proj1; btScalar lin_vel1 = fwd_w1.dot(vel1); btScalar w1_rpm = fabs(rads2rpm(lin_vel1/wheelInfo1.m_wheelsRadius)); btScalar delta1 = (lin_vel1/wheelInfo1.m_wheelsRadius)*step; wheelInfo1.m_linear_velocity = lin_vel1; wheelInfo1.m_angular_velocity = lin_vel1/wheelInfo1.m_wheelsRadius; WheelInfo & wheelInfo2 = m_wheelInfo[2]; wheelInfo2.m_last_linear_velocity = wheelInfo2.m_linear_velocity; btVector3 relpos2 = wheelInfo2.m_raycastInfo.m_hardPointWS - getRigidBody()->getCenterOfMassPosition(); btVector3 vel2 = getRigidBody()->getVelocityInLocalPoint(relpos2); btScalar proj2 = fwd.dot(wheelInfo2.m_raycastInfo.m_contactNormalWS); btVector3 fwd_w2 = fwd - wheelInfo2.m_raycastInfo.m_contactNormalWS * proj2; btScalar lin_vel2 = fwd_w2.dot(vel2); //btScalar w2_rpm = fabs(rads2rpm(lin_vel2/wheelInfo2.m_wheelsRadius)); btScalar delta2 = (lin_vel2/wheelInfo2.m_wheelsRadius)*step; wheelInfo2.m_linear_velocity = lin_vel2; wheelInfo2.m_angular_velocity = lin_vel2/wheelInfo2.m_wheelsRadius; WheelInfo & wheelInfo3 = m_wheelInfo[3]; wheelInfo3.m_last_linear_velocity = wheelInfo3.m_linear_velocity; btVector3 relpos3 = wheelInfo3.m_raycastInfo.m_hardPointWS - getRigidBody()->getCenterOfMassPosition(); btVector3 vel3 = getRigidBody()->getVelocityInLocalPoint(relpos3); btScalar proj3 = fwd.dot(wheelInfo3.m_raycastInfo.m_contactNormalWS); btVector3 fwd_w3 = fwd - wheelInfo3.m_raycastInfo.m_contactNormalWS * proj3; btScalar lin_vel3 = fwd_w3.dot(vel3); //btScalar w3_rpm = fabs(rads2rpm(lin_vel3/wheelInfo3.m_wheelsRadius)); btScalar delta3 = (lin_vel3/wheelInfo3.m_wheelsRadius)*step; wheelInfo3.m_linear_velocity = lin_vel3; wheelInfo3.m_angular_velocity = lin_vel3/wheelInfo3.m_wheelsRadius; ///////////////////////////// // // Update engine // // m_last_engine_rpm = m_engine_rpm; m_last_throttle = m_throttle; btScalar to_engine_rpm = btScalar(0.0f); if (m_differential_type == 0) { to_engine_rpm = btMax(wheelInfo2.m_rpm,wheelInfo3.m_rpm); } if (m_gear == 1) // idle { m_engine_rpm = btScalar(m_rpm_data[m_graphs_size-1]*m_throttle); } else { m_engine_rpm = to_engine_rpm*m_gears_coefficients[m_gear]*m_final_drive*m_gears_eff; } if (m_engine_rpm > btScalar(m_rpm_data[m_graphs_size-1]*m_throttle)) { m_engine_rpm = m_rpm_data[m_graphs_size-1]*m_throttle; } if (m_engine_rpm < btScalar(m_rpm_data[0])) { m_engine_rpm = btScalar(m_rpm_data[0]); } btScalar torque = lookup_value(m_engine_rpm, m_rpm_data,m_torque_data,m_graphs_size)*m_throttle; #ifdef SHOW_MOTOR_INFO m_info_engine_torque = torque; m_info_engine_power = (torque*2.0f*SIMD_PI*m_engine_rpm)/60.0f; #endif m_info_engine_rpm = m_engine_rpm + (rand() % 10 + 1); // drive force to apply to chassis at both rear wheel's // contact points in local space btScalar Fdrive; if (m_gear == 0) { Fdrive = (m_gears_coefficients[m_gear]*m_gears_eff*torque)/wheelInfo2.m_wheelsRadius; Fdrive *= 0.5f; // per wheel Fdrive *= -1.0f; } //if (m_gear == 1) //{ //Fdrive = btScalar(0.0f); //} else { Fdrive = (m_gears_coefficients[m_gear]*m_final_drive*m_gears_eff*torque)/wheelInfo2.m_wheelsRadius; Fdrive *= 0.5f; // per wheel } btScalar to_rear_wheel_rpm; // acceleration (depends on m_inertia_coef) is essential to update engine RPM btScalar acceleration = (torque*m_gears_coefficients[m_gear]*m_final_drive*m_gears_eff)/m_inertia_coef; btScalar engine_rpm = m_engine_rpm + rads2rpm(acceleration)*step; if (m_gear == 0) { to_rear_wheel_rpm = engine_rpm/(m_gears_coefficients[m_gear]*m_gears_eff); to_rear_wheel_rpm *= 0.2f; //? wheelInfo2.m_engine_force = wheelInfo3.m_engine_force = Fdrive; wheelInfo2.m_rpm = wheelInfo3.m_rpm = to_rear_wheel_rpm; if (to_rear_wheel_rpm > (m_rpm_data[m_graphs_size-1]*m_throttle)/(m_gears_coefficients[m_gear]*m_final_drive*m_gears_eff)) { to_rear_wheel_rpm = (m_rpm_data[m_graphs_size-1]*m_throttle)/(m_gears_coefficients[m_gear]*m_final_drive*m_gears_eff); } } else if (m_gear == 1) { to_rear_wheel_rpm = 0.0f; wheelInfo2.m_engine_force = wheelInfo3.m_engine_force = btScalar(0.0f); wheelInfo2.m_rpm = wheelInfo3.m_rpm = to_rear_wheel_rpm = 0.0f; } else { to_rear_wheel_rpm = engine_rpm/(m_gears_coefficients[m_gear]*m_final_drive*m_gears_eff); wheelInfo2.m_engine_force = wheelInfo3.m_engine_force = Fdrive; wheelInfo2.m_rpm = wheelInfo3.m_rpm = to_rear_wheel_rpm; if (to_rear_wheel_rpm > (m_rpm_data[m_graphs_size-1]*m_throttle)/(m_gears_coefficients[m_gear]*m_final_drive*m_gears_eff)) { to_rear_wheel_rpm = (m_rpm_data[m_graphs_size-1]*m_throttle)/(m_gears_coefficients[m_gear]*m_final_drive*m_gears_eff); } } btScalar rear_wheel_delta = rpm2rads(to_rear_wheel_rpm)*step; // // // ///////////////////////////// ///////////////////////////// // // Update wheel rotation // if (wheelInfo0.m_brake > btScalar(0.0f)) delta0 = btScalar(0.0f); if (wheelInfo1.m_brake > btScalar(0.0f)) delta1 = btScalar(0.0f); if (wheelInfo2.m_brake > btScalar(0.0f)) { delta2 = btScalar(0.0f); rear_wheel_delta = btScalar(0.0f); } if (wheelInfo3.m_brake > btScalar(0.0f)) { delta3 = btScalar(0.0f); rear_wheel_delta = btScalar(0.0f); } // 0 if (wheelInfo0.m_raycastInfo.m_isInContact) { wheelInfo0.m_rotation += delta0; wheelInfo0.m_rpm = w0_rpm; } else { wheelInfo0.m_rotation *= 0.99f; } // 1 if (wheelInfo1.m_raycastInfo.m_isInContact) { wheelInfo1.m_rotation += delta1; wheelInfo1.m_rpm = w1_rpm; } else { wheelInfo1.m_rotation *= 0.99f; } // 2 if ( wheelInfo2.m_raycastInfo.m_isInContact && ( fabs(rear_wheel_delta) < fabs(delta2) ) ) { wheelInfo2.m_rotation += delta2; } else { if ((m_throttle > btScalar(0.0f)) && (m_gear != 1)) { if (m_gear == 0) { wheelInfo2.m_rotation -= rear_wheel_delta; } else { wheelInfo2.m_rotation += rear_wheel_delta; } } } // 3 if ( wheelInfo3.m_raycastInfo.m_isInContact && ( fabs(rear_wheel_delta) < fabs(delta3) ) ) { wheelInfo3.m_rotation += delta3; } else { if ((m_throttle > btScalar(0.0f)) && (m_gear != 1)) { if (m_gear == 0) { wheelInfo3.m_rotation -= rear_wheel_delta; } else { wheelInfo3.m_rotation += rear_wheel_delta; } } } // // ///////////////////////////// }
void dns_cli::process_command(const std::string& cmd, const std::string& args) { std::vector<std::string> argv; boost::split(argv, args, boost::is_any_of(" "), boost::token_compress_on); //std::stringstream ss(args); TODO: Unnecessary? const dns_db_ptr db = std::dynamic_pointer_cast<dns_db>(client()->get_chain()); const dns_wallet_ptr wallet = std::dynamic_pointer_cast<dns_wallet>(client()->get_wallet()); if (cmd == "bid_on_domain") { if (check_unlock()) { FC_ASSERT(argv.size() == 3); // cmd name amount std::string name = argv[1]; asset bid = asset(uint64_t(atoi(argv[2].c_str()))); signed_transactions tx_pool; auto tx = wallet->bid_on_domain(name, bid, tx_pool, *db); client()->broadcast_transaction(tx); } } else if (cmd == "auction_domain") { if (check_unlock()) { FC_ASSERT(argv.size() == 3); // cmd name price std::string name = argv[1]; asset price = asset(uint64_t(atoi(argv[2].c_str()))); signed_transactions tx_pool; auto tx = wallet->auction_domain(name, price, tx_pool, *db); client()->broadcast_transaction(tx); } } else if (cmd == "transfer_domain") { if (check_unlock()) { FC_ASSERT(argv.size() == 3); // cmd name to std::string name = argv[1]; auto to_owner = bts::blockchain::address(argv[2]); signed_transactions tx_pool; auto tx = wallet->transfer_domain(name, to_owner, tx_pool, *db); client()->broadcast_transaction(tx); } } else if (cmd == "update_domain_record") { if (check_unlock()) { FC_ASSERT(argv.size() == 3); // cmd name path std::string name = argv[1]; asset bid = asset(uint64_t(atoi(argv[2].c_str()))); signed_transactions tx_pool; auto tx = wallet->bid_on_domain(name, bid, tx_pool, *db); client()->broadcast_transaction(tx); } // convert arbitrary json value to string..., this validates that it parses // properly. //fc::variant val = fc::json::from_string(json_value); } else if (cmd == "list_active_auctions") { FC_ASSERT(argv.size() == 1); auto active_auctions = get_active_auctions(*db); for (auto output : active_auctions) { auto dns_output = to_domain_output(output); std::cout << "[" << output.amount.get_rounded_amount() << "] " << dns_output.name << "\n"; } } else if (cmd == "lookup_domain_record") { FC_ASSERT(argv.size() == 2); std::string name = argv[1]; auto value = lookup_value(name, *db); std::string record; from_variant(value, record); std::cout << record << "\n"; } else { cli::process_command(cmd, args); } }