ask help: I need to create a demo application in Java to test my new designed Java Api
- by Christophe
A new programmer needs yourhelp.
I'm working on a porject of re-developement of Java driver for the company's PIN pad terminals.
the Java Api (CPXApplicationUpdate) will allow the applications in pinpads to be updated and to be downloaded at different speed (Baud rate).
the Java Api was created. i followed the protocolto build the message. the message is to send to a RS-232 port.
i'm trying to use setter and getter to let the code work as an API.
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Properties;
public class CPXApplicationUpdate extends CPXCommand {
private int speed; // TODO: temporary variable for baud rate test stub.
// speed: baud rate of the maintenance application performing DL
/** Creates a new instance of CPXApplicationUpdate */
public CPXApplicationUpdate() {
speed = 9600; // no baud rate change
CPXProcessor.logger.fine("-------CPXApplicationUpdate constructor");
// setParam("timeout", _cmdInfo.getDefaultParValue("timeout"));
}
public CPXApplicationUpdate(int speedinit) {
speed = speedinit; // TODO: where to get the speed? wait for user input.
CPXProcessor.logger.fine("-------CPXApplicationUpdate constructor");
// setParam("timeout", _cmdInfo.getDefaultParValue("timeout"));
}
public void setSpeed(int speed){
this.speed = speed;
}
protected void buildRequest() throws ElitePortException {
String trans = "";
// build the full-qualified message
trans = addToRequest(trans, (char) 0);
trans = addToRequest(trans, (char) 5);
trans = addToRequest(trans, (char) 6);
trans = addToRequest(trans, (char) 0);
trans = addToRequest(trans, (char) 0);
trans = addToRequest(trans, (char) 2);
switch (speed) {
case 9600:
trans = addToRequest(trans, (char) 0x09);
break;
case 19200:
trans = addToRequest(trans, (char) 0x0A);
break;
case 115200:
trans = addToRequest(trans, (char) 0x0E);
break;
default:
// TODO: unexpected baud rate. throw();
break;
}
trans = EncryptBinary(trans);
trans = "F0." + trans;
wrapRequest(trans);
}
protected String addToRequest(String req, char c) {
CPXProcessor.logger.fine("adding char to request: I-" + (int) c + " C-"
+ c + " H-" + Integer.toHexString((int) c));
return req + c;
}
protected String addToRequest(String req, String s) {
CPXProcessor.logger.fine("adding String to request: S-" + s);
return req + s;
}
protected String addToRequest(String req) {
return req;
}
public void analyzeResponse() {
String response_transaction, response;
int absLen = _response.length();
if (absLen < 4)
return;
response = _response.substring(3);
CPXProcessor.logger.fine("stripped response=[" + response + "]");
for (int i = 0; i < response.length(); i++) {
char c = response.charAt(i);
CPXProcessor.logger.fine("[" + i + "] = " + c + " <> "
+ Integer.toHexString((int) c));
}
int status = (short) response.charAt(3);
CPXProcessor.logger.fine("status = " + status);
_outputValues.put("status", "" + status);
}
please help me to correct the code.
Now, i need to create a demo application to test if this java driver (Java Api) works.
the value of the speed can be input by users (command line), or creat property files. how can i do that?