2

送受信パケット数をクリアして0からやり直すことはできますか??

送受信パケットを取得するコード:

long  no_of_packet_Sent = RadioInfo.getNumberOfPacketsSent();

long  no_of_packet_Received = RadioInfo.getNumberOfPacketsReceived();
4

1 に答える 1

1

これに対する答えは見つかりませんでしたが、別のオプションは、データをテキストファイルに書き込んでから、「パケット数の取得」からテキストファイル内のデータを差し引くことです。

private static String fileFormatString(String filename) {
    return filename.replace(" ".charAt(0),"_".charAt(0));
}
public static String readTextFile(String fName) {
    fName = fileFormatString(fName);
    String result = null;
    FileConnection fconn = null;
    DataInputStream is = null;
    try {
        fconn = (FileConnection) Connector.open(fName, Connector.READ_WRITE);
        is = fconn.openDataInputStream();
        byte[] data = IOUtilities.streamToBytes(is);
        result = new String(data);
    } catch (IOException e) {
        System.out.println("Error on read: "+fName+" - " + e.getMessage());
    } finally {
        try {
            if (null != is) is.close();
            if (null != fconn) fconn.close();
        } catch (IOException e) {
            System.out.println("Error on read IO: "+fName+" - " + e.getMessage());
        }
    }
    return result;
}
public static void writeTextFile(String fName, String text) {
    fName = fileFormatString(fName);
    DataOutputStream os = null;
    FileConnection fconn = null;
    try {
        fconn = (FileConnection) Connector.open(fName, Connector.READ_WRITE);
        if (fconn.exists());
        if (!fconn.exists()) fconn.create();
        os = fconn.openDataOutputStream();
        os.write(text.getBytes());
    } catch (IOException e) {
        System.out.println("Error on write: "+fName+" - " + e.getMessage());
    } finally {
        try {
            if (null != os) os.close();
            if (null != fconn) fconn.close();
        } catch (IOException e) {
            System.out.println("Error on write IO: "+fName+" - " + e.getMessage());
        }
    }
}
long no_of_packet = RadioInfo.getNumberOfPacketsSent()+RadioInfo.getNumberOfPacketsReceived();
DTHelper.writeTextFile(text_file_name,""+no_of_packet );

String readnumberofkbytes=readTextFile(text_file_name);
long Longreadnumberofbytes = Long.parseLong(readnumberofbytes);

long CurrentNumberofDataUsed= no_of_packet -Longreadnumberofbytes;
于 2012-11-20T09:48:59.780 に答える