Wifi MultiTest .02 - updated WiFi sample code

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

Moderators: cheriff, TyRaNiD

Post Reply
PspPet
Posts: 210
Joined: Wed Mar 30, 2005 2:13 am
Contact:

Wifi MultiTest .02 - updated WiFi sample code

Post by PspPet »

Wifi MultiTest .02
http://aibohack.com/psp/wifitest.htm
http://aibohack.com/psp/wifitest.htm#DEV

I've updated my WiFi test program. The WiFi multi-test program serves several purposes - basic WiFi access, how to connect to other Sony devices; a generally useful PSP program and sample source code.

I've split this into two topics, for people who only want to run the program, and for developers who want to write code based on the sceNetINet sockets-like layer.

This thread is for developers using the source code.
For discussion of the binary program (as a user) including WiFi connect woes, please post on this thread: http://forums.ps2dev.org/viewtopic.php?t=2542

-----
Yes, the DHCP limitation is still there (hard coded IP addresses still required - no DHCP)
The picker will only list non-DHCP connections (so the user can't pick an unsupported configuration). If you have none it will complain. If you have only one, it will automatically pick it. If you have two or more (up to 5) it will let you pick the one you want to use.

Now uses the PSPSDK (version 522 or later required). The initial release of the PSPSDK will not work.

FWIW: Historical topics (some related to WiFi, others related to library loading and patching) can be found on the sceNet/sceHttp thread:
http://forums.ps2dev.org/viewtopic.php?t=2211.
Polymira
Posts: 11
Joined: Tue Jun 21, 2005 3:42 pm

Post by Polymira »

that's neat...

My question is, why is the DHCP limitation there? Do we just need to port over dhclient? Or is it more then that?
rest05
Posts: 12
Joined: Sat Jul 09, 2005 12:09 pm

need some help

Post by rest05 »

this app is nice, but iam having a small problem, how do i config my IP from the "upsend" app you gave us, do we have to config this in the "slideshow", if so how do i change the info on there cause it wont let you type in the cmd, ----> help please, thanx Rest05
PspPet
Posts: 210
Joined: Wed Mar 30, 2005 2:13 am
Contact:

Post by PspPet »

> My question is, why is the DHCP limitation there?
The system already supports DHCP.
This is a limitation in the current sample (reverse engineered from games that do similar but different things). It will take some research and experimentation to figure out what is missing (probably a callback or some other flag bits).

----
> how do i config my IP from the UDPSEND app you gave us, do we have to config this in the "slideshow"
These are command line tools (start a Windows command prompt first)
The udpsend program takes the IP address of the PSP as the first argument on the command line.

The "slideshow.bat" is a simple batch file for illustration purposes. Change the IP address in the batch file (10.0.1.101) to the address of your PSP. Add more interesting JPG files too.
Hippo
Posts: 19
Joined: Sat Jun 25, 2005 10:51 am

Post by Hippo »

Is it just me, or does the photo frame not work properly? I've found that it only works with images < 1400 bytes or so, and even then it distorts the image. It isn't the udpsend program, as I tried writing my own and it still fails to display images properly, if at all. I'm using the pre-built 1.50 version; any ideas?
pcostabel
Posts: 11
Joined: Sat Jun 25, 2005 1:19 am

Post by pcostabel »

I'm having problems making this work using the latest PSPSDK. The precompiled app works fine, but the one I compile gets stuck on the Pick Connection screen.
I have a similar problem with the previous wifi example, except that it works fine if I don't use PSPSDK. I adapted it to use the sdk and everything works up to the sceNetApctlGetState loop, where it never gets the state 4.
Have you tried it with the latest sdk?
Thanks.
holger
Posts: 204
Joined: Thu Aug 18, 2005 10:57 am

Re: Wifi MultiTest .02 - updated WiFi sample code

Post by holger »

PspPet wrote:Wifi MultiTest .02
http://aibohack.com/psp/wifitest.htm
http://aibohack.com/psp/wifitest.htm#DEV

I've updated my WiFi test program. The WiFi multi-test program serves several purposes - basic WiFi access, how to connect to other Sony devices; a generally useful PSP program and sample source code.

I've split this into two topics, for people who only want to run the program, and for developers who want to write code based on the sceNetINet sockets-like layer.
Is anybody working on incorporating the sceNet* stubs into the SDK and wrapping them with newlib/psplibc sockets?
mrbrown
Site Admin
Posts: 1537
Joined: Sat Jan 17, 2004 11:24 am

Re: Wifi MultiTest .02 - updated WiFi sample code

Post by mrbrown »

holger wrote:Is anybody working on incorporating the sceNet* stubs into the SDK and wrapping them with newlib/psplibc sockets?
BSD sockets don't belong in libc. Besides, can't you essentially do

Code: Select all

#define recv sceNetInetRecv
?
holger
Posts: 204
Joined: Thu Aug 18, 2005 10:57 am

Re: Wifi MultiTest .02 - updated WiFi sample code

Post by holger »

mrbrown wrote:BSD sockets don't belong in libc.
where else do they belong?
holger
Posts: 204
Joined: Thu Aug 18, 2005 10:57 am

Re: Wifi MultiTest .02 - updated WiFi sample code

Post by holger »

mrbrown wrote:BSD sockets don't belong in libc. Besides, can't you essentially do

Code: Select all

#define recv sceNetInetRecv
?
I believe this should properly done by the <machine/socketcall.h> file, included by newlib-1.13.0/newlib/libc/sys/linux/socket.c, don't you think?
mrbrown
Site Admin
Posts: 1537
Joined: Sat Jan 17, 2004 11:24 am

Post by mrbrown »

Do you mean making them all aliases? If the arguments match up exactly, then yeah, that should work. Beware that SCE could've renamed them because they take the same arguments but have different semantics. Or it could've just been overkill :).

I dunno, shoving them into libc just seems messy to me, but it is relatively painless. I'd say, go for it :).
PspPet
Posts: 210
Joined: Wed Mar 30, 2005 2:13 am
Contact:

Post by PspPet »

Old question:
> Is it just me, or does the photo frame not work properly? I've found that it only works with images < 1400 bytes or so, and even then it distorts the image
Try the sample images (one sample is 28KB) - http://www.aibohack.com/psp/wifi_photo_samples.zip
There is a minor bug in the JPEG->RGB->Screen code. It doesn't handle 32 bit alignment properly. If the original image X dimension is a multiple of 4 it should work (no distortion). Full screen width is recommended for other reasons.
=======
> I'm having problems making this work using the latest PSPSDK.
I haven't built it recently, but it was working up until now.
If you have a reproducable case (where the binary works and the rebuilt binary does not) please send me an email.
=======
> Is anybody working on incorporating the sceNet* stubs into the SDK
A few people have mentioned it. I haven't bothered since it requires a lot of non-trivial code, not simply stubs (thunk trickery and semi-sample code - most wrapped in the 'nlh.cpp' file)
Also to provide a more complete example including connection picking and timeouts etc -- requires making a fat example with helper libraries (generally against the rules of PSPSDK samples)

BUT there is no reason to wait for PSPSDK support (you can do it now):
If you have an existing program that uses sockets, you can adapt it using this sample and helpers like "#define recv sceNetInetRecv".
It is a close approximation, but not perfect. When it works, it can save a lot of time.
HOWEVER, it is unlikely that the PSP socket implementation (sceNetInet) is perfectly compatible with your existing Berkeley sockets code.
[some things like "setsockopt" for timeouts simply do not work]
w.kosma
Posts: 19
Joined: Fri Oct 28, 2005 11:33 pm

Post by w.kosma »

hello,

would anyone be so kind an translate udpsend code to something understandable
for unix/bsd (or point how to do it)
the orignal is win only, (pasted below)

thanks,
wojciech

Code: Select all

// PSP UDP Send
//  primarily for sending image data
// limited to 30KB

#include <stdio.h>
#include <windows.h>    // Sleep
#pragma comment&#40;lib, "wsock32.lib"&#41;

#define MAX_DATA_SIZE   30000

// keep UDP file size small to avoid problems

/////////////////////////////////////////////////////////////

WSADATA g_wsaData;

byte g_image&#91;MAX_DATA_SIZE&#93;;
int g_cbImage = 0;

/////////////////////////////////////////////////////////////

bool ParseIPAddrString&#40;byte ipAddr&#91;4&#93;, const char* szIPAddr&#41;
&#123;
    int b1, b2, b3, b4;
    if &#40;sscanf&#40;szIPAddr, "%d.%d.%d.%d", &b1, &b2, &b3, &b4&#41; != 4&#41;
        return false;
    ipAddr&#91;0&#93; = b1;
    ipAddr&#91;1&#93; = b2;
    ipAddr&#91;2&#93; = b3;
    ipAddr&#91;3&#93; = b4;
    return true;
&#125;

int main&#40;int argc, char* argv&#91;&#93;&#41;
&#123;
    if &#40;argc != 4&#41;
    &#123;
	    printf&#40;"usage&#58; udpsend psp_ip_address port data_file\n"&#41;;
        return -1;
    &#125;
    const char* szIPForward = argv&#91;1&#93;;
    int port = atoi&#40;argv&#91;2&#93;&#41;;
    const char* szDataFile = argv&#91;3&#93;;

	byte ipaddrDest&#91;4&#93;;
    if &#40;!ParseIPAddrString&#40;ipaddrDest, szIPForward&#41;&#41;
    &#123;
        printf&#40;"udpsend&#58; Bad IP address\n"&#41;;
        return -1;
    &#125;


    // load file
    FILE* pf = fopen&#40;szDataFile, "rb"&#41;;
    if &#40;pf == NULL&#41;
    &#123;
        printf&#40;"udpsend&#58; missing data file\n"&#41;;
        return -1;
    &#125;
    fseek&#40;pf, 0, SEEK_END&#41;;
    g_cbImage = ftell&#40;pf&#41;;
    fseek&#40;pf, 0, SEEK_SET&#41;;
    if &#40;g_cbImage <= 0&#41;
    &#123;
        printf&#40;"udpsend&#58; data file too small\n"&#41;;
        fclose&#40;pf&#41;;
        return -1;
    &#125;
    if &#40;g_cbImage > MAX_DATA_SIZE&#41;
    &#123;
        printf&#40;"udpsend&#58; data file too big &#40;limited to %d&#41;\n", MAX_DATA_SIZE&#41;;
        fclose&#40;pf&#41;;
        return -1;
    &#125;
    if &#40;fread&#40;g_image, g_cbImage, 1, pf&#41; != 1&#41;
    &#123;
        printf&#40;"udpsend&#58; data read error\n"&#41;;
        fclose&#40;pf&#41;;
        return -1;
    &#125;
    fclose&#40;pf&#41;;

// WiFi send

    if &#40;WSAStartup&#40;MAKEWORD&#40;1,1&#41;, &g_wsaData&#41; != 0&#41; // windows specific
    &#123;
        printf&#40;"udpsend&#58; winsock init error\n"&#41;;
        return -1;
    &#125;

// general socket stuff
    // send data as on big UDP send to a specific IP address

	SOCKET hSock = socket&#40;AF_INET, SOCK_DGRAM, 0&#41;;
    if &#40;hSock == INVALID_SOCKET&#41; 
    &#123;
        printf&#40;"udpsend&#58; socket create error\n"&#41;;
        goto cleanup;
    &#125;

	SOCKADDR_IN sinDest;
	sinDest.sin_family = AF_INET;
	sinDest.sin_port = htons&#40;port&#41;;
    sinDest.sin_addr.S_un.S_un_b.s_b1 = ipaddrDest&#91;0&#93;;
    sinDest.sin_addr.S_un.S_un_b.s_b2 = ipaddrDest&#91;1&#93;;
    sinDest.sin_addr.S_un.S_un_b.s_b3 = ipaddrDest&#91;2&#93;;
    sinDest.sin_addr.S_un.S_un_b.s_b4 = ipaddrDest&#91;3&#93;;
	
	if &#40;sendto&#40;hSock, &#40;char*&#41;g_image, g_cbImage, 0,
	            &#40;struct sockaddr*&#41;&sinDest, sizeof&#40;sinDest&#41;&#41; != g_cbImage&#41;
    &#123;
        printf&#40;"udpsend&#58; sendto error\n"&#41;;
    &#125;

    // that's all folks...

cleanup&#58;
	WSACleanup&#40;&#41;; // windows specific

    return 0;
&#125;


nab
Posts: 1
Joined: Mon Mar 13, 2006 1:32 pm
Contact:

udpsend translated to java

Post by nab »

Here is a very simple version of PspPet's udpsend code writen in java.

Code: Select all

/*
 * udpsend.java
 *
 * Created on April 16, 2006, 6&#58;12 PM
 */

import java.io.*;
import java.net.*;
/**
 *
 * @author Nab
 * Sample code to create Datagram was taken from http&#58;//javaalmanac.com.
 */
public class udpsend &#123;
  
  public static void main&#40;String&#91;&#93; args&#41; &#123;
    
    // Create an unbound socket
    Socket sock = new Socket&#40;&#41;;
    
    // Create a socket with a timeout
    try &#123;
      // Replace "192.168.1.104" with the IP address of PSP
      InetAddress addr = InetAddress.getByName&#40;"192.168.1.104"&#41;;
      int port = 100;
      
      // Insert jpg location here
      // Make sure to use '\\' and not '\'
      File pic = new File&#40;"D&#58;\\Documents and Settings\\Nab\\Desktop\\pic.jpg"&#41;;
      long length = pic.length&#40;&#41;;
      
      // Create a buffer for the picture
      byte&#91;&#93; buf = new byte&#91;&#40;int&#41;length&#93;;
      buf = getBytesFromFile&#40;pic&#41;;
      
      /* Create DatagramPacket and DatagramSocket
       * *
       * buf - the packet data.
       * length - the packet length must be less than or equal to buf.length
       * address - the destination address.
       * port - the destination port number.
       * 
       */
      DatagramPacket request = new DatagramPacket&#40;buf, buf.length, addr, port&#41;;
      DatagramSocket socket = new DatagramSocket&#40;&#41;;
      socket.send&#40;request&#41;;
      
    &#125; catch &#40;UnknownHostException e&#41; &#123;
      System.out.print&#40;"Unknown host\n"&#41;;
    &#125; catch &#40;SocketException e&#41; &#123;
    &#125; catch &#40;SocketTimeoutException e&#41; &#123;
      System.out.print&#40;"Timeout\n"&#41;;
    &#125; catch &#40;IOException e&#41; &#123;
      System.out.print&#40;"Error with input\n"&#41;;
    &#125;
  &#125; // Main
  
  /**
   * Returns the contents of the file in a byte array.
   * Function getBytesFromFile&#40;&#41; was taken from http&#58;//javaalmanac.com/egs/java.io/File2ByteArray.html.
   */
  public static byte&#91;&#93; getBytesFromFile&#40;File file&#41; throws IOException &#123;
    InputStream is = new FileInputStream&#40;file&#41;;
    
    // Get the size of the file
    long length = file.length&#40;&#41;;
    
    // You cannot create an array using a long type.
    // It needs to be an int type.
    // Before converting to an int type, check
    // to ensure that file is not larger than Integer.MAX_VALUE.
    if &#40;length > Integer.MAX_VALUE&#41; &#123;
      // File is too large
    &#125;
    
    // Create the byte array to hold the data
    byte&#91;&#93; bytes = new byte&#91;&#40;int&#41;length&#93;;
    
    // Read in the bytes
    int offset = 0;
    int numRead = 0;
    while &#40;offset < bytes.length
             && &#40;numRead=is.read&#40;bytes, offset, bytes.length-offset&#41;&#41; >= 0&#41; &#123;
      offset += numRead;
    &#125;
    
    // Ensure all the bytes have been read in
    if &#40;offset < bytes.length&#41; &#123;
      throw new IOException&#40;"Could not completely read file "+file.getName&#40;&#41;&#41;;
    &#125;
    
    // Close the input stream and return bytes
    is.close&#40;&#41;;
    return bytes;
  &#125; // getBytesFromFile
&#125; // Class
Instructions
1)Install Java Platform from http://java.sun.com/javase/downloads/index.htm.
2)Copy code to text file named udpsend.java and insert the IP address and jpg location in the code.
3)Use an IDE (Integrated Development Environment) like Dr Java to compile and run the code. Or you can do it through the command line.

Note: I have noticed that the first the program is run nothing happens. You may have to run program more then once to get the image to display on the PSP.
Post Reply