STM32L-Discovery error message? - stm32ldiscovery

I'm trying to program a stm32l-discovery board and have come across this error that keeps appearing when I try to build my project.
error: #29: expected an expression
for (int i = 0; i <999; i++){
I'm using Keil uVision 4.
Source:
while (1) {
////fade up
int i = 0;
for (int i = 0; i <999; i++) {
TIM_SetCompare2(TIM2,i);
////Pulse width is set with this function
delay(100);
//// the '2' relates to the channel in use
}
}
Anyone know what this means?

Related

How to know how many tasks are already completed?

In C++ Builder 10.3.3 I'm using the following test code:
int count = 500;
_di_ITask* task = new _di_ITask[count];
ProgressBar1->Position = 0;
for(int i = 0; i < count; i++){
task[i] = TTask::Create([i, this](){
// do something...
Sleep(10);
});
task[i]->Start();
//ProgressBar1->Position = numberOfFinishedTasks;
//Application->ProcessMessages();
}
TTask::WaitForAll(task, count - 1);
In this case there are 500 test tasks and I would like my ProgressBar component to show the current number of completed tasks. I don't know how to get that info. Thanks!
The simplest solution is to have the lambda itself update the ProgressBar before exiting. You can use TThread::Synchronize() or TThread::Queue() for that.
The problem is, TTask::WaitForAll() is a blocking method that does not pump the main UI message queue at all, so Synchronize()/Queue() requests will not be processed at all. You can get around that by calling WaitForAll() in a loop with a timeout so that the loop can pump messages as needed.
Try something like this:
int count = 500;
std::vector<_di_ITask> task(count);
ProgressBar1->Position = 0;
ProgressBar1->Min = 0;
ProgressBar1->Max = count;
ProgressBar1->Step = 1;
for(int i = 0; i < count; ++i){
task[i] = TTask::Create(
[i, this](){
// do something...
TThread::Queue(nullptr, ProgressBar1->StepIt);
}
);
task[i]->Start();
}
while (!TTask::WaitForAll(task.data(), count - 1, 1000)){
Application->ProcessMessages();
}

Variable has incomplete type 'struct my_error_mgr'

When I try to build this code, the line struct my_error_mgr jerr; gives the error "Variable has incomplete type 'struct my_error_mgr'
#import "Engine.h"
#include "jpeglib.h"
#implementation Engine
+(void)test{
struct jpeg_decompress_struct cinfo;
struct my_error_mgr jerr;
FILE * infile;
if ((infile = fopen(filename, "rb")) == NULL) {
fprintf(stderr, "can't open %s\n", filename);
return 0;
}
cinfo.err = jpeg_std_error(&jerr.pub);
jerr.pub.error_exit = my_error_exit;
if (setjmp(jerr.setjmp_buffer)) {
jpeg_destroy_decompress(&cinfo);
fclose(infile);
return 0;
}
jpeg_create_decompress(&cinfo);
jpeg_stdio_src(&cinfo, infile);
(void) jpeg_read_header(&cinfo, TRUE);
jvirt_barray_ptr* coeffs_array;
coeffs_array = jpeg_read_coefficients(&cinfo);
BOOL done = FALSE;
for (int ci = 0; ci < 3; ci++)
{
JBLOCKARRAY buffer_one;
JCOEFPTR blockptr_one;
jpeg_component_info* compptr_one;
compptr_one = cinfo.comp_info + ci;
for (int by = 0; by < compptr_one->height_in_blocks; by++)
{
buffer_one = (cinfo.mem->access_virt_barray)((j_common_ptr)&cinfo, coeffs_array[ci], by, (JDIMENSION)1, FALSE);
for (int bx = 0; bx < compptr_one->width_in_blocks; bx++)
{
blockptr_one = buffer_one[0][bx];
for (int bi = 0; bi < 64; bi++)
{
blockptr_one[bi]++;
}
}
}
}
write_jpeg(output, &cinfo, coeffs_array); // saving modified JPEG to the output file
jpeg_destroy_decompress(&cinfo);
fclose(infile);
}
#end
When I try to comment out all lines related to this error, I then get a EXC_BAD_ACCESS runtime error on the line
(void) jpeg_read_header(&cinfo, infile);
I'm trying to modify the DCT coefficients of a saved JPEG image in iOS with the eventual goal of creating a JPEG steganography app. I have the following code attempting to add one to each DCT coefficient. I'm using the libjpeg library. The code is a combination of Objective-C and C.
A quick note, the variable filename is equal to "/Users/ScottBouloutian/Library/Application Support/iPhone Simulator/7.0.3/Applications/27A0450E-4685-4C3E-AAC8-A0CC6C85359E/Crypsis.app/screen.jpg", which is the path to the JPEG image I am trying to modify.
What is wrong with the code I have? Is it something dumb like a missing include or something wrong with my file path?
Whatever struct my_error_mgr is, the compiler can't find its declaration as a type. You need to include the header that has that declaration.
I was getting the following error in my code:
Variable has incomplete type 'RCTLayoutMetrics' (aka 'struct CG_BOXABLE')
I upgraded to Xcode Version 9.2 (9C40b) and it fixed the issue.

Xlib Muti-thread program only works under strace

I'm writing a muti-thread program using xlib, pthread and cairo.
This program create a thread in order to draw ten points after a click event.
The problem is:
After the program drew three points, it got crashed and xlib complaint
X Error of failed request: BadRequest (invalid request code or no such operation)
Major opcode of failed request: 0 ()
Serial number of failed request: 67
Current serial number in output stream: 97
However, it can work properly when I'm using strace like "strace ./a.out".
Here's my code-clips:
void *draw_point(void *arg) { //paint random-postion point
int i = 0;
int seed;
double x ,y;
srand(seed);
cairo_set_source_rgba (cairo, 1, 0.2, 0.2, 0.6);
for(i = 0; i< 10; i++) {
x = rand() % 200;
y = rand() % 200;
if(candraw) {
cairo_arc (cairo, x, y, 10.0, 0, 2*M_PI);
cairo_fill (cairo);
}
hasdraw = true;
sleep(1);
}
return NULL;
}
bool win_main(void)
{
int clickx = 0, clicky = 0;
unsigned long valuemask;
XEvent event;
valuemask = ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | PointerMotionMask;
XSelectInput(display, win, valuemask);
pthread_t thread;
while (1) {
while (XPending(display) == 0) {
candraw = true;
if(hasdraw)
XFlush(display);
candraw = false;
}
XNextEvent(display, &event);
candraw = false;
switch (event.type) {
case MotionNotify:
//...
break;
case ButtonPress:
clickx = event.xbutton.x;
clicky = event.xbutton.y;
if(clicky < 50)
pthread_create(&thread, NULL, draw_point, NULL);
break;
case ButtonRelease:
//...
break;
default:
break;
}
}
return 0;
}
Does anyone has an idea about this weird problem?
Thanks a lot!
The problem is caused by using multi-threading with the 2 threads trying to access the display at the same.
strace will change the timing, so the threads are accessing the display at different times.
Xlib does have functions to prevent conflict. Lookup XInitThreads, which enables thread support and XLockDisplay and XUnlockDisplay, which you will need to call from each thread before and after accessing the display.

How to get package name using blackberry

I am new to blackberry development, Is it possible to get package name of the application which is installed in device. I din't get any reference for this.
int[] handle = codeModuleManager.getModuleHandles();
for(int i=0; i<handle.length; i++){
ApplicationDescriptor[] app_descriptors = CodeModuleManager.getApplicationDescriptors(handle[i]);
if(app_descriptors != null){
System.out.println("app_descriptors length "+ app_descriptors.length);
for(int j=0; j< app_descriptors.length; j++){
System.out.println("Iterating the arraylist :: "+ app_descriptors[j].toString());
}
}
}
Try this -
This will get all the installed modules.
int[] v=net.rim.device.api.system.CodeModuleManager.getModuleHandles();
For getting the ApplicationDescriptors associated with the module, use the following code -
net.rim.device.api.system.CodeModuleManager.getApplicationDescriptors(int moduleHandle)
Edit : -
int[] handle = CodeModuleManager.getModuleHandles();
for(int i=0; i<handle.length; i++){
ApplicationDescriptor[] app_descriptors = CodeModuleManager.getApplicationDescriptors(handle[i]);
if(app_descriptors != null){
System.out.println("app_descriptors length "+ app_descriptors.length);
for(int j=0; j< app_descriptors.length; j++){
String moduleName = app_descriptors[i].getModuleName();
String name = app_descriptors[i].getName();
}
}
}

madvise() function not working

I am trying madvise() to mark allocated memory as mergeable so that two applications having same pages can be merged.
While using the madvise() function it shows "invalid argument".
#include<stdio.h>
#include<sys/mman.h>
#include<stdlib.h>
#include<errno.h>
#define ADDR 0xf900f000
int main()
{
int *var1=NULL,*var2=NULL;
size_t size=0;
size = 1000*sizeof(int);
var1 = (int*)malloc(size);
var2 = (int *)malloc(size);
int i=0;
for(i=0;i<999;i++)
{
var1[i] = 1;
}
for(i=0;i<999;i++)
{
var2[i] = 1;
}
i = -1;
while(i<0)
{
i = madvise((void *)var1, size, MADV_MERGEABLE); //to declare mergeable
printf("%d %p\n", i, var1); //to print the output value
err(1,NULL); //to print the generated error
i = madvise((void *)var2, size, MADV_MERGEABLE); //to declare mergeable
printf("%d\n", i);
}
return 0;
}
Error:
a.out: Invalid argument
Please help me.
Thank You.
You can only merge whole pages. You can't merge arbitrary chunks of data.

Resources