Object Does Not Name a Type - c++

I have looked at the SDL documentation, and an online tutorial regarding its use, but I must be doing something incorrectly.
SDL_Rect TOP_LEFT_VIEWPORT;
TOP_LEFT_VIEWPORT.x = 0;
TOP_LEFT_VIEWPORT.y = 0;
TOP_LEFT_VIEWPORT.h = HEIGHT / 2;
TOP_LEFT_VIEWPORT.w = WIDTH / 2;
The line after I declare TOP_LEFT_VIEWPORT the compiler says "TOP_LEFT_VIEWPORT does not name a type"
I also attempted copy-pasting the code example from https://wiki.libsdl.org/SDL_Rect and it also received the same error.
Thanks for any responses!

Related

How to use Union Types Protobuf C++

I am new in using Protobuf. I have a server client communication (UDP) in C++. Now I use Protobuf to send a message which contains some Information to the Server.
package Test;
message vName{
required int32 name = 1;
}
message vNat{
required int32 nat = 1;
}
message vTan{
required int32 tan = 1;
}
message Test{
enum Type { vName = 1; vNAT = 2; vTAN = 3;}
required Type type = 1;
optional vName name = 2;
optional vNat nat = 2;
optional vTan tan = 2;
}
Now i want only send the Information which is set. For example Type is 1. Then how can i access or set the name?
Can anybody make an small snippet that i can understand how to use it?
I apologize for my english skills :D
Protobuf version: 2.5.0
OS: Windows
Enviroment: Visual Studio
Language: C++
From https://developers.google.com/protocol-buffers/docs/techniques#union
You may also want to have an enum field that identifies which message is filled in, so that you can switch on it:
message OneMessage {
enum Type { FOO = 1; BAR = 2; BAZ = 3; }
// Identifies which field is filled in.
required Type type = 1;
// One of the following will be filled in.
optional Foo foo = 2;
optional Bar bar = 3;
optional Baz baz = 4;
}
How can I use this in the Code? I think this is what I want. Have anybody an idea where i can find an example?
It sounds like what you're looking for is this, instead of using optional fields and a workaround-enum.

Changing Mavlink Message Rate ArduPilotMega

I am working on a project that uses Mavlink protocol (in c++) to communicate with the ArduPilotMega (2.6).
I am able to read messages such as ATTITUDE for example. The current message rate (for all messages) is 2Hz and I would like to increase this rate.
I found out that I should probably set MESSAGE_INTERVAL using MAV_CMD_SET_MESSAGE_INTERVAL in order to change it.
So my question is:
How do I send this command message using mavlink in c++?
I tried doing it using the code below but it did not work. I guess I have to use the command I mentioned above, but I don't know how.
mavlink_message_t command;
mavlink_message_interval_t interval;
interval.interval_us = 100000;
interval.message_id = 30;
mavlink_msg_message_interval_encode(255, 200, &command, &interval);
p_sensorsPort->write_message(command);
Update: I also tried this code below, maybe I am not giving it the right system id or component id.
mavlink_message_t command;
mavlink_command_long_t interval;
interval.param1 = MAVLINK_MSG_ID_ATTITUDE;
interval.param2 = 100000;
interval.command = MAV_CMD_SET_MESSAGE_INTERVAL;
interval.target_system = 0;
interval.target_component = 0;
mavlink_msg_command_long_encode(255, 0, &command, &interval);
p_sensorsPort->write_message(command);
Maybe I am missing something about the difference between target_system, target_component and sysid, compid. I tried few values for each but nothing worked.
Is there any ACK that will be able to tell me if it even got the command?
I guess you missed start_stop field. the below sample is working.
final msg_request_data_stream msg = new msg_request_data_stream ();
msg.req_message_rate = rate;
msg.req_stream_id = (short) streamId;
msg.target_component = (short)compID;
msg.target_system = (short)sysID;
/*
GCS_COMMON.cpp contains code that sends when value =1
and stop when value = 0
that is it.
*/
if (rate > 0) {
msg.start_stop = 1;
} else {
msg.start_stop = 0;
}
From Robotis Stack Exchange answer,
In order to change the message rate, the simplest way is to change the SR_* parameters value using Mission Planner. The maximum rate is 10Hz.
For example, in order to change the ATTITUDE message rate to be 10Hz I just had to change the SR_EXTRA1 parameter to be 10.
For more information about which parameter changes each message see GCS_Mavlink.cpp file in ArduCopter firmware.

Error while compiling protocol buffer on mac

I am following the tutorial for protocol buffers and I keep running into different errors while compiling. my addressbook.proto file is in /Users/flexmaster411/protobuffer
protoc -I=/Users/flexmaster411/protobuffer --python_out= /Users/flexmaster411/protobuffer/addressbook.proto /Users/flexmaster411/protobuffer
I keep getting the following error even though I have syntax = "proto3" on my proto file
[libprotobuf WARNING google/protobuf/compiler/parser.cc:471] No syntax specified for the proto file. Please use 'syntax = "proto2";' or 'syntax = "proto3";' to specify a syntax version. (Defaulted to proto2 syntax.)
Not sure if I have correctly done the destination folders set up which is causing this or not Any help appreciated
syntax = "proto3";
package tutorial;
message Person {
string name = 1;
int32 id = 2; // Unique ID number for this person.
string email = 3;
enum PhoneType {
MOBILE = 0;
HOME = 1;
WORK = 2;
}
message PhoneNumber {
string number = 1;
PhoneType type = 2;
}
repeated PhoneNumber phones = 4;
}
// Our address book file is just one of these.
message AddressBook {
repeated Person people = 1;
}
It looks like you reversed the order of the parameters. /Users/flexmaster411/protobuffer is your output directory, so it should appear with --python_out. Since you specified it second, protoc thinks you're telling it that /Users/flexmaster411/protobuffer is an input. So it's trying to open a directory and then parse it as a .proto file. Amusingly, read() on a directory returns no data, which protoc interprets as a perfectly valid .proto file that simply doesn't declare anything! But it then gives you a warning because this empty file doesn't have any syntax line.
I think what you meant to type is:
protoc -I=/Users/flexmaster411/protobuffer --python_out=/Users/flexmaster411/protobuffer /Users/flexmaster411/protobuffer/addressbook.proto

Assertion failed while creating Menu Item Label in cocos2dx

I am building a game in cocos2dx in which i have to create menu item label. I am creating them in a loop and then adding them in menu:
auto menuForNumberButtons = Menu::create();
menuForNumberButtons->setPosition(Vec2(0,0));
this->addChild(menuForNumberButtons, 3);
for (int yy = 0; yy < 3; yy++ )
{
for (int xx = 0; xx < 3; xx++)
{
counterOfNumers++;
MenuItemLabel *numberButton=MenuItemLabel::create(Label::createWithTTF(String::createWithFormat("%d",counterOfNumers)->getCString(), "arial.ttf", visibleSize.width*0.05), this, menu_selector(BSHSuDokuKeypad::numberButtonPressed));
numberButton->setScaleX(widthOfNumberCell*0.5 / numberButton->getBoundingBox().size.width);
numberButton->setScaleY(heightOfNumberCell*0.5 / numberButton->getBoundingBox().size.height);
numberButton->setPosition(Vec2(visibleSize.width*0.005+widthOfNumberCell*xx + numberButton->getBoundingBox().size.width*0.5, visibleSize.height*0.7+ heightOfNumberCell*yy + numberButton->getBoundingBox().size.height*0.5));
menuForNumberButtons->addChild(numberButton);}}
but when i click on any number. it gives me an error saying assertion failed without calling the callback function.
Any help?
Well it sounds like some precondition/ postcondition is failing when some function is called. Since you're dealing with quite a few objects, I'm betting that your issue originates in the failed creation of your MenuItemLabel.
I'd recommend further inspection of this line:
MenuItemLabel *numberButton=MenuItemLabel::create(Label::createWithTTF(String::createWithFormat("%d",counterOfNumers)->getCString(), "arial.ttf", visibleSize.width*0.05), this, menu_selector(BSHSuDokuKeypad::numberButtonPressed));
Now, I'm not familiar with this language so I can't tell you much about syntax but looking at the API I've discovere that this line format should be formatted:
static MenuItemLabel * create (Node *label, Ref *target, SEL_MenuHandler selector)
Wish I could do more for ya, but hopefully I pointed you in the direction of progress

How to get the screen size with C++ builder (Firemonkey)

I know it is a stupid question, but when changing visual libraries I found a "throuble" with FMX...
My problem is: I need to do my own border, so I set the propriety to Border Style:"None", but the application runs in full screen, also covering the windows toolbar, so I would like a way to resize the application form according to the screen eg.:
mainForm->Height = Screen->Height - 10;
It is possible using VCL, but are there any way to do it using FMX library?
The maximum I conquested with FMX is (I don't know how does it returns values, and the kind of values):
Screen->Size(); // TSize
I've also conquested it now, but I have compiler error:
TSize* Tamanho = new TSize;
Tamanho = Screen->Size();
frmPrincipal->Width = Tamanho->Width;
frmPrincipal->Height = Tamanho->Height - 10;
Error:"E2034 Cannot covert 'TSize' to 'TSize*'"
Finally I've tried to put it on frmPrincipal.h, but the same error:
TSize *Tamanho;
PS.: Other possible solutions to solve the "main problem" are acceptable...
Thanks a LOT!
TScreen::Size() return an actual instance of the TSize struct, not a TSize* pointer. You need to change your code accordingly:
TSize Tamanho = Screen->Size();
frmPrincipal->Width = Tamanho.Width;
frmPrincipal->Height = Tamanho.Height - 10;
Alternatively, you can use FMX's Platform Services framework to access the IFMXScreenService interface directly (this is what TScreen::Size() uses internally):
_di_IInterface Intf;
if (TPlatformServices::Current->SupportsPlatformService(__uuidof(IFMXScreenService), Intf))
{
_di_IFMXScreenService Svc = Intf;
TPoint size = Svc->GetScreenSize().Round();
frmPrincipal->Width = size.X;
frmPrincipal->Height = size.Y - 10;
}