const char* _scanf_getf(const char *str, float* dst)
{
  char *end;
  float f = string2float((char*)str, &end);
  *dst = f;
  return end;
}
Exemple #2
0
// converts a single "number(%|pt)" to an ui_float
static pair<float, gui_theme::VALUE_TYPE> str_to_ui_float_pair(const string& val_str) {
	const auto at_pos(val_str.find("@"));
	if(at_pos != string::npos) {
		return { 0.0f, gui_theme::VALUE_TYPE::CENTER };
	}
	
	const auto perc_pos(val_str.find("%"));
	if(perc_pos != string::npos) {
		// [0, 100] -> [0, 1]
		const float scaled_value(string2float(val_str.substr(0, perc_pos)) * 0.01f);
		return { scaled_value, gui_theme::VALUE_TYPE::PERCENTAGE };
	}
	
	const auto pt_pos(val_str.find("pt"));
	if(pt_pos != string::npos) {
		return { string2float(val_str), gui_theme::VALUE_TYPE::POINT };
	}
	
	return { string2float(val_str), gui_theme::VALUE_TYPE::PIXEL };
};
Exemple #3
0
//##ModelId=4A2B758102CE
movedata cls_ai::GetNewAnglePos(floatpoint src_point, int speed,int mode,float angle)
{
	// TODO: Add your specialized code here.
	// NOTE: Requires a correct return value to compile.
	lua_settop(L,0);//重置栈索引
	lua_getglobal(L,"GetNewAnglePos");
	if(!lua_isfunction(L,-1)){
		MessageBox(globalhwnd,"脚本里没有GetNewAnglePos函数","",MB_OK);
	}
	lua_pushnumber(L,(float)src_point.x);

	lua_pushnumber(L,(float)src_point.y);
	lua_pushnumber(L,speed);
	lua_pushnumber(L,mode);
	lua_pushnumber(L,(float)angle);
	lua_call(L,5,1);
	string str=lua_tostring(L,-1);
	vector<string > v=explode(",",str);
	//MessageBox(NULL,v[0].c_str(),"坐标",MB_OK);
	//MessageBox(NULL,v[1].c_str(),"坐标",MB_OK);
	int new_x=string2int(v[0].c_str());
	int new_y=string2int(v[1].c_str());
	float new_angle;
	if (v.size()==3)//代表有3个未劈开的字符
	{
	 new_angle=string2float(v[2].c_str());
	}
	/*int ints=(int)lua_tonumber(L,-1);
	char buf[20];
	sprintf(buf,"%d",ints);
	MessageBox(NULL,buf,"",MB_OK);*/
	//POINT pt;
	//pt.x=0;
	//pt.y=0;
	//pt.x=new_x;
	//pt.y=new_y;
	movedata mdata;
	mdata.x=new_x;
	mdata.y=new_y;
	mdata.angle=new_angle;
	return mdata;
}
Exemple #4
0
/*
 * Decode one item and put it in "res".  If "res" is NULL only advance.
 * Must already have skipped white space.
 *
 * Return FAIL for a decoding error (and give an error).
 * Return MAYBE for an incomplete message.
 */
    static int
json_decode_item(js_read_T *reader, typval_T *res, int options)
{
    char_u	*p;
    int		len;
    int		retval;
    garray_T	stack;
    typval_T	item;
    typval_T	*cur_item;
    json_dec_item_T *top_item;
    char_u	key_buf[NUMBUFLEN];

    ga_init2(&stack, sizeof(json_dec_item_T), 100);
    cur_item = res;
    init_tv(&item);
    if (res != NULL)
    init_tv(res);

    fill_numbuflen(reader);
    p = reader->js_buf + reader->js_used;
    for (;;)
    {
	top_item = NULL;
	if (stack.ga_len > 0)
	{
	    top_item = ((json_dec_item_T *)stack.ga_data) + stack.ga_len - 1;
	    json_skip_white(reader);
	    p = reader->js_buf + reader->js_used;
	    if (*p == NUL)
	    {
		retval = MAYBE;
		if (top_item->jd_type == JSON_OBJECT)
		    /* did get the key, clear it */
		    clear_tv(&top_item->jd_key_tv);
		goto theend;
	    }
	    if (top_item->jd_type == JSON_OBJECT_KEY
					    || top_item->jd_type == JSON_ARRAY)
	    {
		/* Check for end of object or array. */
		if (*p == (top_item->jd_type == JSON_ARRAY ? ']' : '}'))
		{
		    ++reader->js_used; /* consume the ']' or '}' */
		    --stack.ga_len;
		    if (stack.ga_len == 0)
		    {
			retval = OK;
			goto theend;
		    }
		    if (cur_item != NULL)
			cur_item = &top_item->jd_tv;
		    goto item_end;
		}
	    }
	}

	if (top_item != NULL && top_item->jd_type == JSON_OBJECT_KEY
		&& (options & JSON_JS)
		&& reader->js_buf[reader->js_used] != '"'
		&& reader->js_buf[reader->js_used] != '\''
		&& reader->js_buf[reader->js_used] != '['
		&& reader->js_buf[reader->js_used] != '{')
	{
	    char_u *key;

	    /* accept an object key that is not in quotes */
	    key = p = reader->js_buf + reader->js_used;
	    while (*p != NUL && *p != ':' && *p > ' ')
		++p;
	    if (cur_item != NULL)
	    {
		cur_item->v_type = VAR_STRING;
		cur_item->vval.v_string = vim_strnsave(key, (int)(p - key));
		top_item->jd_key = cur_item->vval.v_string;
	    }
	    reader->js_used += (int)(p - key);
	}
	else
	{
	    switch (*p)
	    {
		case '[': /* start of array */
		    if (top_item && top_item->jd_type == JSON_OBJECT_KEY)
		    {
			retval = FAIL;
			break;
		    }
		    if (ga_grow(&stack, 1) == FAIL)
		    {
			retval = FAIL;
			break;
		    }
		    if (cur_item != NULL && rettv_list_alloc(cur_item) == FAIL)
		    {
			cur_item->v_type = VAR_SPECIAL;
			cur_item->vval.v_number = VVAL_NONE;
			retval = FAIL;
			break;
		    }

		    ++reader->js_used; /* consume the '[' */
		    top_item = ((json_dec_item_T *)stack.ga_data)
								+ stack.ga_len;
		    top_item->jd_type = JSON_ARRAY;
		    ++stack.ga_len;
		    if (cur_item != NULL)
		    {
			top_item->jd_tv = *cur_item;
			cur_item = &item;
		    }
		    continue;

		case '{': /* start of object */
		    if (top_item && top_item->jd_type == JSON_OBJECT_KEY)
		    {
			retval = FAIL;
			break;
		    }
		    if (ga_grow(&stack, 1) == FAIL)
		    {
			retval = FAIL;
			break;
		    }
		    if (cur_item != NULL && rettv_dict_alloc(cur_item) == FAIL)
		    {
			cur_item->v_type = VAR_SPECIAL;
			cur_item->vval.v_number = VVAL_NONE;
			retval = FAIL;
			break;
		    }

		    ++reader->js_used; /* consume the '{' */
		    top_item = ((json_dec_item_T *)stack.ga_data)
								+ stack.ga_len;
		    top_item->jd_type = JSON_OBJECT_KEY;
		    ++stack.ga_len;
		    if (cur_item != NULL)
		    {
			top_item->jd_tv = *cur_item;
			cur_item = &top_item->jd_key_tv;
		    }
		    continue;

		case '"': /* string */
		    retval = json_decode_string(reader, cur_item, *p);
		    break;

		case '\'':
		    if (options & JSON_JS)
			retval = json_decode_string(reader, cur_item, *p);
		    else
		    {
			EMSG(_(e_invarg));
			retval = FAIL;
		    }
		    break;

		case ',': /* comma: empty item */
		    if ((options & JSON_JS) == 0)
		    {
			EMSG(_(e_invarg));
			retval = FAIL;
			break;
		    }
		    /* FALLTHROUGH */
		case NUL: /* empty */
		    if (cur_item != NULL)
		    {
			cur_item->v_type = VAR_SPECIAL;
			cur_item->vval.v_number = VVAL_NONE;
		    }
		    retval = OK;
		    break;

		default:
		    if (VIM_ISDIGIT(*p) || *p == '-')
		    {
#ifdef FEAT_FLOAT
			char_u  *sp = p;

			if (*sp == '-')
			{
			    ++sp;
			    if (*sp == NUL)
			    {
				retval = MAYBE;
				break;
			    }
			    if (!VIM_ISDIGIT(*sp))
			    {
				EMSG(_(e_invarg));
				retval = FAIL;
				break;
			    }
			}
			sp = skipdigits(sp);
			if (*sp == '.' || *sp == 'e' || *sp == 'E')
			{
			    if (cur_item == NULL)
			    {
				float_T f;

				len = string2float(p, &f);
			    }
			    else
			    {
				cur_item->v_type = VAR_FLOAT;
				len = string2float(p, &cur_item->vval.v_float);
			    }
			}
			else
#endif
			{
			    varnumber_T nr;

			    vim_str2nr(reader->js_buf + reader->js_used,
				    NULL, &len, 0, /* what */
				    &nr, NULL, 0);
			    if (cur_item != NULL)
			    {
				cur_item->v_type = VAR_NUMBER;
				cur_item->vval.v_number = nr;
			    }
			}
			reader->js_used += len;
			retval = OK;
			break;
		    }
		    if (STRNICMP((char *)p, "false", 5) == 0)
		    {
			reader->js_used += 5;
			if (cur_item != NULL)
			{
			    cur_item->v_type = VAR_SPECIAL;
			    cur_item->vval.v_number = VVAL_FALSE;
			}
			retval = OK;
			break;
		    }
		    if (STRNICMP((char *)p, "true", 4) == 0)
		    {
			reader->js_used += 4;
			if (cur_item != NULL)
			{
			    cur_item->v_type = VAR_SPECIAL;
			    cur_item->vval.v_number = VVAL_TRUE;
			}
			retval = OK;
			break;
		    }
		    if (STRNICMP((char *)p, "null", 4) == 0)
		    {
			reader->js_used += 4;
			if (cur_item != NULL)
			{
			    cur_item->v_type = VAR_SPECIAL;
			    cur_item->vval.v_number = VVAL_NULL;
			}
			retval = OK;
			break;
		    }
#ifdef FEAT_FLOAT
		    if (STRNICMP((char *)p, "NaN", 3) == 0)
		    {
			reader->js_used += 3;
			if (cur_item != NULL)
			{
			    cur_item->v_type = VAR_FLOAT;
			    cur_item->vval.v_float = NAN;
			}
			retval = OK;
			break;
		    }
		    if (STRNICMP((char *)p, "Infinity", 8) == 0)
		    {
			reader->js_used += 8;
			if (cur_item != NULL)
			{
			    cur_item->v_type = VAR_FLOAT;
			    cur_item->vval.v_float = INFINITY;
			}
			retval = OK;
			break;
		    }
#endif
		    /* check for truncated name */
		    len = (int)(reader->js_end - (reader->js_buf + reader->js_used));
		    if (
			    (len < 5 && STRNICMP((char *)p, "false", len) == 0)
#ifdef FEAT_FLOAT
			    || (len < 8 && STRNICMP((char *)p, "Infinity", len) == 0)
			    || (len < 3 && STRNICMP((char *)p, "NaN", len) == 0)
#endif
			    || (len < 4 && (STRNICMP((char *)p, "true", len) == 0
				       ||  STRNICMP((char *)p, "null", len) == 0)))

			retval = MAYBE;
		    else
			retval = FAIL;
		    break;
	    }

	    /* We are finished when retval is FAIL or MAYBE and when at the
	     * toplevel. */
	    if (retval == FAIL)
		break;
	    if (retval == MAYBE || stack.ga_len == 0)
		goto theend;

	    if (top_item != NULL && top_item->jd_type == JSON_OBJECT_KEY
		    && cur_item != NULL)
	    {
		top_item->jd_key = get_tv_string_buf_chk(cur_item, key_buf);
		if (top_item->jd_key == NULL)
		{
		    clear_tv(cur_item);
		    EMSG(_(e_invarg));
		    retval = FAIL;
		    goto theend;
		}
	    }
	}

item_end:
	top_item = ((json_dec_item_T *)stack.ga_data) + stack.ga_len - 1;
	switch (top_item->jd_type)
	{
	    case JSON_ARRAY:
		if (res != NULL)
		{
		    listitem_T	*li = listitem_alloc();

		    if (li == NULL)
		    {
			clear_tv(cur_item);
			retval = FAIL;
			goto theend;
		    }
		    li->li_tv = *cur_item;
		    list_append(top_item->jd_tv.vval.v_list, li);
		}
		if (cur_item != NULL)
		    cur_item = &item;

		json_skip_white(reader);
		p = reader->js_buf + reader->js_used;
		if (*p == ',')
		    ++reader->js_used;
		else if (*p != ']')
		{
		    if (*p == NUL)
			retval = MAYBE;
		    else
		    {
			EMSG(_(e_invarg));
			retval = FAIL;
		    }
		    goto theend;
		}
		break;

	    case JSON_OBJECT_KEY:
		json_skip_white(reader);
		p = reader->js_buf + reader->js_used;
		if (*p != ':')
		{
		    if (cur_item != NULL)
			clear_tv(cur_item);
		    if (*p == NUL)
			retval = MAYBE;
		    else
		    {
			EMSG(_(e_invarg));
			retval = FAIL;
		    }
		    goto theend;
		}
		++reader->js_used;
		json_skip_white(reader);
		top_item->jd_type = JSON_OBJECT;
		if (cur_item != NULL)
		    cur_item = &item;
		break;

	    case JSON_OBJECT:
		if (cur_item != NULL
			&& dict_find(top_item->jd_tv.vval.v_dict,
						 top_item->jd_key, -1) != NULL)
		{
		    EMSG2(_("E938: Duplicate key in JSON: \"%s\""),
							     top_item->jd_key);
		    clear_tv(&top_item->jd_key_tv);
		    clear_tv(cur_item);
		    retval = FAIL;
		    goto theend;
		}

		if (cur_item != NULL)
		{
		    dictitem_T *di = dictitem_alloc(top_item->jd_key);

		    clear_tv(&top_item->jd_key_tv);
		    if (di == NULL)
		    {
			clear_tv(cur_item);
			retval = FAIL;
			goto theend;
		    }
		    di->di_tv = *cur_item;
		    di->di_tv.v_lock = 0;
		    if (dict_add(top_item->jd_tv.vval.v_dict, di) == FAIL)
		    {
			dictitem_free(di);
			retval = FAIL;
			goto theend;
		    }
		}

		json_skip_white(reader);
		p = reader->js_buf + reader->js_used;
		if (*p == ',')
		    ++reader->js_used;
		else if (*p != '}')
		{
		    if (*p == NUL)
			retval = MAYBE;
		    else
		    {
			EMSG(_(e_invarg));
			retval = FAIL;
		    }
		    goto theend;
		}
		top_item->jd_type = JSON_OBJECT_KEY;
		if (cur_item != NULL)
		    cur_item = &top_item->jd_key_tv;
		break;
	}
    }

    /* Get here when parsing failed. */
    if (res != NULL)
    {
	clear_tv(res);
	res->v_type = VAR_SPECIAL;
	res->vval.v_number = VVAL_NONE;
    }
    EMSG(_(e_invarg));

theend:
    ga_clear(&stack);
    return retval;
}
Exemple #5
0
unique_ptr<gui_theme::draw_style_data> gui_theme::process_draw_style_data(const gui_theme::DRAW_STYLE style, const xml::xml_node* node) {
	//
	const auto str_to_float4 = [](const string& float4_str) -> float4 {
		const vector<string> float4_tokens { core::tokenize(float4_str, ',') };
		if(float4_tokens.size() != 4) {
			oclr_error("invalid float4 token count: %u!", float4_tokens.size());
			return float4(0.0f, 1.0f, 0.0f, 1.0f); // green -> invalid color/float4
		}
		return float4(string2float(float4_tokens[0]),
					  string2float(float4_tokens[1]),
					  string2float(float4_tokens[2]),
					  string2float(float4_tokens[3]));
	};
	const auto str_to_ui_color = [&str_to_float4](const string& color_str) -> ui_color {
		const auto comma_pos(color_str.find(","));
		
		// no comma -> must be a scheme reference
		if(comma_pos == string::npos) {
			return ui_color { color_str }; // validity must be checked later
		}
		// comma -> must be a raw color
		return ui_color { str_to_float4(color_str) };
	};
	
	// gradient helpers:
	const auto str_to_gradient = [](const string& gradient_str) -> gfx2d::GRADIENT_TYPE {
		static const unordered_map<string, gfx2d::GRADIENT_TYPE> types {
			{ "horizontal", gfx2d::GRADIENT_TYPE::HORIZONTAL },
			{ "vertical", gfx2d::GRADIENT_TYPE::VERTICAL },
			{ "diagonal_lr", gfx2d::GRADIENT_TYPE::DIAGONAL_LR },
			{ "diagonal_rl", gfx2d::GRADIENT_TYPE::DIAGONAL_RL },
		};
		
		const auto iter = types.find(gradient_str);
		if(iter == types.cend()) {
			oclr_error("invalid gradient type: %s!", gradient_str);
			return gfx2d::GRADIENT_TYPE::HORIZONTAL;
		}
		return iter->second;
	};
	
	const auto str_to_gradient_stops = [](const string& stops_str) -> float4 {
		const auto tokens = core::tokenize(stops_str, ',');
		float4 ret(0.0f);
		for(size_t i = 0; i < std::min(tokens.size(), (size_t)4); i++) {
			ret[i] = string2float(tokens[i]);
		}
		return ret;
	};
	
	const auto str_to_gradient_colors = [&str_to_ui_color](const string& gradient_colors) -> vector<ui_color> {
		const auto color_tokens = core::tokenize(gradient_colors, ';');
		vector<ui_color> colors;
		for(size_t i = 0; i < std::min(color_tokens.size(), (size_t)4); i++) {
			colors.emplace_back(str_to_ui_color(color_tokens[i]));
		}
		return colors;
	};
	
	// texture helpers:
	const auto str_to_coords = [](const string& coords_str) -> pair<float2, float2> {
		if(coords_str == "INVALID") return make_pair(float2(0.0f), float2(1.0f)); // default
		
		const auto coords_tokens = core::tokenize(coords_str, ';');
		if(coords_tokens.size() != 2) {
			oclr_error("invalid coord token count (%u) for coords: %s!", coords_tokens.size(), coords_str);
			return make_pair(float2(0.0f), float2(1.0f));
		}
		
		const auto bottom_left_tokens = core::tokenize(coords_tokens[0], ',');
		const auto top_right_tokens = core::tokenize(coords_tokens[1], ',');
		return make_pair(bottom_left_tokens.size() >= 2 ?
						 float2(string2float(bottom_left_tokens[0]), string2float(bottom_left_tokens[1])) :
						 float2(string2float(bottom_left_tokens[0])),
						 top_right_tokens.size() >= 2 ?
						 float2(string2float(top_right_tokens[0]), string2float(top_right_tokens[1])) :
						 float2(string2float(top_right_tokens[0])));
	};
	
	//
	switch(style) {
		case DRAW_STYLE::FILL:
			return make_unique<ds_fill>(str_to_ui_color((*node)["color"]));
		case DRAW_STYLE::BORDER_FILL:
			return make_unique<ds_border_fill>(str_to_ui_float(str_to_ui_float_pair((*node)["thickness"])),
											   str_to_ui_color((*node)["color"]));
		case DRAW_STYLE::GRADIENT:
			return make_unique<ds_gradient>(str_to_gradient((*node)["gradient"]),
											str_to_gradient_stops((*node)["stops"]),
											str_to_gradient_colors((*node)["colors"]));
		case DRAW_STYLE::BORDER_GRADIENT:
			return make_unique<ds_border_gradient>(str_to_ui_float(str_to_ui_float_pair((*node)["thickness"])),
												   str_to_gradient((*node)["gradient"]),
												   str_to_gradient_stops((*node)["stops"]),
												   str_to_gradient_colors((*node)["colors"]));
		case DRAW_STYLE::BORDER_TEXTURE:
		case DRAW_STYLE::TEXTURE: {
			string tex_name = (*node)["name"];
			image* texture = nullptr;
			if(tex_name.find(".png") != string::npos) {
				// TODO: stores textures; add/allow internal engine image names?
				texture = texture_manager::add_texture(oclraster::data_path(tex_name));
				tex_name = "";
			}
			auto coords = str_to_coords((*node)["coords"]);
			float depth = ((*node)["depth"] == "INVALID" ? 0.0f : string2float((*node)["depth"]));
			bool passthrough = ((*node)["passthrough"] == "INVALID" ? false : string2bool((*node)["passthrough"]));
			bool is_gradient = ((*node)["gradient"] != "INVALID");
			const bool is_mul_color = ((*node)["mul"] != "INVALID");
			const bool is_add_color = ((*node)["add"] != "INVALID");
			const bool is_grad_mul_interp = ((*node)["mul_interpolator"] != "INVALID");
			const bool is_grad_add_interp = ((*node)["add_interpolator"] != "INVALID");
			
			if(style == DRAW_STYLE::TEXTURE) {
				return make_unique<ds_texture>(std::move(texture),
											   std::move(tex_name),
											   std::move(coords.first),
											   std::move(coords.second),
											   std::move(depth),
											   std::move(passthrough),
											   is_mul_color ?
											   str_to_ui_color((*node)["mul"]) : ui_color(float4(1.0f)),
											   is_add_color ?
											   str_to_ui_color((*node)["add"]) : ui_color(float4(0.0f)),
											   std::move(is_gradient),
											   is_grad_mul_interp ?
											   str_to_float4((*node)["mul_interpolator"]) : float4(0.5f),
											   is_grad_add_interp ?
											   str_to_float4((*node)["add_interpolator"]) : float4(0.0f),
											   is_gradient ?
											   ds_gradient(str_to_gradient((*node)["gradient"]),
														   str_to_gradient_stops((*node)["stops"]),
														   str_to_gradient_colors((*node)["colors"])) :
											   ds_gradient());
			}
			return make_unique<ds_border_texture>(str_to_ui_float(str_to_ui_float_pair((*node)["thickness"])),
												  std::move(texture),
												  std::move(tex_name),
												  std::move(coords.first),
												  std::move(coords.second),
												  std::move(depth),
												  std::move(passthrough),
												  is_mul_color ?
												  str_to_ui_color((*node)["mul"]) : ui_color(float4(1.0f)),
												  is_add_color ?
												  str_to_ui_color((*node)["add"]) : ui_color(float4(0.0f)),
												  std::move(is_gradient),
												  is_grad_mul_interp ?
												  str_to_float4((*node)["mul_interpolator"]) : float4(0.5f),
												  is_grad_add_interp ?
												  str_to_float4((*node)["add_interpolator"]) : float4(0.0f),
												  is_gradient ?
												  ds_gradient(str_to_gradient((*node)["gradient"]),
															  str_to_gradient_stops((*node)["stops"]),
															  str_to_gradient_colors((*node)["colors"])) :
												  ds_gradient());
		}
		case DRAW_STYLE::TEXT:
			return make_unique<ds_text>(str_to_ui_color((*node)["color"]));
	}
	oclr_unreachable();
}
Exemple #6
0
/*
 * parse internal tmp_ structures, fused by pushdata, and set the data flag when done
 */
void NMEA::parsedata() {
	int received_cks = 16*digit2dec(tmp_szChecksum[0]) + digit2dec(tmp_szChecksum[1]);
	//uart1.Send("seq: [cc:%X][words:%d][rc:%s:%d]\r\n", m_nChecksum,m_nWordIdx, tmp_szChecksum, received_cks);
	// check checksum, and return if invalid!
	if (m_nChecksum != received_cks) {
		//m_bFlagDataReady = false;
		return;
	}
	/* $GPGGA
	 * $GPGGA,hhmmss.ss,llll.ll,a,yyyyy.yy,a,x,xx,x.x,x.x,M,x.x,M,x.x,xxxx*hh
	 * ex: $GPGGA,230600.501,4543.8895,N,02112.7238,E,1,03,3.3,96.7,M,39.0,M,,0000*6A,
	 *
	 * WORDS:
	 *  1    = UTC of Position
	 *  2    = Latitude
	 *  3    = N or S
	 *  4    = Longitude
	 *  5    = E or W
	 *  6    = GPS quality indicator (0=invalid; 1=GPS fix; 2=Diff. GPS fix)
	 *  7    = Number of satellites in use [not those in view]
	 *  8    = Horizontal dilution of position
	 *  9    = Antenna altitude above/below mean sea level (geoid)
	 *  10   = Meters  (Antenna height unit)
	 *  11   = Geoidal separation (Diff. between WGS-84 earth ellipsoid and mean sea level.  
	 *      -geoid is below WGS-84 ellipsoid)
	 *  12   = Meters  (Units of geoidal separation)
	 *  13   = Age in seconds since last update from diff. reference station
	 *  14   = Diff. reference station ID#
	 *  15   = Checksum
	 */
	if (mstrcmp(tmp_words[0], "$GPGGA") == 0) {
		// Check GPS Fix: 0=no fix, 1=GPS fix, 2=Dif. GPS fix
		if (tmp_words[6][0] == '0') { 
			// clear data
			res_fLatitude = 0;
			res_fLongitude = 0;
			m_bFlagDataReady = false;
			return;
		}			
		// parse time
		res_nUTCHour = digit2dec(tmp_words[1][0]) * 10 + digit2dec(tmp_words[1][1]);
		res_nUTCMin = digit2dec(tmp_words[1][2]) * 10 + digit2dec(tmp_words[1][3]);
		res_nUTCSec = digit2dec(tmp_words[1][4]) * 10 + digit2dec(tmp_words[1][5]);
		// parse latitude and longitude in NMEA format
		res_fLatitude = string2float(tmp_words[2]);
		res_fLongitude = string2float(tmp_words[4]);
		// get decimal format
		if (tmp_words[3][0] == 'S') res_fLatitude  *= -1.0;
		if (tmp_words[5][0] == 'W') res_fLongitude *= -1.0;
		float degrees = trunc(res_fLatitude / 100.0f);
		float minutes = res_fLatitude - (degrees * 100.0f);
		res_fLatitude = degrees + minutes / 60.0f;
		degrees = trunc(res_fLongitude / 100.0f);
		minutes = res_fLongitude - (degrees * 100.0f);
		res_fLongitude = degrees + minutes / 60.0f;
		
		// parse number of satellites
		res_nSatellitesUsed = (int)string2float(tmp_words[7]);
		
		// parse altitude
		res_fAltitude = string2float(tmp_words[9]);
		
		// data ready
		m_bFlagDataReady = true;
	}
	
	/* $GPRMC
	 * note: a siRF chipset will not support magnetic headers.
	 * $GPRMC,hhmmss.ss,A,llll.ll,a,yyyyy.yy,a,x.x,x.x,ddmmyy,x.x,a*hh
	 * ex: $GPRMC,230558.501,A,4543.8901,N,02112.7219,E,1.50,181.47,230213,,,A*66,
	 *
	 * WORDS:
	 *  1	 = UTC of position fix
	 *  2    = Data status (V=navigation receiver warning)
	 *  3    = Latitude of fix
	 *  4    = N or S
	 *  5    = Longitude of fix
	 *  6    = E or W
	 *  7    = Speed over ground in knots
	 *  8    = Track made good in degrees True, Bearing This indicates the direction that the device is currently moving in, 
	 *       from 0 to 360, measured in “azimuth”.
	 *  9    = UT date
	 *  10   = Magnetic variation degrees (Easterly var. subtracts from true course)
	 *  11   = E or W
	 *  12   = Checksum
	 */
	if (mstrcmp(tmp_words[0], "$GPRMC") == 0) {
		// Check data status: A-ok, V-invalid
		if (tmp_words[2][0] == 'V') {
			// clear data
			res_fLatitude = 0;
			res_fLongitude = 0;
			m_bFlagDataReady = false;
			return;
		}
		// parse time
		res_nUTCHour = digit2dec(tmp_words[1][0]) * 10 + digit2dec(tmp_words[1][1]);
		res_nUTCMin = digit2dec(tmp_words[1][2]) * 10 + digit2dec(tmp_words[1][3]);
		res_nUTCSec = digit2dec(tmp_words[1][4]) * 10 + digit2dec(tmp_words[1][5]);
		// parse latitude and longitude in NMEA format
		res_fLatitude = string2float(tmp_words[3]);
		res_fLongitude = string2float(tmp_words[5]);
		// get decimal format
		if (tmp_words[4][0] == 'S') res_fLatitude  *= -1.0;
		if (tmp_words[6][0] == 'W') res_fLongitude *= -1.0;
		float degrees = trunc(res_fLatitude / 100.0f);
		float minutes = res_fLatitude - (degrees * 100.0f);
		res_fLatitude = degrees + minutes / 60.0f;
		degrees = trunc(res_fLongitude / 100.0f);
		minutes = res_fLongitude - (degrees * 100.0f);
		res_fLongitude = degrees + minutes / 60.0f;
		//parse speed
		// The knot (pronounced not) is a unit of speed equal to one nautical mile (1.852 km) per hour
		res_fSpeed = string2float(tmp_words[7]);
		res_fSpeed *= 1.852; // convert to km/h
		// parse bearing
		res_fBearing = string2float(tmp_words[8]);
		// parse UTC date
		res_nUTCDay = digit2dec(tmp_words[9][0]) * 10 + digit2dec(tmp_words[9][1]);
		res_nUTCMonth = digit2dec(tmp_words[9][2]) * 10 + digit2dec(tmp_words[9][3]);
		res_nUTCYear = digit2dec(tmp_words[9][4]) * 10 + digit2dec(tmp_words[9][5]);
		
		// data ready
		m_bFlagDataReady = true;
	}		
}
Exemple #7
0
/*
 * Decode one item and put it in "res".  If "res" is NULL only advance.
 * Must already have skipped white space.
 *
 * Return FAIL for a decoding error.
 * Return MAYBE for an incomplete message.
 */
    static int
json_decode_item(js_read_T *reader, typval_T *res, int options)
{
    char_u	*p;
    int		len;

    fill_numbuflen(reader);
    p = reader->js_buf + reader->js_used;
    switch (*p)
    {
	case '[': /* array */
	    return json_decode_array(reader, res, options);

	case '{': /* object */
	    return json_decode_object(reader, res, options);

	case '"': /* string */
	    return json_decode_string(reader, res);

	case ',': /* comma: empty item */
	    if ((options & JSON_JS) == 0)
		return FAIL;
	    /* FALLTHROUGH */
	case NUL: /* empty */
	    if (res != NULL)
	    {
		res->v_type = VAR_SPECIAL;
		res->vval.v_number = VVAL_NONE;
	    }
	    return OK;

	default:
	    if (VIM_ISDIGIT(*p) || *p == '-')
	    {
		char_u  *sp = p;

#ifdef FEAT_FLOAT
		if (*sp == '-')
		{
		    ++sp;
		    if (*sp == NUL)
			return MAYBE;
		    if (!VIM_ISDIGIT(*sp))
			return FAIL;
		}
		sp = skipdigits(sp);
		if (*sp == '.' || *sp == 'e' || *sp == 'E')
		{
		    if (res == NULL)
		    {
			float_T f;

			len = string2float(p, &f);
		    }
		    else
		    {
			res->v_type = VAR_FLOAT;
			len = string2float(p, &res->vval.v_float);
		    }
		}
		else
#endif
		{
		    long nr;

		    vim_str2nr(reader->js_buf + reader->js_used,
			    NULL, &len, 0, /* what */
			    &nr, NULL, 0);
		    if (res != NULL)
		    {
			res->v_type = VAR_NUMBER;
			res->vval.v_number = nr;
		    }
		}
		reader->js_used += len;
		return OK;
	    }
	    if (STRNICMP((char *)p, "false", 5) == 0)
	    {
		reader->js_used += 5;
		if (res != NULL)
		{
		    res->v_type = VAR_SPECIAL;
		    res->vval.v_number = VVAL_FALSE;
		}
		return OK;
	    }
	    if (STRNICMP((char *)p, "true", 4) == 0)
	    {
		reader->js_used += 4;
		if (res != NULL)
		{
		    res->v_type = VAR_SPECIAL;
		    res->vval.v_number = VVAL_TRUE;
		}
		return OK;
	    }
	    if (STRNICMP((char *)p, "null", 4) == 0)
	    {
		reader->js_used += 4;
		if (res != NULL)
		{
		    res->v_type = VAR_SPECIAL;
		    res->vval.v_number = VVAL_NULL;
		}
		return OK;
	    }
	    /* check for truncated name */
	    len = (int)(reader->js_end - (reader->js_buf + reader->js_used));
	    if ((len < 5 && STRNICMP((char *)p, "false", len) == 0)
		    || (len < 4 && (STRNICMP((char *)p, "true", len) == 0
			       ||  STRNICMP((char *)p, "null", len) == 0)))
		return MAYBE;
	    break;
    }

    if (res != NUL)
    {
	res->v_type = VAR_SPECIAL;
	res->vval.v_number = VVAL_NONE;
    }
    return FAIL;
}
Exemple #8
0
bool XMLBBoxReader::getNextFrameResult(vector<Result2D>& result)
{
	bool rt=false;
	result.clear();
	while (frame!=NULL)
	{
		if (!xmlStrcmp(frame->name,BAD_CAST"frame"))
		{
			rt=true;//get the successive frame
			xmlNodePtr objectList;
			objectList=frame->children;
			while (objectList!=NULL)//objectlist level
			{
				if (!xmlStrcmp(objectList->name,BAD_CAST"objectlist"))
				{
					xmlNodePtr object=objectList->children;
					while (object!=NULL)//object level
					{
						if (!xmlStrcmp(object->name,BAD_CAST"object"))
						{
							Result2D res;
							temp=xmlGetProp(object,BAD_CAST"id");
							res.id=string2int((char*)temp);
							xmlFree(temp);
							xmlNodePtr box=object->children;
							while (box!=NULL)
							{
								if (!xmlStrcmp(box->name,BAD_CAST"box"))
								{
									temp=xmlGetProp(box,BAD_CAST"h");
									res.h=(float)string2float((char*)temp);
									xmlFree(temp);
									temp=xmlGetProp(box,BAD_CAST"w");
									res.w=(float)string2float((char*)temp);
									xmlFree(temp);
									temp=xmlGetProp(box,BAD_CAST"xc");
									res.xc=(float)string2float((char*)temp);
									xmlFree(temp);
									temp=xmlGetProp(box,BAD_CAST"yc");
									res.yc=(float)string2float((char*)temp);
									xmlFree(temp);
									break;
								}
								box=box->next;
							}
							result.push_back(res);
						}
						object=object->next;
					}
					break;
				}	
				objectList=objectList->next;
			}
			break;
		}
		frame=frame->next;
	}
	if (frame!=NULL)
	{
		frame=frame->next;
	}		
	return rt;
}