Ejemplo n.º 1
0
struct platform_device *__init at32_add_device_abdac(unsigned int id)
{
	struct platform_device *pdev;

	if (id != 0)
		return NULL;

	pdev = platform_device_alloc("abdac", id);
	if (!pdev)
		return NULL;

	if (platform_device_add_resources(pdev, abdac0_resource,
				ARRAY_SIZE(abdac0_resource)))
		goto err_add_resources;

	select_peripheral(PB(20), PERIPH_A, 0);	/* DATA1	*/
	select_peripheral(PB(21), PERIPH_A, 0);	/* DATA0	*/
	select_peripheral(PB(22), PERIPH_A, 0);	/* DATAN1	*/
	select_peripheral(PB(23), PERIPH_A, 0);	/* DATAN0	*/

	abdac0_pclk.dev = &pdev->dev;
	abdac0_sample_clk.dev = &pdev->dev;

	platform_device_add(pdev);
	return pdev;

err_add_resources:
	platform_device_put(pdev);
	return NULL;
}
void gn(ll n,int op=12323){
    if(isp(n)) {s[l++]=n;return;}
    ll x=PB(n);
    while(x==n) x=PB(n,--op);
    gn(x);
    gn(n/x);
}
Ejemplo n.º 3
0
int8_t GSwifi::factorySetup(uint32_t initial_baud) {
    clear();

    // version 2.5.1 firmware starts with 115200 baud rate
    // version 2.5.1 (Tue, Dec 10, 2013 at 2:14 PM) firmware starts with 9600 baud rate
    // version 2.4.3 firmware starts with 9600 baud rate
    serial_->begin(initial_baud);

    // need this to ignore invalid response
    command(PB("AT",1), GSCOMMANDMODE_NORMAL, GS_TIMEOUT_SHORT);
    if (did_timeout_) {
        return -1;
    }

    setBaud(57600);

    command(PB("ATE0",1), GSCOMMANDMODE_NORMAL);

    // enable bulk data mode
    command(PB("AT+BDATA=1",1), GSCOMMANDMODE_NORMAL);

    command(PB("AT&W0",1), GSCOMMANDMODE_NORMAL);
    if (did_timeout_) {
        return -1;
    }
    return 0;
}
Ejemplo n.º 4
0
void filters_brightness(unsigned char *image, int width, int height, int depth, int stride, int ibright) {
	register int i, j;
	register unsigned char *pBuf = NULL;
	double c;
	int tempC;

	if (ibright > 0) {
		ibright = ibright * 150 / 100;
		c = 0.000172 * ibright * ibright + 0.001093 * ibright + 0.2;
		for (i = 0; i < 256; i++) {
			tempC = (int)(255 - (255 - i) * pow(1 - i / 255.0, c) - 0.5);
			gTable[i] = CLAMP(tempC);
		}
	}
	else {
		ibright = ibright * 180 / 100;
		c = 0.00001077 * ibright * ibright + 0.00582 * ibright + 0.88;
		for (i = 0; i < 256; i++) {
			tempC = (int)(255 - 255 * pow(1 - i / 255.0, c) - 0.5);
			gTable[i] = CLAMP(tempC);
		}
	}

	for(j = 0; j < height; j++) {
		pBuf = image + j * stride;
		for(i = 0; i < width; i++, pBuf += depth) {
	    	PR(pBuf) = *(gTable + PR(pBuf));
	    	PG(pBuf) = *(gTable + PG(pBuf));
	    	PB(pBuf) = *(gTable + PB(pBuf));
		}
	}
}
Ejemplo n.º 5
0
// mDNS setup has to be done while joined to network
int8_t GSwifi::setupMDNS() {
    char *cmd;

    // no impact on discoverability
    // command(PB("AT+DHCPSRV",1), GSCOMMANDMODE_NORMAL);

    command(PB("AT+MDNSSTART",1), GSCOMMANDMODE_NORMAL);

    // ex: "00:1d:c9:01:99:99"
    cmd = PB("AT+MDNSHNREG=IRKitXXXX,local",1);
    strcpy( cmd+13, hostname() );
    cmd[22] = ',';
    command(cmd, GSCOMMANDMODE_MDNS);

    cmd = PB("AT+MDNSSRVREG=IRKitXXXX,,_irkit,_tcp,local,80",1);
    strcpy( cmd+14, hostname() );
    cmd[23] = ',';
    command(cmd, GSCOMMANDMODE_MDNS);

    command(PB("AT+MDNSANNOUNCE",1), GSCOMMANDMODE_NORMAL);
    if (did_timeout_) {
        return -1;
    }
    return 0;
}
Ejemplo n.º 6
0
struct platform_device *__init at32_add_device_ac97c(unsigned int id)
{
	struct platform_device *pdev;

	if (id != 0)
		return NULL;

	pdev = platform_device_alloc("atmel_ac97c", id);
	if (!pdev)
		return NULL;

	if (platform_device_add_resources(pdev, atmel_ac97c0_resource,
				ARRAY_SIZE(atmel_ac97c0_resource)))
		goto err_add_resources;

	select_peripheral(PB(20), PERIPH_B, 0);	/* SYNC	*/
	select_peripheral(PB(21), PERIPH_B, 0);	/* SDO	*/
	select_peripheral(PB(22), PERIPH_B, 0);	/* SDI	*/
	select_peripheral(PB(23), PERIPH_B, 0);	/* SCLK	*/

	atmel_ac97c0_pclk.dev = &pdev->dev;

	platform_device_add(pdev);
	return pdev;

err_add_resources:
	platform_device_put(pdev);
	return NULL;
}
Ejemplo n.º 7
0
int GSwifi::disconnect () {
    joined_     = false;
    listening_  = false;
    limited_ap_ = false;
    command(PB("AT+NCLOSEALL",1),  GSCOMMANDMODE_NORMAL);
    command(PB("AT+WD",1),         GSCOMMANDMODE_NORMAL);
    command(PB("AT+DHCPSRVR=0",1), GSCOMMANDMODE_NORMAL);
    return 0;
}
Ejemplo n.º 8
0
void exposure(unsigned char *image, int width, int height, int depth, int stride, int scale) {
    register int i, j;
    register unsigned char *pBuf;
    int m =   (255 - scale);

    for (j = 0; j < height; j++) {
        pBuf = image + j * stride;
        for (i = 0; i < width; i++, pBuf += depth) {
            PR(pBuf) = CLAMP((int)(255 * PR(pBuf) / m));
            PG(pBuf) = CLAMP((int)(255 * PG(pBuf) / m));
            PB(pBuf) = CLAMP((int)(255 * PB(pBuf) / m));
        }
    }
}
Ejemplo n.º 9
0
int8_t GSwifi::writeHead (int8_t cid, uint16_t status_code) {
    char *cmd = PB("S0",1);
    cmd[ 1 ]  = i2x(cid);

    escape( cmd );

    serial_->print(P("HTTP/1.0 "));
    char *msg;
    switch (status_code) {
    case 200:
        msg = P("200 OK");
        break;
    case 400:
        msg = P("400 Bad Request");
        break;
    case 404:
        msg = P("404 Not Found");
        break;
    case 500:
    default:
        msg = P("500 Internal Server Error");
        break;
    }

    serial_->println(msg);
    serial_->print("Access-Control-Allow-Origin: *\r\nServer: IRKit/");
    serial_->println(version);
    serial_->println(P("Content-Type: text/plain\r\n"));
}
Ejemplo n.º 10
0
int8_t GSwifi::checkVersion() {
    command(PB("AT+VER=?",1), GSCOMMANDMODE_VERSION);
    if (did_timeout_) {
        return -1;
    }
    return 0;
}
Ejemplo n.º 11
0
char* GSwifi::password() {
    // reuse index: 0 area
    // this should be safe if we immediately call `strcpy( target, password() )`
    // char *ret = PB("XXXX,XXXXXXXXXX", 0); // 2015-11-28 eqiglii: replace XXXXXXXXXX with your irkit 10 digits wifi password
    char *ret = PB("XXXX,1547131217", 0);
    return ret + 5; // we detect ^ this pattern in password replacer
}
Ejemplo n.º 12
0
/*
** Common implementation for the ticket setup editor pages.
*/
static void tktsetup_generic(
  const char *zTitle,           /* Page title */
  const char *zDbField,         /* Configuration field being edited */
  const char *zDfltValue,       /* Default text value */
  const char *zDesc,            /* Description of this field */
  char *(*xText)(const char*),  /* Validity test or NULL */
  void (*xRebuild)(void),       /* Run after successful update */
  int height                    /* Height of the edit box */
){
  const char *z;
  int isSubmit;

  login_check_credentials();
  if( !g.perm.Setup ){
    login_needed(0);
    return;
  }
  if( PB("setup") ){
    cgi_redirect("tktsetup");
  }
  isSubmit = P("submit")!=0;
  z = P("x");
  if( z==0 ){
    z = db_get(zDbField, (char*)zDfltValue);
  }
  style_header("Edit %s", zTitle);
  if( P("clear")!=0 ){
    login_verify_csrf_secret();
    db_unset(zDbField, 0);
    if( xRebuild ) xRebuild();
    cgi_redirect("tktsetup");
  }else if( isSubmit ){
    char *zErr = 0;
    login_verify_csrf_secret();
    if( xText && (zErr = xText(z))!=0 ){
      cgi_printf("<p class=\"tktsetupError\">ERROR: %h</p>\n",(zErr));
    }else{
      db_set(zDbField, z, 0);
      if( xRebuild ) xRebuild();
      cgi_redirect("tktsetup");
    }
  }
  cgi_printf("<form action=\"%s/%s\" method=\"post\"><div>\n",(g.zTop),(g.zPath));
  login_insert_csrf_secret();
  cgi_printf("<p>%s</p>\n"
         "<textarea name=\"x\" rows=\"%d\" cols=\"80\">%h</textarea>\n"
         "<blockquote><p>\n"
         "<input type=\"submit\" name=\"submit\" value=\"Apply Changes\" />\n"
         "<input type=\"submit\" name=\"clear\" value=\"Revert To Default\" />\n"
         "<input type=\"submit\" name=\"setup\" value=\"Cancel\" />\n"
         "</p></blockquote>\n"
         "</div></form>\n"
         "<hr />\n"
         "<h2>Default %s</h2>\n"
         "<blockquote><pre>\n"
         "%h\n"
         "</pre></blockquote>\n",(zDesc),(height),(z),(zTitle),(zDfltValue));
  style_footer();
}
Ejemplo n.º 13
0
static void
tda998x_write_avi(struct tda998x_priv *priv, struct drm_display_mode *mode)
{
	u8 buf[PB(HDMI_AVI_INFOFRAME_SIZE) + 1];

	memset(buf, 0, sizeof(buf));
	buf[HB(0)] = HDMI_INFOFRAME_TYPE_AVI;
	buf[HB(1)] = 0x02;
	buf[HB(2)] = HDMI_AVI_INFOFRAME_SIZE;
	buf[PB(1)] = HDMI_SCAN_MODE_UNDERSCAN;
	buf[PB(2)] = HDMI_ACTIVE_ASPECT_PICTURE;
	buf[PB(3)] = HDMI_QUANTIZATION_RANGE_FULL << 2;
	buf[PB(4)] = drm_match_cea_mode(mode);

	tda998x_write_if(priv, DIP_IF_FLAGS_IF2, REG_IF2_HB0, buf,
			 sizeof(buf));
}
Ejemplo n.º 14
0
static void
tda998x_write_aif(struct tda998x_priv *priv, struct tda998x_encoder_params *p)
{
	u8 buf[PB(HDMI_AUDIO_INFOFRAME_SIZE) + 1];

	memset(buf, 0, sizeof(buf));
	buf[HB(0)] = HDMI_INFOFRAME_TYPE_AUDIO;
	buf[HB(1)] = 0x01;
	buf[HB(2)] = HDMI_AUDIO_INFOFRAME_SIZE;
	buf[PB(1)] = p->audio_frame[1] & 0x07; /* CC */
	buf[PB(2)] = p->audio_frame[2] & 0x1c; /* SF */
	buf[PB(4)] = p->audio_frame[4];
	buf[PB(5)] = p->audio_frame[5] & 0xf8; /* DM_INH + LSV */

	tda998x_write_if(priv, DIP_IF_FLAGS_IF4, REG_IF4_HB0, buf,
			 sizeof(buf));
}
Ejemplo n.º 15
0
//colorTable[stepr * stepg * stepb]
void point_table(unsigned char *image, unsigned char *colorTable, int width, int height, int depth, int stride, int stepr, int stepg, int stepb) {
    int i, j;
    static int STEP = 3;
    unsigned char  *pBuf;

    int r, g, b;
    int lut_r, lut_g, lut_b;
    float fr, fg, fb;
    float dr, dg, db;
    int p;
    int off[8] = {
            STEP * 0 ,                                     STEP * 1,
            STEP * (stepb) ,                            STEP * (stepb+ 1),
            STEP * (stepb * stepg) ,                STEP * (stepb * stepg + 1),
            STEP * (stepb * stepg + stepb),    STEP * (stepb * stepg + stepb +1)};

    float scaler = (stepr - 1) / 256.f;
    float scaleg = (stepg - 1) / 256.f;
    float scaleb = (stepb - 1) / 256.f;

    for(j = 0; j < height; j++) {
        pBuf = image + j * stride;
        for(i = 0; i < width; i++, pBuf += depth) {
            r = PR(pBuf);
            g = PG(pBuf);
            b = PB(pBuf);

            fb = b*scaler;
            fg = g*scaleg;
            fr = r*scaleb;
            lut_b = (int)fb;
            lut_g = (int)fg;
            lut_r = (int)fr;
            dr = fr-lut_r;
            dg = fg-lut_g;
            db = fb-lut_b;

            p = lut_b + lut_g * stepb + lut_r * stepg * stepb;
            p *= STEP;

            PR(pBuf) = interp(colorTable,p  ,off,dr,dg,db);
            PG(pBuf) = interp(colorTable,p+1,off,dr,dg,db);
            PB(pBuf) = interp(colorTable,p+2,off,dr,dg,db);
        }
    }
}
Ejemplo n.º 16
0
static void
tda998x_write_if(struct tda998x_priv *priv, uint8_t bit, uint16_t addr,
		 uint8_t *buf, size_t size)
{
	buf[PB(0)] = tda998x_cksum(buf, size);

	reg_clear(priv, REG_DIP_IF_FLAGS, bit);
	reg_write_range(priv, addr, buf, size);
	reg_set(priv, REG_DIP_IF_FLAGS, bit);
}
Ejemplo n.º 17
0
char* GSwifi::hostname() {
    // reuse index: 0 area
    // this should be safe if we immediately call `strcpy( target, hostname() )`
    char *ret = PB("IRKit%%%%", 0);
    ret[ 5 ] = mac_[12];
    ret[ 6 ] = mac_[13];
    ret[ 7 ] = mac_[15];
    ret[ 8 ] = mac_[16];
    return ret;
}
Ejemplo n.º 18
0
void vibrance(unsigned char *image, int width, int height, int depth, int stride, float scale) {
    int i, j;
    unsigned char  *pBuf;
    float Vib = scale / 100.f;
    float mVibranceTab[512] = {0};
    int r, g, b, gray;
    int maxgb, red;
    float gs, sx, S;
    int dr,dg,db;

    for(i = -255; i < 256; i++) {
        mVibranceTab[i + 255] = Vib / (1+exp(-(i / 256.0f)*3));
    }

    for(j = 0; j < height; j++) {
        pBuf = image + j * stride;
        for(i = 0; i < width; i++, pBuf += depth, pBuf += depth) {
            r = PR(pBuf);
            g = PG(pBuf);
            b = PB(pBuf);

            gray = GRAY(r, g, b);

            if(g > b) {
                maxgb = g;
            } else {
                maxgb = b;
            }

            red = r - maxgb + 255;

            sx = mVibranceTab[red];

            dr = (int)(r + (r - gray) * sx);
            dg = (int)(g + (g - gray) * sx);
            db = (int)(b + (b - gray) * sx);

            PR(pBuf)  = CLAMP(dr);
            PG(pBuf) = CLAMP(dg);
            PB(pBuf)  = CLAMP(db);
        }
    }
}
Ejemplo n.º 19
0
int GSwifi::listen() {
    command(PB("AT+NSTCP=80",1), GSCOMMANDMODE_CONNECT);
    if (did_timeout_) {
        return -1;
    }

    server_cid_ = connected_cid_;
    listening_  = true;

    return 0;
}
Ejemplo n.º 20
0
// does recurse
int8_t GSwifi::close (int8_t cid) {
    char *cmd = PB("AT+NCLOSE=0", 1);
    cmd[ 10 ] = i2x(cid);

    TIMER_STOP( timers_[cid] );

    command(cmd, GSCOMMANDMODE_NORMAL);
    if (did_timeout_) {
        return -1;
    }
    return 0;
}
Ejemplo n.º 21
0
struct platform_device *__init
at32_add_device_spi(unsigned int id, struct spi_board_info *b, unsigned int n)
{
	/*
	 * Manage the chipselects as GPIOs, normally using the same pins
	 * the SPI controller expects; but boards can use other pins.
	 */
	static u8 __initdata spi0_pins[] =
		{ GPIO_PIN_PA(3), GPIO_PIN_PA(4),
		  GPIO_PIN_PA(5), GPIO_PIN_PA(20), };
	static u8 __initdata spi1_pins[] =
		{ GPIO_PIN_PB(2), GPIO_PIN_PB(3),
		  GPIO_PIN_PB(4), GPIO_PIN_PA(27), };
	struct platform_device *pdev;

	switch (id) {
	case 0:
		pdev = &atmel_spi0_device;
		select_peripheral(PA(0),  PERIPH_A, 0);	/* MISO	 */
		select_peripheral(PA(1),  PERIPH_A, 0);	/* MOSI	 */
		select_peripheral(PA(2),  PERIPH_A, 0);	/* SCK	 */
		at32_spi_setup_slaves(0, b, n, spi0_pins);
		break;

	case 1:
		pdev = &atmel_spi1_device;
		select_peripheral(PB(0),  PERIPH_B, 0);	/* MISO  */
		select_peripheral(PB(1),  PERIPH_B, 0);	/* MOSI  */
		select_peripheral(PB(5),  PERIPH_B, 0);	/* SCK   */
		at32_spi_setup_slaves(1, b, n, spi1_pins);
		break;

	default:
		return NULL;
	}

	spi_register_board_info(b, n);
	platform_device_register(pdev);
	return pdev;
}
Ejemplo n.º 22
0
int8_t GSwifi::setRegDomain (char regdomain) {

#if WIFI_MODULE == GS1011MEPS
    if (regdomain == 1) {
        regdomain = 3;
    }
#endif

    char *cmd = PB("AT+WREGDOMAIN=%",1);
    cmd[ 14 ] = regdomain;
    command(cmd, GSCOMMANDMODE_NORMAL);
    return 0;
}
Ejemplo n.º 23
0
struct platform_device *__init
at32_add_device_ssc(unsigned int id, unsigned int flags)
{
	struct platform_device *pdev;

	switch (id) {
	case 0:
		pdev = &ssc0_device;
		if (flags & ATMEL_SSC_RF)
			select_peripheral(PA(21), PERIPH_A, 0);	/* RF */
		if (flags & ATMEL_SSC_RK)
			select_peripheral(PA(22), PERIPH_A, 0);	/* RK */
		if (flags & ATMEL_SSC_TK)
			select_peripheral(PA(23), PERIPH_A, 0);	/* TK */
		if (flags & ATMEL_SSC_TF)
			select_peripheral(PA(24), PERIPH_A, 0);	/* TF */
		if (flags & ATMEL_SSC_TD)
			select_peripheral(PA(25), PERIPH_A, 0);	/* TD */
		if (flags & ATMEL_SSC_RD)
			select_peripheral(PA(26), PERIPH_A, 0);	/* RD */
		break;
	case 1:
		pdev = &ssc1_device;
		if (flags & ATMEL_SSC_RF)
			select_peripheral(PA(0), PERIPH_B, 0);	/* RF */
		if (flags & ATMEL_SSC_RK)
			select_peripheral(PA(1), PERIPH_B, 0);	/* RK */
		if (flags & ATMEL_SSC_TK)
			select_peripheral(PA(2), PERIPH_B, 0);	/* TK */
		if (flags & ATMEL_SSC_TF)
			select_peripheral(PA(3), PERIPH_B, 0);	/* TF */
		if (flags & ATMEL_SSC_TD)
			select_peripheral(PA(4), PERIPH_B, 0);	/* TD */
		if (flags & ATMEL_SSC_RD)
			select_peripheral(PA(5), PERIPH_B, 0);	/* RD */
		break;
	case 2:
		pdev = &ssc2_device;
		if (flags & ATMEL_SSC_TD)
			select_peripheral(PB(13), PERIPH_A, 0);	/* TD */
		if (flags & ATMEL_SSC_RD)
			select_peripheral(PB(14), PERIPH_A, 0);	/* RD */
		if (flags & ATMEL_SSC_TK)
			select_peripheral(PB(15), PERIPH_A, 0);	/* TK */
		if (flags & ATMEL_SSC_TF)
			select_peripheral(PB(16), PERIPH_A, 0);	/* TF */
		if (flags & ATMEL_SSC_RF)
			select_peripheral(PB(17), PERIPH_A, 0);	/* RF */
		if (flags & ATMEL_SSC_RK)
			select_peripheral(PB(18), PERIPH_A, 0);	/* RK */
		break;
	default:
		return NULL;
	}

	platform_device_register(pdev);
	return pdev;
}
Ejemplo n.º 24
0
// factory should issue following commands:
// % AT
// % ATE0
// % ATB=38400
// % AT&W0
// % AT&Y0
int8_t GSwifi::setup(GSEventHandler on_disconnect, GSEventHandler on_reset) {
    on_disconnect_ = on_disconnect;
    on_reset_      = on_reset;

    clear();

    // baud rate is written into default profile in factory
    serial_->begin(57600);

    // how to change baud rate (2.5.1 has only one profile, don't need to send AT&Y0)
    // setBaud(57600);
    // command(PB("ATE0",1), GSCOMMANDMODE_NORMAL);
    // command(PB("AT&W0",1), GSCOMMANDMODE_NORMAL);
    // command(PB("AT&Y0",1), GSCOMMANDMODE_NORMAL);

    // need this to ignore initial response
    command(PB("AT",1), GSCOMMANDMODE_NORMAL);
    if (did_timeout_) {
        // return here to speed up after hardware reset
        return -1;
    }

    // disable external PA
    // we might be connected to GS1011MIPS or GS1011MEPS
    command(PB("AT+EXTPA=0",1), GSCOMMANDMODE_NORMAL);
    delay( 100 );

    // explicitly set transmit power
    command(PB("AT+WP=0",1), GSCOMMANDMODE_NORMAL);

    // write this before AT&K1, cert includes XON or XOFF hex
    writeCert();

    // enable software flow control
    command(PB("AT&K1",1), GSCOMMANDMODE_NORMAL);

    // get my mac address
    command(PB("AT+NMAC=?",1), GSCOMMANDMODE_MAC);

    // disable association keep alive timer
    command(PB("AT+PSPOLLINTRL=0",1), GSCOMMANDMODE_NORMAL);

    // set system time (must be within cert valid period)
    command(PB("AT+SETTIME=01/01/2015,00:00:00",1), GSCOMMANDMODE_NORMAL);

    if (did_timeout_) {
        return -1;
    }

    return 0;
}
Ejemplo n.º 25
0
int main(int argc, char **argv) {
    vb::Hub H("Deterministic Fourier law", argc, argv, "a=2,b=.2394879347,n=500,m=1000,t=100");
    size_t  nn = H['n'], nn2 = nn / 2, mm = H['m'], tt = H['t'];
    state::a = H['a'];
    state::b = H['b'];
    std::vector<double> profile(nn, 0), boltzmann(mm, 0), var(tt, 0);

    vb::ProgressBar PB(mm);
    for (size_t i = 0; i < mm; ++i) {
        Model M(nn);
        M[nn2].v = 1;
        for (size_t t = 0; t < tt; ++t) {
            PB.set(i);
            M.swipe();
            double v = 0;
            for (size_t k = 0; k < nn; ++k) v += double((k - nn2) * (k - nn2)) * M[k].v * M[k].v;
            var[t] += v;
        }
        for (size_t k = 0; k < nn; ++k) profile[k] += M[k].v * M[k].v;
        boltzmann[i] = M[nn / 2].v;
    }

    {
        std::ofstream of("out.profile");
        for (auto u : profile) of << u << std::endl;
    }
    {
        std::ofstream of("out.variance");
        for (auto u : var) of << u << std::endl;
    }
    {
        auto   nclass = size_t(sqrt(double(H['m'])));
        double bmin = 0, bmax = 0;
        for (auto b : boltzmann) {
            bmin = std::min(bmin, b);
            bmax = std::max(bmax, b);
        }
        std::vector<int> data(nclass);
        for (auto b : boltzmann) data[unsigned((nclass - .01) * (b - bmin) / (bmax - bmin))]++;
        std::ofstream of("out.boltzmann");
        for (size_t i = 0; i < nclass; ++i) of << bmin + i * (bmax - bmin) / nclass << " " << data[i] << std::endl;
    }
}
Ejemplo n.º 26
0
int8_t GSwifi::startLimitedAP () {
    char *cmd;

    disconnect();

    command(PB("AT+NSET=192.168.1.1,255.255.255.0,192.168.1.1",1), GSCOMMANDMODE_NORMAL);

    // password area overwritten in factory
    // AT+WPAPSK=IRKitXXXX,XXXXXXXXXX
    cmd = PB("AT+WPAPSK=",1);
    strcpy( cmd+10, hostname() );
    cmd[19] = ',';
    strcpy( cmd+20, password() );
    cmd[30] = 0;
    command(cmd, GSCOMMANDMODE_NORMAL, GS_TIMEOUT_LONG);

    // WPA2
    command(PB("AT+WSEC=8",1),           GSCOMMANDMODE_NORMAL);
    command(PB("AT+WAUTH=0",1),          GSCOMMANDMODE_NORMAL);

    // limited AP
    command(PB("AT+WM=2",1),             GSCOMMANDMODE_NORMAL);

    command(PB("AT+DHCPSRVR=1",1),       GSCOMMANDMODE_NORMAL);

    // start
    cmd = PB("AT+WA=%",1);
    strcpy( cmd+6, hostname() );
    command(cmd, GSCOMMANDMODE_NORMAL, GS_TIMEOUT_LONG);

    if (did_timeout_) {
        return -1;
    }

    limited_ap_ = true;

    return 0;
}
Ejemplo n.º 27
0
Archivo: main.cpp Proyecto: Vort/VortOS
// ----------------------------------------------------------------------------
void Entry()
{
	// Move cursor off-screen
	_outpw(0x3D4, 0x070E);
	_outpw(0x3D4, 0xD00F);

	CKernelHeader* KH = (CKernelHeader*)CMemMap::c_KernelImageBase;
	dword* BootInfo = (dword*)(*(dword*)(CMemMap::c_KernelImageBase + 0x100));

	RawOutString("Checking Kernel...", 0, 0, 0xA);
	if (IsKernelOK(*KH, BootInfo))
	{
		RawOutString("OK", 18, 0, 0xA);
	}
	else
	{
		RawOutString("Fail", 18, 0, 0xC);
		ErrIf(true);
	}

	dword BootType = BootInfo[1];
	dword DriversCount = BootInfo[2] - 1;
	CDriverInfo DriverInfos[12];

	for (dword i = 0; i < DriversCount; i++)
	{
		DriverInfos[i].m_BytesSize = BootInfo[3 + (i + 1) * 3];
		DriverInfos[i].m_LoadPage  = BootInfo[4 + (i + 1) * 3];
		char* Name = PC(BootInfo[5 + (i + 1) * 3]);

		for (int j = 0;; j++)
		{
			DriverInfos[i].m_Name[j] = Name[j];
			if (Name[j] == 0)
				break;
		}
	}

	InitPIT();

	CPhysMemManager PMM;
	PMM.AllocBlockAt(KH->GetKernelCodeBase(), KH->m_KernelCodePageCount, false);
	PMM.AllocBlockAt(KH->GetKernelRDataBase(), KH->m_KernelRDataPageCount, false);
	PMM.AllocBlockAt(KH->GetKernelDataBase(), KH->m_KernelDataPageCount, true);
	PMM.AllocBlockAt((byte*)CMemMap::c_VideoRamTextBase, 8, true);
	__writecr3(CMemMap::c_PmmPageDirectory);
	SetupCR0();

	for (dword i = 0; i < DriversCount; i++)
	{
		PMM.AllocBlockAt(
			DriverInfos[i].GetImageBase(),
			DriverInfos[i].GetImagePageCount(), false);
	}

	CGDT GDT(PMM);
	GDT.CreateNewDescriptor(0, 0xFFFFF, 0x92, 1);
	GDT.CreateNewDescriptor(0, 0xFFFFF, 0x98, 1);
	GDT.CreateNewDescriptor(0, 0xFFFFF, 0xF2, 1);
	GDT.CreateNewDescriptor(0, 0xFFFFF, 0xF8, 1);

	static const dword HeapPageCount = 32;
	void* HeapBlock = PMM.AllocBlock(HeapPageCount);
	CHeap SysHeap(PB(HeapBlock), HeapPageCount * 4096);
	g_SysHeap = &SysHeap;

	CTask KernelTask(GDT, true, 0, 0, 0, 0, CMemMap::c_PmmPageDirectory);
	KernelTask._setActive();

	CIntManager IM(PMM, KernelTask.GetTSS().GetSelector());

	CKernel K(KernelTask, PMM, IM, GDT, IM.GetIDT(),
		BootType, DriverInfos, DriversCount);
}
Ejemplo n.º 28
0
    {GPIOG,   NULL, NULL,  7, 0, ADCx}, /* D103/PG7 */
    {GPIOG,   NULL, NULL,  8, 0, ADCx}, /* D104/PG8 */
    {GPIOG,   NULL, NULL,  9, 0, ADCx}, /* D105/PG9 */
    {GPIOG,   NULL, NULL, 10, 0, ADCx}, /* D106/PG10 */
    {GPIOG,   NULL, NULL, 11, 0, ADCx}, /* D107/PG11 */
    {GPIOG,   NULL, NULL, 12, 0, ADCx}, /* D108/PG12 */
    {GPIOG,   NULL, NULL, 13, 0, ADCx}, /* D109/PG13 */
    {GPIOG,   NULL, NULL, 14, 0, ADCx}, /* D110/PG14 */
    {GPIOG,   NULL, NULL, 15, 0, ADCx}, /* D111/PG15 */
#endif

};


extern const uint8 boardPWMPins[BOARD_NR_PWM_PINS] __FLASH__ = {
    PA(0), PA(1), PA(2), PA(3), PA(6), PA(7), PA(8), PA(9), PA(10), PB(0), PB(1), PB(6), PB(7), PB(8), PB(9)
};

extern const uint8 boardADCPins[BOARD_NR_ADC_PINS] __FLASH__ = {
    PA(0), PA(1), PA(2), PA(3), PA(4), PA(5), PA(6), PA(7), PB(0), PB(1), PC(0), PC(1), PC(2), PC(3), PC(4), PC(5)
};


#if defined(INIT_SRAM)

/* FIXME [0.0.12] see comment by BOARD_NR_USED_PINS in maple_native.h */
extern const uint8 boardUsedPins[BOARD_NR_USED_PINS] __FLASH__ = {
    BOARD_LED_PIN, BOARD_BUTTON_PIN, BOARD_JTMS_SWDIO_PIN,
    BOARD_JTCK_SWCLK_PIN, BOARD_JTDI_PIN, BOARD_JTDO_PIN, BOARD_NJTRST_PIN
};
Ejemplo n.º 29
0
int
picdraw_linearrow(int xox, int xoy, ob *xu, ns *xns)
{
    ob* pf;
    ob* pt;
    int x1, y1;
    int x2, y2;

    printf("+ # linearrow head %d %d %d\n", 
        xu->cob.arrowheadpart,
        xu->cob.arrowbackheadtype,
        xu->cob.arrowbackheadtype);

    x1 = xox+xu->csx;
    y1 = xoy+xu->csy;
    x2 = xox+xu->cex;
    y2 = xoy+xu->cey;

    pf = NULL;
    if(xu->cafrom) {
        pf = ns_find_obj(xns, xu->cafrom);
        printf("%s: pf %p\n", __func__, pf);
        if(!pf) {
            goto to_phase;
        }
        if(pf->cfixed) {
            printf("  from %d,%d\n", pf->gx, pf->gy);
            x1 = pf->gx;
            y1 = pf->gy;
        }
    }

to_phase:

    pt = NULL;
    if(xu->cafrom) {
        pt = ns_find_obj(xns, xu->cato);
        printf("%s: pt %p\n", __func__, pt);
        if(!pt) {
            goto apply;
        }
        if(pt->cfixed) {
            printf("  to %d,%d\n", pt->gx, pt->gy);
            x2 = pt->gx;
            y2 = pt->gy;
        }
    }

apply:
    printf("%s: from (%d,%d) to (%d,%d)\n", __func__, x1, y1, x2, y2);
#if 0
    printf("+ line from (%d,%d) to (%d,%d) # line\n", x1, y1, x2, y2);
#endif
    printf("+ line from (%d,%d) to (%d,%d) <-> thick 2 # line\n", x1, y1, x2, y2);


#if 0
    if(xu->cob.arrowforeheadtype>0) {
#endif
    if(xu->cob.arrowheadpart & AR_FORE) {
        int xdir;
        xdir = (int)(atan2((y2-y1),(x2-x1))/rf);
        picdraw_arrowhead(xu->cob.arrowforeheadtype, xdir, x2, y2);
    }
#if 0
    if(xu->cob.arrowbackheadtype>0) {
#endif
    if(xu->cob.arrowheadpart & AR_BACK) {
        int xdir;
        xdir = (int)(atan2((y1-y2),(x1-x2))/rf);
        picdraw_arrowhead(xu->cob.arrowbackheadtype, xdir, x1, y1);
    }

out:
    return 0;
}

        
int
picdraw_line(int xox, int xoy, ob *xu, ns *xns)
{
    ob* pf;
    ob* pt;
    int x1, y1;
    int x2, y2;

    printf("+ # linearrow\n");

    x1 = xox+xu->csx;
    y1 = xoy+xu->csy;
    x2 = xox+xu->cex;
    y2 = xoy+xu->cey;

    pf = NULL;
    if(xu->cafrom) {
        pf = ns_find_obj(xns, xu->cafrom);
        printf("%s: pf %p\n", __func__, pf);
        if(!pf) {
            goto to_phase;
        }
        if(pf->cfixed) {
            printf("  from %d,%d\n", pf->gx, pf->gy);
            x1 = pf->gx;
            y1 = pf->gy;
        }
    }

to_phase:

    pt = NULL;
    if(xu->cafrom) {
        pt = ns_find_obj(xns, xu->cato);
        printf("%s: pt %p\n", __func__, pt);
        if(!pt) {
            goto apply;
        }
        if(pt->cfixed) {
            printf("  to %d,%d\n", pt->gx, pt->gy);
            x2 = pt->gx;
            y2 = pt->gy;
        }
    }

apply:
    printf("%s: from (%d,%d) to (%d,%d)\n", __func__, x1, y1, x2, y2);
    printf("+ line from (%d,%d) to (%d,%d) # line\n", x1, y1, x2, y2);

out:
    return 0;
}

int
picdrawobj(ob *u, int *xdir, int ox, int oy, ns *xns)
{
    int wd, ht;
    int g;

    printf("%s: oid %d xdir %d ox,oy %d,%d\n",
        __func__, u->oid, *xdir, ox, oy);
    
    wd = u->crx-u->clx;
    ht = u->cty-u->cby;

    printf("%s: b oid %d - %d,%d s %d,%d e %d,%d o %d,%d\n",
        __func__, u->oid,
        u->cx, u->cy, u->csx, u->csy, u->cex, u->cey, u->ox, u->coy);

    printf("+ # oid %d, type %d START\n", u->oid, u->type);

#if 0
    PB(u);
    PQQ(u);
#endif
    PD(ox+u->csx, oy+u->csy);
#if 0
#endif
    printf("+ line from (%d,%d) to (%d,%d) thick 0.1 # sxy->exy\n",
        ox+u->csx, oy+u->csy, ox+u->cex, oy+u->cey);

    g = eval_dir(u, xdir);
    if(g>0) {
        goto out;
    }

    if(u->type==CMD_LINE) {
        printf("+   line from (%d,%d) to (%d,%d) thick 1.5 \"%d\" \"\" # line\n",
            ox+u->csx, oy+u->csy, ox+u->cex, oy+u->cey, u->oid);
        picdraw_linearrow(ox, oy, u, xns);
    }
    if(u->type==CMD_ARROW) {
        picdraw_linearrow(ox, oy, u, xns);
#if 0
        int dx, dy;
        int r;
        printf("+   line from (%d,%d) to (%d,%d) thick 1.5 \"%d\" \"\" # arrow\n",
            ox+u->csx, oy+u->csy, ox+u->cex, oy+u->cey, u->oid);
#if 0
        r = u->cht/2;
#endif
        r = def_arrowsize;

        dx =  (int)(r*cos((*xdir+180+def_arrowangle/2)*rf));
        dy =  (int)(r*sin((*xdir+180+def_arrowangle/2)*rf));
        printf("+   line from (%d,%d) to (%d,%d) thick 1.5\n",
            ox+u->cex, oy+u->cey, ox+u->cex+dx, oy+u->cey+dy);

        dx =  (int)(r*cos((*xdir+180-def_arrowangle/2)*rf));
        dy =  (int)(r*sin((*xdir+180-def_arrowangle/2)*rf));
        printf("+   line from (%d,%d) to (%d,%d) thick 1.5\n",
            ox+u->cex, oy+u->cey, ox+u->cex+dx, oy+u->cey+dy);
#endif
    }
    if(u->type==CMD_PLINE) {
        int dx, dy;
        int r;
        if(u->cht < u->cwd) { r = u->cht; } else { r = u->cwd; }
        r = r/2;

        dx = (int)(r*cos((*xdir+90)*rf));
        dy = (int)(r*sin((*xdir+90)*rf));
printf("+ # dir %d; dx,dy %d,%d\n", *xdir, dx, dy);
        printf("+   line from (%d,%d) to (%d,%d) thick 0.1\n",
            ox+u->clx, oy+u->cy, ox+u->crx, oy+u->cy);
        printf("+   line from (%d,%d) to (%d,%d) thick 0.1\n",
            ox+u->csx, oy+u->csy, ox+u->cex, oy+u->cey);
        printf("+   line from (%d,%d) to (%d,%d) thick 1.5 \"%d   \"# pline\n",
            ox+u->cx-dx, oy+u->cy-dy, ox+u->cx+dx, oy+u->cy+dy, u->oid);

    }
    if(u->type==CMD_MOVE) {
        printf("+   # empty as \"move\"\n");
        printf("+   box at (%d,%d) width %d height %d \"%d\" invis\n",
            ox+u->cx, oy+u->cy, u->crx-u->clx, u->cty-u->cby, u->oid);
    }

    if(u->type==CMD_DMY1) {
        printf("+   box at (%d,%d) width %d height %d rad %d \"%d\"\n",
            ox+u->cx, oy+u->cy, u->crx-u->clx, u->cty-u->cby, wd/8, u->oid);
    }
    if(u->type==CMD_DMY2) {
        printf("+   box at (%d,%d) width %d height %d rad %d \"%d\"\n",
            ox+u->cx, oy+u->cy, u->crx-u->clx, u->cty-u->cby, wd/8, u->oid);
    }

    if(u->type==CMD_BOX) {
        printf("+   box at (%d,%d) width %d height %d rad %d \"%d\"\n",
            ox+u->cx, oy+u->cy, u->crx-u->clx, u->cty-u->cby, wd/8, u->oid);
        printf("+   box at (%d,%d) width %d height %d rad %d thickness %d \"%d\"\n",
            ox+u->cx, oy+u->cy, u->crx-u->clx, u->cty-u->cby, wd/8, u->cob.outlinethick, u->oid);
    }
    if(u->type==CMD_CIRCLE) {
        printf("+   circle at (%d,%d) rad %d \"%d\"\n",
            ox+u->cx, oy+u->cy, u->cwd/2, u->oid);
    }
    if(u->type==CMD_ELLIPSE) {
        printf("+   ellipse at (%d,%d) width %d height %d \"%d\"\n",
            ox+u->cx, oy+u->cy, u->crx-u->clx, u->cty-u->cby, u->oid);
    }
    if(u->type==CMD_POLYGON) {
#if 0
        printf("+   box at (%d,%d) width %d height %d \"%p\"\n",
            ox+u->cx, oy+u->cy, u->crx-u->clx, u->cty-u->cby, u);
#endif
        printf("+   line from (%d,%d) to (%d,%d) to (%d,%d) to (%d,%d)\n",
            ox+u->clx, oy+u->cby, ox+(u->clx+u->crx)/2, oy+u->cty,
            ox+u->crx, oy+u->cby, ox+u->clx, oy+u->cby);
    }
    printf("+ # oid %d, type %d DONE\n", u->oid, u->type);

out:
    printf("%s: a oid %d - %d,%d s %d,%d e %d,%d o %d,%d\n",
        __func__, u->oid,
        u->cx, u->cy, u->csx, u->csy, u->cex, u->cey, u->ox, u->coy);

    return 0;
}
Ejemplo n.º 30
0
int
picdrawchunk(ob *xch, int gox, int goy, ns *xns)
{
    int ik;
    int i;
    ob* u;

    printf("%s: oid %d x,y %d,%d\n", __func__, xch->oid, gox, goy);

    printf("%s:   oid %d wxh %dx%d o %d,%d\n",
        __func__, xch->oid, xch->wd, xch->ht, xch->ox, xch->oy);
    printf("%s: b oid %d - %d,%d s %d,%d e %d,%d o %d,%d\n",
        __func__, xch->oid,
 xch->cx, xch->cy, xch->csx, xch->csy, xch->cex, xch->cey, xch->ox, xch->coy);

    printf("+ ##### oid %d START\n", xch->oid);

    cha_reset(&xch->cch);

    PB(xch);
#if 0
#endif
    PQ(xch);

#if 1
    printf("%p (%d,%d)->(%d,%d) (%d,%d) (%d,%d)-(%d,%d)\n",
        xch,
        xch->csx, xch->csy, xch->cex, xch->cey,
        xch->cx, xch->cy, xch->clx, xch->cby, xch->crx, xch->cty);
    printf("%p+(%d,%d) (%d,%d)->(%d,%d) (%d,%d) (%d,%d)-(%d,%d)\n",
        xch, gox, goy,
        gox+xch->csx, goy+xch->csy, gox+xch->cex, goy+xch->cey,
        gox+xch->cx, goy+xch->cy, gox+xch->clx, goy+xch->cby, gox+xch->crx, goy+xch->cty);
#endif

    
#if 0
    printf("+ arrow from (%d,%d) to (%d,%d)\n",
        gox+xch->csx, goy+xch->csy,
        gox+xch->cex, goy+xch->cey);
    printf("+ circle at (%d,%d) rad %d dashed\n",
        gox+xch->cx, goy+xch->cy, xch->cmr);
    printf("+ line from (%d,%d) to (%d,%d) to (%d,%d) to (%d,%d) to (%d,%d) dashed\n",
        gox+xch->clx, gox+xch->cby, gox+xch->clx, gox+xch->cty,
        gox+xch->crx, gox+xch->cty, gox+xch->crx, gox+xch->cby,
        gox+xch->clx, gox+xch->cby);
#endif

#if 0
    printf("+ box at (%d,%d) width 5 height 5 thick 2\n",
        xch->cox, xch->coy);
#endif
#if 0
    PC(xch->cox, xch->coy);
#endif
    PC(xch->cx, xch->cy);

    printf("+ circle at (%d,%d) rad 2 fill 1\n",
        xch->csx, xch->csy);
    printf("+ circle at (%d,%d) rad 2 fill 0\n",
        xch->cex, xch->cey);
#if 0
#endif

#if 0
    printf("+ circle at (%d,%d) rad %d dashed\n",
        gox+xch->cox+xch->cx, xch->coy+goy+xch->cy, xch->cmr);
    printf("+ circle at (%d,%d) rad %d dashed\n",
        xch->cox+xch->cx, xch->coy+xch->cy, xch->cmr);
#endif

    for(i=0;i<xch->cch.nch;i++) {
        u = (ob*)xch->cch.ch[i];
        if(u->type==CMD_CHUNK) {
#if 0
            ik = picdrawchunk(u, xch->x+xch->ox, xch->y+xch->oy, xns);
#endif
            ik = picdrawchunk(u,
                    xch->x+xch->ox+u->ox,
                    xch->y+xch->oy+u->oy, xns);
        }
        else {
            ik = picdrawobj(u, &xch->cch.dir, xch->x+xch->ox, xch->y+xch->oy, xns);
        }
    }

    printf("+ ##### oid %d DONE\n", xch->oid);

    printf("%s: a oid %d - %d,%d s %d,%d e %d,%d o %d,%d\n",
        __func__, xch->oid, 
        xch->cx, xch->cy, xch->csx, xch->csy, xch->cex, xch->cey, xch->ox, xch->coy);

    return 0;
}