Buffer flush

Questions, comments and general discussion about Ribsu
Locked
siberian
Posts: 3
Joined: Sun Aug 03, 2008 12:06 am
Contact:

Buffer flush

Post by siberian » Wed Apr 01, 2009 10:10 pm

I've been trying unsuccessfully to run ribsu as a stdout app. What happens is that its not flushing its buffer after each command so I either have to fill the buffer up or quit the app to get the result. This happens if I pipe at the command line, write to a named pipe or load it in java using exec.

I've tried to compile the source but my xcode skills are lacking so I get strange errors.

Xyster, any chance of getting a change so that ribsu flushes the buffer on each input received? This would let me continue building my automation app.

Tx!
John-

xyster
Site Admin
Posts: 605
Joined: Thu May 19, 2005 10:15 pm
Contact:

Re: Buffer flush

Post by xyster » Thu Apr 02, 2009 7:38 am

Hello John,

What kind of errors is xcode giving you? It's a fairly simple project.
I did take a quick look at the code and I believe you can fix this in ribsu_cli/main.c at line 128 right after:
printf("%s\n", hex->buf);

Add:

fflush(stdout);

Guest

Re: Buffer flush

Post by Guest » Thu Apr 02, 2009 9:29 am

Thanks for the response, I think your right thats exactly what to do.

When I try to compile via xcode it tells me it can't find libribsu but that should be a target of the compile, not a requirement, so I'm a tad confused.

Any tips are appreciated but I understand you don't want to be XCode Newbie tech support ;). If I can get it to build though I think I'll be able to iterate any changes I need and get them back to you for commit.

My goal is the AppleTV project where you plug a usbuirt into appletv and are in business.

John-

xyster
Site Admin
Posts: 605
Joined: Thu May 19, 2005 10:15 pm
Contact:

Re: Buffer flush

Post by xyster » Thu Apr 02, 2009 9:56 am

ribsu is split into two:
1. ribsu the library
2. ribsu_cli which gives you the CLI interface we are trying to tweak.

Make sure you compile first the ribsu project. This should generate the library.
Once you've generated the library, you should be able to compile ribsu_cli.
To verify the library is visible to the ribsu_cli project, ensure that libribsu appears in black (not in red) the Xcode project file list. If it still shows up as red then I goofed in creating the Xcode project. To fix this, find the generated libribsu in the ribsu/build directory and drag it on to the Xcode ribsu_cli project file list.

Guest

Re: Buffer flush

Post by Guest » Thu Apr 02, 2009 11:04 am

You are right, I mis-stated my error sorry for the false lead. I can't get the library to compile which causes CLI to fail.

John-
--------------------
Building target “ribsu” of project “ribsu” with configuration “Debug” — (18 errors, 2 warnings)
cd /Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu
/Developer/usr/bin/gcc-4.0 -x c -arch i386 -fmessage-length=0 -pipe -Wno-trigraphs -fpascal-strings -fasm-blocks -O0 -Wreturn-type -Wunused-variable -isysroot /Developer/SDKs/MacOSX10.4u.sdk -mfix-and-continue -mmacosx-version-min=10.4 -gdwarf-2 -I/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/build/ribsu.build/Debug/ribsu.build/ribsu.hmap -F/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/build/Debug -I/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/build/Debug/include -I/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/build/ribsu.build/Debug/ribsu.build/DerivedSources -include /var/folders/g5/g5Ll0UzmEWi3GfZAQqKF9E+++TI/-Caches-/com.apple.Xcode.501/SharedPrecompiledHeaders/ribsu_Prefix-bmyxtuxvbrwpkufxgrinsgtllzmu/ribsu_Prefix.pch -c /Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c -o /Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/build/ribsu.build/Debug/ribsu.build/Objects-normal/i386/usb.o
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c:80: error: syntax error before 'buffer'
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c:80: warning: no semicolon at end of struct or union
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c:82: error: syntax error before 'buffer'
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c:84: error: syntax error before '}' token
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c:84: warning: data definition has no type or storage class
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c:91: error: syntax error before '*' token
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c:94: error: syntax error before '*' token
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c: In function 'usb_add_source':
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c:109: error: 'ctx' undeclared (first use in this function)
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c:109: error: (Each undeclared identifier is reported only once
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c:109: error: for each function it appears in.)
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c: At top level:
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c:214: error: syntax error before 'buffer'
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c: In function 'usb_set_callback':
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c:216: error: 'ctx' undeclared (first use in this function)
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c: At top level:
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c:229: error: syntax error before 'buffer'
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c: In function 'usb_write':
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c:231: error: 'ctx' undeclared (first use in this function)
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c:235: error: 'ctx0' undeclared (first use in this function)
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c:239: error: 'buf' undeclared (first use in this function)
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c: In function 'usb_shutdown':
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c:263: error: 'ctx' undeclared (first use in this function)
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c: At top level:
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c:529: error: syntax error before '*' token
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c: In function 'initUIRT':
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c:551: error: 'ctx' undeclared (first use in this function)
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c: At top level:
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c:572: error: syntax error before '*' token
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c: In function 'async_read':
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c:576: error: 'ctx' undeclared (first use in this function)
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c: In function 'usb_read_callback':
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c:589: error: 'ctx' undeclared (first use in this function)
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c:80: error: syntax error before 'buffer'
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c:80: warning: no semicolon at end of struct or union
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c:82: error: syntax error before 'buffer'
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c:84: error: syntax error before '}' token
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c:84: warning: data definition has no type or storage class
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c:91: error: syntax error before '*' token
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c:94: error: syntax error before '*' token
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c:109: error: 'ctx' undeclared (first use in this function)
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c: At top level:
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c:214: error: syntax error before 'buffer'
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c:216: error: 'ctx' undeclared (first use in this function)
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c: At top level:
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c:229: error: syntax error before 'buffer'
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c:231: error: 'ctx' undeclared (first use in this function)
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c:235: error: 'ctx0' undeclared (first use in this function)
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c:239: error: 'buf' undeclared (first use in this function)
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c:263: error: 'ctx' undeclared (first use in this function)
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c: At top level:
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c:529: error: syntax error before '*' token
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c:551: error: 'ctx' undeclared (first use in this function)
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c: At top level:
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c:572: error: syntax error before '*' token
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c:576: error: 'ctx' undeclared (first use in this function)
/Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c:589: error: 'ctx' undeclared (first use in this function)
Build failed (18 errors, 2 warnings)

Guest

Re: Buffer flush

Post by Guest » Thu Apr 02, 2009 11:27 am

Forgot to mention that i am working with the latest from svn with no changes.

xyster
Site Admin
Posts: 605
Joined: Thu May 19, 2005 10:15 pm
Contact:

Re: Buffer flush

Post by xyster » Sat Apr 04, 2009 7:35 am

Try adding:

#include "ribsu-util.h"

somewhere at the top of usb.c (line 18, for instance)

Guest

Re: Buffer flush

Post by Guest » Sat Apr 04, 2009 12:17 pm

Perfect, that did it. I added the header and then had to copy libribsu over to the cli project and it seems to be flushing properly, at least when I pipe it to more.

I'll hook it up to my java app this evening, this is very exciting!

Thanks Xyster.
John-

xyster
Site Admin
Posts: 605
Joined: Thu May 19, 2005 10:15 pm
Contact:

Re: Buffer flush

Post by xyster » Sat Apr 04, 2009 1:42 pm

Good news. Keep us posted on your project. It sounds interesting.

Guest

Re: Buffer flush

Post by Guest » Sat Apr 04, 2009 9:01 pm

Some progress on my AppleTV. I compiled for 10.4 and it seems to run fine but its not finding the USB-UIRT.

bash-2.05b# ./ribsu104
ERR: usb: /Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c(289): Unable to find an interface
ERR: usb: /Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/usb.c(175): Failed to find interface
ERR: ribsu: /Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu/ribsu.c(90): Failed to find TTY device.
ERR: main: /Users/jarmstrong/Desktop/ribsudev/ribsu-read-only/ribsu_cli/main.c(101): Failed to initialize ribsu

system_profiler finds it:

USB-UIRT:

Version: 4.00
Bus Power (mA): 500
Speed: Up to 12 Mb/sec
Manufacturer: FTDI
Product ID: 0xf850
Vendor ID: 0x0403

The vendor ID matches o.vid in ribsu.c so it *should* find it I think.

Any ideas on what's misfiring?

BTW- Flush is working great, tx for the help!

John-

xyster
Site Admin
Posts: 605
Joined: Thu May 19, 2005 10:15 pm
Contact:

Re: Buffer flush

Post by xyster » Sat Apr 04, 2009 9:39 pm

I'm on thin ice here. I've never played with this on Apple TV and wrote this a long time ago so I don't remember al the details. This seems like an Apple TV issue. You may want to play with the

usbConfig and usbIntNum settings in usb.c:151-152

I don't remember what they do so this could be unrelated.

Locked