Exemplo n.º 1
0
/* 启动星球运行支持
*/
static void* _STInitPlanet(void* _v) {
    struct configOption *confOpt;
    char tmpstr[ALLOW_PATH_SIZE] = {""};


    /* 游戏服务端初始化 */
    confOpt = configGet(g_conf, "planet_server", "relative_path");
    if (confOpt) {

        if (confOpt->valueLen > ALLOW_PATH_SIZE) {
            trvExit(0, "星球文件地址太长");
        }
        confOptToStr(confOpt, tmpstr);
        snprintf(g_srvPlanetdir, ALLOW_PATH_SIZE, "%s/../planet/%s", g_basedir, tmpstr);
        STServerInit();
    }


    /* 游戏客户端初始化 */
    confOpt = configGet(g_conf, "planet_client", "relative_path");
    if (confOpt) {

        if (confOpt->valueLen > ALLOW_PATH_SIZE) {
            trvExit(0, "星球文件地址太长");
        }
        confOptToStr(confOpt, tmpstr);
        snprintf(g_cliPlanetdir, ALLOW_PATH_SIZE, "%s/../planet/%s", g_basedir, tmpstr);
        STClientInit();
    }

    return NULL;
}
Exemplo n.º 2
0
// Password authentication for admin interface
int myPassFn(HttpdConnData *connData, int no, char *user, int userLen, char *pass, int passLen)
 {
  if(no==0)
   {
    os_strncpy(user, configGet()->admin_user, userLen);
    os_strncpy(pass, configGet()->admin_pass, passLen);
    return 1;
   }
  return 0;
 }
Exemplo n.º 3
0
int Hdf::compare(const char *v2) const {
  const char *v1 = configGet();
  if (v1 == nullptr && v2 == nullptr) return 0;
  if (v1 == nullptr) return -1;
  if (v2 == nullptr) return 1;
  return strcmp(v1, v2);
}
Exemplo n.º 4
0
double Hdf::configGetDouble(double defValue /* = 0 */) const {
  const char *v = configGet();
  if (v == nullptr) return defValue;

  char *endptr = nullptr;
  double n = strtod(v, &endptr);
  if (!endptr && !*endptr) {
    throw HdfDataTypeException(this, "double", v);
  }

  return n;
}
Exemplo n.º 5
0
uint64_t Hdf::getUInt(uint64_t defValue, const char *type, uint64_t mask) const {
  const char *v = configGet();
  if (v == nullptr) return defValue;

  char *endptr = nullptr;
  int64_t n = strtoull(v, &endptr, 0);
  if ((!endptr && !*endptr) || (mask && ((uint64_t)n & mask))) {
    throw HdfDataTypeException(this, type, v);
  }

  return n;
}
Exemplo n.º 6
0
int64_t Hdf::getInt(int64_t defValue, const char *type, int64_t maxValue) const {
  const char *v = configGet();
  if (v == nullptr) return defValue;

  char *endptr = nullptr;
  int64_t n = strtoll(v, &endptr, 0);
  if ((!endptr && !*endptr) ||
      (maxValue && (n > maxValue || n < (- maxValue - 1)))) {
    throw HdfDataTypeException(this, type, v);
  }

  return n;
}
Exemplo n.º 7
0
// Initialize wifi, sensors and push data
void ICACHE_FLASH_ATTR init_done(void)
 {
  // Init wifi IP configuration
  configInitIP();

  // Init sensors
  sensorsInit();

  if(configGet()->sensor_mode==MODE_NORMAL)
   {
    // Normal mode
    pushSensorData();
   } else {
    // Configuration mode
    statusLed(LED_BLINK);
   }
 }
Exemplo n.º 8
0
/* 启动网络
*/
static void* _NTInit(void* _v) {
    pthread_mutex_lock(&g_rootThreadMutex);

    int listenPort;
    struct configOption *confOpt;
    char tmpstr[TMPSTR_SIZE] = {""};

    confOpt = configGet(g_conf, "net_server", "port");

    if (NULL != confOpt) {

        if (confOpt->valueLen > TMPSTR_SIZE) {
            trvExit(0, "监听端口太大");
        }

        memcpy(tmpstr, confOpt->value, confOpt->valueLen);
        tmpstr[confOpt->valueLen] = 0;
        listenPort = atoi(tmpstr);
    }
    else listenPort = -1; /* 输入一个不正常的监听端口,意味着不监听 */


    if (ERRNO_ERR == NTInit(listenPort)) {
        trvExit(0, "初始化网络失败");
    }

    /*
    if(aeCreateTimeEvent(g_server.el, 1, serverCron, NULL, NULL) == AE_ERR) {
        trvLogE("Can't create the serverCron time event.");
        exit(1);
    }
    */


    aeSetBeforeSleepProc(g_server.el, beforeSleep);

    pthread_mutex_unlock(&g_rootThreadMutex);

    pthread_cond_signal(&g_rootThreadCond);

    aeMain(g_server.el);
    aeDeleteEventLoop(g_server.el);

    return NULL;
}
Exemplo n.º 9
0
int motor_adc_init(void)
{
	_shunt_resistance = configGet("mot_i_shunt_mr") / 1000.0f;

	chSysDisable();

	RCC->AHBENR |= RCC_AHBENR_DMA1EN;  // Never disabled

	RCC->CFGR &= ~RCC_CFGR_ADCPRE;
#if STM32_PCLK2 == 72000000
	// ADC clock 72 / 6 = 12 MHz
	RCC->CFGR |= RCC_CFGR_ADCPRE_DIV6;
#else
#  error "What's wrong with PCLK2?"
#endif
	chSysEnable();

	enable();

	return 0;
}
Exemplo n.º 10
0
bool Hdf::configGetBool(bool defValue /* = false */) const {
  const char *v = configGet();
  if (v == nullptr) return defValue;
  return convertRawConfigToBool(v);
}
Exemplo n.º 11
0
std::string Hdf::configGetString(const std::string &defValue /* = "" */) const {
  const char *v = configGet();
  if (v == nullptr) return defValue;
  return v;
}
Exemplo n.º 12
0
static void configure(void)
{
	_params.timing_advance_deg64        = configGet("mot_tim_adv") * 64 / 60;
	_params.motor_bemf_window_len_denom = configGet("mot_bemf_win_den");
	_params.bemf_valid_range_pct128     = configGet("mot_bemf_range") * 128 / 100;
	_params.zc_failures_max  = configGet("mot_zc_fails_max");
	_params.zc_detects_min   = configGet("mot_zc_dets_min");
	_params.comm_period_max  = configGet("mot_comm_per_max") * HNSEC_PER_USEC;
	_params.comm_blank_hnsec = configGet("mot_blank_usec") * HNSEC_PER_USEC;

	_params.spinup_timeout              = configGet("mot_spup_to_ms") * HNSEC_PER_MSEC;
	_params.spinup_start_comm_period    = configGet("mot_spup_st_cp") * HNSEC_PER_USEC;
	_params.spinup_end_comm_period      = configGet("mot_spup_en_cp") * HNSEC_PER_USEC;
	_params.spinup_num_good_comms       = configGet("mot_spup_gcomms");
	_params.spinup_duty_cycle_increment = configGet("mot_spup_dc_inc");

	/*
	 * Validation
	 */
	if (_params.comm_period_max > motor_timer_get_max_delay_hnsec()) {
		_params.comm_period_max = motor_timer_get_max_delay_hnsec();
	}

	if (_params.spinup_end_comm_period > _params.comm_period_max) {
		_params.spinup_end_comm_period = _params.comm_period_max;
	}

	_params.adc_sampling_period = motor_adc_sampling_period_hnsec();

	printf("Motor: RTCTL config: Max comm period: %u usec, BEMF window denom: %i\n",
		(unsigned)(_params.comm_period_max / HNSEC_PER_USEC),
		_params.motor_bemf_window_len_denom);
}
Exemplo n.º 13
0
int main(int argc, char *argv[]) {
    struct configOption *confOpt;
    char tmpstr[ALLOW_PATH_SIZE] = {""};
    pthread_t ntid;

    g_logdir = NULL;
    g_logF = stderr;
    g_logFInt = STDERR_FILENO;

    setlocale(LC_ALL,"");

    zmalloc_enable_thread_safeness();

    snprintf(tmpstr, ALLOW_PATH_SIZE, "%s/../", argv[0]);
    if (NULL == realpath(tmpstr, g_basedir)) {
        trvExit(0, "获取当前路径失败");
    }

    g_conf = initConfig();

    snprintf(tmpstr, ALLOW_PATH_SIZE, "%s/../conf/default.conf", g_basedir);
    configRead(g_conf, tmpstr);

    if (argc > 1) configRead(g_conf, argv[1]); /* argv[1] 是配置文件路径 */

    if (NULL == g_conf->contents) {
        trvExit(0, "请选择配置文件");
    }

    confOpt = configGet(g_conf, "log", "dir");
    if (confOpt) {
        g_logdir = (char *)zmalloc(confOpt->valueLen+1);
        memcpy(g_logdir, confOpt->value, confOpt->valueLen);
        g_logdir[confOpt->valueLen] = 0x00;
        g_logF = fopen(g_logdir, "a+");
        g_logFInt = fileno(g_logF);
    }

    signal(SIGHUP, SIG_IGN);
    signal(SIGPIPE, SIG_IGN);
    setupSignalHandlers();


    /**
     * 主线程睡眠,等待网络就绪
     * 单独开一个线程处理网路
     */
    pthread_mutex_lock(&g_rootThreadMutex);
    pthread_create(&ntid, NULL, _NTInit, NULL);
    pthread_cond_wait(&g_rootThreadCond, &g_rootThreadMutex);
    pthread_mutex_unlock(&g_rootThreadMutex);


    _STInitPlanet(NULL);


    /* 主线程睡眠,避免退出进程 */
    pthread_cond_wait(&g_rootThreadCond, &g_rootThreadMutex);
    pthread_mutex_unlock(&g_rootThreadMutex);

    return 0;
}
Exemplo n.º 14
0
Arquivo: motor.c Projeto: branux/sapog
static void configure(void)
{
	_params.dc_min_voltage    = configGet("mot_v_min");
	_params.dc_spinup_voltage = configGet("mot_v_spinup");
	_params.dc_step_max    = configGet("mot_dc_accel");
	_params.dc_slope       = configGet("mot_dc_slope");

	_params.poles = configGet("mot_num_poles");
	_params.reverse = configGet("ctl_dir");

	_params.comm_period_limit = motor_rtctl_get_min_comm_period_hnsec();
	_params.rpm_max = comm_period_to_rpm(_params.comm_period_limit);
	_params.rpm_min = configGet("mot_rpm_min");

	_params.current_limit = configGet("mot_i_max");
	_params.current_limit_p = configGet("mot_i_max_p");

	_params.voltage_current_lowpass_tau = 1.0f / configGet("mot_lpf_freq");
	_params.num_unexpected_stops_to_latch = configGet("mot_stop_thres");

	printf("Motor: RPM range: [%u, %u]; poles: %i\n", _params.rpm_min, _params.rpm_max, _params.poles);
}