Beispiel #1
0
static config_t get_timer_values(const plc_t plc, 
                          const config_t state){
    config_t ret = state;
    sequence_t timers = get_sequence_entry(CONFIG_TIMER, ret);
    if(timers == NULL){
       
        return state;
    } 
    variable_t viter = timers->vars;
    int i = 0;
    long val = 0;
    BYTE out = 0;
    while(i < timers->size){
        if(viter != NULL) {
           
            val = plc->t[i].V;
            out = plc->t[i].Q;    
            char vs[TINYBUF];
            memset(vs,0, TINYBUF);
            sprintf(vs,"%ld",val); 
            viter->params = update_param(
                                viter->params,
                                "VALUE",
                                 vs);
            viter->params = update_param(
                                viter->params,
                                "OUT",
                                out?"TRUE":"FALSE");
                                             	        
	    }
	    viter = &(timers->vars)[++i];
    }
    return ret;
}
Beispiel #2
0
static config_t get_pulse_values(const plc_t plc, 
                          const config_t state){
    config_t ret = state;
    sequence_t pulses = get_sequence_entry(CONFIG_PULSE, ret);
    if(pulses == NULL){
       
        return state;
    } 
    variable_t viter = pulses->vars;
    int i = 0;
    BYTE out = 0;
    while(i < pulses->size){
        if(viter != NULL) {
        
            out = plc->s[i].Q;    
            viter->params = update_param(
                                viter->params,
                                "OUT",
                                out?"TRUE":"FALSE");
                                             	        
	    }
	    viter = &(pulses->vars)[++i];
    }
    return ret;
}
Beispiel #3
0
static config_t get_reg_values(const plc_t plc, 
                        const config_t state){
    config_t ret = state;
    sequence_t regs = get_sequence_entry(CONFIG_MREG, ret);
    if(regs == NULL){
       
        return state;
    } 
    variable_t viter = regs->vars;
    int i = 0;
    uint64_t val = 0;
    while(i < regs->size){
        if(viter != NULL) {
           
            val = plc->m[i].V;    
            char vs[TINYBUF];
            memset(vs,0, TINYBUF);
            sprintf(vs,"%ld", val); 
            viter->params = update_param(
                                viter->params,
                                "VALUE",
                                 vs);	        
	    }
	    viter = &(regs->vars)[++i];
    }
    return ret;
}
Beispiel #4
0
static config_t get_dio_values(const plc_t plc, 
                        const config_t state, 
                        BYTE type){
    config_t ret = state;
    sequence_t dios = get_sequence_entry(type, ret);
    if(dios == NULL || (
        type != CONFIG_DI &&
        type != CONFIG_DQ)) {
        
        return state;
    } 
    variable_t viter = dios->vars;
    int i = 0;
    BYTE val = 0;
    while(i < dios->size){
        if(viter != NULL) {
           
            if(type == CONFIG_DI){
                val = plc->di[i].I;
            } else if(type == CONFIG_DQ){
                val = plc->dq[i].Q;    
            }
            viter->params = update_param(
                                viter->params,
                                "STATE",
                                 val?"TRUE":"FALSE");	        
	        
	    }
	    viter = &(dios->vars)[++i];
    }
    return ret;
}
Beispiel #5
0
 int main()
{  
     int i,k;
     init();    /* initialize values*/
     //printf("va\t vb\t vc\t sa\t sb\t sc\t f\t pa\t pb\t pc\n");
    
      for(i=0;i<noi;i++)
      { update_param(i);
           //printf("a=%lf \n b=%lf\n c=%lf\n",gbesta,gbestb,gbestc);
           for(k=0;k<nop;k++)
           {/* following line to be added to view iterations*/
             //printf("%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",vc[k],sa[k],sb[k],sc[k],f[k],pbesta[k],pbestb[k],pbestc[k]);
             
             updatea(k);           /*update to find new a value*/
             updateb(k);         /*update particle to new b value*/
             updatec(k);
             cal_fn(k);           /* calculate function fn value*/
             find_pbest(k); 
              update_param(k);      /* find the personal best for this particle*/
          
           }
         
           find_gbest();         /* find global best position traversed so far*/
      }
   

    printf("a=%lf \n b=%lf\nc=%lf\n",gbesta,gbestb,gbestc);
    double mare=0,tmre=0;
    printf("Estimated effort \t actual effort\n");
    printf("---------------------------------------------\n");
    for(i=0;i<nop;i++)     /* calculation of efort values from final values of a,b,c*/
    {  
       gfunc=gbesta*pow(size[i],gbestb)+(gbestc*me[i]);
       mare=gfunc-eval[i];
       mare=mare<0?-mare:mare;
       tmre+=mare;
       printf("%lf\t\t %lf\n",gfunc,eval[i]);
    }
/* displaying the MARE value*/
    tmre=tmre/nop;
    printf("total mre=%lf\n",tmre);

return 0;
}
Beispiel #6
0
static config_t get_aio_values(const plc_t plc, 
                        const config_t state, 
                        BYTE type){
    config_t ret = state;
    sequence_t aios = get_sequence_entry(type, ret);
    if(aios == NULL || (
        type != CONFIG_AI &&
        type != CONFIG_AQ &&
        type != CONFIG_MVAR)) {
        
        return state;
    } 
    variable_t viter = aios->vars;
    int i = 0;
    double val = 0;
    char valbuf[TINYBUF] = "";
    while(i < aios->size){
        if(viter != NULL) {
           
            if(type == CONFIG_AI){
                val = plc->ai[i].V;
            } else if(type == CONFIG_AQ){
                val = plc->aq[i].V;    
            } else if(type == CONFIG_MVAR){
                val = plc->mr[i].V;    
            }
            sprintf(valbuf, "%f", val);
            viter->params = update_param(
                                viter->params,
                                "VALUE",
                                 valbuf);	        
	        
	    }
	    viter = &(aios->vars)[++i];
    }
    return ret;
}
Beispiel #7
0
void result::update(pool_node_ptr const& node, call_ptr const& _call)
{
	{
		boost::lock_guard<boost::mutex> lock(m_mutex);
		if(m_ready)
			return;

		BOOST_ASSERT(m_id);
		BOOST_ASSERT(!m_exception);
		BOOST_ASSERT(m_pointers.empty());

		if(_call && (_call->id() == m_id))
		{
			boost::swap(m_exception, _call->m_exception);
			if(!m_exception)
			{
				try
				{
					boost::swap(m_pointers, _call->m_pointers);
					update_param(*node, _call);
				}
				catch(...)
				{
					m_exception = current_exception();
				}
			}
		}
		else
		{
			m_exception = boost::make_shared<remote_error>
				(remote_error::invalid_return_type, "invalid return call");
		}
		m_ready = true;
	}
	m_condition.notify_all();
}
Beispiel #8
0
config_t store_seq_value(
                    const sequence_t s,
                    unsigned char idx,  
                    const char * key,
                    const char * value, 
                    config_t config){
    config_t conf = config;                
    if( s == NULL ||
        key == NULL || 
        value == NULL ||
        idx >= s->size) {     
        conf->err = CONF_ERR;
        
        return conf;
    }            
    variable_t var = &(s->vars[idx]);
    s->vars[idx].index = idx;
    if(!strcmp(key, "ID")){
        s->vars[idx].name = strdup_r(var->name, value);
    } else {
        s->vars[idx].params = update_param(s->vars[idx].params,key,value);    
    }   
    return conf;                       
}
Beispiel #9
0
static int decompress(struct nx842_crypto_ctx *ctx,
		      struct nx842_crypto_param *p,
		      struct nx842_crypto_header_group *g,
		      struct nx842_constraints *c,
		      u16 ignore)
{
	unsigned int slen = be32_to_cpu(g->compressed_length);
	unsigned int required_len = be32_to_cpu(g->uncompressed_length);
	unsigned int dlen = p->oremain, tmplen;
	unsigned int adj_slen = slen;
	u8 *src = p->in, *dst = p->out;
	u16 padding = be16_to_cpu(g->padding);
	int ret, spadding = 0;
	ktime_t timeout;

	if (!slen || !required_len)
		return -EINVAL;

	if (p->iremain <= 0 || padding + slen > p->iremain)
		return -EOVERFLOW;

	if (p->oremain <= 0 || required_len - ignore > p->oremain)
		return -ENOSPC;

	src += padding;

	if (slen % c->multiple)
		adj_slen = round_up(slen, c->multiple);
	if (slen < c->minimum)
		adj_slen = c->minimum;
	if (slen > c->maximum)
		goto usesw;
	if (slen < adj_slen || (u64)src % c->alignment) {
		/* we can append padding bytes because the 842 format defines
		 * an "end" template (see lib/842/842_decompress.c) and will
		 * ignore any bytes following it.
		 */
		if (slen < adj_slen)
			memset(ctx->sbounce + slen, 0, adj_slen - slen);
		memcpy(ctx->sbounce, src, slen);
		src = ctx->sbounce;
		spadding = adj_slen - slen;
		slen = adj_slen;
		pr_debug("using decomp sbounce buffer, len %x\n", slen);
	}

	if (dlen % c->multiple)
		dlen = round_down(dlen, c->multiple);
	if (dlen < required_len || (u64)dst % c->alignment) {
		dst = ctx->dbounce;
		dlen = min(required_len, BOUNCE_BUFFER_SIZE);
		pr_debug("using decomp dbounce buffer, len %x\n", dlen);
	}
	if (dlen < c->minimum)
		goto usesw;
	if (dlen > c->maximum)
		dlen = c->maximum;

	tmplen = dlen;
	timeout = ktime_add_ms(ktime_get(), DECOMP_BUSY_TIMEOUT);
	do {
		dlen = tmplen; /* reset dlen, if we're retrying */
		ret = ctx->driver->decompress(src, slen, dst, &dlen, ctx->wmem);
	} while (ret == -EBUSY && ktime_before(ktime_get(), timeout));
	if (ret) {
usesw:
		/* reset everything, sw doesn't have constraints */
		src = p->in + padding;
		slen = be32_to_cpu(g->compressed_length);
		spadding = 0;
		dst = p->out;
		dlen = p->oremain;
		if (dlen < required_len) { /* have ignore bytes */
			dst = ctx->dbounce;
			dlen = BOUNCE_BUFFER_SIZE;
		}
		pr_info_ratelimited("using software 842 decompression\n");
		ret = sw842_decompress(src, slen, dst, &dlen);
	}
	if (ret)
		return ret;

	slen -= spadding;

	dlen -= ignore;
	if (ignore)
		pr_debug("ignoring last %x bytes\n", ignore);

	if (dst == ctx->dbounce)
		memcpy(p->out, dst, dlen);

	pr_debug("decompress slen %x padding %x dlen %x ignore %x\n",
		 slen, padding, dlen, ignore);

	return update_param(p, slen + padding, dlen);
}
Beispiel #10
0
static int compress(struct nx842_crypto_ctx *ctx,
		    struct nx842_crypto_param *p,
		    struct nx842_crypto_header_group *g,
		    struct nx842_constraints *c,
		    u16 *ignore,
		    unsigned int hdrsize)
{
	unsigned int slen = p->iremain, dlen = p->oremain, tmplen;
	unsigned int adj_slen = slen;
	u8 *src = p->in, *dst = p->out;
	int ret, dskip = 0;
	ktime_t timeout;

	if (p->iremain == 0)
		return -EOVERFLOW;

	if (p->oremain == 0 || hdrsize + c->minimum > dlen)
		return -ENOSPC;

	if (slen % c->multiple)
		adj_slen = round_up(slen, c->multiple);
	if (slen < c->minimum)
		adj_slen = c->minimum;
	if (slen > c->maximum)
		adj_slen = slen = c->maximum;
	if (adj_slen > slen || (u64)src % c->alignment) {
		adj_slen = min(adj_slen, BOUNCE_BUFFER_SIZE);
		slen = min(slen, BOUNCE_BUFFER_SIZE);
		if (adj_slen > slen)
			memset(ctx->sbounce + slen, 0, adj_slen - slen);
		memcpy(ctx->sbounce, src, slen);
		src = ctx->sbounce;
		slen = adj_slen;
		pr_debug("using comp sbounce buffer, len %x\n", slen);
	}

	dst += hdrsize;
	dlen -= hdrsize;

	if ((u64)dst % c->alignment) {
		dskip = (int)(PTR_ALIGN(dst, c->alignment) - dst);
		dst += dskip;
		dlen -= dskip;
	}
	if (dlen % c->multiple)
		dlen = round_down(dlen, c->multiple);
	if (dlen < c->minimum) {
nospc:
		dst = ctx->dbounce;
		dlen = min(p->oremain, BOUNCE_BUFFER_SIZE);
		dlen = round_down(dlen, c->multiple);
		dskip = 0;
		pr_debug("using comp dbounce buffer, len %x\n", dlen);
	}
	if (dlen > c->maximum)
		dlen = c->maximum;

	tmplen = dlen;
	timeout = ktime_add_ms(ktime_get(), COMP_BUSY_TIMEOUT);
	do {
		dlen = tmplen; /* reset dlen, if we're retrying */
		ret = ctx->driver->compress(src, slen, dst, &dlen, ctx->wmem);
		/* possibly we should reduce the slen here, instead of
		 * retrying with the dbounce buffer?
		 */
		if (ret == -ENOSPC && dst != ctx->dbounce)
			goto nospc;
	} while (ret == -EBUSY && ktime_before(ktime_get(), timeout));
	if (ret)
		return ret;

	dskip += hdrsize;

	if (dst == ctx->dbounce)
		memcpy(p->out + dskip, dst, dlen);

	g->padding = cpu_to_be16(dskip);
	g->compressed_length = cpu_to_be32(dlen);
	g->uncompressed_length = cpu_to_be32(slen);

	if (p->iremain < slen) {
		*ignore = slen - p->iremain;
		slen = p->iremain;
	}

	pr_debug("compress slen %x ignore %x dlen %x padding %x\n",
		 slen, *ignore, dlen, dskip);

	return update_param(p, slen, dskip + dlen);
}
Beispiel #11
0
int execute(const cmd_t* cmd)
{
	int ret = 0;
	tsip_ssession_id_t sid;
	tsk_istr_t istr;

	if(!cmd){
		TSK_DEBUG_ERROR("Invalid parameter");
		return -1;
	}

	tsk_safeobj_lock(ctx);

	switch(cmd->type){
		case cmd_audio:
		case cmd_audiovideo:
			{
				TSK_DEBUG_INFO("command=audio/video");
				if((sid = invite_handle_cmd(cmd->type, cmd->opts)) != TSIP_SSESSION_INVALID_ID){
					if(cmd->sidparam){
						tsk_itoa(sid, &istr);
						update_param(cmd->sidparam, istr);
					}
				}
				break;
			}
		case cmd_config_session:
			{
				TSK_DEBUG_INFO("command=config-session");
				break;
			}
		case cmd_config_stack:
			{
				TSK_DEBUG_INFO("command=config-satck");
				ret = stack_config(cmd->opts);
				break;
			}
		case cmd_dtmf:
			{
				const opt_t* opt;
				TSK_DEBUG_INFO("command=dtmf");
				if(!(opt = opt_get_by_type(cmd->opts, opt_sid)) || tsk_strnullORempty(opt->value)){ /* --sid option */
					TSK_DEBUG_ERROR("++dtmf command need --sid option");
					break;
				}
				if(!(opt = opt_get_by_type(cmd->opts, opt_event)) || tsk_strnullORempty(opt->value)){ /* --event option */
					TSK_DEBUG_ERROR("++dtmf command need --event option");
					break;
				}
				invite_handle_cmd(cmd->type, cmd->opts);
				break;
			}
		case cmd_dump:
			{
				TSK_DEBUG_INFO("command=dump");
				ret = stack_dump();
				break;
			}
		case cmd_ect:
		{
			const opt_t* opt;
			TSK_DEBUG_INFO("command=ect");
			if((opt = opt_get_by_type(cmd->opts, opt_sid)) && !tsk_strnullORempty(opt->value)){
				TSK_DEBUG_ERROR("++ect command need --sid option");
				ret = -1;
				break;
			}
			if((opt = opt_get_by_type(cmd->opts, opt_to)) && !tsk_strnullORempty(opt->value)){
				TSK_DEBUG_ERROR("++ect command need --to option");
				ret = -1;
				break;
			}
			invite_handle_cmd(cmd->type, cmd->opts);
			break;
		}
		case cmd_exit:
			{
				TSK_DEBUG_INFO("command=exit");
				goto bail;
				break;
			}
		case cmd_file:
			{
				const opt_t* opt;
				TSK_DEBUG_INFO("command=file");
				if(!(opt = opt_get_by_type(cmd->opts, opt_path)) || tsk_strnullORempty(opt->value)){
					TSK_DEBUG_ERROR("++file command need --path option");
					break;
				}
				if((sid = invite_handle_cmd(cmd->type, cmd->opts)) != TSIP_SSESSION_INVALID_ID){
					if(cmd->sidparam){
						tsk_itoa(sid, &istr);
						update_param(cmd->sidparam, istr);
					}
				}
				break;
			}
		case cmd_hangup:
			{
				const opt_t* opt;
				TSK_DEBUG_INFO("command=hangup");
				if((opt = opt_get_by_type(cmd->opts, opt_sid)) && !tsk_strnullORempty(opt->value)){ /* --sid option */
					ret = session_hangup(tsk_atoll(opt->value));
				}
				else{
					TSK_DEBUG_ERROR("++hangup command need --sid option");
					ret = -1;
				}
				break;
			}
		case cmd_help:
			{
				TSK_DEBUG_INFO("command=help");
				cmd_print_help();
				break;
			}
		case cmd_hold:
			{
				const opt_t* opt;
				TSK_DEBUG_INFO("command=hold");
				if((opt = opt_get_by_type(cmd->opts, opt_sid)) && !tsk_strnullORempty(opt->value)){ /* --sid option */
					invite_handle_cmd(cmd->type, cmd->opts);
				}
				else{
					TSK_DEBUG_ERROR("++hold command need --sid option");
					ret = -1;
				}
				break;
			}
		case cmd_message:
			{
				TSK_DEBUG_INFO("command=message");
				if((sid = message_handle_cmd(cmd->type, cmd->opts)) != TSIP_SSESSION_INVALID_ID){
					if(cmd->sidparam){
						tsk_itoa(sid, &istr);
						update_param(cmd->sidparam, istr);
					}
				}
				break;
			}

		case cmd_options:
			{
				TSK_DEBUG_INFO("command=options");
				if((sid = options_handle_cmd(cmd->type, cmd->opts)) != TSIP_SSESSION_INVALID_ID){
					if(cmd->sidparam){
						tsk_itoa(sid, &istr);
						update_param(cmd->sidparam, istr);
					}
				}
				break;
			}
		case cmd_publish:
			{
				TSK_DEBUG_INFO("command=publish");
				if((sid = publish_handle_cmd(cmd->type, cmd->opts)) != TSIP_SSESSION_INVALID_ID){
					if(cmd->sidparam){
						tsk_itoa(sid, &istr);
						update_param(cmd->sidparam, istr);
					}
				}
				break;
			}
		case cmd_register:
			{
				TSK_DEBUG_INFO("command=register");
				if((sid = register_handle_cmd(cmd->type, cmd->opts)) != TSIP_SSESSION_INVALID_ID){
					if(cmd->sidparam){
						tsk_itoa(sid, &istr);
						update_param(cmd->sidparam, istr);
					}
				}
				break;
			}
		case cmd_resume:
			{
				const opt_t* opt;
				TSK_DEBUG_INFO("command=resume");
				if((opt = opt_get_by_type(cmd->opts, opt_sid)) && !tsk_strnullORempty(opt->value)){ /* --sid option */
					invite_handle_cmd(cmd->type, cmd->opts);
				}
				else{
					TSK_DEBUG_ERROR("++resume command need --sid option");
					ret = -1;
				}
				break;
			}
		case cmd_run:
			{
				TSK_DEBUG_INFO("command=run");
				ret = stack_run(cmd->opts);
				break;
			}
		case cmd_scenario:
			{
				TSK_DEBUG_INFO("command=scenario");
				break;
			}
		case cmd_sleep:
			{
				const opt_t* opt;
				double seconds;

				tsk_safeobj_unlock(ctx); /* beacuse of callback function */

				if((opt = opt_get_by_type(cmd->opts, opt_sec)) && !tsk_strnullORempty(opt->value)){ /* --sec option */
					seconds = strtod(opt->value, tsk_null); /* strtod() is better than atof() */
					if(seconds<=0){
						printf("\n==== Press ENTER to continue...\n");
						getchar();
					}
					else{
						TSK_DEBUG_INFO("Sleeping %f seconds", seconds);
						tsk_thread_sleep((uint64_t)(seconds * 1000));
					}
				}
				else{
					TSK_DEBUG_WARN("++sleep need --sec option.");
				}
				return 0; /* bail: will unlock again */
			}
		case cmd_sms:
			{
				TSK_DEBUG_INFO("command=sms");
				if((sid = message_handle_cmd(cmd->type, cmd->opts)) != TSIP_SSESSION_INVALID_ID){
					if(cmd->sidparam){
						tsk_itoa(sid, &istr);
						update_param(cmd->sidparam, istr);
					}
				}
				break;
			}
		case cmd_stop:
			{
				TSK_DEBUG_INFO("command=stop");
				tsip_stack_stop(ctx->stack);
				break;
			}
		case cmd_subscribe:
			{
				TSK_DEBUG_INFO("command=subscribe");
				if((sid = subscribe_handle_cmd(cmd->type, cmd->opts)) != TSIP_SSESSION_INVALID_ID){
					if(cmd->sidparam){
						tsk_itoa(sid, &istr);
						update_param(cmd->sidparam, istr);
					}
				}
				break;
			}
		case cmd_video:
			{
				TSK_DEBUG_INFO("command=video");
				break;
			}
		default:
			{
				TSK_DEBUG_ERROR("%d not a valid command.", cmd);
				break;
			}
	}

bail:
	tsk_safeobj_unlock(ctx);

	return ret;
}