Adhoc questiion

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Art
Posts: 642
Joined: Wed Nov 09, 2005 8:01 am

Adhoc questiion

Post by Art »

Hi Guys,
I just started playing with Adhoc between two PSPs,
and got streaming data working in both 1.50 and 3.xx,
but all sample code seems to send data in only one direction from the Server to the Client.

Clearly for a game to work, the Server PSP would need to know what's going on
with the Client PSP as well.

Is there any sample code to show data flow in both directions?
Cheers, Art.
If not actually, then potentially.
Insert_witty_name
Posts: 376
Joined: Wed May 10, 2006 11:31 pm

Post by Insert_witty_name »

That depends on what protocol you're using.

Are you using PDP, PTP or GameMode?
Art
Posts: 642
Joined: Wed Nov 09, 2005 8:01 am

Post by Art »

No idea,
The only samples I have are all similar to this loop

Code: Select all

int user_main(SceSize args, void *argp){

	SetupCallbacks();

	static char buffer[0x8000];
	unsigned int length;
	int err, bD = 0;
	int i, done, mainDone, server=0;
	
	char *data;
	int size = 0;
	
	SceCtrlData pad;
	
	pspDebugScreenInit();
	
	do {
	
		if((adhocInit("") >= 0) && ((server = adhocSelect()) >=0)){
			
			pspDebugScreenPrintf("\n\n## AdHoc INITALISED ##\n\n");
			
			sceKernelDelayThread(1000000);
			
			if(server)
				pspDebugScreenPrintf("Server Assigned\n\n");
			else
				pspDebugScreenPrintf("Client Assigned\n\n");

			if(server){
				sceKernelDelayThread(5000000);
				done = 0;
				do {
					sceCtrlReadBufferPositive(&pad, 1);
					if(pad.Buttons != 0)
						if(pad.Buttons & PSP_CTRL_CROSS)
							done = 1;
					
					if((i % 2) == 0){
						data = ".";
						i = 0;
					} else
						data = "|";
					i++;
					
					if(done == 1)
						data = "x";
					size = sizeof(data);
					
					err = adhocSendRecvAck(&size, 4);
					err = adhocSendRecvAck(&data, 4);  //# send data
					
					pspDebugScreenPrintf("%s", data);
				} while(done==0);
				
			} else {
				done = 0;
				do {
					//sceCtrlReadBufferPositive(&pad, 1);
					//if(pad.Buttons != 0)
					//	if(pad.Buttons & PSP_CTRL_CROSS)
					//		done = 1;
					
					size = 0;
					length = 4;
					err = adhocRecvSendAck(&size, &length);
					
					length = size;
					err = adhocRecvSendAck(&data, &length);
					data = (char *)data;
					
					if(data == "x")
						done = 1;
					
					pspDebugScreenPrintf("%s", data);
				} while(done==0);
				
			}
		
		}
		
		pspDebugScreenPrintf("\n\n");
		
		adhocTerm();
		
		done = 0;
		pspDebugScreenInit();
		pspDebugScreenPrintf("\n\nPress START to Exit, X to Continue\n\n");
		do {
			sceCtrlReadBufferPositive(&pad, 1);
			if(pad.Buttons != 0){
				if(pad.Buttons & PSP_CTRL_START){
					done = 1; mainDone=1;
					sceKernelExitGame();
				}
				if(pad.Buttons & PSP_CTRL_CROSS)
					done = 1; mainDone=0;
			}
		} while(!done);
		
	} while(!mainDone);
	
	//pspDebugScreenPrintf("Press any key to exit..\n");
	//done = 0;
	//do {
	//	sceCtrlReadBufferPositive(&pad, 1);
	//	if(pad.Buttons != 0)
	//		done = 1;
	//} while(!done);
	
	sceKernelExitGame();
}
If there is a more efficient (faster way, I'd love to see a sample).
Maybe the updated sdk has some, but I'll never get to see those by updating. It's only ever worked the once.
If not actually, then potentially.
Insert_witty_name
Posts: 376
Joined: Wed May 10, 2006 11:31 pm

Post by Insert_witty_name »

I think those functions are from PSPPet's original adhoc sample code, which is almost 3 years old.

You would be better to update your SDK, I've added lots of adhoc goodies over the past months.

The code from PSPPet's sample uses PDP (similar to UDP) and it is possible to send in both directions.

If I recall correctly the adhoc adhocSendRecvAck() function sends some data, then waits for a response from the receiver to acknowledge.

You also have the option of PTP, which is peer-to-peer and is perfect for two way transmission between two PSPs.
Art
Posts: 642
Joined: Wed Nov 09, 2005 8:01 am

Post by Art »

The SDK I use is about as old as it gets, but there are some extra libs I've collected.
If I update a lot of my stuff stops working, and I only know that from a precompiled toolchain I've tried on another op system
I can't (in practice) upgrade the normal way if I wanted to (ie. sh /toolchain.sh 6 doesn't do anything).
f I recall correctly the adhoc adhocSendRecvAck() function sends some data, then waits for a response from the receiver to acknowledge.
The adhocSendRecvAck() is being used to both send and receive in this code,
but depending only on whether the PSP is the client or server.
If not actually, then potentially.
pspjoke
Posts: 14
Joined: Mon Jun 23, 2008 10:10 am

Post by pspjoke »

Art wrote:The adhocSendRecvAck() is being used to both send and receive in this code,
but depending only on whether the PSP is the client or server.
nope..

notice to send the function is

Code: Select all

adhocSendRecvAck
and to receive is

Code: Select all

adhocRecvSendAck
im using this same code, just starting on ad-hoc as well.

and i also ported zorbas adhoc sample to the new sdk..
but ... you only need the old one so.. pointless to mention, w/e
take a look at zorbas sample as well, theres much to learn if you look at both.
Art
Posts: 642
Joined: Wed Nov 09, 2005 8:01 am

Post by Art »

I did just notie that today ;) I was seeing the same command.

Now I suppose I need to figure out how to send other types of variables.
If not actually, then potentially.
pspjoke
Posts: 14
Joined: Mon Jun 23, 2008 10:10 am

Post by pspjoke »

Art wrote:I did just notie that today ;) I was seeing the same command.

Now I suppose I need to figure out how to send other types of variables.
lol, i don't think thats to hard.

what im trying to do is find the perfect delay between sending two things.

you can either have lag and no loss sync, or you can have near perfect response but you can bet at some point you will loose sync.
The people here make me feel like shit :/
Way to advanced... (hate being a programming noob.)
phobox
Posts: 127
Joined: Mon Mar 24, 2008 6:22 pm

Post by phobox »

pspjokeand wrote: i also ported zorbas adhoc sample to the new sdk..
please, can you post it?
Ciao! from Italy
pspjoke
Posts: 14
Joined: Mon Jun 23, 2008 10:10 am

Post by pspjoke »

phobox wrote:
pspjokeand wrote: i also ported zorbas adhoc sample to the new sdk..
please, can you post it?
sure http://www.mediafire.com/?2mzxd5mgnnu
The people here make me feel like shit :/
Way to advanced... (hate being a programming noob.)
Post Reply