Ricercare contatto in rubrica con Javaphone API
cdb = javax.pim.addressbook.ContactDatabase()
db = cdb.openDatabase() # Apre database di default
dbnames = cdb.getDatabaseNames() # elenca db disponibili
scorre i vari items:
cis = ecd.items()
ci = cis.next()
Crea gruppo (=categoria su a1000):
g = javax.pim.addressbook.ContactGroup()
aggiunge card (precedentemente creata o trovata) al gruppo:
g.addContact(c)
imposta nome gruppo:
g.setFormattedName(“nome”)
Trova nominativo “tizio” in campo “N”:
nomi = ecd.items(“N”,”tizio”)
nomi.next().getName() # mostra nome/i trovato/i
Scaricare file tramite HTTP
Scaricare file tramite HTTP
(INCOMPLETO)
import os
import java.lang
import java.lang.String
import java.net.URL
import java.net.HttpURLConnection
import jarray
import java.io.BufferedOutputStream
import java.io.FileOutputStream
class test(java.awt.Frame):
def __init__(self):
self.size=(208,276)
self.myOutput=java.awt.TextArea(“Test \n\n”)
self.add(“Center”,self.myOutput)
self.myMenuBar=java.awt.MenuBar()
self.myMenu=java.awt.Menu(“Menu”)
self.myReadFile=java.awt.MenuItem(“Verifica”,actionPerformed=self.doRead)
self.myMenuExit=java.awt.MenuItem(“Exit”,actionPerformed=self.doExit)
self.myMenuBar.add(self.myMenu)
self.myMenu.add(self.myReadFile)
self.myMenu.add(self.myMenuExit)
self.setMenuBar(self.myMenuBar)
self.setVisible(1)
def doRead(self,event):
h = java.net.HttpURLConnection
u = java.net.URL
bos = java.io.BufferedOutputStream
fos = java.io.FileOutputStream
url = u(“http://jumpjack.altervista.org/index.html”)
self.myOutput.appendText(“opening conncetion…\n”)
conn = url.openConnection()
self.myOutput.appendText(“getting stream…\n”)
i = conn.getInputStream()
self.myOutput.appendText(“opening output file…\n”)
o = bos(fos(“d:\\jython\\google.txt”))
self.myOutput.appendText(“start reading…\n”)
buffer = jarray.zeros(1024,’b')
numWritten = 0
numRead = i.read(buffer)
while numRead != -1:
o.write(buffer)
numWritten += numRead
self.myOutput.appendText(“1024 bytes read…\n”)
numRead = i.read(buffer)
self.myOutput.appendText(“Completed.\n”)
o.write(buffer)
i.close()
o.close()
def doExit(self,event):
java.lang.System.exit(0)
if __name__==”__main__”:
myApp=test()
Compiling .py scripts to .jar files
I successfully compiled .py scripts into jar files!
Set classpath:
set classpath = C:\Symbian\UIQ_21\erj\Ext\qawt.jar;C:\Symbian\UIQ_21\erj\Ext\util.jar;C:\Symbian\UIQ_21\epoc32\Java\ext\javaphone.jar;C:\Symbian\UIQ_21\epoc32\Java\lib\classes.zip
Generate the .class files:
jythonc -J “-classpath C:\Symbian\UIQ_21\erj\Ext\qawt.jar;C:\Symbian\UIQ_21\erj\Ext\util.jar;C:\Symbian\UIQ_21\epoc32\Java\ext\javaphone.jar;C:\Symbian\UIQ_21\epoc32\Java\lib\classes.zip” -CC:\Programmi\internet\Java\j2sdk1.4.2_10\bin\javac jython_script.py
Go to jpywork folder in Jython folder and generate .jar file:
jar -cf jython_script.jar jython_script*.class
Use aifbuilder to generate proper aif/app/txt file
Move aif/app/txt/jar file to c:\system\app\jython_script folder
Well, now comes the bad part: application does NOT start properly, due to well known NoClassDefFoundError , but maybe here somebody else can help me?
Possible solutions:
http://www.ssec.wisc.edu/~tomw/visadtutor/compile.html (cambiare command line di compilazione)
http://osdir.com/ml/lang.jython.user/2006-03/msg00077.html (mettere in .jar tutte le librerie jython)
Appunti su invio SMS con l’a1000 tramite comandi AT
Da http://www.multitech.com/DOCUMENTS/Collateral/manuals/S000371B.pdf (ottima guida generale):
Abbreviazioni:
ME = Mobile Equipment
MS = Mobile Station
TA = Terminal Adapter (equivalent to Mobile Equipment (ME) which stands for the GSM module described here. It uses GSM default alphabet as its character set.)
DCE = Data Communication Equipment
TE = Terminal Equipment (TE is the device connected to the TA via serial interface. In most cases TE is an ANSI/ASCII terminal thatdoes not fully support the GSM default alphabet, for example MS Hyperterminal)
DTE = Data Terminal Equipment
CAUTION: ASCII alphabet (TE) is not GSM alphabet (TA/ME)
Several problems resulting from the use of GSM alphabet with ASCII terminal equipment:
• “@” character with GSM alphabet value 0 is not printable by an ASCII terminal program (e.g., Microsoft©
Hyperterminal®).
• “@” character with GSM alphabet value 0 will terminate any C string! This is because the 0 is defined as C
string end tag. Therefore, the GSM Null character may cause problems on application level when using a
‘C’- function as “strlen()”. This can be avoided if it is represented by an escape sequence as shown in the
table below.
By the way, this may be the reason why even network providers often replace “@”with “@=*” in their SIM
application.
• Other characters of the GSM alphabet are misinterpreted by an ASCII terminal program. For example, GSM
“ö” (as in “Börse”) is assumed to be “|” in ASCII, thus resulting in “B|rse”. This is because both alphabets
mean different characters with values hex. 7C or 00 and so on.
• In addition, decimal 17 and 19 which are used as XON/XOFF control characters when software flow control
is activated, are interpreted as normal characters in the GSM alphabet. —>non usare XON/XOFF per comunicare col cellulare!!!
Table 1.5: Examples for character definitions depending on alphabet
GSM 03.38 character, GSM character hex. value, Corresponding ASCII character, ASCII Esc sequence, Hex Esc sequence
Ö, 5C, \ \5C, 5C ,35 ,43
“ ,22, “ ,\22 ,5C, 32 ,32
ò, 08, BSP, 8, 5C, 30, 38
@, 00, NULL, 0, 5C, 30, 30
CAUTION: Often, the editors of terminal programs do not recognize escape sequences. In this case, an escape
sequence will be handled as normal characters. The most common workaround to this problem is to write a
script which includes a decimal code instead of an escape sequence. This way you can write, for example, short
messages which may contain differently coded characters.
———- INIZIO PROVE ————
Sembra che i Motorola adottino un sistema proprietario (“manufacturer specific”) per inviare messaggi tramite comandi AT (AT+CSMS –> 128,1,1,1) .
Sembra anche che si debba per forza PRIMA scriverli in memoria (AT+CMGW) e che si debba usare numeri con notazione internazionale (+39…)
Ho fatto questi test usando Hyperterminal dopo aver sbloccato la porta da Mrouter, e configurando hyperterminal cosi’:
porta:
com23 (ma varia a seconda di quando/come si connette il cell…)
921600 bps
8,n,1
senza controllo di flusso
Emulazione terminale: TTY (senza nessuna configurazione particolare)
Risultati:
–>AT+CSMS
+CSMS: 128,1,1,1 (MODO PROPRIETARIO, Mobile Terminated, Mobile Originated, Broadcast type)
Comando AT+CPMS (memoria preferita):
–>AT+CPMS=mem1[,mem2[,mem3]]
mem1 = memoria da cui i messaggi sono LETTI e CANCELLATI
mem2 = memoria in cui SCRIVERE e da cui INVIARE
mem3 = memoria in cui RICEVERE i messaggi
Risultato:
–>AT+CPMS=?
+CPMS: (“MT”,”IM”,”OM”,”BM”,”DM”),(“OM”,”DM”),(“IM”)
MT = totale
IM = INBOX
OM = OUTBOX
BM = BROADCAST
DM = DRAFT
OK
–>AT+CMGW=”+393331234567″
> prova
> pippo
> [CTRL+Z]
+CMGW: 6
at+cpms=”OM”
+CPMS: 2,88
at+cmgl=”STO UNSENT”
OK
at+cpms=”OM”,”DM”
+CPMS: 2,88,3,88
at+cmgd=6
+CMS ERROR: invalid preferred memory storage
at+cpms=”DM”
+CPMS: 3,88
OK
at+cmgd=6
OK
(cioe’ posso cancellare da DM ma non da OM?)
at+cpms=”DM”,”OM”
+CPMS: 2,88,2,88
OK
at+cmgl=?
+CMGL: (“REC UNREAD”, “REC READ”, “STO UNSENT”, “STO SENT”, “ALL”)
OK
at+cmgl=”STO UNSENT”
+CMS ERROR: operation not allowed
at+cpms=”OM”
+CPMS: 2,88
OK
at+cmgl=”STO UNSENT”
OK
(cioe’ non posso elencare (CMGL) da DM, ma solo da OM?)
at+cpms=”DM”,”OM”
+CPMS: 2,88,2,88
OK
at+cmgd=1
+CMS ERROR: invalid preferred memory storage
at+cmgd=2
OK
at+cmgd=5
OK
at+cpms?
+CPMS: “DM”,0,88,”OM”,2,88,”IM”,0,88
OK
(??? BOH?? ha cancellato da DM)
Possono presemtarsi errori diversi nel tentare di cancellare… ma chissa’ da cosa dipendono?!?
at+cpms=”OM”,”DM”
+CPMS: 2,88,0,88
OK
at+cmgd=1
+CMS ERROR: memory failure
at+cmgd=2
+CMS ERROR: invalid memory index
at+cmgd=3
OK
at+cpms?
+CPMS: “OM”,1,88,”DM”,0,88,”IM”,0,88
Perche’ non viene spedito??
at+cmgw=”+393331234567″
> OM,DM,IM
>
+CMGW: 2
OK
at+cmss=2
+CMS ERROR: ME failure (=errore Mobile Equipment, ovvero del cellulare)
NOTA: su una SIM Vodafone (invece che USIM 3), con cellulare sbloccato, i comandi +CMGL e +CMGR sembrano (quasi) funzionare bene!
Leggere il contenuto della clibpoard DI SISTEMA
import java.awt.Toolkit
import java.awt.datatransfer
tk = java.awt.Toolkit
dt=tk.getDefaultToolkit()
cl=dt.getSystemClipboard()
a= java.lang.Object
cont = cl.getContents(a)
dfs=cont.getTransferDataFlavors()
val=cont.getTransferData(dfs[0])
Elenco font disponibili in Jython/PersonalJava
import java.awt.Toolkit
t = java.awt.Toolkit
t.getDefaultToolkit().getFontList()
Codici di tastiera Motorola a1000 (OPL)
Joy up 63558
Joy down 63559
Joy left 63560
Joy right 63561
Fire 63542
Game A 63580
Game B 63581?
On/Off 63567
Altri tasti: non rilevabili in OPL
Tasti “teorici”:
Prossimo campo: 0xf6dc
Campo precedente: 0xf6dd
Inizio riga: 0xf802
Fine riga: 0xf803
Cursore alto: 0xf809
Cursore basso: 0xf80a
Cursore sinistra: 0xf807
Cursore destra: 0xf808
Date format in Symbian phones
Symbian devices stores time/date information using an integer which represents microseconds elapsed since 1/jan/0000 in Gregorian Calendar.
Example:
‘[] (16’00e0d8c8757752c0)/1000000 = [2005-07-16 16:24:19]
This line is coded in “AddUp” language: AddUp is a freeware calculator which allows doing complex calculations with very large numbers, and doing conversions between number formats.
‘[] means “convert to Gregorian Date the following number
16′ means “following number is represented in base-16″
[2005-07-16 16:24:19] Square brackets include a date in format yyyy-mm-dd hh:mm:ss
So, date ‘ 2005-07-16 16:24:19‘ will be represented by sequence “00e0d8c8757752c0″, i. e. 00 e0 d8 c8 75 77 52 c0 , which is stored in reverse order, i.e. c0 52 77 75 c8 d8 e0 00 .
To convert an hexadecimal sequence to a Gregorian date:
- write the 8 bytes sequence in reverse order; for example:
00E112D7F85CD680 (always begins with 00e1 or 00e0)
- write it into Windows calculator (in hexadecimal mode)
- switch to decimal mode: you’ll obtain number of milliseconds since 1/jan/0001 00:00 :
63352588554000000
- Divide by 1000000 to obtain seconds
63352588554
- Subtract 1 year and 11 days (year 0000 an d day 0 do not exists in Gregorian calendar, and 101 days were “deleted” in Gregorian calendar); to do this, subtract 32486400:
63320102154
- Divide by 86400 to obtain days:
732871,55270833333333333333333333
- Add fix number 1721423.5 (days between start of Julian calendar and start of Gregorian calendar):
2454295,0527083333333333333333333
- Put this number in a Julian->Gregorian converter like this one (be sure to use proper decimal separator, depending on your country: “.” or “,”? )
In this particular case, you’ll get 2007/07/13 13:15:53
RapidQ/VisualBasic source to make the conversions (require this RapidQ source also list at the end of this page):
function microdate(s as string) as string
DefInt y,m,d,intdays,intmin,inthours
DefLng dd,lngdays
DefDbl dbldays,decimals,hours,minutes
s = mid$(s,5,6)
intdays = val(convbase$(s,16,10))
dbldays= (intdays* 16^6 / 1000000) /86400 + 729749.93962022 – 12 ‘ Gregorian correction (not included in TimeSerial???)
lngdays = int(dbldays)
‘ print “stringa ricevuta: “,s,” – giorni equivalenti: “,intdays,”-”,dbldays,”-”,lngdays
dd = datefromserial(lngdays,y,m,d)
y=y-1 ‘ TimeSerial starts counting from AD 1, Symbian starts from AD 0.
decimals = dbldays-lngdays
hours = decimals*86400/3600
minutes = int((hours – int(hours))*60)
inthours = int(hours)
intmin= int(minutes)
microdate = lead0$(y) & “/” & lead0$(m) & “/” & lead0$(d) & ” – ” & lead0$(inthours) & “:” & lead0$(intmin) & “; “
end function
The TimeFromSerial source:
FUNCTION DateFromSerial(dateSerial AS LONG, ByRef Year AS LONG, ByRef Month AS LONG, ByRef Day AS LONG) AS LONG
‘ declare
DEFLNG daysCount, dayOfMonth, dayTotal ‘ initialize
Year = 1
Month = 1
daysCount = dateSerial – 1 ‘ pre-process
IF daysCount > 146096 THEN
Year = Year + (daysCount \ 146097) * 400
daysCount = (daysCount MOD 146097)
END IF
IF daysCount > 36523 THEN
dayTotal = (daysCount \ 36524)
IF dayTotal < 4 THEN
Year = Year + (dayTotal * 100)
daysCount = (daysCount MOD 36524)
ELSE
Year = Year + 300
daysCount = 36524
END IF
END IF
IF daysCount > 1460 THEN
Year = Year + (daysCount \ 1461) * 4
daysCount = (daysCount MOD 1461)
END IF
IF daysCount > 364 THEN
dayTotal = (daysCount \ 365)
IF dayTotal < 4 THEN
Year = Year + dayTotal
daysCount = (daysCount MOD 365)
ELSE
Year = Year + 3
daysCount = 365
END IF
END IF ‘ process
Day = daysCount + 1
dayOfMonth = &H3DFF7F9F
IF Day > 58 AND isLeapYear(Year) THEN dayOfMonth = (dayOfMonth + 32)
DO
dayTotal = (dayOfMonth AND 31)
IF dayTotal >= Day THEN EXIT DO
Day = Day – dayTotal
Month = Month + 1
dayOfMonth = (dayOfMonth \ 32)
IF dayOfMonth = 0 THEN dayOfMonth = &H3FEFFBFF
LOOP ‘ exit
Result = (dateSerial MOD 7)
END FUNCTION
Compilare Java, Personal Java e Jython con PSPad
Configurazione per compilare classi Java e Personal Java tramite text editor PSPad:
Compilatore:
C:\Programmi\internet\Java\j2sdk1.4.2_10\bin\javac
Parametri (tutto su un unica riga):
-target 1.1
-classpath c:\Symbian\UIQ_70\epoc32\Java\ext\javaphone.jar;
C:\Symbian\6.0\NokiaJava\erj\utilities\Awt\cawt.jar;
C:\Symbian\6.0\NokiaJava\erj\lib\classes.zip;
D:\programmi\programmazione\jdk1.1.8\lib\classes.zip;
d:\programmi\programmazione\jython\jython.jar %File%
Spiegazione:
-target 1.1 = compila per PersonalJava (basato su JDK 1.1.8); non serve se si usa il JDK 1.1.8 (che non supporta opzione -target)
c:\Symbian\UIQ_70\epoc32\Java\ext\javaphone.jar = per programmi che fanno uso delle Javaphone API
Questi non so perche’ siano qui…. Deriveranno da una vecchia installazione dell’sdk per nokia:
C:\Symbian\6.0\NokiaJava\erj\utilities\Awt\cawt.jar;
C:\Symbian\6.0\NokiaJava\erj\lib\classes.zip
Le librerie specifiche di PersonalJava
D:\programmi\programmazione\jdk1.1.8\lib\classes.zip
Librerie necessarie per compilare i file .java prodotti dal compilatore Jythonc:
d:\programmi\programmazione\jython\jython.jar
L’output di Jythonc si compila, ma poi non si riesce ad eseguire la classe risultante…
La variabile di ambiente CLASSPATH contiene:
D:\programmi\programmazione\jdk1.1.8
Accedere alla porta COM dell’a1000 con le Javaphone API
http://www2.mokabyte.it/cms/article.run?articleId=IMR-4TE-FU8-AKB_7f000001_30480431_06a21703
http://www.mokabyte.it/2000/01/jca.htm
import javax.comm.CommPortIdentifier
cpi = javax.comm.CommPortIdentifier
portid = cpi.getPortIdentifier(“COM1″)
port = portid.open(“MiaApplicazione”,5000) # Stringa arbitraria che dice al Sistema quale applicazione sta richiedendo l’uso della porta; massimo tempo di attesa per ottenere il possesso della porta.
port.setSerialPortParams(115200,port.DATABITS_8,port.STOPBITS_1,port.PARITY_NONE) # parametri consentiti: da verificare
# parametri per GPS (forse…):
port.setSerialPortParams(4800, SerialPort.DATABITS_8,SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
formato stringa NMEA (GPS):
$GPGGA,164922.982,3859.4108,N,00856.1785,E,1,04,3.4,127.9,M
$GPGGA,xxxx, lat, N, long, E, 1, NumSats, 3.4, altitudine ,M
Lettura dati:
inputbuf = port.getInputStream()
byte= inputbuf.read()
1 comment