void setOutput(Output p_output, int16_t p_value) { RC_ASSERT(p_output < Output_Count); RC_ASSERT(p_value == Out_Max || p_value == Out_Min || (p_value >= -358 && p_value <= 358)); s_values[p_output] = p_value; }
RIOTRtnE RServerCSLtr_Init(RServerCSLtr ** rtn_csLtr) { RC_ASSERT(*rtn_csLtr == NULL); RIOTRtnE ret; RServerCSLtr * csLtr = NULL; // Alloc memory and setting default value if ((csLtr = malloc(sizeof(RServerCSLtr))) == NULL) { RC_LOG_E("memory allocate failed!"); ret = RC_ERR_NOMEM; goto fail_and_exit; } memset(csLtr, 0, sizeof(RServerCSLtr)); csLtr->status = RC_STATUS_INITIAL; csLtr->sfd = 0; if (evhr_create(&csLtr->evhr) != EVHR_RTN_SUCCESS) { RC_LOG_E("evhr_create failed!"); ret = RC_ERR_NOMEM; goto fail_and_exit; } // RServerCSLtr initial success RC_LOG_D("RServerCSLtr initial success."); *rtn_csLtr = csLtr; return RC_SUCCESS; fail_and_exit: do_destroy(csLtr); return ret; }
void OutputChannelProcessor::setSource(OutputChannel p_source) { RC_TRACE("set source: %d", p_source); RC_ASSERT(p_source <= OutputChannel_Count); m_source = p_source; }
void Gyro::setType(Type p_type) { RC_TRACE("set type: %d", p_type); RC_ASSERT(p_type < Type_Count); m_type = p_type; }
void Gyro::setMode(Mode p_mode) { RC_TRACE("set mode: %d", p_mode); RC_ASSERT(p_mode < Mode_Count); m_mode = p_mode; }
void SwitchModifier::setIndex(Switch p_index) { RC_TRACE("set index: %d", p_index); RC_ASSERT(p_index <= Switch_Count); m_index = p_index; }
static void do_status_change(RServerCSLtr * csLtr, RIOTStatusE status) { RC_ASSERT(csLtr); RC_LOG_D("RServerCSLtr status change, old[%d] => new[%d]", csLtr->status, status); csLtr->status = status; }
RIOTRtnE RServerCSLtr_Stop(RServerCSLtr * csLtr) { RC_ASSERT(csLtr); do_stop(csLtr); return RC_SUCCESS; }
static void do_stop(RServerCSLtr * csLtr) { RC_ASSERT(csLtr); // stop dispatch if (csLtr->evhr) evhr_stop(csLtr->evhr); }
RIOTRtnE RServerCSLtr_Destroy(RServerCSLtr * csLtr) { RC_ASSERT(csLtr); RC_LOG_D("RServerCSLtr destroy now."); do_destroy(csLtr); RC_LOG_D("RServerCSLtr was destroy."); return RC_SUCCESS; }
static RIOTRtnE do_init(RServerCtx ** rtn_ctx) { RC_ASSERT(*rtn_ctx == NULL); RIOTRtnE ret; RServerCtx * ctx = NULL; if ((ctx = malloc(sizeof(RServerCtx))) == NULL) return RC_ERR_NOMEM; memset(ctx, 0, sizeof(RServerCtx)); ctx->status = RC_STATUS_INITIAL; ctx->cfg.port = RSERVER_CFG_DEFAULT_PORT; // Initial Evhr RC_LOG_D(" ==> [Evhr]"); if (evhr_create(&ctx->evhr) != EVHR_RTN_SUCCESS) { RC_LOG_E("Initial Evhr failed!"); ret = RC_ERR_NOMEM; goto error_return; } // Initial CusEv RC_LOG_D(" ==> [CusEv]"); if ((ctx->cusEv = evhr_cus_event_add( ctx->evhr, EVHR_PTR_TO_DATA(ctx), gRServerCusEvDispatch)) == NULL) { RC_LOG_E("Initial CusEv failed!"); ret = RC_ERR_NOMEM; goto error_return; } // Initial taskPool RC_LOG_D(" ==> [TaskPool]"); if (tpool_create(&ctx->taskPool, 5) != TPOOL_SUCCESS) { RC_LOG_E("Initial TaskPool failed!"); ret = RC_ERR_NOMEM; goto error_return; } // Initial RSUnit Socket RC_LOG_D(" ==> [RServerCSListener]"); if ((ret = RServerCSLtr_Init(&ctx->csLtr)) != RC_SUCCESS) { RC_LOG_E("Initial RServerCSListener failed! ret[%d]", ret); goto error_return; } *rtn_ctx = ctx; return RC_SUCCESS; error_return : do_destroy(ctx); return ret; }
RIOTRtnE RServerCSLtr_Start(RServerCSLtr * csLtr) { RC_ASSERT(csLtr); RIOTRtnE ret; EvhrEv * ev; // create csLtr and binding port if ((ret = rc_socket_create_and_bind(gRServerCtx->cfg.port, &csLtr->sfd)) != RC_SUCCESS) { RC_LOG_E("socket_create_and_bind failed! ret[%d]", ret); goto fail_and_exit; } // setting non-blocking if ((ret = rc_socket_setting_non_blocking(csLtr->sfd)) != RC_SUCCESS) { RC_LOG_E("socket_setting_non_blocking failed! ret[%d]", ret); goto fail_and_exit; } // start socket listen if (listen(csLtr->sfd, SOMAXCONN) == -1) { RC_LOG_E("socket listen failed!"); ret = RC_ERR; goto fail_and_exit; } // binding event to callback if ((ev = evhr_event_add( csLtr->evhr, csLtr->sfd, EVHR_EV_FLAG_CLOSE_FD_ON_DEL, EVHR_PTR_TO_DATA(csLtr), ctrl_session_accept, NULL, ctrl_session_err)) == NULL) { RC_LOG_E("binding event failed!"); ret = RC_ERR; goto fail_and_exit; } do_status_change(csLtr, RC_STATUS_RUNNING); evhr_dispatch(csLtr->evhr); do_status_change(csLtr, RC_STATUS_STOPPED); evhr_event_del(ev); return RC_SUCCESS; fail_and_exit: if (csLtr->sfd > 0) { close(csLtr->sfd); csLtr->sfd = 0; } do_status_change(csLtr, RC_STATUS_ERROR); return ret; }
static void do_status_change(RServerCtx * ctx, RIOTStatusE status) { RC_ASSERT(ctx); if (ctx->status == status) return; EvhrData data; data.u16 = (u16)(((u8) status << 0)) | (u16)(((u8) ctx->status) << 8); gRServerCusEvTrigger(CUS_EVT_SERVER_STATUS_CHANGE, data); RC_LOG_D("Server status change, old[%d] => new[%d]", ctx->status, status); ctx->status = status; }
void RotaryEncoder::setPinB(uint8_t p_pin) { RC_TRACE("set pin B: %u", p_pin); RC_ASSERT(p_pin != m_pinA); #ifdef RC_USE_EXTINT if (p_pin != m_pinB) { extint::disable(m_pinB); #endif m_pinB = p_pin; pinMode(m_pinB, m_pullUp ? INPUT_PULLUP : INPUT); #ifdef RC_USE_EXTINT extint::enable(m_pinB, extint::ISC_Change, RotaryEncoder::isr, this); } #endif }
int16_t getOutput(Output p_output) { RC_ASSERT(p_output < Output_Count); return s_values[p_output]; }
int16_t getInput(Input p_input) { RC_ASSERT(p_input < Input_Count); return s_values[p_input]; }
void setInput(Input p_input, int16_t p_value) { RC_ASSERT(p_input < Input_Count); RC_ASSERT_MINMAX(p_value, -358, 358); s_values[p_input] = p_value; }