How to Disconnect dialled call after some time automatically in blackberry? - blackberry

I have required to disconnect outgoing call on specific number when apps launch.
Thanks !!

I use following code.
public void disconnect()
{
EventInjector.KeyCodeEvent pressEndKey = new EventInjector.KeyCodeEvent( KeyCodeEvent.KEY_DOWN, (char) Keypad.KEY_END, 0);
EventInjector.KeyCodeEvent releaseEndKey = new EventInjector.KeyCodeEvent( KeyCodeEvent.KEY_UP, (char) Keypad.KEY_END, 0);
EventInjector.invokeEvent(pressEndKey);
EventInjector.invokeEvent(releaseEndKey);
}

Related

Arduino Temboo Google Sheets response code 0 returned, still not working

So I'm trying to update a gooogle sheet through Temboo and an Arduino Yun. I can run the AppendValues choreo and AppendRow choreo from the Temboo site just fine and everything updates, but running the choreos through the arduino .ino shows no updates on the google sheet. I get a return code of 0 from running the choreo though. So I know Oauth is working and google and temboo are talking, so there must be a problem in my code?
I have double checked AccountName, Password, AppKey, refresh token, client secret, client id, spreadsheet id, spreadsheet name, etc in the Arduino code (tried AppendValuesChoreo and AppendRowChoreo).
AppendRow .ino:
// Include required libraries
#include <Bridge.h>
#include <Temboo.h>
// Debug mode ?
boolean debug_mode = true;
void setup() {
//start serial
Serial.begin(115200);
delay(4000);
while(!Serial);
// Start bridge
Bridge.begin();
Serial.println("Setup complete. Waiting for sensor input...\n");
}
void loop() {
Serial.println("\nCalling the /Library/Google/Spreadsheets/AppendRow Choreo...");
// Append data to Google Docs sheet
runAppendRow();
// Repeat every 10 seconds
delay(10000);
}
// Function to add data to Google Docs
void runAppendRow() {
TembooChoreo AppendRowChoreo;
// Invoke the Temboo client
AppendRowChoreo.begin();
// Set Temboo account credentials
AppendRowChoreo.setAccountName("");
AppendRowChoreo.setAppKeyName("myFirstApp");
AppendRowChoreo.setAppKey("");
// Identify the Choreo to run
AppendRowChoreo.setChoreo("/Library/Google/Spreadsheets/AppendRow");
// your Google username (usually your email address)
AppendRowChoreo.addInput("Username", "");
// your Google account password
AppendRowChoreo.addInput("Password", "");
// the title of the spreadsheet you want to append to
AppendRowChoreo.addInput("SpreadsheetTitle", "Yun");
// Format data
String data = "123,921";
// Set Choreo inputs
AppendRowChoreo.addInput("RowData", data);
// Run the Choreo
unsigned int returnCode = AppendRowChoreo.run();
// A return code of zero means everything worked
if (returnCode == 0) {
if (debug_mode == true){
Serial.println("Completed execution of the /Library/Google/Spreadsheets/AppendRow Choreo.\n");
Serial.println("Row added: " + data);
}
} else {
// A non-zero return code means there was an error
// Read and print the error message
while (AppendRowChoreo.available()) {
char c = AppendRowChoreo.read();
if (debug_mode == true){ Serial.print(c); }
}
if (debug_mode == true){ Serial.println(); }
}
AppendRowChoreo.close();
}
AppendVValues .ino:
#include <Bridge.h>
#include <Temboo.h>
int calls = 1; // Execution count, so this doesn't run forever
int maxCalls = 10; // Maximum number of times the Choreo should be executed
void setup() {
Serial.begin(9600);
// For debugging, wait until the serial console is connected
delay(4000);
while(!Serial);
Bridge.begin();
}
void loop() {
if (calls <= maxCalls) {
Serial.println("Running AppendValues - Run #" + String(calls++));
TembooChoreo AppendValuesChoreo;
// Invoke the Temboo client
AppendValuesChoreo.begin();
// Set Temboo account credentials
AppendValuesChoreo.setAccountName("");
AppendValuesChoreo.setAppKeyName("");
AppendValuesChoreo.setAppKey("");
// Set Choreo inputs
AppendValuesChoreo.addInput("RefreshToken", "");
AppendValuesChoreo.addInput("ClientSecret", "");
AppendValuesChoreo.addInput("Values", "[[15,49]]");
AppendValuesChoreo.addInput("ClientID", "");
AppendValuesChoreo.addInput("SpreadsheetID", "");
// Identify the Choreo to run
AppendValuesChoreo.setChoreo("/Library/Google/Sheets/AppendValues");
// Run the Choreo; when results are available, print them to serial
AppendValuesChoreo.run();
while(AppendValuesChoreo.available()) {
char c = AppendValuesChoreo.read();
Serial.print(c);
}
AppendValuesChoreo.close();
}
Serial.println("Waiting...");
delay(30000); // wait 30 seconds between AppendValues calls
}
Looks like they only support rev1, and the original shields. Hopefully they'll update services for the rev2 boards soon.

Arduino's serial communication with gsm board

I am trying to write a program where arduino receives text from the gsm module.But my program is able to read the first text and perform a duty,but i want it to receive multiple texts and perform individual tasks for each respective texts?Any help will be great.Thank You.
#include <SoftwareSerial.h>
SoftwareSerial gsm(2, 3);
String inString[64]; // string to hold input coming from device
String read;
int count = 0;
boolean verifyingDone = false; // flags to determine the action completed and to perform next action
boolean regist = false;
boolean registercomplete = false;
boolean location = false;
void setup()
{
// put your setup code here, to run once:
Serial.begin(9600);
gsm.begin(4800);
delay(100);
gsm.print("ate0\r"); // removes the echo from the device
delay(100);
gsm.print("at+cnmi=1,2,0,0,0\r"); // to receive a text
Serial.print("The Device has been Intiated");
}
void loop() {
if (gsm.available())
{
while (gsm.available())
{
read = gsm.readString();
verifyNum(); // verifying the number
/* verifyingDone=true;
if(verifyingDone){
delay(1000);
gsm.print("at+cgpsinfo\r");
delay(1000);
checkGps();
verifyingDone=false;
*/
reading1: inString[count++] = read;
Serial.print(String(read));
if (count == 64) {
break;
}
}
delay(200);
count = 0;
}
}
void clearBufferArray()
{
for (int i = 0; i < count; i++)
{
inString[i] = "";
}
}
void verifyNum() {
if (read.startsWith("\r\n+CMT: ")) { // checking the incoming text and verifying the pre-defined number
int index1 = read.indexOf('"');
int index2 = read.indexOf('"', index1 + 1);
String Number = read.substring(index1 + 2, index2);
char floatbuf[100]; // make this at least big enough for the whole string
Number.toCharArray(floatbuf, 100);
int number = atoi(floatbuf);
//Serial.println(number);
delay(1000);
if (strcmp(number, 24190) == 0)
{
Serial.println("The Sending number is " + Number);
Serial.println("This is the registered number");
regist = true;
if (regist) {
gsm.print("AT+CMGS=\"0434519166\"\r"); // Sending registeration confirmation via sms
delay(100);
gsm.print("Success this mobile number has been registered .\r");
gsm.print("\r");
delay(100);
gsm.println((char)26);
delay(10000);
registercomplete = true;
if (regist == true && registercomplete == true) { //after complete registeration ,checking the gps and sending the co-ordinates
checkGps();
delay(500);
}
}
else {
gsm.print("AT+CMGSO=\"0434519166\" \,\"Someone tried to access your device\"\r"); // When not a registered number
}
}
}
}
void checkGps()
{
Serial.print("Gps Search has started");
delay(10000);//big delay to complete previous process //Not able to do this process completely------>Coz not able to re-read the string obtained from the first read..have to find an alternate to read incoming signals efficiently and re-using it
clearBufferArray();
delay(1000);
gsm.write("at+cgpsinfo\r");
delay(10000);
Serial.println();
Serial.println();
Serial.print("Locating.....Wait for a moment");
/*int spacePosition = read.indexOf(':');
if (read.charAt(spacePosition + 1) == ',' && regist==true )*/
if (read.startsWith("\r\n+CGPINFO:,,,"))
{
Serial.println("GPS signal not found.Go outside"); //
gsm.print("AT+CMGS=\"0434519166\"\r"); // Sending location as sms
delay(100);
gsm.print("GPS signal not found.Go outside ");
gsm.print("\r");
delay(100);
gsm.println((char)26);
delay(1000);
regist = false;
}
else
{
Serial.println("Signal found");
gsm.print("AT+CMGS=\"0434519166\"\r"); //Confirming signal found and sending location----->location finding programs can be obtained from previouses sketches
delay(100);
gsm.print("GPS found.Location will be sent soon ");
gsm.print("\r");
delay(100);
gsm.println((char)26);
delay(1000);
}
}
Thank You,Above code is justa tryout ,any help is welcome!

How to interrupt an xQueueReceive() API in FreeRTOS?

In the following code
SendMessage() is the API called by the user to send a message over USB
UsbDataReceived() is the function called by another thread when data is received on the USB
Task() is the thread created in init() that reads from the queue filled by SendMessage() and calls the low level usb function to send a message
UsbConnected() is the function called by another thread when a USB device is connected.
I need to implement the following behaviour:
Once a message has been sent, no new messages can be sent up to when an answer for the last message has arrived
When UsbConnected() is called, all of the queues must be emptied and if the thread Task() is waiting on the queue AnswerQueue, it has to be unblocked so that it can go back to wait on the queue CommandQueue
An example of my best solution is listed below.
I had to post an EVENT_QUEUE_RESETTED message on both of the queues with a particular order.
Is it possible to achieve the same result in a less cumbersome way?
void UsbhOut(Message_t );
int UsbConnected;
QueueHandle_t MessageQueue;
typedef enum
{
EVENT_QUEUE_RESETTED,
EVENT_NEW_MESSAGE,
EVENT_NEW_ANSWER,
} Event_t;
typedef struct
{
Event_t Event;
uint8_t Data[32];
} CommandQueue_t;
typedef struct
{
Event_t Event;
uint8_t Data[32];
} AnswerQueue_t;
void init(void)
{
MessageQueue = xQueueCreate(sizeof(Message_t), 10);
AnswerQueue = xQueueCreate(sizeof(Message_t), 10);
xTaskCreate(Task, "", 200, NULL, 1, NULL);
}
void UsbConnected(void)
{
CommandEvent.Event = EVENT_QUEUE_RESETTED;
AnswerEvent.Event = EVENT_QUEUE_RESETTED;
UsbConnected = 1;
xQueueReset(MessageQueue);
xQueueReset(AnswerQueue);
/* The order here is fundmental */
xQueueSend(AnswerQueue, &AnswerEvent, 0);
xQueueSend(MessageQeueue, &CommandEvent, 0);
}
int SendMessage(uint8_t * Data)
{
CommandQueue_t CommandEvent;
CommandEvent.Event = EVENT_NEW_MESSAGE;
memcpy(&CommandEvent, Message, 32);
if(xQueueSend(MessageQueue, &CommandEvent, 0) == pdTRUE)
return 0;
else
return -1;
}
void UsbDataReceived(uint8_t * Data)
{
AnswerQueue_t AnswerEvent;
AnswerEvent.Event = EVENT_NEW_ANSWER;
memcpy(AnswerEvent.Data, Data, 32);
xQueueSend(AnswerQueue, &AnswerEvent,0);
}
void Task(void *pvParameters)
{
CommandQueue_t CommandEvent;
AnswerQueue_t AnswerEvent;
CommandCallback_t * Callback;
while(1)
{
xQueueReceive(UsbhStaticData.CommandSenderQueue, &CommandEvent, portMAX_DELAY);
if(CommandEvent.Event == CommandSenderQueueData_t::EVENT_QUEUE_RESETTED)
{
continue;
}
/* Low level Usb fucntion used to send Data */
UsbdSendData(Command.Data);
xQueueReceive(UsbhStaticData.AnswerReceivdQueue, &AnswerEvent, portMAX_DELAY);
if(AnswerEvent.Event == AnswerReceivedQueueData_t::EVENT_QUEUE_RESETTED)
{
continue;
}
else if(AnswerEvent.Event == AnswerReceivedQueueData_t::EVENT_ANSWER_RECEIVED)
{
ParseData(AnswerEvent.Data);
}
}
}
You could use Queue Sets
FreeRTOS Queue Set API
That way you could create a Queue Set containing a queue and a semaphore. Your task would block on the Queue Set. It would then get unblocked by either receiving a message from the queue or you incrementing the semaphore.

blackberry socket connection

I am trying to write simple socket program in blackberry, but it is not working. I have tried a lot. Please someone help me. Is any additional settings are required with simulator?
Thanks in advance :)
try
{
StreamConnection conn =(StreamConnection)Connector.open("socket://some ip:4444;deviceside=false,Connector.READ_WRITE,true");
OutputStreamWriter _out = new OutputStreamWriter(conn.openOutputStream());
String data = "This is a test\n";
int length = data.length();
_out.write(data, 0, length);
InputStreamReader _in = new InputStreamReader(conn.openInputStream());
char[] input = new char[length];
for ( int i = 0; i < length; ++i )
{
input[i] = (char)_in.read();
};
_in.close();
_out.close();
conn.close();
}
If you are trying to connect exactly how you have mentioned above then you indeed are not supposed to be able to connect:
StreamConnection conn =(StreamConnection)Connector.open("socket://some
ip:4444;deviceside=false,Connector.READ_WRITE,true")
because there was a wrongly placed quotation mark after the boolean value true, which should have been placed after ...deviceside=false, i.e. the correct StreamConnection should have formed somewhat like this:
StreamConnection conn =(StreamConnection)Connector.open("socket://some
ip:4444;deviceside=false",Connector.READ_WRITE,true);
The Connector.READ_WRITE and the boolean values are the parameters for the Connector.Open() method.
check the following link it may be help you
http://supportforums.blackberry.com/t5/Java-Development/Different-ways-to-make-an-HTTP-or-socket-connection/ta-p/445879

Programmatically invoke browser in Blackberry

Need to show browser through my application.
My application should go in background and browser should come in foreground.
int moduleHandle =
CodeModuleManager.getModuleHandle("net_rim_bb_browser_daemon");
if (moduleHandle > 0)
{
// Use the default browser application descriptor as the
// model descriptor.
ApplicationDescriptor[] browserDescriptors =
CodeModuleManager.getApplicationDescriptors(moduleHandle);
// Create the new application descriptor.
String[] args = {"url", url, null};
// Turn off auto restart (the original descriptor has it
// turned on) so we don't end up in a never ending loop of
// restarting the browser.
int flags = browserDescriptors[0].getFlags() ^
ApplicationDescriptor.FLAG_AUTO_RESTART;
ApplicationDescriptor newDescriptor =
new ApplicationDescriptor
(
browserDescriptors[0],
"BrowserPS",
args,
null,
-1,
null,
-1,
flags
);
// Run the application.
try
{
ApplicationManager.getApplicationManager().
runApplication(newDescriptor);
}
catch (ApplicationManagerException ame)
{
System.err.println(ame.toString());
}
}
This is my code it's working fine in simulator, but not on actual device.
any help.
Try like
BrowserSession browserSession = Browser.getDefaultSession();
browserSession.displayPage(URL);

Resources