Пример #1
0
static void jl_serialize_module(ios_t *s, jl_module_t *m)
{
    // set on every startup; don't save
    jl_sym_t *jhsym = jl_symbol("JULIA_HOME");
    writetag(s, jl_module_type);
    jl_serialize_value(s, m->name);
    jl_serialize_value(s, m->parent);
    size_t i;
    void **table = m->bindings.table;
    for(i=1; i < m->bindings.size; i+=2) {
        if (table[i] != HT_NOTFOUND &&
            !(table[i-1] == jhsym && m == jl_core_module)) {
            jl_binding_t *b = (jl_binding_t*)table[i];
            if (!(b->owner != m && m == jl_main_module)) {
                jl_serialize_value(s, b->name);
                jl_serialize_value(s, b->value);
                jl_serialize_value(s, b->type);
                jl_serialize_value(s, b->owner);
                write_int8(s, (b->constp<<2) | (b->exportp<<1) | (b->imported));
            }
        }
    }
    jl_serialize_value(s, NULL);
    if (m == jl_main_module) {
        write_int32(s, 1);
        jl_serialize_value(s, (jl_value_t*)jl_core_module);
    }
    else {
        write_int32(s, m->usings.len);
        for(i=0; i < m->usings.len; i++) {
            jl_serialize_value(s, (jl_value_t*)m->usings.items[i]);
        }
    }
}
Пример #2
0
static void jl_serialize_module(ios_t *s, jl_module_t *m)
{
    writetag(s, jl_module_type);
    jl_serialize_value(s, m->name);
    size_t i;
    void **table = m->bindings.table;
    for(i=1; i < m->bindings.size; i+=2) {
        if (table[i] != HT_NOTFOUND) {
            jl_binding_t *b = (jl_binding_t*)table[i];
            jl_serialize_value(s, b->name);
            jl_serialize_value(s, b->value);
            jl_serialize_value(s, b->type);
            write_int8(s, b->constp);
            write_int8(s, b->exportp);
        }
    }
    jl_serialize_value(s, NULL);
    table = m->macros.table;
    for(i=1; i < m->macros.size; i+=2) {
        if (table[i] != HT_NOTFOUND) {
            jl_serialize_value(s, table[i-1]);
            jl_serialize_value(s, table[i]);
        }
    }
    jl_serialize_value(s, NULL);
}
Пример #3
0
static void jl_serialize_tag_type(ios_t *s, jl_value_t *v)
{
    if (jl_is_struct_type(v)) {
        writetag(s, (jl_value_t*)jl_struct_kind);
        jl_serialize_value(s, jl_struct_kind);
        write_uint16(s, jl_tuple_len(((jl_struct_type_t*)v)->names));
        write_int32(s, ((jl_struct_type_t*)v)->uid);
        write_int32(s, ((jl_struct_type_t*)v)->size);
        write_int32(s, ((jl_struct_type_t*)v)->alignment);
        size_t nf = jl_tuple_len(((jl_struct_type_t*)v)->names);
        ios_write(s, (char*)&((jl_struct_type_t*)v)->fields[0], nf*sizeof(jl_fielddesc_t));
        jl_serialize_value(s, ((jl_struct_type_t*)v)->name);
        jl_serialize_value(s, ((jl_struct_type_t*)v)->parameters);
        jl_serialize_value(s, ((jl_struct_type_t*)v)->super);
        jl_serialize_value(s, ((jl_struct_type_t*)v)->names);
        jl_serialize_value(s, ((jl_struct_type_t*)v)->types);
        jl_serialize_value(s, ((jl_struct_type_t*)v)->ctor_factory);
        jl_serialize_value(s, ((jl_struct_type_t*)v)->env);
        jl_serialize_value(s, ((jl_struct_type_t*)v)->linfo);
        jl_serialize_fptr(s, ((jl_struct_type_t*)v)->fptr);
    }
    else if (jl_is_bits_type(v)) {
        writetag(s, jl_struct_kind);
        jl_serialize_value(s, jl_bits_kind);
        if (v == (jl_value_t*)jl_int32_type)
            write_uint8(s, 2);
        else if (v == (jl_value_t*)jl_bool_type)
            write_uint8(s, 3);
        else if (v == (jl_value_t*)jl_int64_type)
            write_uint8(s, 4);
        else
            write_uint8(s, 0);
        jl_serialize_value(s, ((jl_tag_type_t*)v)->name);
        jl_serialize_value(s, ((jl_bits_type_t*)v)->parameters);
        write_int32(s, ((jl_bits_type_t*)v)->nbits);
        jl_serialize_value(s, ((jl_bits_type_t*)v)->super);
        write_int32(s, ((jl_bits_type_t*)v)->uid);
    }
    else {
        assert(jl_is_tag_type(v));
        writetag(s, jl_tag_kind);
        jl_serialize_value(s, ((jl_tag_type_t*)v)->name);
        jl_serialize_value(s, ((jl_tag_type_t*)v)->parameters);
        jl_serialize_value(s, ((jl_tag_type_t*)v)->super);
    }
}
Пример #4
0
static void jl_serialize_tag_type(ios_t *s, jl_value_t *v)
{
    if (jl_is_struct_type(v)) {
        writetag(s, (jl_value_t*)jl_struct_kind);
        jl_serialize_value(s, jl_struct_kind);
        jl_serialize_value(s, ((jl_struct_type_t*)v)->name);
        jl_serialize_value(s, ((jl_struct_type_t*)v)->parameters);
        jl_serialize_value(s, ((jl_struct_type_t*)v)->super);
        jl_serialize_value(s, ((jl_struct_type_t*)v)->names);
        jl_serialize_value(s, ((jl_struct_type_t*)v)->types);
        jl_serialize_value(s, ((jl_struct_type_t*)v)->ctor_factory);
        jl_serialize_value(s, ((jl_struct_type_t*)v)->env);
        jl_serialize_value(s, ((jl_struct_type_t*)v)->linfo);
        jl_serialize_fptr(s, ((jl_struct_type_t*)v)->fptr);
        write_int32(s, ((jl_struct_type_t*)v)->uid);
    }
    else if (jl_is_bits_type(v)) {
        writetag(s, jl_struct_kind);
        jl_serialize_value(s, jl_bits_kind);
        if (v == (jl_value_t*)jl_int32_type)
            write_uint8(s, 2);
        else if (v == (jl_value_t*)jl_bool_type)
            write_uint8(s, 3);
        else if (v == (jl_value_t*)jl_int64_type)
            write_uint8(s, 4);
        else
            write_uint8(s, 0);
        jl_serialize_value(s, ((jl_tag_type_t*)v)->name);
        jl_serialize_value(s, ((jl_bits_type_t*)v)->parameters);
        write_int32(s, ((jl_bits_type_t*)v)->nbits);
        jl_serialize_value(s, ((jl_bits_type_t*)v)->super);
        write_int32(s, ((jl_bits_type_t*)v)->uid);
    }
    else {
        assert(jl_is_tag_type(v));
        writetag(s, jl_tag_kind);
        jl_serialize_value(s, ((jl_tag_type_t*)v)->name);
        jl_serialize_value(s, ((jl_tag_type_t*)v)->parameters);
        jl_serialize_value(s, ((jl_tag_type_t*)v)->super);
    }
}
Пример #5
0
/*
 * Attempt to release the lease.
 * Return 1 if succedded, 0 if not , and < 0 on errors.
 */
int
release(int fd, off_t offset, char *id, int force)
{
    char curr[taglen+1] = "";

    if (!force) {
        if (readtag(fd, offset, curr, 0) < 0)
            return -errno;

        if (!sameid(curr, id))
            return 0;
    }

    return writetag(fd, offset, freetag, 0) < 0 ? -1 : 1;
}
Пример #6
0
int
writetimestamp(int fd, off_t offset, const char *id, char *tag, long long *ts)
{
    struct timeval tv;
    long long t;
    int r;

    gettimeofday(&tv, 0);
    t = tv.tv_sec * 1000000ll + tv.tv_usec;
    buildtag(tag, id, t);
    r = writetag(fd, offset, tag, 1);
    if (r > 0)
        *ts = t;
    return r;
}
Пример #7
0
static void jl_serialize_value_(ios_t *s, jl_value_t *v)
{
    if (v == NULL) {
        write_uint8(s, Null_tag);
        return;
    }

    void **bp = ptrhash_bp(&ser_tag, v);
    if (*bp != HT_NOTFOUND) {
        write_as_tag(s, (uint8_t)(ptrint_t)*bp);
        return;
    }

    if (tree_literal_values) {
        // compressing tree
        if (!is_ast_node(v)) {
            writetag(s, (jl_value_t*)LiteralVal_tag);
            write_uint16(s, literal_val_id(v));
            return;
        }
    }
    else {
        bp = ptrhash_bp(&backref_table, v);
        if (*bp != HT_NOTFOUND) {
            write_uint8(s, BackRef_tag);
            write_int32(s, (ptrint_t)*bp);
            return;
        }
        ptrhash_put(&backref_table, v, (void*)(ptrint_t)ios_pos(s));
    }

    size_t i;
    if (jl_is_tuple(v)) {
        size_t l = ((jl_tuple_t*)v)->length;
        if (l <= 255) {
            writetag(s, jl_tuple_type);
            write_uint8(s, (uint8_t)l);
        }
        else {
            writetag(s, (jl_value_t*)LongTuple_tag);
            write_int32(s, l);
        }
        for(i=0; i < l; i++) {
            jl_serialize_value(s, jl_tupleref(v, i));
        }
    }
    else if (jl_is_symbol(v)) {
        size_t l = strlen(((jl_sym_t*)v)->name);
        if (l <= 255) {
            writetag(s, jl_symbol_type);
            write_uint8(s, (uint8_t)l);
        }
        else {
            writetag(s, (jl_value_t*)LongSymbol_tag);
            write_int32(s, l);
        }
        ios_write(s, ((jl_sym_t*)v)->name, l);
    }
    else if (jl_is_array(v)) {
        jl_array_t *ar = (jl_array_t*)v;
        writetag(s, (jl_value_t*)jl_array_type);
        jl_serialize_value(s, ar->type);
        jl_value_t *elty = jl_tparam0(ar->type);
        for (i=0; i < ar->ndims; i++)
            jl_serialize_value(s, jl_box_long(jl_array_dim(ar,i)));
        if (jl_is_bits_type(elty)) {
            size_t tot = ar->length * ar->elsize;
            ios_write(s, ar->data, tot);
        }
        else {
            for(i=0; i < ar->length; i++) {
                jl_serialize_value(s, jl_cellref(v, i));
            }
        }
    }
    else if (jl_is_expr(v)) {
        jl_expr_t *e = (jl_expr_t*)v;
        size_t l = e->args->length;
        if (l <= 255) {
            writetag(s, jl_expr_type);
            write_uint8(s, (uint8_t)l);
        }
        else {
            writetag(s, (jl_value_t*)LongExpr_tag);
            write_int32(s, l);
        }
        jl_serialize_value(s, e->head);
        jl_serialize_value(s, e->etype);
        for(i=0; i < l; i++) {
            jl_serialize_value(s, jl_exprarg(e, i));
        }
    }
    else if (jl_is_some_tag_type(v)) {
        jl_serialize_tag_type(s, v);
    }
    else if (jl_is_typevar(v)) {
        writetag(s, jl_tvar_type);
        jl_serialize_value(s, ((jl_tvar_t*)v)->name);
        jl_serialize_value(s, ((jl_tvar_t*)v)->lb);
        jl_serialize_value(s, ((jl_tvar_t*)v)->ub);
        write_int8(s, ((jl_tvar_t*)v)->bound);
    }
    else if (jl_is_function(v)) {
        writetag(s, jl_func_kind);
        jl_serialize_value(s, v->type);
        jl_function_t *f = (jl_function_t*)v;
        jl_serialize_value(s, (jl_value_t*)f->linfo);
        jl_serialize_value(s, f->env);
        if (f->linfo && f->linfo->ast &&
            (jl_is_expr(f->linfo->ast) || jl_is_tuple(f->linfo->ast)) &&
            f->fptr != &jl_trampoline) {
            write_int32(s, 0);
        }
        else {
            jl_serialize_fptr(s, f->fptr);
        }
    }
    else if (jl_is_lambda_info(v)) {
        writetag(s, jl_lambda_info_type);
        jl_lambda_info_t *li = (jl_lambda_info_t*)v;
        jl_serialize_value(s, li->ast);
        jl_serialize_value(s, (jl_value_t*)li->sparams);
        // don't save cached type info for code in the Base module, because
        // it might reference types in the old System module.
        if (li->module == jl_base_module)
            jl_serialize_value(s, (jl_value_t*)jl_null);
        else
            jl_serialize_value(s, (jl_value_t*)li->tfunc);
        jl_serialize_value(s, (jl_value_t*)li->name);
        jl_serialize_value(s, (jl_value_t*)li->specTypes);
        jl_serialize_value(s, (jl_value_t*)li->specializations);
        jl_serialize_value(s, (jl_value_t*)li->inferred);
        jl_serialize_value(s, (jl_value_t*)li->file);
        jl_serialize_value(s, (jl_value_t*)li->line);
        jl_serialize_value(s, (jl_value_t*)li->module);
    }
    else if (jl_typeis(v, jl_module_type)) {
        jl_serialize_module(s, (jl_module_t*)v);
    }
    else if (jl_typeis(v, jl_methtable_type)) {
        writetag(s, jl_methtable_type);
        jl_methtable_t *mt = (jl_methtable_t*)v;
        jl_serialize_methlist(s, mt->defs);
        jl_serialize_methlist(s, mt->cache);
        jl_serialize_value(s, mt->cache_1arg);
        write_int32(s, mt->max_args);
    }
    else if (jl_typeis(v, jl_task_type)) {
        jl_error("Task cannot be serialized");
    }
    else {
        jl_value_t *t = (jl_value_t*)jl_typeof(v);
        if (jl_is_bits_type(t)) {
            void *data = jl_bits_data(v);
            if (t == (jl_value_t*)jl_int64_type &&
                *(int64_t*)data >= S32_MIN && *(int64_t*)data <= S32_MAX) {
                writetag(s, (jl_value_t*)SmallInt64_tag);
                write_int32(s, (int32_t)*(int64_t*)data);
            }
            else {
                int nb = ((jl_bits_type_t*)t)->nbits;
                writetag(s, jl_bits_kind);
                jl_serialize_value(s, t);
                ios_write(s, data, nb/8);
            }
        }
        else if (jl_is_struct_type(t)) {
            writetag(s, jl_struct_kind);
            jl_serialize_value(s, t);
            size_t nf = ((jl_struct_type_t*)t)->names->length;
            size_t i;
            for(i=0; i < nf; i++) {
                jl_value_t *fld = ((jl_value_t**)v)[i+1];
                jl_serialize_value(s, fld);
            }
            if (t == jl_idtable_type) {
                jl_cell_1d_push(idtable_list, v);
            }
        }
        else {
            assert(0);
        }
    }
}
Пример #8
0
int VacpacketParsing()
{
	bool bDataChk = true;
	float dVac[2];

	char cAIVal[11];	
	int iFor = 0;
	int iFor2 = 0;
	int iTmpStartCnt = 21;
	int iVac[4];
//	char opr[1];
	int iopr = 0;
	char amp[1];
	int iamp = 0;
//	char temp;
	
	cUINT  type;

//printf(" dataBuf : %s        Length : %d       \n",dataBuf, strlen(dataBuf));

	//데이터가 정상적인지 여부와 데이터 자르기
	if (dataBuf[0] != 0x02) bDataChk = false;	//첫번째 데이터가 stx인지 확인
	if (bDataChk == false)	return 0;

	//Data 분리
	memset(dVac, 0x00, sizeof(dVac));
	type   = DBR_FLOAT;
		
	for ( iFor = 0; iFor < 2; iFor++ )
	{
		memset(cAIVal,0x00,sizeof(cAIVal));
		for (iFor2 = 0; iFor2 < 10; iFor2++)
		{
			cAIVal[iFor2] = dataBuf[(iFor2+1)+(iFor*10)];
		}
		dVac[iFor] = atof(cAIVal);
		fltWriteDATA = dVac[iFor];
		printf("Dual Guage Value%d : %f\n", iFor, fltWriteDATA);
		writetag(T_CIP_REAL, VacTagDatachid2[iFor]);					
	}

	//TMP
	for ( iFor = 0; iFor < 2; iFor++ )
	{
		memset(cAIVal,0x00,sizeof(cAIVal));
		for (iFor2 = 0; iFor2 < 4 ; iFor2++)
		{			
			switch (iFor2)
			{
				case 0:
					cAIVal[iFor2] = dataBuf[(iFor2)+(iFor*4)+iTmpStartCnt];
					iopr = cAIVal[iFor2];
					if(iopr > 0x19)
					{
						//TMP4는 Nor.Op값을 0x33으로 주고 나머지는 0x23으로 준다.
						if(iFor == 0)
						{
							iWriteDATA = cAIVal[iFor2]-0x20;
						}
						else
						{
							iWriteDATA = cAIVal[iFor2]-0x30;
						}	
					}
					else
					{
						iWriteDATA = cAIVal[iFor2];
					}
					printf("iWriteDATA = %d\n", iWriteDATA);
					if(iWriteDATA < 0) iWriteDATA = 0;
					writetag(T_CIP_INT, TmpStsTagDatachid[iFor]);
					break;
				case 1:
					iamp = 0;
					memset(amp, 0x00, sizeof(amp));
					//cAIVal[iFor2] = dataBuf[(iFor2)+(iFor*4)+iTmpStartCnt];
					amp[0] = abs(dataBuf[(iFor2)+(iFor*4)+iTmpStartCnt]);
					//temp = dataBuf[(iFor2)+(iFor*4)+iTmpStartCnt] << 6;
					//amp[0] = temp >> 6;
					//printf("AMP : %1x     val : %d\n", amp[0], iamp);
					fltWriteDATA = amp[0]/25.5;//cAIVal[iFor2]/25.5;
					//printf("test :%d\n", dataBuf[50]);
					//printf("fltWriteDATA = %f\n", fltWriteDATA);
					//if(fltWriteDATA < 0) 
					//{
					//	fltWriteDATA *= -1.6;	//-값이 나오면 +값으로 변환하기 위하여
					//}
					writetag(T_CIP_REAL, TmpAmpTagDatachid[iFor]);
					break;
				case 2:
					cAIVal[iFor2] = dataBuf[(iFor2)+(iFor*4)+iTmpStartCnt];
					iWriteDATA = cAIVal[iFor2];
					writetag(T_CIP_INT, TmpRpmTagDatachid[iFor]);					
					break;
				case 3:
					cAIVal[iFor2] = dataBuf[(iFor2)+(iFor*4)+iTmpStartCnt];
					iWriteDATA = cAIVal[iFor2];
					writetag(T_CIP_INT, TmpTempTagDatachid[iFor]);					
					break;				
			}
						
			//printf("TMP value%d : %d\n", iFor2+1, cAIVal[iFor2]);
			printf("TMP%d   value%d : %x\n",iFor+2, iFor2+1, dataBuf[(iFor2)+(iFor*4)+iTmpStartCnt]);
		}
		iVac[iFor] = atoi(cAIVal);
		//printf("TMP Value : %i\n",iVac[iFor]);
	}

	return 1;
}