Exemple #1
0
/*
 *      complex(kind=8) raised to a real(kind=8) = _CTOR
 *
 *	x = a+b*i
 *
 *	if ((x == 0+0*i) && (y == 0)) then return(NAN)
 *	if (x == 0+0*i) then return(0+0*i)
 *	if (y == 0) then return(1+0*i)
 */
void
_CTOR(c_complex_t *ret_val,
	c_complex_t x,
	_f_real8 *r)
{
	_f_real8 __atan2(_f_real8 x, _f_real8 y);
	_f_real8 __cos(_f_real8 x);
	_f_real8 __exp(_f_real8 x);
	_f_real8 __log(_f_real8 x);
	_f_real8 __sin(_f_real8 x);
	_f_real8 _CABS(c_complex_t z);
	_f_real8 y = *r;
	_f_real8 one;
	_f_real8 two;
	if (x.real == (_f_real8) 0.0 && x.imag == (_f_real8) 0.0) {
		if (y == (_f_real8) 0.0) {
			ret_val->real = _SGL_NaN;
			ret_val->imag = _SGL_NaN;
		}
		else {
			ret_val->real = (_f_real8) 0.0;
			ret_val->imag = (_f_real8) 0.0;
		}
		return;
	}
	one = y * __atan2(x.imag, x.real);
	two = y * __log(_CABS(x));
	ret_val->real = __exp(two) * __cos(one);
	ret_val->imag = __exp(two) * __sin(one);
}
Exemple #2
0
void __log_pdu(const char *func, int line, int level, struct PDU *pdu)
{
	unsigned char char_buf[BUFFER_SIZE];
	int char_cnt = 0;
	unsigned char *buf;
	int i;

	if (log_level < level)
		return;

	buf = (void *)&pdu->bhs;
	__log(func, line, LOG_DEBUG, level, "BHS: (%p)", buf);
	for (i = 0; i < BHS_SIZE; i++)
		dump_char(*buf++);
	dump_line();

	buf = (void *)pdu->ahs;
	__log(func, line, LOG_DEBUG, level, "AHS: (%p)", buf);
	for (i = 0; i < pdu->ahssize; i++)
		dump_char(*buf++);
	dump_line();

	buf = (void *)pdu->data;
	__log(func, line, LOG_DEBUG, level, "Data: (%p)", buf);
	for (i = 0; i < pdu->datasize; i++)
		dump_char(*buf++);
	dump_line();
}
static void read_triggers(void)
{
  File f = cfg_file;
  String line;
  uint32_t pos = 0;

  Serial.println("reading trigger list");

  if (!f)
    return;

  __log("DBG: %s: f.available=%d\n", __func__, f.available());
  while (f.available()) {
    __log("DBG: read_triggers: position %u\n", pos);
    //Serial.printf("- pos %u\n", pos);

    if (!f.seek(pos, SeekSet)) {
      Serial.println("read_triggers: failed seek\n");
      break;
    }

    line = f.readStringUntil('\n');
    if (!line)
      break;
    // is line null if this fails?
    
    if (line.startsWith("[logic") ||
        line.startsWith("[input") ||
        line.startsWith("[output")) {
      String section = get_section(line);
      read_trigger(section.c_str());
    }
    pos += line.length() + 1;
  }
}
static bool read_trigger_timer(class timer_trigger *tt, const char *section, char *buff, int buff_sz)
{
  unsigned long time;
  bool ok;
  
  if (!tt)
    return false;

  tt->set_length(1000UL);   // default is 1sec

  ok = cfgfile.getValue(section, "time", buff, buff_sz);
  if (!ok)
    ok = cfgfile.getValue(section, "length", buff, buff_sz);
  if (ok) {
    if (!parse_time(buff, &time)) {
      __log("ERR: failed to parse time %s\n", buff);
      return false;
    }

    __log("time set to %lu\n", time);
    tt->set_length(time);
  }

  return true;
}
Exemple #5
0
void __noreturn log_errno(const char *str, ...)
{
    va_list ap;
    char *buff;

    va_start(ap, str);
    (void) vasprintf(&buff, str, ap);
    va_end(ap);

    __log("%s: %s (%d): %s\n", prog, buff, errno, strerror(errno));
    __log("%s: error is not recoverable, terminating now...\n", prog);
    exit(EXIT_FAILURE);
}
Exemple #6
0
void __noreturn error_nret(const char *str, ...)
{
    va_list ap;
    char *buff;

    va_start(ap, str);
    vasprintf(&buff, str, ap); 
    va_end(ap);

    __log(buff);
    __log("%s: error is not recoverable, terminating now...\n", prog);
    exit(EXIT_FAILURE);
}
Exemple #7
0
void error(int error_type, const char *str, ...)
{
    va_list va;
    char *buff;

    va_start(va, str);
    (void) vasprintf(&buff, str, va);
    va_end(va);

    if (error_type == LOG_NULL) {       /* special type for logging */    
        __log("%s: %s", prog, buff);
    } else {
        __log("%s: %s: %s", prog, type_strings[error_type], buff);
    }
}
Exemple #8
0
int raft_recv_requestvote(raft_server_t* me_, int node, msg_requestvote_t* vr,
                          msg_requestvote_response_t *r)
{
    raft_server_private_t* me = (raft_server_private_t*)me_;

    if (raft_get_current_term(me_) < vr->term)
        me->voted_for = -1;

    if (vr->term < raft_get_current_term(me_) ||
        /* we've already voted */
        -1 != me->voted_for ||
        /* we have a more up-to-date log */
        vr->last_log_idx < me->current_idx)
        r->vote_granted = 0;
    else
    {
        raft_vote(me_, node);
        r->vote_granted = 1;
    }

    __log(me_, "node requested vote: %d replying: %s",
          node, r->vote_granted == 1 ? "granted" : "not granted");

    r->term = raft_get_current_term(me_);
    return 0;
}
Exemple #9
0
int raft_recv_requestvote(raft_server_t* me_, int node, msg_requestvote_t* vr)
{
    raft_server_private_t* me = (void*)me_;
    msg_requestvote_response_t r;

    if (raft_get_current_term(me_) < vr->term)
    {
        me->voted_for = -1;
    }

    if (vr->term < raft_get_current_term(me_) ||
        /* we've already voted */
        -1 != me->voted_for ||
        /* we have a more up-to-date log */
        vr->last_log_idx < me->current_idx)
    {
        r.vote_granted = 0;
    }
    else
    {
        raft_vote(me_,node);
        r.vote_granted = 1;
    }

    __log(me_, NULL, "node requested vote: %d replying: %s",
            node, r.vote_granted == 1 ? "granted" : "not granted");

    r.term = raft_get_current_term(me_);
    if (me->cb.send)
        me->cb.send(me->cb_ctx, me, node, RAFT_MSG_REQUESTVOTE_RESPONSE,
                (void*)&r, sizeof(msg_requestvote_response_t));

    return 0;
}
Exemple #10
0
int raft_apply_entry(raft_server_t* me_)
{
    raft_server_private_t* me = (raft_server_private_t*)me_;

    /* Don't apply after the commit_idx */
    if (me->last_applied_idx == me->commit_idx)
        return -1;

    int log_idx = me->last_applied_idx + 1;

    raft_entry_t* e = raft_get_entry_from_idx(me_, log_idx);
    if (!e)
        return -1;

    __log(me_, NULL, "applying log: %d, id: %d size: %d",
          me->last_applied_idx, e->id, e->data.len);

    me->last_applied_idx++;
    if (me->cb.applylog)
        me->cb.applylog(me_, me->udata, e);

    /* voting cfg change is now complete */
    if (log_idx == me->voting_cfg_change_log_idx)
        me->voting_cfg_change_log_idx = -1;

    return 0;
}
Exemple #11
0
int raft_periodic(raft_server_t* me_, int msec_since_last_period)
{
    raft_server_private_t* me = (raft_server_private_t*)me_;

    __log(me_, "periodic elapsed time: %d", me->timeout_elapsed);

    switch (me->state)
    {
    case RAFT_STATE_FOLLOWER:
        if (me->last_applied_idx < me->commit_idx)
            if (-1 == raft_apply_entry(me_))
                return -1;
        break;
    }

    me->timeout_elapsed += msec_since_last_period;

    if (me->state == RAFT_STATE_LEADER)
    {
        if (me->request_timeout <= me->timeout_elapsed)
        {
            raft_send_appendentries_all(me_);
            me->timeout_elapsed = 0;
        }
    }
    else if (me->election_timeout <= me->timeout_elapsed)
        raft_election_start(me_);

    return 0;
}
Exemple #12
0
static void run_check(void) {
	int i;
	time_t curtime;
        struct tm *loctime;
	char fname[150];
	char info[150];

	if(taskq==0 && file_exists("/bin/taskq-check")) {
		run_daemon("taskq-check","/bin/taskq-check");
	}

	if(!file_exists(DIRQUE)) xmkdir(DIRQUE);
	for(i=0; i < listcnt;i++) {
		if(listq[i].cmd && listq[i].status==0) {
			curtime=time(NULL);
        		loctime=localtime(&curtime);
			memset(fname,0x0,sizeof(fname));
			snprintf(fname,sizeof(fname),"%s/%s",DIRQUE,listq[i].cmd);
			if(file_exists(fname)) continue;
			strftime(info, sizeof(info), "%d/%m/%Y %T",loctime);
			save_to_file(fname,"%s",info);
			//printf("[%s] Service %s down\n",info,listq[i].prog);
			memset(info,0x0,sizeof(info));
			__log(listq[i].prog);
		}
	}
}
Exemple #13
0
int raft_recv_requestvote_response(raft_server_t* me_, int node,
        msg_requestvote_response_t* r)
{
    raft_server_private_t* me = (void*)me_;

    __log(me_, NULL, "node responded to requestvote: %d status: %s",
            node, r->vote_granted == 1 ? "granted" : "not granted");

    if (raft_is_leader(me_))
        return 0;

    assert(node < me->num_nodes);

//    if (r->term != raft_get_current_term(me_))
//        return 0;

    if (1 == r->vote_granted)
    {
        int votes;

        me->votes_for_me[node] = 1;
        votes = raft_get_nvotes_for_me(me_);
        if (raft_votes_is_majority(me->num_nodes, votes))
            raft_become_leader(me_);
    }

    return 0;
}
Exemple #14
0
/*
 * Clean up Sana-II Interfaces
 *
 * Note: main interface queue is SNAFU after deinitializing
 */
void 
sana_deinit(void)
{
  struct sana_softc *ssc; 
  struct IOSana2Req *req;

  assert(SanaPort);

  while (ssq) {
    sana_down(ssq);
    if (ssq->ss_if.if_flags & IFF_RUNNING) {
      sana_unrun(ssq);
    }
    ssc = ssq;
    ssq = ssc->ss_next;
    /* Close device */ 
    req = CreateIOSana2Req(ssc);
    if (req) {
      CloseDevice((struct IORequest*)req);
      DeleteIOSana2Req(req);
    } else {
      __log(LOG_ERR, "sana_deinit(): Couldn't close device %s\n",
	  ssc->ss_name);
    }
  }

  if (SanaPort) {
    /* Clear possible pending signals */
    SetSignal(1<<SanaPort->mp_SigBit, 0L);
    DeleteMsgPort(SanaPort);
    SanaPort = NULL;
  }
}
static void read_depends(void)
{
  File f = cfg_file;
  String line;
  uint32_t pos = 0;

  Serial.println("reading dependency info");

  if (!f)
    return;

  while (true) {
    if (!f.seek(pos, SeekSet)) {
      Serial.println("read_triggers: failed seek\n");
      break;
    }

    if (f.available() <= 0)
      break;
    
    line = f.readStringUntil('\n');
    if (!line)
      break;
 
    if (line.startsWith("[dependency")) {
      String section = get_section(line);
      __log("DBG: found depdency section '%s'\n", section.c_str());
      read_dependency(section.c_str());
    }
    pos += line.length() + 1;
  }
}
Exemple #16
0
void _pb_log_fn(const char *func, const char *fmt, ...)
{
	va_list ap;
	pb_log("%s: ", func);
	va_start(ap, fmt);
	__log(fmt, ap);
	va_end(ap);
}
Exemple #17
0
void pb_log(const char *fmt, ...)
{
	va_list ap;
	va_start(ap, fmt);
	__log_timestamp();
	__log(fmt, ap);
	va_end(ap);
}
Exemple #18
0
void raft_become_follower(raft_server_t* me_)
{
    raft_server_private_t* me = (void*)me_;

    __log(me_, NULL, "becoming follower");

    raft_set_state(me_, RAFT_STATE_FOLLOWER);
    me->voted_for = -1;
}
Exemple #19
0
void raft_election_start(raft_server_t* me_)
{
    raft_server_private_t* me = (void*)me_;

    __log(me_, NULL, "election starting: %d %d, term: %d",
            me->election_timeout, me->timeout_elapsed, me->current_term);

    raft_become_candidate(me_);
}
Exemple #20
0
void log_info(const char *szMsg, ... )
{
       if (log_level < FCTLOG_LEVEL_INFO)
            return;
       
		va_list marker;
		va_start( marker ,szMsg );  
		__log(szMsg , FCTLOG_LEVEL_INFO, marker);
		va_end( marker );   
}
Exemple #21
0
void _pb_debug_fl(const char *func, int line, const char *fmt, ...)
{
	va_list ap;
	if (!debug)
		return;
	pb_log("%s:%d: ", func, line);
	va_start(ap, fmt);
	__log(fmt, ap);
	va_end(ap);
}
Exemple #22
0
void _pb_debug_fn(const char *func, const char *fmt, ...)
{
	va_list ap;
	if (!debug)
		return;
	pb_log("%s: ", func);
	va_start(ap, fmt);
	__log(fmt, ap);
	va_end(ap);
}
Exemple #23
0
int raft_recv_requestvote_response(raft_server_t* me_,
                                   raft_node_t* node,
                                   msg_requestvote_response_t* r)
{
    raft_server_private_t* me = (raft_server_private_t*)me_;

    __log(me_, node, "node responded to requestvote status: %s",
          r->vote_granted == 1 ? "granted" : "not granted");

    if (!raft_is_candidate(me_))
    {
        return 0;
    }
    else if (raft_get_current_term(me_) < r->term)
    {
        raft_set_current_term(me_, r->term);
        raft_become_follower(me_);
        return 0;
    }
    else if (raft_get_current_term(me_) != r->term)
    {
        /* The node who voted for us would have obtained our term.
         * Therefore this is an old message we should ignore.
         * This happens if the network is pretty choppy. */
        return 0;
    }

    __log(me_, node, "node responded to requestvote: %d status: %s ct:%d rt:%d",
          node, r->vote_granted == 1 ? "granted" : "not granted",
          me->current_term,
          r->term);

    if (1 == r->vote_granted)
    {
        if (node)
            raft_node_vote_for_me(node, 1);
        int votes = raft_get_nvotes_for_me(me_);
        if (raft_votes_is_majority(me->num_nodes, votes))
            raft_become_leader(me_);
    }

    return 0;
}
Exemple #24
0
void pb_debug(const char *fmt, ...)
{
	va_list ap;
	if (!debug)
		return;
	va_start(ap, fmt);
	__log_timestamp();
	__log(fmt, ap);
	va_end(ap);
}
Exemple #25
0
void log_error(const char *szMsg, ... )
{       
        if (log_level < FCTLOG_LEVEL_ERROR)
            return;
            
		va_list marker;
		va_start( marker ,szMsg );  
		__log(szMsg , FCTLOG_LEVEL_ERROR, marker);
		va_end( marker );   
	
}
Exemple #26
0
void log_warn(const char *szMsg, ... )
{
        if (log_level < FCTLOG_LEVEL_ALERT)
            return;
       
		va_list marker;
		va_start( marker ,szMsg );  
		__log(szMsg , FCTLOG_LEVEL_ALERT, marker);
		va_end( marker );   
	
}
Exemple #27
0
void __log_errno(int err, const char *file, const char *fn, int line, int level)
{
    char buf[128];
    int n;
    strerror_r(err, buf, sizeof buf);
    n = strlen(buf);
    buf[n] = '\n';
    buf[n+1] = 0;
    __log(file, fn, line, level, buf);

}
Exemple #28
0
void log_debug(const char *szMsg, ... )
{
       if (log_level < FCTLOG_LEVEL_DEBUG)
            return;
   		
		va_list marker;
		va_start( marker ,szMsg );  
		__log(szMsg , FCTLOG_LEVEL_DEBUG, marker);
		va_end( marker );   
		
	
}
static void read_dependency(const char *section)
{
  class trigger *target = cfg_lookup_trigger(section, "target");
  //class trigger *src;

  if (!target) {
    __log("DBG: no dependency target for '%s'\n", section);
    return;
  }

  read_dependency_srcs(target, section, "source", add_dep);
  // todo - if set/reset, add set/reset dependencies
}
Exemple #30
0
int raft_send_requestvote(raft_server_t* me_, int node)
{
    raft_server_private_t* me = (raft_server_private_t*)me_;
    msg_requestvote_t rv;

    __log(me_, "sending requestvote to: %d", node);

    rv.term = me->current_term;
    rv.last_log_idx = raft_get_current_idx(me_);
    if (me->cb.send_requestvote)
        me->cb.send_requestvote(me_, me->udata, node, &rv);
    return 0;
}