Ejemplo n.º 1
0
int chunk_load(FILE *fd) {
	uint8_t hdr[8];
	uint8_t loadbuff[16];
	const uint8_t *ptr;
	int32_t r;
	uint64_t chunkid,nextchunkid;
	uint32_t version,lockedto;

	if (fread(hdr,1,8,fd)!=8) {
		return -1;
	}
	ptr = hdr;
	nextchunkid = get64bit(&ptr);
	printf("# nextchunkid: %016"PRIX64"\n",nextchunkid);
	for (;;) {
		r = fread(loadbuff,1,16,fd);
		(void)r;
		ptr = loadbuff;
		chunkid = get64bit(&ptr);
		version = get32bit(&ptr);
		lockedto = get32bit(&ptr);
		if (chunkid==0 && version==0 && lockedto==0) {
			return 0;
		}
		printf("*|i:%016"PRIX64"|v:%08"PRIX32"|t:%10"PRIu32"\n",chunkid,version,lockedto);
	}
}
Ejemplo n.º 2
0
void masterconn_chunkop(masterconn *eptr,const uint8_t *data,uint32_t length) {
	uint64_t chunkid;
	uint32_t version,newversion;
	uint64_t copychunkid;
	uint32_t copyversion;
	uint32_t leng;
	uint8_t *ptr;
	void *packet;

	if (length!=8+4+8+4+4+4) {
		syslog(LOG_NOTICE,"MATOCS_CHUNKOP - wrong size (%"PRIu32"/32)",length);
		eptr->mode = KILL;
		return;
	}
	chunkid = get64bit(&data);
	version = get32bit(&data);
	newversion = get32bit(&data);
	copychunkid = get64bit(&data);
	copyversion = get32bit(&data);
	leng = get32bit(&data);
	packet = masterconn_create_detached_packet(eptr,CSTOMA_CHUNKOP,8+4+4+8+4+4+1);
	ptr = masterconn_get_packet_data(packet);
	put64bit(&ptr,chunkid);
	put32bit(&ptr,version);
	put32bit(&ptr,newversion);
	put64bit(&ptr,copychunkid);
	put32bit(&ptr,copyversion);
	put32bit(&ptr,leng);
	job_chunkop(masterconn_chunkopfinished,packet,chunkid,version,newversion,copychunkid,copyversion,leng);
}
Ejemplo n.º 3
0
int fs_loadedge(FILE *fd) {
	uint8_t uedgebuff[4+4+2];
	const uint8_t *ptr;
	uint32_t parent_id;
	uint32_t child_id;
	uint16_t nleng;

	if (fread(uedgebuff,1,4+4+2,fd)!=4+4+2) {
		fprintf(stderr,"loading edge: read error\n");
		return -1;
	}
	ptr = uedgebuff;
	parent_id = get32bit(&ptr);
	child_id = get32bit(&ptr);
	if (parent_id==0 && child_id==0) {	// last edge
		return 1;
	}
	nleng = get16bit(&ptr);

	if (parent_id==0) {
		printf("E|p:      NULL|c:%10"PRIu32"|n:",child_id);
	} else {
		printf("E|p:%10"PRIu32"|c:%10"PRIu32"|n:",parent_id,child_id);
	}
	print_name(fd,nleng);
	printf("\n");
	return 0;
}
Ejemplo n.º 4
0
void masterconn_replicate(masterconn *eptr,const uint8_t *data,uint32_t length) {
	uint64_t chunkid;
	uint32_t version;
	uint32_t ip;
	uint16_t port;
	uint8_t *ptr;
	void *packet;

	if (length!=8+4+4+2 && (length<12+18 || length>12+18*100 || (length-12)%18!=0)) {
		syslog(LOG_NOTICE,"MATOCS_REPLICATE - wrong size (%"PRIu32"/18|12+n*18[n:1..100])",length);
		eptr->mode = KILL;
		return;
	}
	chunkid = get64bit(&data);
	version = get32bit(&data);
	packet = masterconn_create_detached_packet(CSTOMA_REPLICATE,8+4+1);
	if (packet==NULL) {
		eptr->mode=KILL;
		return;
	}
	ptr = masterconn_get_packet_data(packet);
	put64bit(&ptr,chunkid);
	put32bit(&ptr,version);
	if (length==8+4+4+2) {
		ip = get32bit(&data);
		port = get16bit(&data);
//		syslog(LOG_NOTICE,"start job replication (%08"PRIX64":%04"PRIX32":%04"PRIX32":%02"PRIX16")",chunkid,version,ip,port);
		job_replicate_simple(eptr->jpool,masterconn_replicationfinished,packet,chunkid,version,ip,port);
	} else {
		job_replicate(eptr->jpool,masterconn_replicationfinished,packet,chunkid,version,(length-12)/18,data);
	}
}
Ejemplo n.º 5
0
static int rep_read(repsrc *rs) {
	int32_t i;
	uint32_t type;
	uint32_t size;
	const uint8_t *ptr;
	while (rs->bytesleft>0) {
		i=read(rs->sock,rs->startptr,rs->bytesleft);
		if (i==0) {
			syslog(LOG_NOTICE,"replicator: connection lost");
			return -1;
		}
		if (i<0) {
			if (ERRNO_ERROR) {
				mfs_errlog_silent(LOG_NOTICE,"replicator: read error");
				return -1;
			}
			return 0;
		}
		replicator_bytesin(i);
//		stats_bytesin+=i;
		rs->startptr+=i;
		rs->bytesleft-=i;

		if (rs->bytesleft>0) {
			return 0;
		}

		if (rs->mode==HEADER) {
			ptr = rs->hdrbuff;
			type = get32bit(&ptr);
			size = get32bit(&ptr);
			if (type==ANTOAN_NOP && size==0) { // NOP
				rs->startptr = rs->hdrbuff;
				rs->bytesleft = 8;
				return 0;
			}

			if (rs->packet) {
				free(rs->packet);
			}
			if (size>0) {
				if (size>MAX_RECV_PACKET_SIZE) {
					syslog(LOG_WARNING,"replicator: packet too long (%"PRIu32"/%u)",size,MAX_RECV_PACKET_SIZE);
					return -1;
				}
				rs->packet = malloc(size);
				passert(rs->packet);
				rs->startptr = rs->packet;
			} else {
				rs->packet = NULL;
			}
			rs->bytesleft = size;
			rs->mode = DATA;
		}
	}
	return 0;
}
Ejemplo n.º 6
0
//读取Master的packet,怀疑是复制chunk操作,待确定
//调用:masterconn_gotpacket()
void masterconn_chunkop(masterconn *eptr,const uint8_t *data,uint32_t length) {
	uint64_t chunkid;
	uint32_t version,newversion;
	uint64_t copychunkid;
	uint32_t copyversion;
	uint32_t leng;
	uint8_t *ptr;
#ifdef BGJOBS
	void *packet;
#else /* BGJOBS */
	uint8_t status;
#endif /* BGJOBS */

	if (length!=8+4+8+4+4+4) {
		syslog(LOG_NOTICE,"MATOCS_CHUNKOP - wrong size (%"PRIu32"/32)",length);
		eptr->mode = KILL;
		return;
	}
	chunkid = get64bit(&data);
	version = get32bit(&data);
	newversion = get32bit(&data);
	copychunkid = get64bit(&data);
	copyversion = get32bit(&data);
	leng = get32bit(&data);
#ifdef BGJOBS
	packet = masterconn_create_detached_packet(CSTOMA_CHUNKOP,8+4+4+8+4+4+1);
	if (packet==NULL) {
		eptr->mode=KILL;
		return;
	}
	ptr = masterconn_get_packet_data(packet);
	put64bit(&ptr,chunkid);
	put32bit(&ptr,version);
	put32bit(&ptr,newversion);
	put64bit(&ptr,copychunkid);
	put32bit(&ptr,copyversion);
	put32bit(&ptr,leng);
	job_chunkop(eptr->jpool,masterconn_chunkopfinished,packet,chunkid,version,newversion,copychunkid,copyversion,leng);
#else /* BGJOBS */
	status = hdd_chunkop(chunkid,version,newversion,copychunkid,copyversion,leng);
	ptr = masterconn_create_attached_packet(eptr,CSTOMA_CHUNKOP,8+4+4+8+4+4+1);
	if (ptr==NULL) {
		eptr->mode=KILL;
		return;
	}
	put64bit(&ptr,chunkid);
	put32bit(&ptr,version);
	put32bit(&ptr,newversion);
	put64bit(&ptr,copychunkid);
	put32bit(&ptr,copyversion);
	put32bit(&ptr,leng);
	put8bit(&ptr,status);
#endif /* BGJOBS */
}
Ejemplo n.º 7
0
Archivo: client.c Proyecto: twonly/mis
ppacket* receivepacket(int sockfd){
  char headbuf[20];
  uint8_t* startptr;
  const uint8_t* ptr;
  int i,hleft;
  ppacket* p;

  hleft = HEADER_LEN;
  startptr = headbuf;
  while(hleft){
    i = read(sockfd,startptr,hleft);
    if(i < 0){
      if(i != -EAGAIN){
        fprintf(stderr,"read error:%d\n",i);
      }
      continue;
    }
    if(i==0){
      fprintf(stderr,"Connection closed\n");
    }

    hleft -= i;
    startptr += i;
  }

  int size,cmd;
  ptr = headbuf;
  size = get32bit(&ptr);
  cmd = get32bit(&ptr);

  printf("got packet:size=%d,cmd=%X\n",size,cmd);
  p = createpacket_r(size,cmd,1);

  while(p->bytesleft){
    i = read(sockfd,p->startptr,p->bytesleft);
    if(i < 0){
      if(i != -EAGAIN){
        fprintf(stderr,"read error:%d\n",i);
      }
      continue;
    }
    if(i==0){
      fprintf(stderr,"Connection closed\n");
    }

    p->bytesleft -= i;
    p->startptr += i;
  }

  p->startptr = p->buf;

  return p;
}
Ejemplo n.º 8
0
uint8_t ConfigPDVelovity(BowlerPacket * Packet){
	uint8_t chan = Packet->use.data[0];

	float KP=0;
	float KD=0;

	KP=(float)get32bit(Packet,1);
	KD=(float)get32bit(Packet,5);

	getPidGroupDataTable(chan)->config.V.P=KP/100.0;
	getPidGroupDataTable(chan)->config.V.D=KD/100.0;

	OnPidConfigure(chan);
	return true; 
}
Ejemplo n.º 9
0
void matomlserv_register(matomlserventry *eptr,const uint8_t *data,uint32_t length) {
	uint8_t rversion;
	uint64_t minversion;

	if (eptr->version>0) {
		syslog(LOG_WARNING,"got register message from registered metalogger !!!");
		eptr->mode=KILL;
		return;
	}
	if (length<1) {
		syslog(LOG_NOTICE,"MLTOMA_REGISTER - wrong size (%"PRIu32")",length);
		eptr->mode=KILL;
		return;
	} else {
		rversion = get8bit(&data);
		if (rversion==1) {
			if (length!=7) {
				syslog(LOG_NOTICE,"MLTOMA_REGISTER (ver 1) - wrong size (%"PRIu32"/7)",length);
				eptr->mode=KILL;
				return;
			}
			eptr->version = get32bit(&data);
			eptr->timeout = get16bit(&data);
		} else if (rversion==2) {
			if (length!=7+8) {
				syslog(LOG_NOTICE,"MLTOMA_REGISTER (ver 2) - wrong size (%"PRIu32"/15)",length);
				eptr->mode=KILL;
				return;
			}
			eptr->version = get32bit(&data);
			eptr->timeout = get16bit(&data);
			minversion = get64bit(&data);
			matomlserv_send_old_changes(eptr,minversion);
		} else {
			syslog(LOG_NOTICE,"MLTOMA_REGISTER - wrong version (%"PRIu8"/1)",rversion);
			eptr->mode=KILL;
			return;
		}
		if (eptr->timeout<10) {
			syslog(LOG_NOTICE,"MLTOMA_REGISTER communication timeout too small (%"PRIu16" seconds - should be at least 10 seconds)",eptr->timeout);
			if (eptr->timeout<3) {
				eptr->timeout=3;
			}
//			eptr->mode=KILL;
			return;
		}
	}
}
Ejemplo n.º 10
0
void masterproxy_getlocation(uint8_t *masterinfo) {
	const uint8_t *rptr = masterinfo+10;
	if (lsock>=0 && get32bit(&rptr)>=0x00010618) {	// use proxy only when master version is greater than or equal to 1.6.24
		put32bit(&masterinfo,proxyhost);
		put16bit(&masterinfo,proxyport);
	}
}
Ejemplo n.º 11
0
void dcache_makeinodehash(dircache *d) {
	const uint8_t *iptr,*ptr,*eptr;
	uint8_t enleng;
	uint32_t hash,disp;
	uint32_t hashmask;

	if (d->hashsize==0) {
		dcache_calchashsize(d);
	}
	hashmask = d->hashsize-1;
	d->inodehashtab = malloc(sizeof(uint8_t*)*d->hashsize);
	memset(d->inodehashtab,0,sizeof(uint8_t*)*d->hashsize);

	ptr = d->dbuff;
	eptr = d->dbuff+d->dsize;
	while (ptr<eptr) {
		enleng = *ptr;
		if (ptr+enleng+40<=eptr) {
			iptr = ptr+1+enleng;
			hash = get32bit(&iptr);
			disp = ((hash*0x53B23891)&hashmask)|1;
			hash *= 0xB28E457D;
			while (d->inodehashtab[hash&hashmask]) {
				hash+=disp;
			}
			d->inodehashtab[hash&hashmask]=ptr+1+enleng;
		}
		ptr+=enleng+40;
	}
}
Ejemplo n.º 12
0
Archivo: client.c Proyecto: twonly/mis
int	ppfs_chmod (const char *path, mode_t mt){
  fprintf(stderr, "ppfs_chmod path : %s\n", path);

  ppacket *s = createpacket_s(4+strlen(path)+4, CLTOMD_CHMOD,-1);
  uint8_t* ptr = s->startptr+HEADER_LEN;

  put32bit(&ptr, strlen(path));
  memcpy(ptr, path, strlen(path));
  ptr+=strlen(path);
  put32bit(&ptr, mt);

  sendpacket(fd, s);
  free(s);

  s = receivepacket(fd);
  const uint8_t* ptr2 = s->startptr;
  int status = get32bit(&ptr2);

  if(status == 0){
    print_attr((const attr*)ptr2);

    attr_cache* ac;
    if(lookup_attr_cache(path,&ac) == 0){
      ac->a.mode = mt;
    }

  }
  free(s);

  return status;
}
Ejemplo n.º 13
0
static inline uint8_t dcache_namehash_get(dircache *d,uint8_t nleng,const uint8_t *name,uint32_t *inode,uint8_t attr[35]) {
	uint32_t hash,disp,hashmask;
	const uint8_t *ptr;

	if (d->namehashtab==NULL) {
		dcache_makenamehash(d);
	}
	hashmask = d->hashsize-1;
	hash = dcache_hash(name,nleng);
	disp = ((hash*0x53B23891)&hashmask)|1;
	while ((ptr=d->namehashtab[hash&hashmask])) {
		if (*ptr==nleng && memcmp(ptr+1,name,nleng)==0) {
			ptr+=1+nleng;
			*inode = get32bit(&ptr);
			if (*ptr) { // are attributes valid ?
				memcpy(attr,ptr,35);
				return 1;
			} else {
				return 0;
			}
		}
		hash+=disp;
	}
	return 0;
}
Ejemplo n.º 14
0
Archivo: client.c Proyecto: twonly/mis
int	ppfs_rmdir (const char *path){
  fprintf(stderr, "ppfs_rmdir path : %s\n", path);

  dir_cache* dc;
  if(lookup_dir_cache(path,&dc) == 0){
    remove_dir_cache(dc);
    free_dir_cache(dc);
  }

  ppacket* p = createpacket_s(4+strlen(path),CLTOMD_RMDIR,-1);
  uint8_t* ptr = p->startptr + HEADER_LEN;

  put32bit(&ptr,strlen(path));
  memcpy(ptr,path,strlen(path));
  ptr += strlen(path);

  sendpacket(fd,p);
  free(p);

  p = receivepacket(fd);
  const uint8_t* ptr2 = p->startptr;
  int status = get32bit(&ptr2);

  fprintf(stderr, "rmdir status:%d\n", status);
  free(p);
  return status;
}
Ejemplo n.º 15
0
Archivo: client.c Proyecto: twonly/mis
int ppfs_utimens(const char* path,const struct timespec tv[2]){ //tv[0]: atime, tv[1] mtime


  ppacket* p = createpacket_s(4+strlen(path)+4+4,CLTOMD_UTIMENS,-1);
  uint8_t* ptr = p->startptr + HEADER_LEN;
  int len = strlen(path);

  put32bit(&ptr,len);
  memcpy(ptr,path,len);
  ptr += len;
  put32bit(&ptr,tv[0].tv_sec);
  put32bit(&ptr,tv[1].tv_sec);

  sendpacket(fd,p);
  free(p);

  p = receivepacket(fd);
  const uint8_t* ptr2 = p->startptr;
  int status = get32bit(&ptr2);
  if(status == 0){
    attr_cache* ac;
    if(lookup_attr_cache(path,&ac) == 0){
      ac->a.atime = tv[0].tv_sec;
      ac->a.ctime = tv[1].tv_sec;
    }
  }

  free(p);
  return status;
}
Ejemplo n.º 16
0
Archivo: client.c Proyecto: twonly/mis
int	ppfs_chown (const char *path, uid_t uid, gid_t gid){
  fprintf(stderr, "ppfs_chown path : %s\n", path);


  ppacket *s = createpacket_s(4+strlen(path)+8, CLTOMD_CHOWN, -1);
  uint8_t* ptr = s->startptr+HEADER_LEN;

  put32bit(&ptr, strlen(path));
  memcpy(ptr, path, strlen(path));
  ptr+=strlen(path);
  put32bit(&ptr, uid);
  put32bit(&ptr, gid);

  sendpacket(fd, s);
  free(s);

  s = receivepacket(fd);
  const uint8_t* ptr2 = s->startptr;
  int status = get32bit(&ptr2);

  if(status == 0){
    print_attr((const attr*)ptr2);

    attr_cache* ac;
    if(lookup_attr_cache(path,&ac) == 0){
      ac->a.uid = uid;
      ac->a.gid = gid;
    }
  }
  free(s);

  return status;
}
Ejemplo n.º 17
0
void csserv_chart(csserventry *eptr,const uint8_t *data,uint32_t length) {
	uint32_t chartid;
	uint8_t *ptr;
	uint32_t l;
	uint16_t w,h;

	if (length!=4 && length!=8) {
		syslog(LOG_NOTICE,"CLTOAN_CHART - wrong size (%"PRIu32"/4|8)",length);
		eptr->state = CLOSE;
		return;
	}
	chartid = get32bit(&data);
	if (length==8) {
		w = get16bit(&data);
		h = get16bit(&data);
	} else {
		w = 0;
		h = 0;
	}
	l = charts_make_png(chartid,w,h);
	ptr = csserv_create_packet(eptr,ANTOCL_CHART,l);
	if (l>0) {
		charts_get_png(ptr);
	}
}
Ejemplo n.º 18
0
/*---------------------------------------------------------------------*/
int client_mknod(char szmac[12], uint64_t parent, uint8_t nleng, const uint8_t *name, uint8_t type, 
             uint32_t mode, uint32_t uid, uint32_t gid, uint32_t rdev,
             uint64_t *inode, uint8_t attr[FILE_ATTR_LEN], uint8_t **dslist, uint32_t *dslistlen)
{            
    int iSendLeng = 8 + 38 + nleng;
    uint8_t *szCommand = (uint8_t *)def_calloc(iSendLeng, sizeof(char));
    char *curr = (char *)szCommand;
    put32bit(&szCommand, CLTODI_FUSE_MKNOD);
    put32bit(&szCommand, 38 + nleng);
    
    memcpy(szCommand, szmac, 12);
    szCommand += 12;
    put64bit(&szCommand, parent);
    put8bit(&szCommand, nleng);
    memcpy(szCommand, name, nleng);
    szCommand += nleng;
    put8bit(&szCommand, type);
    put32bit(&szCommand, mode);
    put32bit(&szCommand, uid);
    put32bit(&szCommand, gid);
    put32bit(&szCommand, rdev);
    
    char *szOutBuf = NULL;
    int iOutLength = 0;

    int ret = net_client_rpc(p_cn_client->p_client,
                            p_cn_client->namenode_info[0].namenode_ip,
                            p_cn_client->namenode_info[0].namenode_port,
                            curr, iSendLeng, &szOutBuf, &iOutLength);
    def_free(curr);
    if (ret != 0)
    {
        if(szOutBuf)
            def_free(szOutBuf);
        ret =  EIO;
    }
    else
    {
        if (iOutLength == 4) 
        {
            const uint8_t * result = (const uint8_t *) szOutBuf;
            ret = get32bit(&result);
        } 
        else 
        {
            uint8_t *out = (uint8_t *) szOutBuf;
            uint64_t t64 = get64bit((const uint8_t **)&out);
            *inode = t64;
            memcpy(attr, out, FILE_ATTR_LEN);
            out += FILE_ATTR_LEN;
            *dslistlen = iOutLength - 8 - FILE_ATTR_LEN;
            *dslist = def_calloc(*dslistlen, sizeof(char));
            memcpy(*dslist, out, *dslistlen);
            ret = STATUS_OK;
        }
        def_free(szOutBuf);
    }
    
    return ret;
}
BOOL ConfigureChannelFromPacket(BowlerPacket * Packet){
	BYTE pin = Packet->use.data[0];
	BYTE mode = GetChannelMode(pin);
	INT32 * data = (INT32 *)(Packet->use.data+1);
	INT32 tmp;
	int i;
	if(configChannelHWPtr!=NULL){
		if(Packet->use.head.DataLegnth>5 && mode != IS_SERVO){
			int numVals = (Packet->use.head.DataLegnth-(4+1))/4;
			for(i=0;i<numVals;i++){
				tmp = get32bit(Packet, (i*4)+1);
				getBcsIoDataTable()[i].PIN.currentValue = tmp;
				data[i]=tmp;
			}
			configChannelHWPtr(pin,numVals,(INT32 * )(Packet->use.data+1));
		}else{
			// Single Byte Servo, legacy HACK
			INT32 value  = Packet->use.data[1];
			configChannelHWPtr(pin,1,&value);
		}
	}else{
		return FALSE;
	}
	FixPacket(Packet);
	return TRUE;
}
Ejemplo n.º 20
0
//读取Master的packet,读取chunk校验和列表(不确定用途)
//调用:masterconn_gotpacket()
void masterconn_chunk_checksum_tab(masterconn *eptr,const uint8_t *data,uint32_t length) {
	uint64_t chunkid;
	uint32_t version;
	uint8_t *ptr;
	uint8_t status;
	uint8_t crctab[4096];

	if (length!=8+4) {
		syslog(LOG_NOTICE,"ANTOCS_CHUNK_CHECKSUM_TAB - wrong size (%"PRIu32"/12)",length);
		eptr->mode = KILL;
		return;
	}
	chunkid = get64bit(&data);
	version = get32bit(&data);
	status = hdd_get_checksum_tab(chunkid,version,crctab);
	if (status!=STATUS_OK) {
		ptr = masterconn_create_attached_packet(eptr,CSTOAN_CHUNK_CHECKSUM_TAB,8+4+1);
	} else {
		ptr = masterconn_create_attached_packet(eptr,CSTOAN_CHUNK_CHECKSUM_TAB,8+4+4096);
	}
	if (ptr==NULL) {
		eptr->mode=KILL;
		return;
	}
	put64bit(&ptr,chunkid);
	put32bit(&ptr,version);
	if (status!=STATUS_OK) {
		put8bit(&ptr,status);
	} else {
		memcpy(ptr,crctab,4096);
	}
}
Ejemplo n.º 21
0
//读取Master的packet,备份chunk
//调用:masterconn_gotpacket()
void masterconn_replicate(masterconn *eptr,const uint8_t *data,uint32_t length) {
	uint64_t chunkid;
	uint32_t version;
//	uint32_t ip;
//	uint16_t port;
	uint8_t *ptr;

	syslog(LOG_WARNING,"This version of chunkserver can perform replication only in background, but was compiled without bgjobs");

	if (length!=8+4+4+2) {
		syslog(LOG_NOTICE,"MATOCS_REPLICATE - wrong size (%"PRIu32"/18)",length);
		eptr->mode = KILL;
		return;
	}
	chunkid = get64bit(&data);
	version = get32bit(&data);
//	ip = get32bit(&data);
//	port = get16bit(&data);

	ptr = masterconn_create_attached_packet(eptr,CSTOMA_REPLICATE,8+4+1);
	if (ptr==NULL) {
		eptr->mode=KILL;
		return;
	}
	put64bit(&ptr,chunkid);
	put32bit(&ptr,version);
	put8bit(&ptr,ERROR_CANTCONNECT);	// any error
}
BOOL SetChanelValueFromPacket(BowlerPacket * Packet){
	BYTE pin = Packet->use.data[0];
	BYTE mode = GetChannelMode(pin);
	if(isStremChannelMode(mode)){
		if(setChanelValueHWPtr!=NULL)
			// Load the data directly into the packet as the buffer
			//Data pointer is offset by one to start after the pin index
			setChanelValueHWPtr(pin,
								Packet->use.head.DataLegnth-(4+1),
								(INT32 *)(Packet->use.data+1),
								(float)0);
			READY(Packet,1,3);
	}else{
		INT32 data = 0;
		INT32 time = 0;

		if(isSingleByteMode(mode)){
			data = Packet->use.data[1];
			if (Packet->use.head.DataLegnth>(4+2)){
				time = get16bit(Packet,2);
			}else{
				time=0;
			}
		}else if(isTwoByteMode(mode)){
			data=get16bit(Packet,1);
			if (Packet->use.head.DataLegnth>(4+3)){
				time= get32bit(Packet,3);
			}else{
				time=0;
			}
		}else{
			data=get32bit(Packet,1);
			if (Packet->use.head.DataLegnth>(4+5)){
				time= get32bit(Packet,5);
			}else{
				time=0;
			}
		}
		getBcsIoDataTable()[pin].PIN.currentValue = data;
		if(setChanelValueHWPtr!=NULL)
			setChanelValueHWPtr(pin,1,&data,(float)time);
		READY(Packet,2,3);
	}

	return TRUE;
}
Ejemplo n.º 23
0
void processLinearInterpPacket(BowlerPacket * Packet){
    if(Packet->use.head.RPC == _SLI){
        //INT32_UNION tmp;
        float tmpData [5];
        int i;

        tmpData[0] = ((float)get32bit(Packet,1));
        for(i=1;i<5;i++){

            tmpData[i] = ((float)get32bit(Packet,(i*4)+1))/1000;
        }
        setInterpolateXYZ(tmpData[1], tmpData[2], tmpData[3],tmpData[0]);
        float extr =tmpData[4]/extrusionScale;
        //println_I("Current Extruder MM=");p_fl_W(tmpData[4]);print_I(", Ticks=");p_fl_W(extr)
        SetPIDTimed(hwMap.Extruder0.index, extr,tmpData[0]);
     }
}
Ejemplo n.º 24
0
static int hb_recv_callback_fun(char *in_buff, int in_length)
{
    int ret = get32bit((const uint8_t **)&in_buff);
    nb_log("client", NB_LOG_DEBUG,
                "recv ret hb inbuff is %d, length is %d", ret, in_length);

    nb_log("client", NB_LOG_DEBUG, "hb close callback OK OK......");
    return 0;
}
Ejemplo n.º 25
0
int client_lookup(uint64_t parent, uint8_t nleng, const uint8_t *name, uint32_t uid, uint32_t gid,
              uint64_t *inode, uint8_t attr[FILE_ATTR_LEN]) 
{

    int iSendLeng = 8 + 20 + nleng;
    uint8_t *szCommand = (uint8_t *)def_calloc(iSendLeng, sizeof(char));
    char *curr = (char *)szCommand;
    put32bit(&szCommand, CLTODI_FUSE_LOOKUP);
    put32bit(&szCommand, 20 + nleng);
    
    put64bit(&szCommand, parent);
    put32bit(&szCommand, nleng);
    memcpy(szCommand, name, nleng);
    szCommand += nleng;
    put32bit(&szCommand, uid);
    put32bit(&szCommand, gid);
    
    char *szOutBuf = NULL;
    int iOutLength = 0;
    int ret = net_client_rpc(p_cn_client->p_client,
                            p_cn_client->namenode_info[0].namenode_ip,
                            p_cn_client->namenode_info[0].namenode_port,
                            curr, iSendLeng,  &szOutBuf, &iOutLength);
    def_free(curr);
    if (ret != 0)
    {   
        nb_log("client lookup", NB_LOG_ERROR, "nn --->cli rpc is error.");
        if(szOutBuf)
            def_free(szOutBuf);
        ret =  EIO;
    }
    else
    {
        if(iOutLength == 4)
        {
            const uint8_t * result = (const uint8_t *) szOutBuf;
            ret = get32bit(&result);
        }
        else if (iOutLength != FILE_ATTR_LEN + 8)
        {   
            ret = EIO;
        }
        else
        {
            const uint8_t *out = (const uint8_t *) szOutBuf;
            *inode = get64bit(&out);
            memcpy(attr, out, FILE_ATTR_LEN);
            ret = STATUS_OK;
        }
        
        def_free(szOutBuf);   
    }
    
    return ret;
}
Ejemplo n.º 26
0
void masterconn_setversion(masterconn *eptr,const uint8_t *data,uint32_t length) {
	uint64_t chunkid;
	uint32_t version;
	uint32_t newversion;
	uint8_t *ptr;
	void *packet;

	if (length!=8+4+4) {
		syslog(LOG_NOTICE,"MATOCS_SET_VERSION - wrong size (%"PRIu32"/16)",length);
		eptr->mode = KILL;
		return;
	}
	chunkid = get64bit(&data);
	newversion = get32bit(&data);
	version = get32bit(&data);
	packet = masterconn_create_detached_packet(eptr,CSTOMA_SET_VERSION,8+1);
	ptr = masterconn_get_packet_data(packet);
	put64bit(&ptr,chunkid);
	job_version(masterconn_jobfinished,packet,chunkid,version,newversion);
}
Ejemplo n.º 27
0
uint8_t SetAllCoProcValues() {
	int i = 0;
	boolean send = true;
	int32_t tmp;
	if (send) {
		LoadCorePacket(&downstreamPacketTemp);
		downstreamPacketTemp.use.head.Method = BOWLER_POST;
		downstreamPacketTemp.use.head.RPC = GetRPCValue("sacv");
		set32bit(&downstreamPacketTemp, 0, 0);   // setting the translation time
		downstreamPacketTemp.use.data[4] = GetNumberOfIOChannels();
		for (i = 0; i < GetNumberOfIOChannels(); i++) {
			tmp = getBcsIoDataTable(i)->PIN.currentValue;
			down[i].changeValue = false;
			set32bit(&downstreamPacketTemp, tmp, (i * 4) + 5);
		}

		downstreamPacketTemp.use.head.DataLegnth = 4 + 4 + 1
				+ (4 * GetNumberOfIOChannels());
		SendPacketToCoProc(&downstreamPacketTemp);
	}

	for (i = 0; i < GetNumberOfIOChannels(); i++) {
		int index = (i * 4) + 1;
		if (isOutputMode(GetChannelMode(i)) == false) {
            tmp= get32bit(&downstreamPacketTemp, index);
			boolean back = (tmp != getBcsIoDataTable(i)->PIN.currentValue);

			setDataTableCurrentValue(i,tmp);
			if (back) {
				getBcsIoDataTable(i)->PIN.asyncDataenabled = true;
			}
		}
		if (GetChannelMode(i) == IS_SERVO) {
			SetServoPos(i, get32bit(&downstreamPacketTemp, index) & 0x000000ff);
		}
		if (GetChannelMode(i) == IS_UART_RX) {

		}
	}
	return true;
}
boolean SetAllChannelValueFromPacket(BowlerPacket * Packet) {
    int32_t * data = (int32_t *) (&Packet->use.data[5] );
    int32_t tmp;

    if (setAllChanelValueHWPtr != NULL) {
    	uint32_t time;
        uint8_t i;

        time=get32bit(Packet, 0);

        for (i = 0; i < GetNumberOfIOChannels(); i++) {
        	if(isOutputMode(GetChannelMode(i))==true){
        		tmp = get32bit(Packet, (i*4) +5);
//        		if(GetChannelMode(i) == IS_SERVO)
//					data[i] = (tmp & 	0x000000ff) | (time<<16);
//        		else
        			data[i] = tmp;
			}else{
				data[i] = getBcsIoDataTable(i)->PIN.currentValue;
			}

        }

        setAllChanelValueHWPtr(data, time);

        for (i = 0; i < GetNumberOfIOChannels(); i++) {
        	if(isOutputMode(GetChannelMode(i))==true){

        		//println_E(__FILE__);println_E("SetAllChannelValueFromPacket");
        		if(GetChannelMode(i)!=IS_SERVO)
        			setDataTableCurrentValue(i,data[i]);
        	}
		}
        //READY(Packet, 3, 3);
        GetAllChanelValueFromPacket(Packet);
    } else {
        return false;
    }
    return true;
}
Ejemplo n.º 29
0
static int master_register(int rfd,uint32_t cuid) {
	uint32_t i;
	const uint8_t *rptr;
	uint8_t *wptr,regbuff[8+73];

	wptr = regbuff;
	put32bit(&wptr,CLTOMA_FUSE_REGISTER);
	put32bit(&wptr,73);
	memcpy(wptr,FUSE_REGISTER_BLOB_ACL,64);
	wptr+=64;
	put8bit(&wptr,REGISTER_TOOLS);
	put32bit(&wptr,cuid);
	put16bit(&wptr,VERSMAJ);
	put8bit(&wptr,VERSMID);
	put8bit(&wptr,VERSMIN);
	if (tcpwrite(rfd,regbuff,8+73)!=8+73) {
		printf("register to master: send error\n");
		return -1;
	}
	if (tcpread(rfd,regbuff,9)!=9) {
		printf("register to master: receive error\n");
		return -1;
	}
	rptr = regbuff;
	i = get32bit(&rptr);
	if (i!=MATOCL_FUSE_REGISTER) {
		printf("register to master: wrong answer (type)\n");
		return -1;
	}
	i = get32bit(&rptr);
	if (i!=1) {
		printf("register to master: wrong answer (length)\n");
		return -1;
	}
	if (*rptr) {
		printf("register to master: %s\n",mfsstrerr(*rptr));
		return -1;
	}
	return 0;
}
Ejemplo n.º 30
0
static void mfs_attr_to_stat(uint32_t inode,uint8_t attr[35], struct stat *stbuf) {
	uint16_t attrmode;
	uint8_t attrtype;
	uint32_t attruid,attrgid,attratime,attrmtime,attrctime,attrnlink;
	uint64_t attrlength;
	const uint8_t *ptr;
	ptr = attr;
	attrtype = get8bit(&ptr);
	attrmode = get16bit(&ptr);
	attruid = get32bit(&ptr);
	attrgid = get32bit(&ptr);
	attratime = get32bit(&ptr);
	attrmtime = get32bit(&ptr);
	attrctime = get32bit(&ptr);
	attrnlink = get32bit(&ptr);
	attrlength = get64bit(&ptr);
	stbuf->st_ino = inode;
	if (attrtype==TYPE_FILE || attrtype==TYPE_TRASH || attrtype==TYPE_RESERVED) {
		stbuf->st_mode = S_IFREG | ( attrmode & 07777);
	} else {
		stbuf->st_mode = 0;
	}
	stbuf->st_size = attrlength;
	stbuf->st_blocks = (attrlength+511)/512;
	stbuf->st_uid = attruid;
	stbuf->st_gid = attrgid;
	stbuf->st_atime = attratime;
	stbuf->st_mtime = attrmtime;
	stbuf->st_ctime = attrctime;
	stbuf->st_nlink = attrnlink;
}