im doing a program that allow my beacon and DK board to start scanning and stop scanning using BLE. I am able to start scanning, but i didn't know how to stop scanning. Can anyone advise me with this? The code provided is my scan_start. Thank you!
static void scan_start(void)
{
uint32_t err_code;
err_code = sd_ble_gap_scan_start(&m_scan_params);
APP_ERROR_CHECK(err_code);
err_code = bsp_indication_set(BSP_INDICATE_SCANNING);
APP_ERROR_CHECK(err_code);
}
Stopping scan_start depends on where you use this function. For example if you use scan_start in main function(before for loop), after a while, if there is no connection, it will enter sleep mode and stop scanning.
Otherwise if you want to control start_scanning time, you can define app_timer function. For example, you can define a timer or button handler that starts scanning when the button is pressed.
If you still can not find the answer you're looking for, there is another suggestion. You can use the stop_scanning function in the file "ble_gap.h" to stop scanning. Function like this;
SVCALL(SD_BLE_GAP_SCAN_STOP, uint32_t, sd_ble_gap_scan_stop(void));
You can use like this;
(void) sd_ble_gap_scan_stop();
If there is any mistake please correct it. I hope that will be useful...
Related
When I try to use the function uv_close((uv_handle_t*)client,NULL) in libuv library to actively close the TCP connection with the client, the error
"main: src/unix/core.c:117: uv_close: Assertion `!uv__is_closing(handle)' failed."
was reported. I search a lot online, but I still cannot find the correct way to solve the problem. I wish someone can tell me why this problem resulted and how to solve it.
You are trying to close a handle that is either already closed or in a closing state (that is, somewhere along the process that brings the handle from being alive to being closed).
As you can see from the code of libuv, the uv_close function starts as:
void uv_close(uv_handle_t* handle, uv_close_cb close_cb) {
assert(!uv__is_closing(handle));
handle->flags |= UV_CLOSING;
// ...
Where uv__is_closing is defined as:
#define uv__is_closing(h) \
(((h)->flags & (UV_CLOSING | UV_CLOSED)) != 0)
To sum up, as soon as uv_close is invoked on a handle, the UV_CLOSING flag is set and it's checked on subsequent calls to avoid multiple runs of the close function. In other terms, you can close a handle only once.
The error comes out because you are probably invoking uv_close more than once for a handle. However, it's hard to say without looking at the real code.
As a side note, you can use uv_is_closing to test your handle if you are in doubt. It's a kind of alias for uv__is_closing.
I've searched around without luck to get the answer to this question.
I'm doing a UART communication, I want to read data continuously if I have the button pressed or in the "down" position. The problem is that I'm using a while loop to do it. When I try to stop reading and release the button, the program freezes and does not respond. Any help will be appreciated it. Part of the code is below.
void MainWindow::on_pushButton_3_toggled(bool checked)
{
while(checked)
{
QByteArray datas = Serial_port.readAll();
ui->textEdit->setText((QString)datas);
qDebug()<<"Im here";
msleep(100);
qDebug()<<datas;
qDebug()<<checked;
}
qDebug()<<checked;
}
You're blocking the event loop, therefore, Qt can't process events. You could try calling QApplication::processEvents() during your loop, and that should make the UI responsive again.
why you need a loop to exec this code? are you using function connect() to made your click event correct? whem you click u start your loop and you don't have a end of this loop, you don't need this loop, you readall from serial port and put it in QBytearray when it finally readall the function read the next line and next at until end of function!
but if your need to continue using the loop try to made a checkbox in your ui, to get true or false and put a if in in loop to stop your loop
if(ui->cb->isChecked())
checked = true;
else
checked=false;
We have an assignment in which we have to implement a printer spooler using linked lists. I have used the list from STL to implement everything. I can get the program to send the print command and maintain status of documents. The problem is I don't know how to mimic/send a dummy print command so the document gets printed. If I use Sleep() there is a delay in the whole program.while I want printing on backhand and others users to have access to the program.
Any help will be appreciated regarding my problem thanks.
In a REAL print spooler, either there are multiple threads (or in Unix, maybe a fork) or the system uses a "wait for several objects" type approach, and when there is something to print, a portion of the document is sent to the printer, set up so that when that portion is "consumed", a waitable object is "ready". Then the spooler waits for something to happen (either a new job or the printed). When the wait is completed, it determines what happened. If it's a new print job, queue it, if it's "some printing completed", it checks if that's the last of the printing and completes the job, or sends more stuff to the printer.
In pseudocdoe it may look something like this:
for(;;)
{
what = wait_for_work();
switch (what)
{
case new_job:
add_new_job();
break;
case print_write_done:
if (document_complete)
remove_current_job();
else
send_more_from_current_job();
break;
case spooler_terminate:
exit(0);
default:
print_error_message();
}
}
Obviously, without seeing your code, it's hard to say how you should implement it. But one could have a timer to simulate the "document being printed in small chunks", say, 10KB is consumed every 100ms, for example.
I'm a rookie programmer, so please be polite.
Well i'm trying to write a simple Terminal Backgammon game, just for fun, but i have a problem.
The entire game runs in a while loop which keeps re running as long as nobody moved all their bricks to the end of the board.
A simple integer controls whatever it is black or white who plays.
I wrote a function to check for any possible moves, cause i want to program to skip the turn in case absolutely no moves can be made.
Well, i want this function to run and in case it returns false(No possible moves) then i want the rest of the code to skip and change the turn to the next player. For example if the dice combination gives no possible moves for black, then i want the program to skip black and go to white.
So i sort of want to break the rest of the while loop, but keep it running.
It's a little complicated for me to explain the issue, but i hope you guys understand.
Thanks alot
- Martin
It sounds like you want to use continue:
while (someCondition)
{
doSomething();
if (someOtherCondition)
continue;
doSomethingElse();
}
In this example, if someOtherCondition is true, the continue statement will cause the program to jump back to the top of the loop rather than continuing to execute the following statements. If someOtherCondition is false, doSomethingElse() will get run as normal.
I think this is roughly what you want to know.
Hope it helps.
while( keepRunning )
{
bool noPossibleMoves = checkForPossibleMoves();
setup for each loop iteration
Do things here that are always necessary.
if( noPossibleMoves )
{
continue; // This will go to the top of the while loop
}
wait for user input etc...
...
...
}
Im trying to parse a file using Bison/Yacc but i want to pause the parsing for a while. The reason i want to do this is that i want to process a huge file sequentially and simulate a java iterator using hasNext() and next() methods.
A trivial example would be, splitting a file by line using yacc so i could call:
while(myYaccObj.hasNext())
{
std::string line = myYaccObj.next()
}
I cant find how to "pause" the file scanning. Is there a way to do that?
The easiest way is just to do the pause directly in you action code. For example, you could have a rule:
rule: whatever { Pause(); }
;
This would call your Pause function which could pause and/or do whatever you want. When you want to continue parsing, simply have the Pause function return.
In fact pausing for me means "keep the state and finish the yyparse" call. For example in my gramar I would do:
rule:
SaveLine;
Pause;
And then the control is returned to my code. I do what i have to do and then I call:
yyparse_resume();
and the parsing continues until another pause or EOF.