|
It actually more complex than that because on a Pi2,Pi3 you have 4 cores so you will have spinlocks/semaphores on all the devices.
What are you doing with cores 1,2,3 at the moment are they still parked or in use?
I assume your code isn't under linux given you have dragged the devices out to objects
Assuming baremetal I would strongly suggest you look at circle
GitHub - rsta2/circle: A C++ bare metal environment for Raspberry Pi with USB[^]
I am not sure you can develop much of a hierarchy it all needs to be fairly flat if you want to use the multicores, welcome to multicore programming
In vino veritas
modified 9-May-18 11:28am.
|
|
|
|
|
I have been taking the free CS50x course from Harvard and just completed the Mario more comfortable problem. This is my code and I wanted to know how the right side of hashes are left aligned even though the code is the same for both left and right hashes.? To be honest I’m new to this and thought it would simply print out two right aligned pyramids with a gap in between.
// Prints bricks, sized as specified by user
#include <cs50.h>
#include <stdio.h>
int main(void)
{
// Prompt user for a positive number to use as height of pyramid
int h;
do
{
h = get_int("Height: ");
}
while (h < 0 || h > 23);
// Print out this many rows
for (int i = 0; i < h; i++)
{
// Print out this many spaces
for (int j = 0; j < h - i; j++)
{
printf(" ");
}
// Print left hashes
for (int j = 0; j < i + 2; j++)
{
printf("#");
}
// Print gap
printf(" ");
// Print right hashes
for (int j = 0; j < i + 2; j++)
{
printf("#");
}
printf("\n");
}
}
|
|
|
|
|
Faith Burnett wrote: To be honest I’m new to this and thought it would simply print out two right aligned pyramids with a gap in between. Those two for() loops are printing the same NUMBER of hashes from where the stdout stream happens to be at the point the for() loop starts printing. Since the stdout stream is at "column" 0 before the first for() loop, the first set of hashes is right justified (preceded with spaces), and since the stdout stream is at "column" H+2 after the first two inner for() loops run, the second set of hashes always starts in the same "column."
You might want to consider changing your for() loop boundaries so that the pyramid has a "pointed" top at level 1, and no leading/trailing spaces at level h :
for (int i = 0; i < h; i++)
{
...
for (int j = 0; j < h - i - 1; j++)
...
for (int j = 0; j < i + 1; j++)
...
for (int j = 0; j < i + 1; j++)
...
}
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
modified 6-May-18 0:28am.
|
|
|
|
|
Thanks for the help David!
|
|
|
|
|
I like to verify actuall value passed from char array to struct pointer
buf array declaration
unsigned char buf[32]; // = { 0x00, 0x04 };
value passed unsigned char 0x04;
buf[0] = command; // passed 0x04 software reset
transmit buffer assignment
xfer[0].tx_buf = (unsigned long) buf;
Now I like to use cout to print the actual value in tx_buf.
From struct declaration I know "tx_buf" is a unsigned long pointer.
Not sure how to access the required value
this gives me the pointer as expected:
<pre lang="c++">cout << "xfer[0].tx_buf " << xfer[0].tx_buf<< endl;
Once I know how to get first value I can probably figure out how to get the whole buf[32] array values.
Thanks for help
Cheers Vaclav
|
|
|
|
|
You need to print each byte independently, after casting them to int , since the char values are unprintable. Something like:
cout << hex << (int)buf[0] << endl;
Use a loop to print more than one value.
|
|
|
|
|
Thanks, but...
I know how to get buf values, what I wanted to verify is that the buf values are actually passed to the struct.
I am having issues verifying that the struct has all of the necessary data.
Some are "straight" values, most via pointers.
BTW
When I use "modifier" hex , not sure I am using correct term as always, in cout << hex << (int)buf[0] << endl;,
then following usage WITHOUT such modifier will continue to print the data in hex
cout << int)buf[0] << endl;
Nice but it can get out of control.
|
|
|
|
|
Vaclav_ wrote: I am having issues verifying that the struct has all of the necessary data. You need to be specific, we cannot guess what these issues may be. And, TBH, my previous reply was also based on a bit of guesswork.
See <iomanip> functions[^] for details on using the hex manipulator.
|
|
|
|
|
I just like <b>to see the value</b> passed to struct pointer.
I can deal with what the functio0n does with it myself.
Perhaps it is all working correctly and my problems are elsewhere.
|
|
|
|
|
I am trying to wrap a c++ class for c. The function uses pass by reference.
Example
Test::funcref(int & h,BSTR & b)
void wrap_funcref(wrap_t *m, int h, BSTR)
{
Test *obj;
if (m == NULL)
return;
obj = static_cast<test *="">(m->obj);
obj->funcref(&h,&b);
}
Not sure if I need to change the c++ functions for *
|
|
|
|
|
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.
|
|
|
|
|