ps2sdk  1.1
A collection of Open Source libraries used for developing applications on Sony's PlayStation 2® (PS2).
ps2cam_rpc.h File Reference
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  EYETOY_FRAME_HEAD
 
struct  PS2CAM_DEVICE_INFO
 
struct  PS2CAM_DEVICE_CONFIG
 

Macros

#define PS2CAM_RPC_GETIRXVERSION   40
 
#define PS2CAM_RPC_INITIALIZE   41
 
#define PS2CAM_RPC_GETDEVCOUNT   42
 
#define PS2CAM_RPC_OPENDEVICE   43
 
#define PS2CAM_RPC_CLOSEDEVICE   44
 
#define PS2CAM_RPC_GETDEVSTATUS   45
 
#define PS2CAM_RPC_GETDEVINFO   46
 
#define PS2CAM_RPC_SETDEVBANDWIDTH   47
 
#define PS2CAM_RPC_READPACKET   48
 
#define PS2CAM_RPC_SETLEDMODE   49
 
#define PS2CAM_RPC_SETDEVCONFIG   50
 
#define PS2CAM_LED_MODE_OFF   0
 
#define PS2CAM_LED_MODE_ON   1
 
#define CAM_STATUS_NOTCONNECTED   0
 
#define CAM_STATUS_CONNECTED   1
 
#define CAM_STATUS_CONNECTEDREADY   2
 
#define CAM_CONFIG_MASK_DIMENSION   0x00000001
 
#define CAM_CONFIG_MASK_OFFSET   0x00000002
 
#define CAM_CONFIG_MASK_DIVIDER   0x00000004
 
#define CAM_CONFIG_MASK_FRAMERATE   0x00000008
 
#define CAM_ERROR_NONE   (00)
 
#define CAM_ERROR_NOTINIT   -(20)
 
#define CAM_ERROR_INVALIDDEVICE   -(21)
 
#define CAM_ERROR_COMMUNKNOWN   -(22)
 
#define CAM_ERROR_DEVNOTREADY   -(23)
 
#define CAM_ERROR_NODEVICE   -(24)
 
#define CAM_ERROR_BADRANGE   -(25)
 
#define CAM_ERROR_UNKNOWN   -(26)
 
#define CAM_ERROR_MAXHANDLE   -(27)
 
#define CAM_ERROR_BADHANDLE   -(28)
 
#define CAM_ERROR_DISCONNECTED   -(29)
 

Functions

int PS2CamInit (int mode)
 
int PS2CamGetIRXVersion (void)
 
int PS2CamGetDeviceCount (void)
 
int PS2CamOpenDevice (int device_index)
 
int PS2CamCloseDevice (int handle)
 
int PS2CamGetDeviceStatus (int handle)
 
int PS2CamGetDeviceInfo (int handle, PS2CAM_DEVICE_INFO *info)
 
int PS2CamSetDeviceBandwidth (int handle, char bandwidth)
 
int PS2CamReadPacket (int handle)
 
int PS2CamSetLEDMode (int handle, int mode)
 
int PS2CamSetDeviceConfig (int handle, PS2CAM_DEVICE_CONFIG *cfg)
 
int PS2CamExtractFrame (int handle, char *buffer, int bufsize)
 

Detailed Description

PS2Camera EE-IOP RPC CALLS

Definition in file ps2cam_rpc.h.

Macro Definition Documentation

◆ CAM_CONFIG_MASK_DIMENSION

#define CAM_CONFIG_MASK_DIMENSION   0x00000001

Definition at line 50 of file ps2cam_rpc.h.

◆ CAM_CONFIG_MASK_DIVIDER

#define CAM_CONFIG_MASK_DIVIDER   0x00000004

Definition at line 52 of file ps2cam_rpc.h.

◆ CAM_CONFIG_MASK_FRAMERATE

#define CAM_CONFIG_MASK_FRAMERATE   0x00000008

Definition at line 53 of file ps2cam_rpc.h.

◆ CAM_CONFIG_MASK_OFFSET

#define CAM_CONFIG_MASK_OFFSET   0x00000002

Definition at line 51 of file ps2cam_rpc.h.

◆ CAM_ERROR_BADHANDLE

#define CAM_ERROR_BADHANDLE   -(28)

invalid device handle

Definition at line 73 of file ps2cam_rpc.h.

◆ CAM_ERROR_BADRANGE

#define CAM_ERROR_BADRANGE   -(25)

a value was out of range

Definition at line 67 of file ps2cam_rpc.h.

◆ CAM_ERROR_COMMUNKNOWN

#define CAM_ERROR_COMMUNKNOWN   -(22)

unknown command

Definition at line 61 of file ps2cam_rpc.h.

◆ CAM_ERROR_DEVNOTREADY

#define CAM_ERROR_DEVNOTREADY   -(23)

device not ready

Definition at line 63 of file ps2cam_rpc.h.

◆ CAM_ERROR_DISCONNECTED

#define CAM_ERROR_DISCONNECTED   -(29)

device was removed

Definition at line 75 of file ps2cam_rpc.h.

◆ CAM_ERROR_INVALIDDEVICE

#define CAM_ERROR_INVALIDDEVICE   -(21)

Definition at line 59 of file ps2cam_rpc.h.

◆ CAM_ERROR_MAXHANDLE

#define CAM_ERROR_MAXHANDLE   -(27)

out of free device handle(s)

Definition at line 71 of file ps2cam_rpc.h.

◆ CAM_ERROR_NODEVICE

#define CAM_ERROR_NODEVICE   -(24)

no compatible device connected

Definition at line 65 of file ps2cam_rpc.h.

◆ CAM_ERROR_NONE

#define CAM_ERROR_NONE   (00)

ok

Definition at line 57 of file ps2cam_rpc.h.

◆ CAM_ERROR_NOTINIT

#define CAM_ERROR_NOTINIT   -(20)

Definition at line 58 of file ps2cam_rpc.h.

◆ CAM_ERROR_UNKNOWN

#define CAM_ERROR_UNKNOWN   -(26)

unknown error

Definition at line 69 of file ps2cam_rpc.h.

◆ CAM_STATUS_CONNECTED

#define CAM_STATUS_CONNECTED   1

connected but initializing

Definition at line 45 of file ps2cam_rpc.h.

◆ CAM_STATUS_CONNECTEDREADY

#define CAM_STATUS_CONNECTEDREADY   2

connect & ready for commands

Definition at line 47 of file ps2cam_rpc.h.

◆ CAM_STATUS_NOTCONNECTED

#define CAM_STATUS_NOTCONNECTED   0

device not connected

Definition at line 43 of file ps2cam_rpc.h.

◆ PS2CAM_LED_MODE_OFF

#define PS2CAM_LED_MODE_OFF   0

Definition at line 37 of file ps2cam_rpc.h.

◆ PS2CAM_LED_MODE_ON

#define PS2CAM_LED_MODE_ON   1

Definition at line 38 of file ps2cam_rpc.h.

◆ PS2CAM_RPC_CLOSEDEVICE

#define PS2CAM_RPC_CLOSEDEVICE   44

Definition at line 22 of file ps2cam_rpc.h.

◆ PS2CAM_RPC_GETDEVCOUNT

#define PS2CAM_RPC_GETDEVCOUNT   42

PS2CamGetDeviceCount

Definition at line 20 of file ps2cam_rpc.h.

◆ PS2CAM_RPC_GETDEVINFO

#define PS2CAM_RPC_GETDEVINFO   46

PS2CamGetInfo

Definition at line 26 of file ps2cam_rpc.h.

◆ PS2CAM_RPC_GETDEVSTATUS

#define PS2CAM_RPC_GETDEVSTATUS   45

PS2CamGetStatus

Definition at line 24 of file ps2cam_rpc.h.

◆ PS2CAM_RPC_GETIRXVERSION

#define PS2CAM_RPC_GETIRXVERSION   40

get irx version

Definition at line 16 of file ps2cam_rpc.h.

◆ PS2CAM_RPC_INITIALIZE

#define PS2CAM_RPC_INITIALIZE   41

PS2CamInit

Definition at line 18 of file ps2cam_rpc.h.

◆ PS2CAM_RPC_OPENDEVICE

#define PS2CAM_RPC_OPENDEVICE   43

Definition at line 21 of file ps2cam_rpc.h.

◆ PS2CAM_RPC_READPACKET

#define PS2CAM_RPC_READPACKET   48

PS2CamReadPacketCOMMAND

Definition at line 30 of file ps2cam_rpc.h.

◆ PS2CAM_RPC_SETDEVBANDWIDTH

#define PS2CAM_RPC_SETDEVBANDWIDTH   47

PS2CamSetDeviceBandwidth

Definition at line 28 of file ps2cam_rpc.h.

◆ PS2CAM_RPC_SETDEVCONFIG

#define PS2CAM_RPC_SETDEVCONFIG   50

Definition at line 34 of file ps2cam_rpc.h.

◆ PS2CAM_RPC_SETLEDMODE

#define PS2CAM_RPC_SETLEDMODE   49

PS2CamSetLEDMode

Definition at line 32 of file ps2cam_rpc.h.

Function Documentation

◆ PS2CamCloseDevice()

int PS2CamCloseDevice ( int  handle)

Definition at line 134 of file ps2cam_rpc.c.

135 {
136  int *ret;
137 
138  ret = (int *)&data[0];
139 
140  ret[0] = handle;
141 
142  SifCallRpc(&cdata, PS2CAM_RPC_CLOSEDEVICE, 0, (void*)(&data[0]),4,(void*)(&data[0]),4,0,0);
143 
144  return ret[0];
145 }
static SifRpcClientData_t cdata
Definition: ps2cam_rpc.c:26
static char data[1024]
Definition: ps2cam_rpc.c:27
#define PS2CAM_RPC_CLOSEDEVICE
Definition: ps2cam_rpc.h:22
int SifCallRpc(SifRpcClientData_t *client, int rpc_number, int mode, void *send, int ssize, void *receive, int rsize, SifRpcEndFunc_t end_function, void *end_param)

References cdata, data, PS2CAM_RPC_CLOSEDEVICE, and SifCallRpc().

◆ PS2CamExtractFrame()

int PS2CamExtractFrame ( int  handle,
char *  buffer,
int  bufsize 
)

Definition at line 284 of file ps2cam_rpc.c.

285 {
286  static EYETOY_FRAME_HEAD *head;
287  static int capturing;
288  static int pos;
289  static int ret;
290  static int pic_size;
291 
292  pos = 0;
293  capturing = 0;
294 
295 
296 
297  while(1)
298  {
299  ret = PS2CamReadPacket(handle);
300 
301  // printf("packet =%d\n",ret);
302  //if read has a error return it
303  if(ret < 0) return ret;
304 
305  head = (EYETOY_FRAME_HEAD *)&campacket[0];
306 
307  if(head->magic2==0xff && head->magic3==0xff && ret!=0)
308  {
309  if(head->type==0x50 && head->frame==0x00)
310  {
311  // start of frame
312  // printf("SOF(%d)\n",ret);
313  if(capturing == 1)
314  {
315  return 0;
316  }
317 
318  memcpy(&buffer[pos], &campacket[16], ret-16 );
319  pos += (ret-16);
320  capturing = 1;
321 
322  }
323  else if(head->type==0x50 && head->frame==0x01)
324  {
325  // frame head with no data
326  // so do nothing
327 
328  }
329  else if(head->type==0x51 && capturing==1)
330  {
331  //end of frame
332  // printf("EOF(%d)\n",ret);
333  pic_size = (int)(((head->Lo) + ((int)(head->Hi)<<8))<<3);
334 
335 
336  if(pos != pic_size)
337  {
338  return 0;
339  }
340  else
341  {
342  return pic_size;
343  }
344  }
345  else
346  {
347  //if it doesnt fit in those pos then it must be data
348  if(capturing==1)
349  {
350  memcpy(&buffer[pos], &campacket[0], ret );
351  pos += (ret);
352  }
353  }
354  }
355  else
356  {
357  // it must be data
358  if(capturing==1 && ret !=0)
359  {
360  memcpy(&buffer[pos], &campacket[0], ret );
361  pos += (ret);
362  }
363  }
364  }
365 
366 }
struct @29::@30 pos
int PS2CamReadPacket(int handle)
Definition: ps2cam_rpc.c:216
static char campacket[896]
Definition: ps2cam_rpc.c:28
u8 buffer[128]
Definition: rpc_client.c:19
unsigned char magic3
Definition: ps2cam_rpc.h:84
unsigned char Hi
Definition: ps2cam_rpc.h:101
unsigned char type
Definition: ps2cam_rpc.h:86
unsigned char Lo
Definition: ps2cam_rpc.h:99
unsigned char frame
Definition: ps2cam_rpc.h:93
unsigned char magic2
Definition: ps2cam_rpc.h:82

References buffer, campacket, EYETOY_FRAME_HEAD::frame, EYETOY_FRAME_HEAD::Hi, EYETOY_FRAME_HEAD::Lo, EYETOY_FRAME_HEAD::magic2, EYETOY_FRAME_HEAD::magic3, pos, PS2CamReadPacket(), and EYETOY_FRAME_HEAD::type.

Referenced by main().

◆ PS2CamGetDeviceCount()

int PS2CamGetDeviceCount ( void  )

Definition at line 102 of file ps2cam_rpc.c.

103 {
104  int *ret;
105 
106  ret = (int *)&data[0];
107 
108  SifCallRpc(&cdata, PS2CAM_RPC_GETDEVCOUNT, 0, (void*)(&data[0]),4,(void*)(&data[0]),4,0,0);
109  nopdelay();
110 
111  return ret[0];
112 }
static void nopdelay(void)
Definition: kernel.h:141
#define PS2CAM_RPC_GETDEVCOUNT
Definition: ps2cam_rpc.h:20

References cdata, data, nopdelay(), PS2CAM_RPC_GETDEVCOUNT, and SifCallRpc().

Referenced by main().

◆ PS2CamGetDeviceInfo()

int PS2CamGetDeviceInfo ( int  handle,
PS2CAM_DEVICE_INFO info 
)

Definition at line 170 of file ps2cam_rpc.c.

171 {
172  int *ret;
173  PS2CAM_DEVICE_INFO *iop_info;
174 
175  ret = (int *)&data[0];
176  iop_info = (PS2CAM_DEVICE_INFO *)&ret[1];
177 
178  ret[0] = handle;
179 
180  memcpy(iop_info, info, info->ssize);
181 
182  SifCallRpc(&cdata, PS2CAM_RPC_GETDEVINFO, 0, (void*)(&data[0]),info->ssize+4,(void*)(&data[0]),info->ssize+4,0,0);
183  nopdelay();
184 
185  memcpy(info, iop_info, iop_info->ssize);
186 
187  return ret[0];
188 }
jpgData * info
Definition: camera-test.c:14
#define PS2CAM_RPC_GETDEVINFO
Definition: ps2cam_rpc.h:26
unsigned int ssize
Definition: ps2cam_rpc.h:107

References cdata, data, info, nopdelay(), PS2CAM_RPC_GETDEVINFO, SifCallRpc(), and PS2CAM_DEVICE_INFO::ssize.

Referenced by main().

◆ PS2CamGetDeviceStatus()

int PS2CamGetDeviceStatus ( int  handle)

Definition at line 151 of file ps2cam_rpc.c.

152 {
153  int *ret;
154 
155 
156  ret = (int *)&data[0];
157 
158  ret[0] = handle;
159 
160 
161  SifCallRpc(&cdata, PS2CAM_RPC_GETDEVSTATUS, 0, (void*)(&data[0]),4,(void*)(&data[0]),4,0,0);
162  nopdelay();
163 
164  return ret[0];
165 }
#define PS2CAM_RPC_GETDEVSTATUS
Definition: ps2cam_rpc.h:24

References cdata, data, nopdelay(), PS2CAM_RPC_GETDEVSTATUS, and SifCallRpc().

Referenced by main().

◆ PS2CamGetIRXVersion()

int PS2CamGetIRXVersion ( void  )

Definition at line 86 of file ps2cam_rpc.c.

87 {
88  int *ret;
89 
90  ret = (int *)&data[0];
91 
92  SifCallRpc(&cdata, PS2CAM_RPC_GETIRXVERSION, 0, (void*)(&data[0]),4,(void*)(&data[0]),4,0,0);
93  nopdelay();
94 
95  return ret[0];
96 }
#define PS2CAM_RPC_GETIRXVERSION
Definition: ps2cam_rpc.h:16

References cdata, data, nopdelay(), PS2CAM_RPC_GETIRXVERSION, and SifCallRpc().

◆ PS2CamInit()

int PS2CamInit ( int  mode)

Definition at line 37 of file ps2cam_rpc.c.

38 {
39  int ret=0;
40  int *buf;
41  // unsigned int i;
42  // int timeout = 100000;
43 
44  if(CamInited)return 0;
45 
46  SifInitRpc(0);
47 
48  while (((ret = SifBindRpc(&cdata, PS2_CAM_RPC_ID, 0)) >= 0) && (cdata.server == NULL))
49  nopdelay();
50 
51  nopdelay();
52 
53 
54 
55  if (ret < 0)return ret;
56 
57 
58 
59  buf = (int *)&data[0];
60  buf[0] = mode;
61 
62  printf("bind done\n");
63 
64  SifCallRpc(&cdata, PS2CAM_RPC_INITIALIZE, 0, (void*)(&data[0]),4,(void*)(&data[0]),4,0,0);
65  nopdelay();
66 
67  CamInited = 1;
68 
69 printf("init done\n");
70 
71 
72  compSema.init_count = 1;
73  compSema.max_count = 1;
74  compSema.option = 0;
76 
77 printf("sema done\n");
78 
79  return buf[0];
80 }
s32 CreateSema(ee_sema_t *sema)
static int CamInited
Definition: ps2cam_rpc.c:25
ee_sema_t compSema
Definition: ps2cam_rpc.c:30
int sem
Definition: ps2cam_rpc.c:32
#define PS2_CAM_RPC_ID
Definition: ps2cam_rpc.c:21
#define PS2CAM_RPC_INITIALIZE
Definition: ps2cam_rpc.h:18
s32 mode
Definition: rpc_client.c:15
void SifInitRpc(int mode)
int SifBindRpc(SifRpcClientData_t *client, int rpc_number, int mode)
struct t_SifRpcServerData * server
Definition: sifrpc.h:142
int init_count
Definition: kernel.h:218
int max_count
Definition: kernel.h:217
u32 option
Definition: kernel.h:221
#define NULL
Definition: tamtypes.h:91

References CamInited, cdata, compSema, CreateSema(), data, ee_sema_t::init_count, ee_sema_t::max_count, mode, nopdelay(), NULL, ee_sema_t::option, PS2_CAM_RPC_ID, PS2CAM_RPC_INITIALIZE, sem, SifRpcClientData_t::server, SifBindRpc(), SifCallRpc(), and SifInitRpc().

Referenced by main().

◆ PS2CamOpenDevice()

int PS2CamOpenDevice ( int  device_index)

Definition at line 118 of file ps2cam_rpc.c.

119 {
120  int *ret;
121 
122  ret = (int *)&data[0];
123 
124  ret[0] = device_index;
125 
126  SifCallRpc(&cdata, PS2CAM_RPC_OPENDEVICE, 0, (void*)(&data[0]),4,(void*)(&data[0]),4,0,0);
127 
128  return ret[0];
129 }
#define PS2CAM_RPC_OPENDEVICE
Definition: ps2cam_rpc.h:21

References cdata, data, PS2CAM_RPC_OPENDEVICE, and SifCallRpc().

Referenced by main().

◆ PS2CamReadPacket()

int PS2CamReadPacket ( int  handle)

Definition at line 216 of file ps2cam_rpc.c.

217 {
218  int *ret;
219  int *iop_addr;
220 
221  WaitSema(sem);
222 
223  ret = (int *)&data[0];
224 
225  ret[0] = handle;
226 
227  SifCallRpc(&cdata, PS2CAM_RPC_READPACKET, 0, (void*)(&data[0]),4,(void*)(&data[0]),4*2,0,0);
228 
229 
230  if(ret[0] < 0) return ret[0];
231 
232 
233  DI();
234  ee_kmode_enter();
235 
236  iop_addr = (int *)(0xbc000000+ret[1]);
237 
238  memcpy(&campacket[0],iop_addr, ret[0]);
239 
240  ee_kmode_exit();
241  EI();
242 
243  //if i add a printf here, the ps2 will exit to sony's explorer
244  SignalSema(sem);
245  return ret[0];
246 }
static int ee_kmode_exit()
Definition: kernel.h:198
s32 SignalSema(s32 sema_id)
static int ee_kmode_enter()
Definition: kernel.h:181
s32 WaitSema(s32 sema_id)
#define DI
Definition: kernel.h:24
#define EI
Definition: kernel.h:25
#define PS2CAM_RPC_READPACKET
Definition: ps2cam_rpc.h:30

References campacket, cdata, data, DI, ee_kmode_enter(), ee_kmode_exit(), EI, PS2CAM_RPC_READPACKET, sem, SifCallRpc(), SignalSema(), and WaitSema().

Referenced by PS2CamExtractFrame().

◆ PS2CamSetDeviceBandwidth()

int PS2CamSetDeviceBandwidth ( int  handle,
char  bandwidth 
)

Definition at line 194 of file ps2cam_rpc.c.

195 {
196  int *ret;
197 
198  ret = (int *)&data[0];
199 
200  ret[0] = handle;
201  ret[1] = bandwidth;
202 
203 
204 
205  SifCallRpc(&cdata, PS2CAM_RPC_SETDEVBANDWIDTH, 0, (void*)(&data[0]),4,(void*)(&data[0]),4,0,0);
206  nopdelay();
207 
208  return ret[0];
209 }
#define PS2CAM_RPC_SETDEVBANDWIDTH
Definition: ps2cam_rpc.h:28

References cdata, data, nopdelay(), PS2CAM_RPC_SETDEVBANDWIDTH, and SifCallRpc().

Referenced by main().

◆ PS2CamSetDeviceConfig()

int PS2CamSetDeviceConfig ( int  handle,
PS2CAM_DEVICE_CONFIG cfg 
)

Definition at line 267 of file ps2cam_rpc.c.

268 {
269  int *ret;
270 
271  ret = (int *)&data[0];
272 
273  ret[0] = handle;
274 
275  memcpy(&ret[1], cfg, cfg->ssize);
276 
277  SifCallRpc(&cdata, PS2CAM_RPC_SETDEVCONFIG, 0, (void*)(&data[0]), 4+cfg->ssize,(void*)(&data[0]),4+cfg->ssize,0,0);
278 
279  return ret[0];
280 }
PS2CAM_DEVICE_CONFIG cfg
Definition: camera-test.c:18
#define PS2CAM_RPC_SETDEVCONFIG
Definition: ps2cam_rpc.h:34
unsigned int ssize
Definition: ps2cam_rpc.h:124

References cdata, cfg, data, PS2CAM_RPC_SETDEVCONFIG, SifCallRpc(), and PS2CAM_DEVICE_CONFIG::ssize.

Referenced by main().

◆ PS2CamSetLEDMode()

int PS2CamSetLEDMode ( int  handle,
int  mode 
)

Definition at line 251 of file ps2cam_rpc.c.

252 {
253  int *ret;
254 
255  ret = (int *)&data[0];
256 
257  ret[0] = handle;
258  ret[1] = mode;
259 
260  SifCallRpc(&cdata, PS2CAM_RPC_SETLEDMODE, 0, (void*)(&data[0]),4,(void*)(&data[0]),4,0,0);
261 
262  return ret[0];
263 }
#define PS2CAM_RPC_SETLEDMODE
Definition: ps2cam_rpc.h:32

References cdata, data, mode, PS2CAM_RPC_SETLEDMODE, and SifCallRpc().