Example #1
0
static void show_trace(FILE *stream, const erlang_trace *t)
{
    fprintf(stream,
            "Trace: Label: %ld, Flags: 0x%lx serial: %ld, prev: %ld From: ",
            t->label,t->flags,t->serial,t->prev);
    show_pid(stream,&t->from);
}
Example #2
0
	void show_welcome() {
		while(m_usb.isConnected()) {
			m_con.clear();
			m_con << "****************************************" << endl;
			m_con << "*     Welcome to Self-Balance Robot    *" << endl;
			m_con << "*                 " VERSION "               *" << endl;
			m_con << "****************************************" << endl;
			m_con << "[1] Calibrations" << endl;
			m_con << "[2] PID Control tuning" << endl;
			m_con << "[3] Save changed" << endl;
			m_con << "[4] Load Default" << endl;
			m_con << "[5] Dashboard" << endl;
			switch(m_con.getc()) {
			case '1' :
				show_mpu6050();
				break;
			case '2' :
				show_pid();
				break;
			case '3' :
				saveConfigure();
				break;
			case '4' :
				setDefault();
				break;
			case '5':
				dashboard();
				break;
			case 'H':
				m_con.printf("High-Water Mark:%d\n", getStackHighWaterMark());
				m_con.getc();
				break;
			}
		}
Example #3
0
static int _log_prepare(int level, struct __sourceloc where)
{
    if (level == LOG_LEVEL_SILENT)
        return 0;
    if (strbuf_is_empty(&logbuf))
        strbuf_init(&logbuf, _log_buf, sizeof _log_buf);
    open_logging(); // Put initial INFO message at start of log file
#ifndef ANDROID
    const char *levelstr = "UNKWN:";
    switch (level) {
    case LOG_LEVEL_FATAL:
        levelstr = "FATAL:";
        break;
    case LOG_LEVEL_ERROR:
        levelstr = "ERROR:";
        break;
    case LOG_LEVEL_INFO:
        levelstr = "INFO:";
        break;
    case LOG_LEVEL_WARN:
        levelstr = "WARN:";
        break;
    case LOG_LEVEL_DEBUG:
        levelstr = "DEBUG:";
        break;
    }
    strbuf_sprintf(&logbuf, "%-6.6s ", levelstr);
#endif
    if (show_pid())
        strbuf_sprintf(&logbuf, "[%5u] ", getpid());
    if (show_time()) {
        struct timeval tv;
        if (gettimeofday(&tv, NULL) == -1) {
            strbuf_puts(&logbuf, "NOTIME______ ");
        } else {
            struct tm tm;
            char buf[20];
            if (strftime(buf, sizeof buf, "%T", localtime_r(&tv.tv_sec, &tm)) == 0)
                strbuf_puts(&logbuf, "EMPTYTIME___ ");
            else
                strbuf_sprintf(&logbuf, "%s.%03u ", buf, tv.tv_usec / 1000);
        }
    }
    if (where.file) {
        strbuf_sprintf(&logbuf, "%s", _trimbuildpath(where.file));
        if (where.line)
            strbuf_sprintf(&logbuf, ":%u", where.line);
        if (where.function)
            strbuf_sprintf(&logbuf, ":%s()", where.function);
        strbuf_putc(&logbuf, ' ');
    } else if (where.function) {
        strbuf_sprintf(&logbuf, "%s() ", where.function);
    }
    strbuf_putc(&logbuf, ' ');
    return 1;
}
Example #4
0
static void show_term(const char *termbuf, int *index, FILE *stream)
{
    int type;
    char smallbuf[EISHOWBUF];
    int version;
    long num;
    double fnum;
    erlang_pid pid;
    erlang_port port;
    erlang_ref ref;
    int i, len;
    char *s;

    ei_get_type_internal(termbuf,index,&type,&len);

    switch (type) {
    case ERL_VERSION_MAGIC:
        /* just skip past this */
        ei_decode_version(termbuf,index,&version);
        show_term(termbuf,index,stream);
        break;

    case ERL_ATOM_EXT:
        ei_decode_atom(termbuf,index,smallbuf);
        fprintf(stream,"%s",smallbuf);
        break;

    case ERL_STRING_EXT:
        /* strings can be much longer than EISHOWBUF */
        if (len < EISHOWBUF) s = smallbuf;
        else if (!(s = malloc(len+1))) break; /* FIXME just break if can't? */

        ei_decode_string(termbuf,index,s);

        if (printable_list_p((uint8 *)s,len)) {
            /* just show it as it is */
            fprintf(stream,"\"%s\"",s);
        } else {
            /* show it as a list instead */
            fprintf(stream,"[");
            for (i=0; i<len; i++) {
                if (i > 0) fprintf(stream,", ");
                fprintf(stream,"%d",s[i]);
            }
            fprintf(stream,"]");
        }

        /* did we allocate anything? */
        if (s && (s != smallbuf)) free(s);

        break;

    /* FIXME add case using ei_decode_longlong */
    case ERL_SMALL_BIG_EXT:
    case ERL_SMALL_INTEGER_EXT:
    case ERL_INTEGER_EXT:
        if (ei_decode_long(termbuf,index,&num) == 0) {
            fprintf(stream,"%ld",num);
        } else {
            ei_decode_skip_bignum(termbuf,index,NULL);
            fprintf(stream,"#Bignum");
        }
        break;

    case ERL_FLOAT_EXT:
    case NEW_FLOAT_EXT:
        ei_decode_double(termbuf,index,&fnum);
        fprintf(stream,"%f",fnum);
        break;

    case ERL_PID_EXT:
        ei_decode_pid(termbuf,index,&pid);
        show_pid(stream,&pid);
        break;

    case ERL_SMALL_TUPLE_EXT:
    case ERL_LARGE_TUPLE_EXT:
        ei_decode_tuple_header(termbuf,index,&len);
        fprintf(stream,"{");
        for (i=0; i<len; i++) {
            if (i > 0) fprintf(stream,", ");
            show_term(termbuf,index,stream);
        }
        fprintf(stream,"}");
        break;

    case ERL_LIST_EXT:
        ei_decode_list_header(termbuf,index,&len);
        fprintf(stream,"[");
        for (i=0; i<len; i++) {
            if (i > 0) fprintf(stream,", ");
            show_term(termbuf,index,stream);
        }
        /* get the empty list at the end */
        ei_decode_list_header(termbuf,index,&len);
        fprintf(stream,"]");
        break;

    case ERL_NIL_EXT:
        ei_decode_list_header(termbuf,index,&len);
        fprintf(stream,"[]");
        break;

    case ERL_REFERENCE_EXT:
    case ERL_NEW_REFERENCE_EXT:
        ei_decode_ref(termbuf,index,&ref);
        fprintf(stream,"#Ref<%s",ref.node);
        for (i = 0; i < ref.len; i++) {
            fprintf(stream,".%u",ref.n[i]);
        }
        fprintf(stream,".%u>",ref.creation);
        break;

    case ERL_PORT_EXT:
        ei_decode_port(termbuf,index,&port);
        fprintf(stream,"#Port<%s.%u.%u>",port.node,port.id,port.creation);
        break;

    case ERL_BINARY_EXT:
        ei_decode_binary(termbuf,index,NULL,&num);
        fprintf(stream,"#Bin<%ld>",num);
        break;

    case ERL_LARGE_BIG_EXT:
        /* doesn't actually decode - just skip over it */
        /* FIXME if GMP, what to do here?? */
        ei_decode_skip_bignum(termbuf,index,NULL);
        fprintf(stream,"#Bignum");
        break;

    case ERL_FUN_EXT: {
        char atom[MAXATOMLEN];
        long idx;
        long uniq;
        const char* s = termbuf + *index, * s0 = s;
        int n_free;

        ++s;
        n_free = get32be(s);
        *index += s - s0;
        ei_decode_pid(termbuf, index, NULL); /* skip pid */
        ei_decode_atom(termbuf, index, atom); /* get module, index, uniq */
        ei_decode_long(termbuf, index, &idx);
        ei_decode_long(termbuf, index, &uniq);
        fprintf(stream,"#Fun<%s.%ld.%ld>", atom, idx, uniq);
        for (i = 0; i < n_free; ++i) {
            /* FIXME how to report error ?! */
            if (ei_skip_term(termbuf, index) != 0)
                fprintf(stderr,"<ERROR> show_msg: unknown type of term !");
        }
        break;
    }
    default:
        fprintf(stream,"#Unknown<%d.%d>",type,len);
        /* unfortunately we don't know how to skip over this type in
         * the buffer if we don't even know what it is, so we return.
         */
        return;
        break;
    }
}
Example #5
0
static void show_msg(FILE *stream, int direction, const erlang_msg *msg,
                     const char *buf)
{
    if (direction) fprintf(stream,"-> ");
    else fprintf(stream,"<- ");

    switch (msg->msgtype) {
    case ERL_LINK:
        fprintf(stream,"LINK From: ");
        show_pid(stream,&msg->from);
        fprintf(stream," To: ");
        show_pid(stream,&msg->to);
        break;

    case ERL_SEND:
        fprintf(stream,"SEND To: ");
        show_pid(stream,&msg->to);
        fprintf(stream,"\n   ");
        /* show the message */
        ei_efprint(stream,buf);
        break;

    case ERL_EXIT:
        fprintf(stream,"EXIT From: ");
        show_pid(stream,&msg->from);
        fprintf(stream," To: ");
        show_pid(stream,&msg->to);
        /* show the reason */
        fprintf(stream,"\n   Reason: ");
        ei_efprint(stream,buf);
        break;

    case ERL_UNLINK:
        fprintf(stream,"UNLINK From: ");
        show_pid(stream,&msg->from);
        fprintf(stream," To: ");
        show_pid(stream,&msg->to);
        break;

    case ERL_REG_SEND:
        fprintf(stream,"REG_SEND From: ");
        show_pid(stream,&msg->from);
        fprintf(stream," To: %s\n   ",msg->toname);
        /* show the message */
        ei_efprint(stream,buf);
        break;

    case ERL_GROUP_LEADER:
        fprintf(stream,"GROUP_LEADER From: ");
        show_pid(stream,&msg->from);
        fprintf(stream," To: ");
        show_pid(stream,&msg->to);
        break;

    case ERL_EXIT2:
        fprintf(stream,"EXIT2 From: ");
        show_pid(stream,&msg->from);
        fprintf(stream," To: ");
        show_pid(stream,&msg->to);
        /* show the reason */
        fprintf(stream,"\n   Reason: ");
        ei_efprint(stream,buf);
        break;

    /* the new TT stuff below */

    case ERL_EXIT_TT:
        fprintf(stream,"EXIT_TT From: ");
        show_pid(stream,&msg->from);
        fprintf(stream," To: ");
        show_pid(stream,&msg->to);
        fprintf(stream,"\n   ");
        show_trace(stream,&msg->token);
        /* show the reason */
        fprintf(stream,"\n   Reason: ");
        ei_efprint(stream,buf);
        break;

    case ERL_EXIT2_TT:
        fprintf(stream,"EXIT2_TT From: ");
        show_pid(stream,&msg->from);
        fprintf(stream," To: ");
        show_pid(stream,&msg->to);
        fprintf(stream,"\n   ");
        show_trace(stream,&msg->token);
        /* show the reason */
        fprintf(stream,"\n   Reason: ");
        ei_efprint(stream,buf);
        break;

    case ERL_SEND_TT:
        fprintf(stream,"SEND_TT To: ");
        show_pid(stream,&msg->to);
        fprintf(stream,"\n   ");
        show_trace(stream,&msg->token);
        fprintf(stream,"\n   ");
        /* show the message */
        ei_efprint(stream,buf);
        break;

    case ERL_REG_SEND_TT:
        fprintf(stream,"REG_SEND_TT From: ");
        show_pid(stream,&msg->from);
        fprintf(stream," To: %s\n   ",msg->toname);
        show_trace(stream,&msg->token);
        fprintf(stream,"\n   ");
        /* show the message */
        ei_efprint(stream,buf);
        break;

    default:
        fprintf(stream,"Unknown message type: %ld",msg->msgtype);
    }
    fprintf(stream,"\n");
}