classification
Title: irda socket support
Type: feature request Stage: test needed
Components: Extension Modules Versions: Python 3.1, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: qyb (1)
Priority: normal Keywords: patch

Created on 2006-07-14 08:19 by qyb, last changed 2009-03-30 05:07 by ajaksu2.

Files
File name Uploaded Description Edit Remove
release24-maint-irda.patch qyb, 2006-07-14 08:24
obex_test.py qyb, 2006-07-14 08:24 complex obex test
Messages (1)
msg50698 - (view) Author: Qiu Yingbo (qyb) Date: 2006-07-14 08:19
the patch implements IrDA socket's getsockaddrarg()
support under Linux and Win32 platform.

Now we can connect to IrDA device from a socket object
and build more flexible wireless application.

I have test it under Windows XP.

Simple test: connect a irda device

from socket import *
from struct import *
s = socket(AF_IRDA, SOCK_STREAM)
info = s.getsockopt(SOL_IRLMP, IRLMP_ENUMDEVICES, 1024)
list = info[4:]
list
addr = unpack('I', list[:4])[0]
s.connect((addr, "IrDA:IrCOMM"))
s.close()


Complex test: Get mobile phone's deviceinfo by OBEX
protocol

from struct import *
from socket import *

def obex_genheader_byte_stream(opcode, byte_stream):
    length = htons(3 + len(byte_stream))
    return chr(opcode) + pack('h', length) + byte_stream

def obex_genheader_unicode(opcode, unistr):
    unistr = unistr + '\x00\x00'
    length = htons(3 + len(unistr))
    return chr(opcode) + pack('h', length) + unistr

def obex_connect(sockobj, target):
    if (len(target)):
        header = obex_genheader_byte_stream(0x46, target)
    else:
        header = ''
    length = htons(7 + len(header))
    cmd = chr(0x80) + pack('h', length) + chr(0x10) +
chr(0) + pack('h', htons(1024)) + header
    sockobj.sendall(cmd)
    return True

def obex_get(sockobj, filename):
    header = obex_genheader_unicode(0x01, filename)
    length = htons(3 + len(header))
    cmd = chr(0x83) + pack('h', length) + header
    sockobj.sendall(cmd)
    return True

s = socket(AF_IRDA, SOCK_STREAM)
info = s.getsockopt(SOL_IRLMP, IRLMP_ENUMDEVICES, 1024)
list = info[4:]
addr = unpack('I', list[:4])[0]
s.connect((addr, "IrDA:OBEX"))
obex_connect(s, '')
response = s.recv(4096)
obex_get(s, "telecom/devinfo.txt".encode('utf-16be'))
response = s.recv(4096)
print response[6:]
s.close()
History
Date User Action Args
2009-03-30 05:07:55ajaksu2setstage: test needed
type: feature request
versions: + Python 3.1, Python 2.7, - Python 2.4
2006-07-14 08:19:28qybcreate