BlitzBasic recieving TCP sent from CCV…? 
Posted: 23 June 2009 09:17 PM   [ Ignore ]
Avatar
RankRank
Joined  2008-11-28
Total Posts:  122
Member

I like to program in BlitzBasic, and I was wondering - How to receive the TCP messages sent from CCV. Blitz has integrated TCP functions and they are readily available for me to use. So, with that being said, I set to work and came up with a code like so:

AppTitle "TUIO in Blitz3D test"
Graphics3D 640,480,0,2


tuio
=OpenTCPStream("localhost",3000)
;
tuio=CreateTCPServer(3000)
If 
tuio<>0 Then 
Print "Server started successfully."
Else
Print 
"Server failed to start."
End
End 
If

 
WriteLine tuio,"GET localhost"
 
WriteLine tuioChr$(10)
 If 
Eof(tuio) Print "Failed.":WaitKey:End 
 
Print "Request sent! Waiting for reply..." 

 
While Not Eof(tuio
  Print 
ReadInt(tuio)
 
Wend
 
If Eof(tuio)=1 Then Print "Success!" Else Print "Error!" 

WaitKey 

End

The only problem is that when I run it, I get a stream with a BUNCH or irrelevant numbers.. They appear to be random and not based on CCV’s output. I have CCV set to send to flash (port 3000) on localhost (127.0.0.1) Anyone else managed to program in BlitzBasic and get TCP streams from CCV? Any help?

Profile
 
 
Posted: 24 June 2009 01:42 AM   [ Ignore ]   [ # 1 ]
Avatar
RankRankRank
Joined  2008-06-16
Total Posts:  330
Sr. Member

The TCP/XML format sent by CCV is just a workaround for talking to Flash, which has quite some overhead compared to UDP.
I’d recommend to use the native binary TUIO UDP packet format, since BlitzBasic apparently can receive UDP packets as well.
But you’d need to implement a OSC decoder first, if there isn’t any available for BlitzBasic, the format is documented at opensoundcontrol.org

 Signature 

TUIO community site: http://www.tuio.org
reacTIVision framework: http://reactivision.sf.net
TUIO & reacTIVision CVS: http://sf.net/projects/reactivision
reacTIVision forum: http://sf.net/apps/phpbb/reactivision

Profile
 
 
Posted: 24 June 2009 03:13 PM   [ Ignore ]   [ # 2 ]
Avatar
RankRank
Joined  2008-11-28
Total Posts:  122
Member

Thanks alot martin! That’s just the information that I’ve been looking for! Maybe soon you’ll see a blitzbasic franework come out for multitouch software! :D

Profile
 
 
Posted: 23 July 2009 11:03 AM   [ Ignore ]   [ # 3 ]
Avatar
RankRankRank
Joined  2008-06-16
Total Posts:  330
Sr. Member

Hello, any news regarding your TUIO implementation for BlitzBasic?

 Signature 

TUIO community site: http://www.tuio.org
reacTIVision framework: http://reactivision.sf.net
TUIO & reacTIVision CVS: http://sf.net/projects/reactivision
reacTIVision forum: http://sf.net/apps/phpbb/reactivision

Profile
 
 
Posted: 23 July 2009 12:06 PM   [ Ignore ]   [ # 4 ]
Avatar
RankRank
Joined  2008-11-28
Total Posts:  122
Member

no, unfortunately I had to reformat my computer, and I got sidetracked. But, I couldn’t figure out how to decode OSC packets… They look complicated!

Profile
 
 
Posted: 23 July 2009 12:15 PM   [ Ignore ]   [ # 5 ]
Avatar
RankRankRank
Joined  2008-06-16
Total Posts:  330
Sr. Member

oh, what a pity, I hope you had backups of your work ...
regarding the decoding of TUIO/OSC packets, this should be very straightforward with a little experience.

here is a quick recipe:
* retrieve UDP packets from UDP port 3333
* get the binary data array from the UDP packet
* check for OSC bundles and segment the data array into OSC messages
* decode the OSC messages, checking the type header in order to know what data types are encoded within each message
* check for the TUIO name space, identifying alive, set and fseq messages
* decode the relevant TUIO messages
* decode the add, remove and update events from the TUIO state messages

you will find detailed information about the OSC encoding here:
http://opensoundcontrol.org/spec-1_0
http://opensoundcontrol.org/spec-1_0-examples

the TUIO message format is documented here:
http://www.tuio.org/?specification

 Signature 

TUIO community site: http://www.tuio.org
reacTIVision framework: http://reactivision.sf.net
TUIO & reacTIVision CVS: http://sf.net/projects/reactivision
reacTIVision forum: http://sf.net/apps/phpbb/reactivision

Profile
 
 
Posted: 23 July 2009 09:57 PM   [ Ignore ]   [ # 6 ]
Avatar
RankRank
Joined  2008-11-28
Total Posts:  122
Member

Thank you very much for the links! They will be very helpful!
Fortunately, I got everything off of my C:/ Drive before reformatting. Else, it wouldn’t have been too hard to make; I have a good memory of code that I write. xD
Hopefully, this can go somewhere. I want to make a 3D modeling program which fully features the benefits of multitouch software (CCV).

...Either that, or I code in C!

Profile
 
 
Posted: 16 August 2009 10:43 PM   [ Ignore ]   [ # 7 ]
Avatar
RankRank
Joined  2008-11-28
Total Posts:  122
Member

well I took some time off to build some more of my table but I took some time tonight and picked it back up to see what I could accomplish. I found a simple little string parsing function which looks for a string inside a string. In other words, I got it to recognize how many touches are on the screen. I’m still a bit lost when it comes to OSC though although I think I’m learning; it sounds no different than a binary type of file so maybe I can work some magic and try to get this thing to recognize points next like X and Y coordinates. Who knows? :D

Profile
 
 
Posted: 25 August 2009 01:06 PM   [ Ignore ]   [ # 8 ]
Avatar
RankRank
Joined  2008-11-28
Total Posts:  122
Member

Back again. I tried my hand at really decoding the OSC messages… I think I’m getting closer but still the ouput doesn’t make too much sense… I get a float value of 1.75242134e+0003… I have no idea. Anyway, I thought I’d post what I have so far and a compiled version for anyone who might be able to help. The EXE outputs strings of
-#BUNDLE
-TUIO OSC MESSAGE
-SESSIONID X Y
-TUIO OSC MESSAGE
-SESSIONID X Y
-TUIO OSC MESSAGE
-SESSIONID X Y
-etc....

it will give you directions in the exe.. Thanks for looking!

Graphics 1250,480,0,2
AppTitle 
"Tuio UDP in BlitzBasic Test"

Global recu$
Global 
rline$
Global 
UDP_Server
Global chng
Global touches#
Global st$,rFloat#

Type template
 Field s
#
 
Field x#
 
Field y#
End Type

For x=1 To 200
 touch
.template=New template
 touch\s
#=0
 
touch\x#=0
 
touch\y#=0
Next




SetBuffer BackBuffer
()
file=WriteFile("test.txt")
startTuioUDPServer
()

While 
Not KeyDown(1)
 If 
Not KeyDown(57)
  Print 
recu$
  
recieveTuioUDP()
  
decryptTuioUDP()
 
End If 
 If 
KeyDown(31
  
WriteLine file,rline$
 
End If
Wend

endTuioUDPServer
()
CloseFile(file)

End




Function decryptTuioUDP()
    
touches=0
    x
%=0
    
For touch.template Each template
        result
$ = parse$(rline$,x,"/tuio/")
        If 
result$ <> "" Then 
          
Print result$
            
occurence$=Mid$(result$,5,6)
            If 
occurence="/2Dcur" Then 
             
;Print occurence$
             
set$=Mid$(result$,24,3)
             If 
set$= "set" Then
                stringToFloat
(Mid$(result$,32,4))
                
touch\s#=Abs(rFloat#) ;sessionId
                
stringToFloat(Mid$(result$,36,4))
                
touch\x#=(Abs(rFloat#)/1280) ;"x = sensor_x / sensor_width"
                
stringToFloat(Mid$(result$,40,4)) ;size of a float=4bytes... not for sure if 4 chars from the read string is the same thing...
                
touch\y#=(Abs(rFloat#)/800) ;"y = sensor_y / sensor_height"
                
Oval touch\x,touch\y,10,10,1    ;make an oval where the touch is not working as of now for some reason.
                Print 
touch\s# + " " + touch\x# + " " + touch\y# ;output the found values
             
End If
            
End If
        
End If
        
x=x+1
    Next
    
    
    
    
End 
Function


Function 
recieveTuioUDP()
    
IP_Client RecvUDPMsg(UDP_Server)
    If 
IP_Client Then 
        
;Print "No UDP message being broadcasted..."
    
;Else 
        
rline$ = ReadLine$(UDP_Server)
        ;Print 
rline$
    
End If 
End Function


Function 
endTuioUDPServer() : CloseUDPStream(UDP_Server) : End Function 

Function 
startTuioUDPServer()
 
UDP_Server CreateUDPStream(3333) ; Port 3333 for UDP OSC tuio messages...
 If 
UDP_Server <>0 Then             sadlythe messages are encrypted so we have to decrypt them
     
Print "Server Start."
    
Print "Press 'ESC' to exit program"
    
Print "Press 'Space' to pause program."
    
Print "Press 'S' to generate a log file of the incoming 'UDP' messages as 'test.txt'"
    
Print "--------------------------------------------------------------------------------"
    
Print " "
    
Print " "
    
Print "Press any key to continue..."
    
WaitKey()
 Else
    Print 
"Can't start Server"
    
End
 End 
If
 
Delay 1000
End 
Function



;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;+ 
BORROWED FUNCTIONS FROM BLITZBASIC ARCHIVES (http://www.blitzbasic.com/codearcs/codearcs.php) +
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Function 
bin2int(this$)
    
thisint 0
    blen 
Len(this$)
    For 
1 To blen
        ibit 
Int(Mid$(this$,a,1))
        If 
ibit thisint thisint + (ibit * (2^(blen a)))
    
Next
    
Return thisint
End 
Function
Function 
floatToString(value#)
    
floatBank=CreateBank(4)
    
PokeFloat floatBank,0,value
    st
$=Chr$(PeekByte(floatBank,0)) + Chr$(PeekByte(floatBank,1)) + Chr$(PeekByte(floatBank,2)) + Chr$(PeekByte(floatBank,3))
    
FreeBank floatBank
End 
Function
Function 
stringToFloat(st$)
    
floatBank=CreateBank(4)
    
PokeByte floatBank,0,Asc(Mid(st,1))
    
PokeByte floatBank,1,Asc(Mid(st,2))
    
PokeByte floatBank,2,Asc(Mid(st,3))
    
PokeByte floatBank,3,Asc(Mid(st,4))
    
rFloat#=PeekFloat(floatBank,0)
    
FreeBank floatBank
End 
Function
Function 
intToString(value)
    
intBank=CreateBank(4)
    
PokeInt intBank,0,value
    st
$=Chr$(PeekByte(intBank,0)) + Chr$(PeekByte(intBank,1)) + Chr$(PeekByte(intBank,2)) + Chr$(PeekByte(intBank,3))
    
FreeBank intBank    
End 
Function
Function 
stringToInt(st$)
    
intBank=CreateBank(4)
    
PokeByte intBank,0,Asc(Mid(st,1))
    
PokeByte intBank,1,Asc(Mid(st,2))
    
PokeByte intBank,2,Asc(Mid(st,3))
    
PokeByte intBank,3,Asc(Mid(st,4))
    
value=PeekInt(intBank,0)
    
FreeBank intBank
    
Return value
End 
Function


Function 
parse$(string2Chk$, ndelimiter$=" ")
    ;
initialize local variables
    Local count
% = 0
    Local findDelimiter
% = 0
    Local position
% = 1
    Local current
$ = ""
    
;'n' must be greater than zero
    
;otherwise exit function and return null string
    
If 0 Then
        
;strip leading and trailing spaces
        string2Chk
$  = Trim(string2Chk$)
        ;
find the word(s)
        
Repeat
            
;first check if the delimiter occurs in string2Chk$
            
findDelimiter% = Instr(string2Chk$,delimiter$,position)
            If 
findDelimiter <> 0 Then
                
;extract current word in string2Chk$
                
current$ = Mid$(string2Chk$,position,findDelimiter-position)
                ;
word extractedincrement counter
                count 
count 1
                
;update the start position of the next pass
                position 
findDelimiter 1
                
;if counter is same as n then exit loop
                
If count n Then findDelimiter 0
            End 
If
        
Until findDelimiter 0
        
;Special Case: only one word and no delimiter(s) or last word in string2Chk$
        If (
count n) And (position <= Len(string2Chk$)) Then
            current
$ = Mid$(string2Chk$,positionLen(string2Chk$) - position+1)
            
count count 1
            
;looking for word that is beyond length of string2Chk$
            If 
count n Then current$ = ""
        
End If
    
End If
    Return 
current$
End Function

File Attachments
BBTuio.zip  (File Size: 605KB - Downloads: 315)
Profile
 
 
Posted: 22 October 2009 11:47 AM   [ Ignore ]   [ # 9 ]
Rank
Joined  2009-10-15
Total Posts:  17
New Member

Hi there,
it’s good to see some familiar code here…
Any news on that client?

miLORD

EDIT:
http://nuigroup.com/forums/viewthread/7448/
My version. To answer your question above: The Int32 and Float32 bytes were in the wrong order, so you’ve got to turn them around.

Profile