これはクラスです。このクラスでintループを計算して比較しますか?
public class Main {
int secondPassed = 0;
Timer mytime = new Timer();
TimerTask mytask = new TimerTask()
{
public void run() {
secondPassed++;
if (secondPassed == 3){
secondPassed = 0;
Convertion callConvertion = new Convertion();
try {
callConvertion.cnvrt();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int donecnvrtin = callConvertion.donecnvrtin();
int donecnvrtout = callConvertion.donecnvrtout();;
System.out.println("IN : " + donecnvrtin);
System.out.println("OUT : " + donecnvrtout);
}
else{
System.out.println("Second : " + secondPassed);
}
}
};
public void start(){
mytime.scheduleAtFixedRate(mytask, 1000,1000);
}
public static void main(String[] args) throws Exception {
Time starter = new Time();
starter.start();
}
}
メイン:そう、私はLPassINでPassINを計算し比較することしようとしている
public class Convertion {
public int PassIN;
public int PassOUT;
public String convertStringToHex(String str){
char[] chars = str.toCharArray();
StringBuffer hex = new StringBuffer();
for(int i = 0; i < chars.length; i++){
hex.append(Integer.toHexString((int)chars[i]));
}
return hex.toString();
}
public void cnvrt(){
Udp callUdp = new Udp();
try {
callUdp.socketp();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String trnsferRP = callUdp.trnsfrRPckt();
Convertion strToHex = new Convertion();
String hex = strToHex.convertStringToHex(trnsferRP);
String cut = hex.substring(10);
String A = cut.substring(0, 2);
String B = cut.substring(2, 4);
String C = cut.substring(4, 6);
String D = cut.substring(6, 8);
int cvA = Integer.parseInt(A);
int cvB = Integer.parseInt(B);
int cvC = Integer.parseInt(C);
int cvD = Integer.parseInt(D);
int calcA = (cvA - 30) * 16;
int calcB = (cvB - 30);
int calcC = (cvC - 30) * 16;
int calcD = (cvD - 30);
this.PassIN = calcA + calcB;
this.PassOUT = calcC + calcD;
int tempIN = 0;
int tempOUT = 0;
int LPassIN;
int LPassOUT;
if (tempIN == 0){
LPassIN = PassIN + tempIN;
System.out.println(LPassIN);
}else if (LPassIN != PassIN){
LPassIN = PassIN;
System.out.println(PassIN);
}else{
System.out.println(LPassIN);
}
if (tempOUT == 0){
LPassOUT = PassOUT + tempOUT;
System.out.println(LPassOUT);
}else if (LPassOUT != PassOUT){
System.out.println(PassOUT);
}else{
System.out.println(LPassOUT);
}
}
public int donecnvrtin(){
return this.PassIN;
}
public int donecnvrtout(){
return this.PassOUT;
}
}
Convertion:udpと
public class Udp {
public String result;
public void socketp() throws Exception {
DatagramSocket clientSocket = new DatagramSocket(10076);
InetAddress IPAddress = InetAddress.getByName("192.168.100.10");
byte[] sendData = new byte[9];
byte[] receiveData = new byte[9];
String sentence = "VDV2bE1";
sendData = sentence.getBytes();
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, 10076);
clientSocket.send(sendPacket);
DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
clientSocket.receive(receivePacket);
clientSocket.close();
this.result = new String(receivePacket.getData());
return;
}
public String trnsfrRPckt(){
return this.result;
}
}
これは、クラスであります私はOをLPassInに渡すことでループを開始します。そして、LPassINはPassINから新しい最初のintを保持します。その後、新しい2番目のintが来たら、変数はint LPassInとPassIN。異なる場合はPassINを印刷し、LPassINに保存/保持します。同じ場合はLPassINを印刷します。新しい第三のintが来るのであれば、それは新しい第二のint
と比較されます
は私の方法で間違っているか、このセットアップのルールがありますか?
*)(UDP callUdp =新しいUDPの程度
[SSCCE](http://sscce.org/) –