Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution to problems with Polish characters #43

Open
TKasperczyk opened this issue Jul 21, 2017 · 0 comments
Open

Solution to problems with Polish characters #43

TKasperczyk opened this issue Jul 21, 2017 · 0 comments

Comments

@TKasperczyk
Copy link

TKasperczyk commented Jul 21, 2017

Hi,

Your library isn't properly converting Polish characters like ą, ś, ę, ć etc. from UTF-8 to UCS2. The resulting data in the PDU gets malformed and after sending it through a GSM modem, the text becomes just a bunch of random characters.
To fix that, you need to change your pack_8bits_to_ucs2 function in messaging/utils.py. Here's how it should look like in order for it to work properly with Polish chars:

def pack_8bits_to_ucs2(message, udh=None):
    # XXX: This does not control the size respect to UDH
    text = message
    nmesg = ''

    if udh is not None:
        text = udh.encode('utf-8', 'ignore') + text

    for n in unicode(text, "utf-8"):
        nmesg += chr(ord(n) >> 8) + chr(ord(n) & 0xFF)
    mlen = len(text.decode("utf-8")) * 2
    message = chr(mlen) + nmesg
    return encode_str(message)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant