Signal Strength - Windows Mobile Development and Hacking General

I am sure this question has been asked and answered many times. However a simple search of my subject line in 'programmers corner' yeilds no results.
How is it possible to obtain the signal strength at the current time?
Thanks, Ben.

In reply to my own message, a quick hack at the ril.h and I have a solution to getting the signal strength. My apologies to the authors of ril.h, and thanks to IP Dashboard for unknowingly providing the calibration.
If anybody want to use this, and until such time as the correct solution is published, this is a hack which works.
Beware, possible bug with rill.dll?? When connected to GPRS, the signal strength is always returned as 69% (183) ???
In ril.h add the following structure:
typedef struct {
DWORD dwUnknown1;
DWORD dwUnknown2;
unsigned char ucSignalQuality;
} RIL_SIGNAL_QUALITY;
And uncomment / adjust the definition of RIL_GetSignalQuality to:
HRESULT RIL_GetSignalQuality(HRIL lphRil);
Add a couple of global variables:
DWORD m_dwSigQuality = 0;
HRESULT m_dwSigQualityID = 0;
Edit the ResultCallback to include this code:
if (hrCmdID == m_dwSigQualityID) {
if (dwCode == 1) {
RIL_SIGNAL_QUALITY *data;
data = (RIL_SIGNAL_QUALITY *)lpData;
m_dwSigQuality = (data->ucSignalQuality == 255)
? 0
: (data->ucSignalQuality * 9 / 7) - 166;
} else {
m_dwSigQuality = 0;
}
m_dwSigQualityID = 0;
}
Add your own method to get the signal strength:
void OnButSigStrengh()
{
m_dwSigQuality = 0;
m_dwSigQualityID = RIL_GetSignalQuality(g_hRil);
int iTimeout = 100;
while (m_dwSigQualityID && iTimeout--) Sleep(10);
CString s;
s.Format(TEXT("Signal Strength = %u%%"), m_dwSigQuality);
MessageBox(s);
}
Which should work.
Ben

Ben -
Nice work -- the code snippet you posted is more or less what we did to get signal strength up and running in IP Dashboard -- of course, I had to do the calibration manually by walking around New York City while a test app spit out readings from the SignalStrength function and I looked at the signal bars, but hey, it was fun. I don't visit often or I would have responded sooner.
Here are the calibration readings we use:
#define ID_PHONEINFO_SIGNALSTRENGTH_POOR 0x80
#define ID_PHONEINFO_SIGNALSTRENGTH_FAIR 0xa1
#define ID_PHONEINFO_SIGNALSTRENGTH_GOOD 0xad
#define ID_PHONEINFO_SIGNALSTRENGTH_EXCELLENT 0xbb
#define ID_PHONEINFO_SIGNALSTRENGTH_NOSIGNAL 0xff
Regards,
Noah
Hudson Mobile
(makers of IP Dashboard)

Hey Noah, you know a very good addition to your program could be.
In the same way that you have that "floating" network icon, that you can position it on top or the bottom, (you even provide exact location on top, which I find it pretty useful). You should make another icon for the signal, just like the one from the phone, but the advantage is that yours can hold any skinning done in the phone. I have tried PocketBlinds, Facelift and others and your Network icon stays where it should, whereas the radio signal icon stays behind the skinning. and the option of making this icon show at the bottom, makes it even better, some people (like me) prefer seeing the icons at the bottom and not on top. This would make a great addition for your program and would make a killer app. Well, that and the addition also of a battery metter
By the way, if you need any kind of help designing the icons let me know, I would like to help

Yorch --
I saw your post at Wormhole Creations' website as well -- my apologies for not writing back, we are putting together our next product right now (tracker for phone voice minute usage) and things are hectic.
There is special code in IP Dashboard to make sure the taskbar icon floats above a skinned interface - we could potentially add a signal strength icon as well. Coincidentally, we really need ICON design help. If you are willing to design some cool icons for signal strength, I think we could probably work it into the product without too much difficulty over the next 1-2 releases. Let's take this to email -- I can be reached at nbreslow AT hudsonmobile.com
As for the Battery meter, we want to keep the product focused, but a simple battery meter function (line item that read: Battery X%) would be pretty easy to add as well.
Thanks for your interest and suggestions,
Noah
Hudson Mobile

Guys - Try Phone Dashboard, a Today Plug-in - Part of it polls real-time signal strength and displays it in percentage terms - v.Useful if you need a real validation of the Signal Strength bar.

Ben
How you getting on?
Drop me a mail...

Hello, the code above works like a charm!
I have however a side-effect: the radio icon on the top bar seems to indicate that the radio is off (I cannot receive calls) when I run the program. A couple of minutes after I close it, it goes back to normal.
This is my initialization line:
res = (*fpTAPIrilInit)(1, AsyncCallBack, NotifyCallBack, RIL_NCLASS_MISC, 0x55AA55AA, &hRil);
Any thoughts?
Many thanks for the help!

why cant ppl just post source codes it would be sooo much helpfull !!!

It need to get signal strength on my Universal, too. So
does it work with on HTC Universal with new WM 6 ?
thanks,

Related

RIL

XDA Developers,
Years ago I downloaded the RIL .dll and API from this site. Then it was only half complete and I had to patch it my self.
I am sure development has been completed since then.
Can anybody tell me if RIL is still maintained by this site? In which case, where can I get it?
Specifically I need signal quality on XDA II upwards. If anybody can help me?
Kind Regards,
Ben
After posting, my text RIL was shown with a link to most of the information.
There is one think I can't understand. The stucture returned as as follows:
int nMinSignalStrength; // @field TBD
int nMaxSignalStrength; // @field TBD
int nLowSignalStrength; // @field TBD
int nHighSignalStrength; // @field TBD
Which have the values (On XDA IIs) of -113, -51, -110, -60
Would any member know what the meaning of these values is?
I have then tried to convert the quality to a percentage. But the percentage always reads way to high, or zero.
My guess is that these are DB and therefore logarithmic. Would any member know how to convert to a linar scale?
My guess is something like: log10(n / 3) where n is any of the above or retuned figure.
Any ideas would be very useful!
Regards, Ben.
Hi,
Code:
HRESULT RIL_GetSignalQuality(
HRIL hRil // @parm handle to RIL instance returned by <f RIL_Initialize>
);
returns the following structure:
Code:
typedef struct rilsignalquality_tag {
DWORD cbSize; // @field structure size in bytes
DWORD dwParams; // @field indicates valid parameters
int nSignalStrength; // @field TBD
int nMinSignalStrength; // @field TBD
int nMaxSignalStrength; // @field TBD
DWORD dwBitErrorRate; // @field bit error rate in 1/100 of a percent
int nLowSignalStrength; // @field TBD
int nHighSignalStrength; // @field TBD
} RILSIGNALQUALITY, *LPRILSIGNALQUALITY;
Why don't you just use nSignalStrength? Sounds pretty simple and linear to me? Nothing to calculate...
In trying to make my posting simple. I think I forgot to clarify my problem
First is the problem that the nSignalStrength falls between two values.
But there are two fields it can fall between:
nMinSignalStrength <= nSignalStrength <= nMaxSignalStrength
nLowSignalStrength <= nSignalStrength <= nHighSignalStrength
Which one should be used? Why are there two?
Secondly, I want to show a percentage result between one of the above. But these figures are, I belive, Decibels (BD). Each 3 DB = a doubling of the value. So 1 = 10%, 4 = 20%, 7 = 40% etc...
Therefore a liniar percent placement of nSignalStrengh tells me nothing. Most values are close to Max, and then suddenly zero.
My math is a little rusty I was hoping somebody may have a nice function for returning the linear range from the logarithmic rage….
Thanks again to any members who can offer some help
Ben
Hmm... but what if min and max are just values currently encountered in your local cell? When you move to another cell you may receive different min/max values. Or maybe these are the values of the farest and nearest cell? I don't know either, but your explanation of min/max sounds worse to me than does mine...
This could be correct. The values I have are on my XDA IIs using O2 are:
Min -113
Low -110
High -60
Max -51
Therefore:
Min < Low < nSignalStrength < High < Max
So I am using Low = 0% and High = 100%. But this returnes figures of above 50% when signal is quite low.
I think the linear conversion is exp(value / 3)
Therefore percent is:
percent = (exp(nSignalStrength / 3) - exp(Low / 3)) / (exp(high / 3) - exp(Low / 3)) * 100;
Which seems to give better figures. But I am not sure how accurate it is..
Any experts on signal quality out there, I'd love to hear from them!
Ben
If anybody is following this thread, this *seems* to return a good percentage for signal quality. I am not sure of the quality or accuracy. But it works
static double dValue, dMax;
dValue = (int)data->nSignalStrength; // (int) to convert twos complement signed integer correctly.
dMax = (int)data->nHighSignalStrength; // (int) to convert twos complement signed integer correctly.
dValue -= (int)data->nLowSignalStrength;
dMax -= (int)data->nLowSignalStrength;
dValue = pow(dValue / -3.0, 2);
dMax = pow(dMax / -3.0, 2);
dValue /= dMax;
dValue *= 100;
if (dValue > 100) dValue = 100; // never
if (dValue < 0) dValue = 0; // never
Regards,
Ben
Hi there, i've been following this thread with interest I have a very limited knowlege of C++ but not even on the PPC.
Would you mind attaching or even PMing your cpp so i could possibly learn more ?
I find i learn more by examples, and am quite interested in making an application that can disable the radio then re-enable it after a set ammount of time (so i can swap between sims, i have a dual sim adapter)
Best thing to do is follow the sample code supplied by these nice gues from xda-developers, by clicking on this RIL link.
BUT replace the ril.h in the .zip archive with the ril.h you will find from the link.
(nb: if the author of this .zip archive is reading, it's way out of date to the ril.h on this site. ps, hows the ril development going?)
If you get the sample code working, this will give you some idea of what is possible. Your options may not be possible. But look at the ril.h and the functions listed. If one of them does what you want, give it a go.
Regards,
Ben

event handling in dynamically created control

Hi all,
I am using eVC++ 4.0, and i've dynamically created a CListView like this:
Code:
lv.Create(0,_T(""),WS_CHILD|WS_VISIBLE,r,this,5);
but I dont know how to handle the events of this control... any ideas??
Mohammad
To get events from a listview (win32) I normally subclass it. I use the subclassing routine to post a message back to the parent when the user is doing something like tapping on it, then the windows routine can check whats selected etc and act on it. Is subclassing possible in mfc ?( I don't use it).
Thank u
but can anybody post some code??
thnx
Ok, I am a bit lazy to look up code at the moment, but here's something:
Yes, subclassing is possible in MFC. You just derive your class from the basic class provided like this:
Code:
class MyListView : pubic CListView
Then you add message handlers in the normal matter.
EDIT: The following passage is incorrect:
But I think subclassing may not be necessary in you case. List box controls send WM_COMMAND messages with notifications of major events like selection change to the parent window. All you have to do is to create a WM_COMMAND handler in your parent class.
Sorry I was thinking of ListBox not list view when I wrote it.
To manually add message handlers you need to put macros like ON_MESAGE or ON_COMMAND in the DECLARE_MESSAGE_MAP section of the class cpp file. All the detaisl are available on MSDN.
Are you saying that a listview will send the same WM_COMMAND as a list box in mfc? Dose this also happen in win32 made listviews. I have always thought it was a bit too tedious to find out when the user taps an item in the listview.
After reading your post levenum I had a quick look and it says that a WM_NOTIFY gets sent to the parent with a LVN_ITEMCHANGED for example. I had not used the LVN_**** because when I looked at them there was none that seem to deal with selections. I would guess that LVN_ITEMACTIVATE or LVN_ODSTATECHANGED would be usefull for this but then a second tap would not be picked up still leaving me wanting subclassing in many situations to get the users tap.
Ok, I have read what u wrote guys and my problem is almost solved, I used the OnNotify() method to handle messages sent from child controls like this:
Code:
BOOL CTest2Dlg::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
// TODO: Add your specialized code here and/or call the base class
if(wParam ==5 ) //5 is control ID
{
NMHDR *ph =(NMHDR*)lParam;
if(ph->code==NM_CLICK)
MessageBox("Click");
else if(ph->code==HDN_ITEMCLICK)
MessageBox("Item Click");
else
{
CString str;
str.Format("%d",ph->code);
MessageBox(str);
}
}
return CDialog::OnNotify(wParam, lParam, pResult);
}
Now there still a very small prolem: what messages should I handle for 'Selected Item Changed' event ?? I know its easy but I couldnt find it
Regards
mohgdeisat: I am sorry, I made a mistake about WM_COMMAND.
OdeeanRDeathshead is right, I was thinking of a list box not list view.
To make up for this, here is some sample code from a win32 dialog app that uses list view control. I hope it will be of some help:
Code:
//this is from the dialog window function:
case WM_NOTIFY: //handle events:
nmhdr = (LPNMHDR)lParam;
switch (nmhdr->idFrom)
{
case IDC_LEDLIST: //list control ID.
return OnLEDListEvent(hwndDlg, (LPNMLISTVIEW)lParam);
break;
}
break;
BOOL OnLEDListEvent(HWND hwndDlg, LPNMLISTVIEW nmlv)
{
/////
// Handles list view control notification messages
switch (nmlv->hdr.code)
{
case LVN_ITEMCHANGED:
return OnLEDListItemChanged(hwndDlg, nmlv);
break;
}
return 0;
}
BOOL OnLEDListItemChanged(HWND hwndDlg, LPNMLISTVIEW nmlv)
{
if (ListView_GetSelectionMark(nmlv->hdr.hwndFrom) != nmlv->iItem) return 0;
/* do what you need here */
return 0;
}
Don't mind the fact that I used 3 different functions. This is part of a bigger program and I am trying to keep things well organized without resorting to classes.
As I understand it, LVN_ITEMCHANGE is received for different reasons so I try to handle only the one coming from selected item. LVN_ITEMACTIVATE is only sent when you double click the item so if you just want to catch selection change you need to use LVN_ITEMCHANGE.
Once again, sorry for confusing you before.
thanx pals, good job!!!
I think my problem is now solved with ur help :wink:
Mohammad
Ok guys, I said that my problem was solved, yet, another problem arises...
When the list view is in the report mode, how can I determine when a header button is clicked, and determine which one was clicked???????
thanx in advance
To identify a header column click, you need to handle the WM_NOTIFY/HDN_ITEMCLICK message. Normally this message will be received by the header's parent control (i.e. the listview) -- some frameworks may redirect the message to the header control itself. I haven't worked with MFC in 10 years so I can't really if it reflects notification messages back to the control.
If you're trying to implement column sort, do yourself a favor and check out the Windows Template Library (WTL) at sourceforge.net. It's a set of C++ template classes that provide a thin yet useful wrapper around the standard Windows UI components. One of the classes is a sortable listview control. I've been using WTL with big Windows for more than 5 years -- you couldn't pay me to go back to MFC.
hi,
I have seen the WTL library and it seems very useful and time-saver, but I have a couple of questions about it:
1. can WTL 8.0 be installed with VC++ 6.0, specifically the appwizard stuff??how?? I see only javascript files of vc7.0 and 7.1 and 8.0!!
2. is there a good documentation about those classes??
Mohammad
I don't know about WTL 8; I'm still using WTL 7.5 with VS .Net 2003 for all my Win32 development. My guess is that it wouldn't work too well, as WTL is based on ATL, which has substantially changed between VC 6 and 7.
Good references for WTL include www.codeproject.com/wtl, and the WTL group over at Yahoo groups (reflected at www.gmane.org).

VS.Net and TimeZones...

Hi all,
I'm trying to fix up a long standing timezone issue with KingFetty's CallCalendar - but there seems to be some WEIRD **** happening with DST time...
At the moment, the code works perfectly - however the call gets logged to the calendar with a start time and end time of 1 hour behind the current device time.
This gets weirder when you add a line like this to the start of the program:
msgbox(Now)
The time shown on the messagebox is 1 hour behind what is shown on the clock :|
My idea was to add the following block of code to the FixTime function to try and fix this:
Dim localZone As TimeZone = TimeZone.CurrentTimeZone
If localZone.IsDaylightSavingTime(StartTime) Then
StartTime = StartTime.AddHours("1")
StopTime = StopTime.AddHours("1")
End If
This is all well and good, however IsDaylightSavingTime returns false! Oh joy.
Has anyone run across the VS strangeness with timezones and daylight savings before?
I have attached the current source to this post for budding VB.Net hackers...
Ok - so I managed to find the problem... It looks like after installing the March 2008 Daylight Savings updates, for my particular timezone you need to change to a different timezone, then switch back to the correct timezone for the registry changes to be applied.
Weird behaviour for this kind of thing as multiple hard resets, soft resets, and power off/on reboots didn't have this effect.
This leads me to believe it's a WM issue. Anyone got any ideas on how to fix this properly?
You will have better luck if you post in the appropriate section of the forum. There is a ''Question and Answers'' section to XDA. This section of the forum hereis for posting completed applications, themes, etc.
erm this is a Question Regarding the Development, so i guess it should stay here
I'm not really sure what's your problem but I exprerienced some issues when I had to deal with timezones. This is what helped me:
Code:
System.Globalization.CultureInfo.CurrentCulture.ClearCachedData();
I've sent the following to MS - as it's quite strange behaviour!
I have run some test with the following simple application:
------------------ Start Sample Code ------------------
Imports System.TimeZone
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim localZone As TimeZone = TimeZone.CurrentTimeZone
MsgBox("Time = " & Now & vbCrLf & "StandardName = " & localZone.StandardName & vbCrLf & "DaylightName" & localZone.DaylightName & vbCrLf & "IsDaylight? = " & localZone.IsDaylightSavingTime(Now))
Me.Close()
End Sub
End Class
------------------ End Sample Code ------------------
On freshly booting the Windows Mobile device, I get the following output:
Time = 17/12/08 6:05:20 PM
StandardName =
DaylightName =
IsDaylight? = False
The clock on the device shows 7:05pm when this test was run.
I change the timezone to +10 Brisbane, Click OK, then click Yes to save the changes to the clock.
I then change the timezone back to +10 Sydney, click ok, then click yes to save changes to the clock.
Upon running the sample code above again, I get the following output:
Time = 17/12/08 7:07:38 PM
StandardName = Sydney Standard Time
DaylightName = Sydney Daylight Time
IsDaylight? = True
The clock on the device showed 7:07 PM at the time of this second test.
To me it seems that on boot, the timezone just isn't set - which is just weird!
Click to expand...
Click to collapse

WM Tactile/Haptic feedback API

Does anyone know how to invoke the tactile feedback from an app. Specifically, I am writing my own keyboard but i would like to generate the little pulses when my virtual keys are pressed. I cant find anything on how to actually do this. presumably it's just one system call.
I have a HTC touch pro 2, so i want to get it working on this at first.
thanks for any help,
You just have to vibrate the phone for a very small time, around 20-50ms.
I don't think there's an API for "haptic feedback", it's just a vibration.
It is just touch-vibrate like you said
Just a tip:
The vibration motor is like the led on your device to handle.
Also the vibration/led id is different on different devices!
Hi,
That's what i was thinking too. I'm going to try the WM Vibrate/VibrateGetDeviceCaps/VibrateStop functions to see if they will do it.
If anyone knows if there's more too it than this, please advise.
thanks,
Unfortunately the Vibrate API does not work. These smartphones are actually pocketPC which doesnt support the API.
Intead i use the NLED interface with led=1. This seems to work to create a basic pulse, but i dont know of any way to adjust the strength of the pulse or even if that's possible.
this is what im doing:
Code:
static void LedOn(int id)
{
NLED_SETTINGS_INFO settings;
settings.LedNum= id;
settings.OffOnBlink= 1;
NLedSetDevice(NLED_SETTINGS_INFO_ID, &settings);
}
static void LedOff(int id)
{
NLED_SETTINGS_INFO settings;
settings.LedNum= id;
settings.OffOnBlink= 0;
NLedSetDevice(NLED_SETTINGS_INFO_ID, &settings);
}
static void key_hepatic_feedback()
{
LedOn(1);
Sleep(20);
LedOff(1);
}
No, the strength isn't adjustable. You can only control the duration.

[Q] Review for my game/app

I´v published my first app on the Android Market. However I have little people in my direct suroundings who have Android Phones so hopefully there are a few people here who can help me by telling my what my application misses.
e.g. I think my app uses little battery power. So maybe anyone can confirm this to me?
becouse i am new to the forum (or .. well not new, but little posts) I can not put the link to my app here. Search on Triton Bubble Breaker on Appbrain or Market to download.
It is a bubble breaker game. Why I developed it when there are other alternatives on the market already? Because I missed the feeling I got when playing it on a old phone for the first time. Wanted to make it faster, simpler, free and maybe add some extra features (that should not be disturbing the simplicity of the game)
(when you are a coder.. I have (maybe a simple) question. When the game is finished I like to save the Score. However I can not do this from a DrawView? only from the main activity, so that i have to use menu buttons to call saving the score... is there a way to save data from view/drawview? )
Thanks in advance, and i wander what you think of my first attempt building a android app.
Good work! Very impressive for a first app!
for saving stuff, use these commands:
(put this at the begining of your class)
public static final String PREFERENCE_FILENAME = "AppGamePrefs";
(put this where you need it, usually located where you are doing the saving)
SharedPreferences gameSettings = getSharedPreferences("MyGamePreferences", MODE_PRIVATE);
SharedPreferences.Editor prefEditor = gameSettings.edit();
(get saved data like this)
score=gameSettings.getInt("score", 0); //"score" is the saved variables name, 0 is the default value incase the variable "score" has not been saved yet
(save like this)
prefEditor.putInt("score", points); // saves to variable "score" with value of variable points (you can change the putInt to putString, putBoolean, etc.)
(this finalizes the save VERY IMPORTANT)
prefEditor.commit();
Hope that helps, keep up the good work!
thanx for the reply. Starting writing in Java (?) was getting used to. I did had some experience with coding in Matlab (if that can be labled programming )
I have tried your advice, I have come across the same code on other fora and samples from google. Only problem is that it doesn't work in the class I am programming in, the drawview class.
In essence my program is setup like this:
public class activity extends Activity
...
public void onCreate(Bundle savedInstanceState) {
...
setContentView(drawView);
...
}
.. some other functions for the menu (from which i can do the code for storing data!)
then it goes into the drawView.
Here my program just draws and draws, until there is a touch on the screen, then it will calculate the new situation. But at a given moment, the game is finished. Then i will draw the finish screen (in the same drawview). I can not get out of this drawview. So i can not do setContentView(results_layout) or something like that. And i can not call the code for saving data because that can not be defined in that class (according to Eclipse).
public class DrawView extends View implements OnTouchListener {
...
@Override protected void onDraw(Canvas canvas) {
Draw everything
...
if game_end = true then {
drawResults
save-code here gives error
}
...
}
public boolean onTouch(View view, MotionEvent event) {
calculate everyting
...
game_end = check_game_end(); //return true or false
}
this is my code in essence. Ofcourse it not all, but this i hope you get my idea/problem.
Thanx for the response again

Categories

Resources