Esempio n. 1
0
e_int32 ls_uninit(laser_sick_t *ls) {
	e_assert(ls&&ls->state, E_ERROR_INVALID_HANDLER);
	if (ls->state == STATE_WORK) {
		ls_cancel(ls);
		Delay(500);
	}
	if (ls->thread_work)
		killthread(ls->thread_work);
	if (ls->thread_read)
		killthread(ls->thread_read);
	if (ls->thread_write)
		killthread(ls->thread_write);
	pool_destroy(&ls->pool);
	memset(ls, 0, sizeof(laser_sick_t));
	free(ls);
	return E_OK;
}
Esempio n. 2
0
int killthreadid(int threadid, int threadnum)
{
	int numthreads=0;

	for (int i=0;i<MAXTHREADS;i++) {
		if (threads[i].id == threadid) {
			if (threadnum > 0) {
				if (threads[i].parent == threadnum || i == threadnum)
					if (killthread(i)) 
						numthreads++;
			} else {
				if (killthread(i)) 
					numthreads++;
			}
		}
	}

	return (numthreads);
}
Esempio n. 3
0
int killthreadall(void)
{
	int numthreads=0;

	for (int i = 0; i < MAX_THREADS; i++)
		if (threads[i].name[0] != '\0')
			if (killthread(i))
				numthreads++;

	return numthreads;
}
Esempio n. 4
0
int main(int argc, char *argv[]) {
	e_int32 ret,i;
	hd_connect_t connect;
	msg_monitor_t monitor = { 0 };
	ethread_t* threads[MAX_CLIENT_SIZE];
	e_uint8 name[128]={'t','e','s','t',0};

	ret = sc_open_socket(&connect, "127.0.0.1", 6666);
	e_assert(ret>0, ret);
	ret = sc_connect(&connect);
	e_assert(ret>0, ret);
	ret = mm_init(&monitor, &connect);
	e_assert(ret>0, ret);
	mm_start(&monitor);

#if 0
	fsocket_t* fd = mm_create_socket(&monitor, name);
	if (!fd) {
		DMSG((STDOUT,"ERROR CREATE FAKE SOCKET\r\n"));
	} else{
		request_thread(fd);
	}
#else
	while (count--) {
		sprintf(name,"Thread[%d]",count);
		fsocket_t* fd = mm_create_socket(&monitor,name);
		DMSG((STDOUT,"create request thread %d\r\n",count));
		ret = createthread("request", (thread_func) &request_thread, (void*) fd,
				NULL, &threads[count]);
		if (ret <= 0) {
			DMSG((STDOUT,"createhread failed!\r\n"));
			return E_ERROR;
		}
		ret = resumethread(threads[count]);
		if (ret <= 0) {
			DMSG((STDOUT,"resumethread failed!\r\n"));
			return E_ERROR;
		}
	}
#endif
	while(count<MAX_CLIENT_SIZE-1) {
		//DMSG((STDOUT,"COUNT = %d",count));
		sleep(1);
	}

	for (i=0;i<MAX_CLIENT_SIZE;i++) {
		killthread( threads[i]);
	}
	mm_stop(&monitor);
	sc_close(&connect);
	return 0;
}
Esempio n. 5
0
int main(int argc, char *argv[])
{
	e_int32 ret,i;

	pool_init(&pool);

	ethread_t* threads[2];
	DMSG((STDOUT, "scan job routine starting write routine...\r\n"));
	ret = createthread("hd_scan_job_write", (thread_func) &write_pool_data_routine,
			&pool, NULL, &threads[0]);
	if (ret <= 0)
	{
		DMSG((STDOUT, "createhread failed!\r\n"));
		return E_ERROR;
	}
	ret = resumethread(threads[0]);
	if (ret <= 0)
	{
		DMSG((STDOUT, "write resumethread failed!\r\n"));
		return E_ERROR;
	}
	DMSG((STDOUT, "scan job routine starting read routine...\r\n"));
	ret = createthread("hd_scan_job_read", (thread_func) &read_pool_data_routine,
			&pool,NULL,  &threads[1]);
	if (ret <= 0)
	{
		DMSG((STDOUT, "createhread failed!\r\n"));
		return E_ERROR;
	}
	ret = resumethread(threads[1]);
	if (ret <= 0)
	{
		DMSG((STDOUT, "read resumethread failed!\r\n"));
		return E_ERROR;
	}

	while(count<2)
	{
		//DMSG((STDOUT,"COUNT = %d",count));
		sleep(1);
	}

	for (i=0;i<2;i++)
	{
		killthread( threads[i]);
	}
	pool_destroy(&pool);
	return 0;
}
Esempio n. 6
0
e_int32 lm_uninit() {
	exit_loop();
	killthread(lm->main_thread);
	semaphore_destroy(&lm->wakeup);
	memset(lm, 0, sizeof(laser_machine_t));
}
Esempio n. 7
0
e_int32 ls_scan(laser_sick_t *ls, char* ptDir, char *grayDir,
		e_uint32 speed_h_delay, const e_float64 start_angle_h,
		const e_float64 end_angle_h, e_uint32 speed_v_hz,
		e_float64 resolution_v, const e_uint32 interlace_v,
		const e_float64 start_angle_v, const e_float64 end_angle_v) {
	e_int32 ret;
	e_assert(ls && ls->state == STATE_IDLE, E_ERROR_INVALID_STATUS);

	ls->state = STATE_WORK;

	ls->on_status_change(ls->ctx, ls->state);

	ret = ls_phrase_config(ls, speed_h_delay, start_angle_h, end_angle_h,
			speed_v_hz, resolution_v, interlace_v, start_angle_v, end_angle_v);
	if (ret <= 0) {
		DMSG((STDOUT, "ls_phrase_config failed!\r\n"));
		ls->state = STATE_IDLE;
		return E_ERROR;
	}

	//创建输出端子
	ls->writer = dm_alloc(ptDir, grayDir, ls->width, ls->height,
			ls->h_w,
			ls->active_sectors.right && ls->active_sectors.left ?
					E_DWRITE : E_WRITE);
	if (ls->writer == 0) {
		DMSG((STDOUT, "dm_alloc failed!\r\n"));
		ls->state = STATE_IDLE;
		return E_ERROR;
	}
	ret = dm_alloc_buffer(ls->writer, DATA_BLOCK_TYPE_COLUMN, &ls->points_polar,
			&ls->points_gray);
	if (e_failed( ret )) {
		DMSG((STDOUT, "dm_alloc_buffer failed!\r\n"));
		ls->state = STATE_IDLE;
		return E_ERROR;
	}
	ls->slip_idx = 0;
	ls->slip_tick = 0;

	DMSG((STDOUT, "scan job routine starting read routine...\r\n"));
	//check priv
	if (ls->thread_work)
		killthread(ls->thread_work);
	ret = createthread("point scan  scan thread",
			(thread_func) &thread_scan_func, ls, NULL, &ls->thread_work);
	if (ret <= 0) {
		DMSG((STDOUT, "create point scan thread failed!\r\n"));
		ls->state = STATE_IDLE;
		return E_ERROR;
	}
	ret = resumethread(ls->thread_work);
	if (ret <= 0) {
		DMSG((STDOUT, "resume point scan  thread failed!\r\n"));
		if (ls->thread_work)
			killthread(ls->thread_work);
		ls->state = STATE_IDLE;
		return E_ERROR;
	}
	DMSG((STDOUT, "point scan job routine start successful.\r\n"));
	return E_OK;
}