Пример #1
0
ER_UINT
net_serial_rea_dat (ID portid, char *buf, UINT len)
{
	T_SERIAL_RPOR	rpor;
	UINT		off;
	int		ch;

	if (!wait_accept && !connected) {
		wait_accept = TRUE;
		if (TCP_ACP_CEP(TCP_CEPID, TCP_REPID, &dst, TMO_NBLK) != E_WBLK)
			return 0;
		}

	while (TRUE) {
		if (connected) {
			off = 0;
			while (off < len && (ch = get_char(TCP_CEPID)) != EOF) {
				*(buf + off ++) = ch;
				if ((net_ioctl & IOCTL_ECHO) != 0) {
					put_char(TCP_CEPID, ch);
					flush_snd_buff(TCP_CEPID);
					}
				}
			return off;
			}
		else if (serial_ref_por(portid, &rpor) == E_OK && rpor.reacnt > 0) {
			return serial_rea_dat(portid, buf, len);
			}
		dly_tsk(500);
		}
	return off;
	}
Пример #2
0
/*
 *  システムログ出力の待ち合わせ
 */
ER
logtask_flush(uint_t count)
{
	T_SYSLOG_RLOG	rlog;
	T_SERIAL_RPOR	rpor;
	ER				ercd, rercd;
	ID my_logtask_portid = get_my_logtask_portid();

	if (sns_dpn()) {
		ercd = E_CTX;
	}
	else {
		for (;;) {
			if (syslog_ref_log(&rlog) < 0) {
				ercd = E_SYS;
				goto error_exit;
			}
			if (rlog.count <= count) {
				if (count == 0U) {
					/*
					 *  countが0の場合には,シリアルバッファが空かを確
					 *  認する.
					 */
					if (serial_ref_por(my_logtask_portid, &rpor) < 0) {
						ercd = E_SYS;
						goto error_exit;
					}
					if (rpor.wricnt == 0U) {
						ercd = E_OK;
						goto error_exit;
					}
				}
				else {
					ercd = E_OK;
					goto error_exit;
				}
			}

			/*
			 *  LOGTASK_FLUSH_WAITミリ秒待つ.
			 */
			rercd = dly_tsk(LOGTASK_FLUSH_WAIT);
			if (rercd < 0) {
				ercd = (rercd == E_RLWAI) ? rercd : E_SYS;
				goto error_exit;
			}
		}
	}

  error_exit:
	return(ercd);
}
Пример #3
0
/*
 *  モニタコマンドブレークの判定
 */
static BOOL
monitor_break()
{
	T_SERIAL_RPOR k_rpor;

	if(mon_infile != stdin)
		return FALSE;
	serial_ref_por(mon_portid, &k_rpor);
	if(k_rpor.reacnt > 0){
		getc(mon_infile);
		return TRUE;
	}
	else
		return FALSE;
}
bool_t isConnected() {
	T_SERIAL_RPOR rpor;
	ER ercd = serial_ref_por(SIO_PORT_SPP_MASTER_TEST, &rpor);
	return ercd == E_OK;
}
Пример #5
0
bool_t ev3_bluetooth_is_connected() {
	T_SERIAL_RPOR rpor;
	ER ercd = serial_ref_por(SIO_PORT_BT, &rpor);
	return ercd == E_OK;
}
Пример #6
0
ER zmodem_recv_file(ID portid, void *buf, SIZE size, SIZE *filesz) {
	/**
	 * Clear SIO port
	 */
	T_SERIAL_RPOR rpor;
	while (1) {
		char buf[1];
		ER ercd = serial_ref_por(portid, &rpor);
		if (ercd != E_OK) return ercd;
		if (rpor.reacnt > 0)
			serial_rea_dat(portid, (char*)&buf, sizeof(buf));
		else
			break;
	}

	/**
	 * Draw GUI
	 */
	font_t *font = global_brick_info.font_w10h16;
	bitmap_t *screen = global_brick_info.lcd_screen;
	offset_y = 0;
	bitmap_bitblt(NULL, 0, 0, screen, 0, offset_y, screen->width, font->height * 2, ROP_CLEAR); // Clear
	bitmap_bitblt(NULL, 0, 0, screen, 0, offset_y, screen->width, font->height, ROP_SET); // Clear
	bitmap_draw_string("Receive App File", screen, (screen->width - strlen("Receive App File") * font->width) / 2, offset_y, font, ROP_COPYINVERTED);
	offset_y += font->height * 2;
	bitmap_bitblt(NULL, 0, 0, screen, 0, offset_y, screen->width, screen->height, ROP_CLEAR); // Clear
	bitmap_draw_string(portid == SIO_PORT_BT ? "Port: Bluetooth" : "Port: Port 1", screen, 0, offset_y, font, ROP_COPY);
	offset_y += font->height * 2;
	bitmap_draw_string("Protocol: ZMODEM", screen, 0, offset_y, font, ROP_COPY);
	offset_y += font->height * 2;
//    syslog(LOG_NOTICE, "%s", cm->title);

	/**
	 * Setup static variables for ZMODEM task
	 */
	sio_portid = portid;
	p_recv_filesz = filesz;

    cookie_io_functions_t  memfile_func = {
        .read  = memfile_read,
        .write = memfile_write,
        .seek  = memfile_seek,
        .close = memfile_close
    };

//    FILE *fp;

    /* Set up the cookie before calling fopencookie() */
    struct memfile_cookie mycookie;
    mycookie.buf = buf;
    mycookie.allocated = size;
    mycookie.offset = 0;
    mycookie.endpos = 0;

    recv_file = fopencookie(&mycookie,"w+", memfile_func);

    /**
     * Act ZMODEM task
     */
    recv_task_compl = false;
    act_tsk(ZMODEM_RECV_TASK);

    /**
     * Task can be terminated by clicking BACK button
     */
    while(!recv_task_compl && !global_brick_info.button_pressed[BRICK_BUTTON_BACK])
    	tslp_tsk(10);
    if (!recv_task_compl) {
    	while(global_brick_info.button_pressed[BRICK_BUTTON_BACK]);
//    	ter_tsk(ZMODEM_RECV_TASK);
    	zm.cancelled = true;
    	while(!recv_task_compl) {
    		rel_wai(ZMODEM_RECV_TASK);
    		tslp_tsk(10);
    	}
    	recv_ercd = E_TMOUT;
    }

    fclose(recv_file);

	/**
	 * Dirty fix, store received file:
	 */
    if (recv_ercd == E_OK) {
    	static char filepath[(MAX_PATH+1*2)];
    	strcpy(filepath, "/ev3rt/apps"/*SD_APP_FOLDER*/);
    	strcat(filepath, "/");
    	strcat(filepath, recv_file_name);
        apploader_store_file(filepath, buf, *filesz);
    }

	return recv_ercd;
}