17
|
1
|
|
2 /*
|
|
3 * @(#)PSXQueueInterface.java 1.1 06/04/01
|
|
4 *
|
|
5 * Copyright 2006 Shinji KONO
|
|
6 *
|
|
7
|
|
8 PSX Lidna
|
|
9 Trasport layer of PSX Linda library
|
|
10
|
|
11 */
|
|
12
|
|
13 package fdl;
|
|
14
|
|
15 import java.nio.ByteBuffer;
|
|
16 import java.nio.ByteOrder;
|
|
17
|
|
18
|
|
19
|
|
20 /**
|
|
21 PSXQueueInterface
|
|
22
|
|
23 */
|
|
24
|
|
25 public class PSX {
|
|
26 static final int PSX_IN = 'i';
|
|
27 static final int PSX_OUT = 'o';
|
|
28 static final int PSX_UPDATE = 'u';
|
|
29 static final int PSX_RD = 'r';
|
|
30 static final int PSX_CHECK = 'c';
|
|
31 static final int PSX_REPLY = '?';
|
|
32 static final int PSX_WAIT_RD = 'w';
|
|
33 static final int PSX_ANSWER = 'a';
|
|
34 static final int PSX_HTTP_ANSWER = 'P'; // Put
|
|
35 static final int PSX_HTTP_REQUEST = 'G'; // Get
|
|
36 static final int PSX_COM_DEBUG = 'D'; //Communication DEBUG
|
|
37
|
|
38 static final int LINDA_PACKET_LENGTH_OFFSET =0;
|
|
39 static final int LINDA_MODE_OFFSET =0+4;
|
|
40 static final int LINDA_ID_OFFSET =1+4;
|
|
41 static final int LINDA_SEQ_OFFSET =3+4;
|
|
42 static final int LINDA_DATA_LENGTH_OFFSET =7+4;
|
|
43 static final int LINDA_HEADER_SIZE =12+4;
|
|
44 static final int INT_SIZE =4;
|
|
45 static final int SHORT_SIZE =2;
|
|
46
|
|
47 static final int PRIVILEGED_ID_START = 32768;
|
|
48 static final int PRIVILEGED_ID_END = 36864;
|
|
49
|
|
50 // this method should be removed
|
|
51 static void setReportCommand(ByteBuffer command, String report_txt) {
|
|
52 command.order(ByteOrder.BIG_ENDIAN);
|
|
53 command.putInt(LINDA_PACKET_LENGTH_OFFSET,(report_txt).length()*2+LINDA_HEADER_SIZE-INT_SIZE);
|
|
54 command.put(LINDA_MODE_OFFSET,(byte)'D');
|
|
55 command.putShort(LINDA_ID_OFFSET,(short) 0);
|
|
56 command.putInt(LINDA_SEQ_OFFSET,0);
|
|
57 command.putInt(LINDA_DATA_LENGTH_OFFSET,(report_txt).length()*2);
|
|
58 command.rewind();
|
|
59 }
|
|
60
|
|
61 static void printCommand(ByteBuffer command, ByteBuffer data) {
|
|
62 char id = (char)command.getShort(LINDA_ID_OFFSET);
|
|
63 System.out.println("LENGTH:"+command.getInt(LINDA_PACKET_LENGTH_OFFSET)+" "+
|
|
64 "MODE:"+(char)command.get(LINDA_MODE_OFFSET)+" "+
|
|
65 "ID:"+(int)id+" "+
|
|
66 "SEQ:"+command.getInt(LINDA_SEQ_OFFSET)+" "+
|
|
67 "DATA LENGTH:"+command.getInt(LINDA_DATA_LENGTH_OFFSET)+" ");
|
|
68 System.out.println("DATA:"+data);
|
|
69 command.rewind();
|
|
70 }
|
|
71
|
|
72 static void printData(ByteBuffer command) {
|
|
73 /*** print data ***/
|
|
74 char id = (char)command.getShort(LINDA_ID_OFFSET);
|
|
75 System.out.println("LENGTH:"+command.getInt(LINDA_PACKET_LENGTH_OFFSET)+" "+
|
|
76 "MODE:"+(char)command.get(LINDA_MODE_OFFSET)+" "+
|
|
77 "ID:"+(int)id+" "+
|
|
78 "SEQ:"+command.getInt(LINDA_SEQ_OFFSET)+" ");
|
|
79 command.rewind();
|
|
80 }
|
|
81
|
|
82
|
|
83 static void setCommand(ByteBuffer command, int _mode, int _id, int _seq, int _datalen) {
|
|
84 command = ByteBuffer.allocate(LINDA_HEADER_SIZE);
|
|
85 command.order(ByteOrder.BIG_ENDIAN);
|
|
86
|
|
87 command.putInt(LINDA_PACKET_LENGTH_OFFSET,
|
|
88 _datalen+LINDA_HEADER_SIZE-INT_SIZE);
|
|
89 command.put(LINDA_MODE_OFFSET,(byte)_mode);
|
|
90 command.putShort(LINDA_ID_OFFSET,(short)_id);
|
|
91 command.putInt(LINDA_SEQ_OFFSET,_seq);
|
|
92 command.putInt(LINDA_DATA_LENGTH_OFFSET,_datalen);
|
|
93 command.rewind();
|
|
94 }
|
|
95
|
|
96 static void setAnserCommand(ByteBuffer command, int seq) {
|
|
97 command.put(LINDA_MODE_OFFSET, (byte)'a');
|
|
98 command.rewind();
|
|
99 command.putInt(LINDA_SEQ_OFFSET, seq);
|
|
100 command.rewind();
|
|
101 }
|
|
102
|
|
103
|
|
104 }
|
|
105
|
|
106 /* end */
|