|
obj = static_cast<Test *>(m->obj); obj->funcref(&h,&b); }
How do you define Test and wrap_t in your C code?
|
|
|
|
|
Hi richard thanks for the reply
obj->funcref(&h,&b); I know this wont work, don't know why I even typed it.
Any way here goes
file.cpp
//------------
// CONSTRUCTOR
//------------
Test::Test()
{
}
//-----------
// DESTRUCTOR
//-----------
Test::~Test()
{
}
HRESULT Test::funcref(int &h, BSTR &b )
{
HRESULT hr = S_OK
char cstr[200];
strcpy_s(cstr, "BLAHHHHH");
*b = A2BSTR(cstr);
return hr;
}
HRESULT Test::funcp(int i,int *y)
{
HRESULT hr = S_OK
*y = i +7;
return hr;
}
file.h
class Test
{
public:
Test();
virtual ~Test();
static HRESULT funcref( int &h,BSTR &b);
static HRESULT funcp(int i, int *y);
};
wrapit.cpp
struct wrapStruct
{
void *obj;
};
extern "C" __declspec(dllexport) wrap_t *wrap_create()
{
wrap_t *m;
Test*obj;
m = static_cast(malloc(sizeof(*m)));
obj= new Test();
m->obj = obj;
return t;
}
extern "C" __declspec(dllexport) void wrap_destroy(wrap_t *m)
{
if (m == NULL)
return;
delete static_cast(m->obj);
free(m);
}
extern "C" __declspec(dllexport) int wrap_funcp(wrapper_L2H *m,int i,int* y)
{
Test *obj;
if (m == NULL)
return false;
obj= static_cast(m->obj);
obj->funcp(i, y);
return true;
}
extern "C" wrapper_API void wrap_funcref(wrap_t *m, int* h,BSTR* b) //?
{
Test *obj;
if (m == NULL)
return false;
obj = static_cast(m->obj);
obj->funcref(h, b);
return true;
}
wrapit.h
#ifdef WRAPPER_EXPORTS
#define wrapper_API __declspec(dllexport)
#else
#define wrapper_API __declspec(dllimport)
#endif
struct wrapStruct;
typedef struct wrapStruct wrap_t
extern "C" wrapper_API wrap_t* wrap__create();
extern "C" wrapper_API void wrap__destroy(wrap_t *m);
extern "C" wrapper_API void wrap_funcref(wrap_t *m, int *h, BSTR* b); //?
extern "C" wrapper_API void wrap_funcp(wrap_t *m, int *y;
useit.c
#include "wrapit.h"
int z=0,uu=0,d=0,p=0;
BSTR uu,nn;
wrap_t *z = wrap_create();
wrap_funcref(&p,&nn); //not sure does not work
wrap_funcp(z,&uu); //works
wrap_destroy(z);
wrap_funcp works
wrap_funcref does not.
|
|
|
|
|
wrap_funcref(&p,&nn);
Where is p defined, and what is it? And where is the missing parameter that should be included per the declaration:
extern "C" wrapper_API void wrap_funcref(wrap_t *m, int *h, BSTR* b);
Some of this might also make a bit more sense if it was properly formatted between <pre lang="c++"></pre> tags, as my samples above. And the use of single letters for variable names is confusing.
|
|
|
|
|
Message Closed
-- modified 20-Jun-18 4:35am.
|
|
|
|
|
Lapmangfpt wrote: j = find(MyList[i].key.begin(), MyList[i].key.end(), tkey); // ERROR 1
// If not, add key and content
if (j == -1) // ERROR 2
You have to compare not wit -1, but with MyList[i].key.end()
|
|
|
|
|
Hi
I have gotten this error from time to time but have always gotten around by doing a build or rebuild
this time I even tried a clean nothing helps
Just wondering is the source stored in the PDB file
|
|
|
|
|
No but the debug information is. If the debugger cannot match the source line with the information in the PDB then it will put this message. Check that you do not have links to out of date files in the project anywhere. Alternatively make sure that there is not a file included somewhere that is not getting rebuilt.
|
|
|
|
|
Richard
I tried for the life of me to figure out why is wasn't being rebuilt I ended up using the option allow source to be different
thanks
|
|
|
|
|
I entered the unit testing world about a year ago and now my team and I start working with Linux.
Which mocking framework do you think is the best for Linux and why?
Thanks!
|
|
|
|
|
Welcome to codeproject.
I don't know.
Here's a Software Test joke instead of an answer:
A senior software tester and a entry level tester went into the company cafeteria and sat down. The senior employee removed a tuna sandwich from an old brown bag. The entry level tester promptly removed a ham sandwich from his man-purse.
Then a security guard noticed that these employees were breaking the rules and quickly came over to the table. "The company rules clearly state that you cannot bring your own lunch to the cafeteria!" the guard exclaimed.
The senior tester looked at the security guard, then shrugged his shoulders and exchanged sandwiches with the entry level tester. "I found a loophole in the company rule." he commented with his mouth full.
Maybe someone with more test experience will answer your question. You might get greater visibility by posting your question in the 'Quick Answers' section.
Best Wishes,
-David Delaune
|
|
|
|
|
All my code is C so unity, ceedling and cmock and it's irrelevent if it's linux, windows or embedded code. At the end of the day you are testing the code not the compiler implementation and optimizations of the code.
There is a pretty good background to it all at
Throwtheswitch.org[^]
There are also forums there if you need to ask questions.
In vino veritas
modified 29-Apr-18 23:18pm.
|
|
|
|
|
The company I work for started using Isolator++ for Linux and it seems to work so far pretty well
|
|
|
|
|
Nice! What are their mocking abilities?
|
|
|
|
|
you can mock and fake almost everything, any kind of
methods,
fields,
behaviors,
interfaces,
dependencies,
Instances, and more.
|
|
|
|
|
|
I have this code, which works on CodeBlocks, but when I try to run it in visual studio code, I get and error saying:
invalid operands to binary expression ('std::ostream' (aka 'basic_ostream<char, char_traits<char> >') and 'std::string' (aka 'basic_string<char, char_traits<char>, allocator<char> >'))
this is the code:
#include <iostream>
using namespace std;
class field{
public:
void Create_Area(int area){
string field[area][area];
for(int y = 0; y < area; y++){
for(int x = 0; x < area; x++){
field[y][x] = "+ ";
cout << field[y][x];
}
cout << endl;
}
}
};
What to do to fix this?
|
|
|
|
|
You cannot create an array on the stack using values that are not known at compile time. You need to change your code to:
void Create_Area(int area){
string field[][] = new string[area][area];
Also, I would suggest not using the class name for an array in that way. And the field variable is not available outside of the method that creates it.
|
|
|
|
|
I have changed that, but now how do I use it in this part?
Field[y][x] = "+ ";
cout << Field[y][x];
also, I don't really understand what you have done in the new string[area][area] part. Why use string instead of field?
|
|
|
|
|
Member 13802912 wrote: how do I use it in this part? Exactly the same as before.
Member 13802912 wrote: the new string[area][area] part. Why use string instead of field? Because you are trying to create an array of string objects. See new Operator (C++)[^].
|
|
|
|
|
fatal error: invalid operands to binary expression ('std::ostream' (aka 'basic_ostream<char>') and 'void')
this is the error i am getting.What should i do?
#include <iostream>
void Find(int arr[], int n, int sum)
{
unordered_set<int> s;
int temp;
for (int i = 0; i < n; i++)
{
temp = sum - arr[i];
if (s.find(temp) != s.end())
cout<< arr[i]<<"+"<< temp<<" ";
s.insert(arr[i]);
}
}
int main()
{
int arr[] = {1,2,3,4,5,6,6,5,56,7,11,13} ;
int n = sizeof(arr)/sizeof(arr[0]);
int sum = 12;
cout<<Find(arr,n,sum);
return 0;
}
|
|
|
|
|
You have declared:
void Find(int arr[], int n, int sum)
cout<<Find(arr,n,sum);
But you cannot print something that is void , i.e something that does not exist.
|
|
|
|
|
So what should i do
Instead of void i used
int Find()
{....
return 0;
}
But at the end of my input extra zero is coming which i dont want.
Thank you!
|
|
|
|
|
Then don't return a value. Leave it as void and remove the cout call at the end of your main method.
BTW in future please open a new question if you have a problem, rather than reopening a thread that is over two years old.
|
|
|
|
|
I hope that someone can help me.
I am currently working on developing a flight simulator with force feedback. To do the calculations of the force feedback, we need to know the position of vertical yoke that we are using. We use two potentiometers to detect the position of the yoke for roll and pitch. The potentiometers are connected with Arduino Uno that will change analog values to digital values:
Digital value of roll will be between [450: 650]
Digital value of pitch will be between [100: 340]
These values then will be sent to Raspberry Pi where we do the calculations of force feedback. I’m using the RS232 protocol (library developed by Teunis van Beelen [link]) to receive the data from Arduino.I'm using a usb cable to send data from Arduino To RPi.
I’m developing the code in Qt Creator in C++
My problem: I received the data packets from Arduino every 10ms, BUT, sometimes the packets are cut into two parts (see figure 1). I can say that for every 100 data packets sent, 6 will be cut. So I will receive 6 times incomplete data packets for the calculations. The "incomplete part" will come together with the next data packet.
For the time being, if the data was cut, the code will just "jump" the data packet and will not do any calculation. But, for optimisation purpose, I need to resolve this problem. By the way, the baudrate is the same for Arduino and RPi that is 115200. The whole program is being developed in C++, so it is not advisable to use pyserial because the program need to receive and calculate the force feedback within 10ms.
[figure1]
Can someone explains why and how did these happen? What do I need to do to resolve this problem?
My code in Arduino
int pinpotRoulis=A0; int valpotRoulis=0;
int valmancheRoulis=0;
int mapRoulis =0;
int pinpotTangage=A5; int valpotTangage=0;
int valmancheTangage=0;
int mapTangage =0;
int voltage = 8;
void setup() {
Serial.begin(115200);
pinMode(voltage,OUTPUT);
digitalWrite(voltage,HIGH);
}
void loop() {
char dataToSend[20];
valpotRoulis = analogRead(pinpotRoulis);
valpotTangage = analogRead(pinpotTangage);
sprintf(dataToSend, "R%dE T%dE", valpotRoulis, valpotTangage);
Serial.println(dataToSend);
printf("%s\n", dataToSend);
delay(10);
}
My code in QtCreator in RPi :
void MainWindow::getPotentiometreFFB(){
do{
n = RS232_PollComport(cport_nr, (unsigned char *) str_recv, (int)BUF_SIZE);
i++;
}while(n <= 0 && i < 1000000);
if(n > 0){
str_recv[n] = 0;
printf("Received %i bytes: '%s'\n", n, str_recv);
position = -1;
for (int j = 0; j < n ; j++)
{
if(str_recv[j]=='R') {
position = j;
break;
}
position = -1;
}
if (position != -1) {
for (int k = 0;k<5;k++)
{
valeur_R[k] = str_recv[position+k];
}
char * ptrsuite_1Chaine = NULL;
ptrsuite_1Chaine = strchr(valeur_R, 'E');
if (ptrsuite_1Chaine != NULL)
{
sscanf(valeur_R,"R%dE",&valRoulis);
valRoulis = minMaxPotentiometre(450, 650, valRoulis);
m_data.roll_cmd = mappingPotentiometreRoulis(valRoulis);
}
}
position = -1;
for (int j = 0; j < n ; j++)
{
if(str_recv[j]=='T') {
position = j;
break;
}
position = -1;
}
if (position != -1) {
for (int k = 0;k<5;k++)
{
valeur_T[k] = str_recv[position+k];
}
char * ptrsuite_2Chaine = NULL;
ptrsuite_2Chaine = strchr(valeur_T, 'E');
if (ptrsuite_2Chaine != NULL)
{
sscanf(valeur_T,"T%dE",&valTangage);
valTangage = minMaxPotentiometre(100, 340, valTangage);
m_data.pitch_cmd = -mappingPotentiometreTangage(valTangage);
}
}
cout<< "Val roulis :" << m_data.roll_cmd << endl;
cout<< "Val tangage :" << m_data.pitch_cmd << endl;
ui->roll_cmd->setValue(m_data.roll_cmd);
ui->pitch_cmd->setValue(m_data.pitch_cmd);
}else{
cout << "No data Roulis tangage" << endl;
}
}
Feel free to ask if you guys need more info from me.
Thank you very much
|
|
|
|
|
The answer is obvious:
You have to rewrite your code to be able to handle incomplete packages.
You got incomplete packets because you stop receiving if any number of data has been received (even a single byte/character). That would be the normal behaviour. The only reason why that happens not very often is that the system has to service also other tasks. And that is not done while waiting (see end of my post)!
Because you are sending only a single kind of data, you can change the data being send using a fixed length format by using leading zeroes:
sprintf(dataToSend, "R%03dE T%03dE", valpotRoulis, valpotTangage); That makes parsing much simpler (e.g. using scanf() ) and you can wait for the known number of characters (11 + line feed):
const int CMD_LENGTH = 12;
while(n < CMD_LENGTH && i < 1000000); By the way: what is the purpose of the undefined variable i here?
But when doing so you will run more into the already existing performance problem of using a polling loop. Waiting for the data wastes a lot of time (10 ms) that is not available for other tasks.
The solution is to put the receiving into an own thread and use the fine Qt signaling features. Because there are only two event data values, there is even no need to use shared variables.
|
|
|
|
|