View Single Post
Marshall Banana's Avatar
Posts: 94 | Thanked: 209 times | Joined on Oct 2009 @ Germany
#238
Originally Posted by KiberGus View Post
OK. We were looking on a wrong documentation, a bit. As far as we use AT commands, we need GSM 07.07 - Main AT commands and Annex A from GSM 07.05 - Additional AT commands (SMS and CBS). Can be downloaded from http://wiki.openmoko.org/wiki/GSM#GS...in_AT_commands

I didn't understood how decoding should be done correctly and where did we made mistakes, but now I know how to check, if user has left ussd menu.

Update: According to documentation cp850 can not be used in ussd reply (at least with dsc field 15). On the other hand, our implementation shouldn't work at all, because we expect (and we get!) 8 bit encoding, while we should get 7 bit encoding. I would appreciate, if you try running these commands in pnatd:
at+cmgf=1
at+cscs="IRA"
at+cusd=1,"<your USSD number>",15

They should produce a lot of digits instead of human readable reply.
For me
at+cmgf=1
at+cscs="IRA"
at+cusd=1,"*100#",15

gives the same output like:
at
at+cusd=1,"*100#",15

+CUSD: 0,"Ihr Guthaben f\x81r die Nr.491234567890 betr\x84gt 13.53 Euro",15

Btw. i don't know if it is really cp850 encoded, that was just my guess.

Possible solution for the problem:
Before using gsmdecode on the reply remove all non-ascii characters from the reply:
Code:
strip_unicode = re.compile("([^-_a-zA-Z0-9!@#%&=,/'\";:~`\$\^\*\(\)\+\[\]\.\{\}\|\?\<\>\\]+|[^\s]+)")
reply=strip_unicode.sub('', reply)
This prevents gsmdecode from failing and properly encoded replys can still be decoded. My reply looks like this after that:
Ihr Guthaben fr die Nr.491234567890 betrgt 13.53 Euro

Second problem with ussdquery.py:
If the decoding of gsmdecode.py produces non ascii characters (Is this possible? i didn't look at gsmdecode.py) ussdquery.py will fail when writing the decoded reply to stdout as it trys to encode it to ascii.
This (python trying to encode the reply to ascii) will only happen if ussdquery.py is called by ussd-widget or ussd-pad. If you execute ussdquery.py directly in the terminal python will encode the output to the standard encoding of your terminal and the problem will probably not show.

Possible solution: Open stdout as binary file.
Code:
sys.stdout=file("/dev/stdout", "wb")

Last edited by Marshall Banana; 2010-02-06 at 10:03. Reason: Typo
 

The Following User Says Thank You to Marshall Banana For This Useful Post: