Android Open Source - remoteyourcam-usb Packet Util






From Project

Back to project page remoteyourcam-usb.

License

The source code is released under:

Apache License

If you think the Android project remoteyourcam-usb listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/**
 * Copyright 2013 Nils Assbeck, Guersel Ayaz and Michael Zoech
 *// w w w.jav  a 2 s .  c o m
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.remoteyourcam.usb.ptp;

import java.nio.ByteBuffer;

import android.util.Log;

public class PacketUtil {

    public static int[] readU32Array(ByteBuffer b) {
        int len = b.getInt();
        int[] a = new int[len];
        for (int i = 0; i < len; ++i) {
            a[i] = b.getInt();
        }
        return a;
    }

    public static int[] readU16Array(ByteBuffer b) {
        int len = b.getInt();
        int[] a = new int[len];
        for (int i = 0; i < len; ++i) {
            a[i] = b.getShort() & 0xFFFF;
        }
        return a;
    }

    public static void writeU16Array(ByteBuffer b, int[] a) {
        b.putInt(a.length);
        for (int v : a) {
            b.putShort((short) v);
        }
    }

    public static int[] readU8Array(ByteBuffer b) {
        int len = b.getInt();
        int[] a = new int[len];
        for (int i = 0; i < len; ++i) {
            a[i] = b.get() & 0xFF;
        }
        return a;
    }

    public static int[] readU32Enumeration(ByteBuffer b) {
        int len = b.getShort() & 0xFFFF;
        int[] a = new int[len];
        for (int i = 0; i < len; ++i) {
            a[i] = b.getInt();
        }
        return a;
    }

    public static int[] readS16Enumeration(ByteBuffer b) {
        int len = b.getShort() & 0xFFFF;
        int[] a = new int[len];
        for (int i = 0; i < len; ++i) {
            a[i] = b.getShort();
        }
        return a;
    }

    public static int[] readU16Enumeration(ByteBuffer b) {
        int len = b.getShort() & 0xFFFF;
        int[] a = new int[len];
        for (int i = 0; i < len; ++i) {
            a[i] = b.getShort() & 0xFFFF;
        }
        return a;
    }

    public static int[] readU8Enumeration(ByteBuffer b) {
        int len = b.getShort() & 0xFFFF;
        int[] a = new int[len];
        for (int i = 0; i < len; ++i) {
            a[i] = b.get() & 0xFF;
        }
        return a;
    }

    public static String readString(ByteBuffer b) {
        int len = b.get() & 0xFF;
        if (len > 0) {
            char[] ch = new char[len - 1];
            for (int i = 0; i < len - 1; ++i) {
                ch[i] = b.getChar();
            }
            // read '\0'
            b.getChar();
            return String.copyValueOf(ch);
        }
        return "";
    }

    public static void writeString(ByteBuffer b, String s) {
        b.put((byte) s.length());
        if (s.length() > 0) {
            for (int i = 0; i < s.length(); ++i) {
                b.putShort((short) s.charAt(i));
            }
            b.putShort((short) 0);
        }
    }

    public static String hexDumpToString(byte[] a, int offset, int len) {
        int lines = len / 16;
        int rest = len % 16;

        StringBuilder b = new StringBuilder((lines + 1) * 97);

        for (int i = 0; i < lines; ++i) {
            b.append(String.format("%04x ", i * 16));
            for (int k = 0; k < 16; ++k) {
                b.append(String.format("%02x ", a[offset + i * 16 + k]));
            }
            for (int k = 0; k < 16; ++k) {
                char ch = (char) a[offset + i * 16 + k];
                b.append(ch >= 0x20 && ch <= 0x7E ? ch : '.');
            }
            b.append('\n');
        }

        if (rest != 0) {
            b.append(String.format("%04x ", lines * 16));
            for (int k = 0; k < rest; ++k) {
                b.append(String.format("%02x ", a[offset + lines * 16 + k]));
            }
            for (int k = 0; k < (16 - rest) * 3; ++k) {
                b.append(' ');
            }
            for (int k = 0; k < rest; ++k) {
                char ch = (char) a[offset + lines * 16 + k];
                b.append(ch >= 0x20 && ch <= 0x7E ? ch : '.');
            }
            b.append('\n');
        }

        return b.toString();
    }

    public static void logHexdump(String tag, byte[] a, int offset, int len) {
        Log.i(tag, hexDumpToString(a, offset, len));
    }

    public static void logHexdump(String tag, byte[] a, int len) {
        logHexdump(tag, a, 0, len);
    }

}




Java Source Code List

com.remoteyourcam.usb.AbstractRycApplication.java
com.remoteyourcam.usb.AppConfig.java
com.remoteyourcam.usb.AppSettings.java
com.remoteyourcam.usb.GestureDetector.java
com.remoteyourcam.usb.MainActivity.java
com.remoteyourcam.usb.PictureView.java
com.remoteyourcam.usb.PropertyAdapter.java
com.remoteyourcam.usb.PropertyData.java
com.remoteyourcam.usb.PropertyDisplayer.java
com.remoteyourcam.usb.PropertyToggle.java
com.remoteyourcam.usb.RycApplication.java
com.remoteyourcam.usb.activities.AppSettingsActivity.java
com.remoteyourcam.usb.ptp.Camera.java
com.remoteyourcam.usb.ptp.EosCamera.java
com.remoteyourcam.usb.ptp.EosConstants.java
com.remoteyourcam.usb.ptp.FocusPoint.java
com.remoteyourcam.usb.ptp.NikonCamera.java
com.remoteyourcam.usb.ptp.PacketUtil.java
com.remoteyourcam.usb.ptp.PtpAction.java
com.remoteyourcam.usb.ptp.PtpCamera.java
com.remoteyourcam.usb.ptp.PtpConstants.java
com.remoteyourcam.usb.ptp.PtpPropertyHelper.java
com.remoteyourcam.usb.ptp.PtpService.java
com.remoteyourcam.usb.ptp.PtpUsbConnection.java
com.remoteyourcam.usb.ptp.PtpUsbService.java
com.remoteyourcam.usb.ptp.WorkerNotifier.java
com.remoteyourcam.usb.ptp.commands.CloseSessionCommand.java
com.remoteyourcam.usb.ptp.commands.Command.java
com.remoteyourcam.usb.ptp.commands.GetDeviceInfoCommand.java
com.remoteyourcam.usb.ptp.commands.GetDevicePropDescCommand.java
com.remoteyourcam.usb.ptp.commands.GetDevicePropValueCommand.java
com.remoteyourcam.usb.ptp.commands.GetObjectCommand.java
com.remoteyourcam.usb.ptp.commands.GetObjectHandlesCommand.java
com.remoteyourcam.usb.ptp.commands.GetObjectInfoCommand.java
com.remoteyourcam.usb.ptp.commands.GetStorageIdsCommand.java
com.remoteyourcam.usb.ptp.commands.GetStorageInfoCommand.java
com.remoteyourcam.usb.ptp.commands.GetStorageInfosAction.java
com.remoteyourcam.usb.ptp.commands.GetThumb.java
com.remoteyourcam.usb.ptp.commands.InitiateCaptureCommand.java
com.remoteyourcam.usb.ptp.commands.OpenSessionCommand.java
com.remoteyourcam.usb.ptp.commands.RetrieveAddedObjectInfoAction.java
com.remoteyourcam.usb.ptp.commands.RetrieveImageAction.java
com.remoteyourcam.usb.ptp.commands.RetrieveImageInfoAction.java
com.remoteyourcam.usb.ptp.commands.RetrievePictureAction.java
com.remoteyourcam.usb.ptp.commands.SetDevicePropValueCommand.java
com.remoteyourcam.usb.ptp.commands.SimpleCommand.java
com.remoteyourcam.usb.ptp.commands.eos.EosCommand.java
com.remoteyourcam.usb.ptp.commands.eos.EosEventCheckCommand.java
com.remoteyourcam.usb.ptp.commands.eos.EosGetLiveViewPictureCommand.java
com.remoteyourcam.usb.ptp.commands.eos.EosOpenSessionAction.java
com.remoteyourcam.usb.ptp.commands.eos.EosSetExtendedEventInfoCommand.java
com.remoteyourcam.usb.ptp.commands.eos.EosSetLiveViewAction.java
com.remoteyourcam.usb.ptp.commands.eos.EosSetPcModeCommand.java
com.remoteyourcam.usb.ptp.commands.eos.EosSetPropertyCommand.java
com.remoteyourcam.usb.ptp.commands.eos.EosTakePictureCommand.java
com.remoteyourcam.usb.ptp.commands.nikon.NikonAfDriveCommand.java
com.remoteyourcam.usb.ptp.commands.nikon.NikonAfDriveDeviceReadyCommand.java
com.remoteyourcam.usb.ptp.commands.nikon.NikonCloseSessionAction.java
com.remoteyourcam.usb.ptp.commands.nikon.NikonCommand.java
com.remoteyourcam.usb.ptp.commands.nikon.NikonEventCheckCommand.java
com.remoteyourcam.usb.ptp.commands.nikon.NikonGetLiveViewImageAction.java
com.remoteyourcam.usb.ptp.commands.nikon.NikonGetLiveViewImageCommand.java
com.remoteyourcam.usb.ptp.commands.nikon.NikonGetVendorPropCodesCommand.java
com.remoteyourcam.usb.ptp.commands.nikon.NikonOpenSessionAction.java
com.remoteyourcam.usb.ptp.commands.nikon.NikonStartLiveViewAction.java
com.remoteyourcam.usb.ptp.commands.nikon.NikonStopLiveViewAction.java
com.remoteyourcam.usb.ptp.model.DeviceInfo.java
com.remoteyourcam.usb.ptp.model.DevicePropDesc.java
com.remoteyourcam.usb.ptp.model.LiveViewData.java
com.remoteyourcam.usb.ptp.model.ObjectInfo.java
com.remoteyourcam.usb.ptp.model.StorageInfo.java
com.remoteyourcam.usb.util.DimenUtil.java
com.remoteyourcam.usb.util.NotificationIds.java
com.remoteyourcam.usb.util.PackageUtil.java
com.remoteyourcam.usb.view.AspectRatioImageView.java
com.remoteyourcam.usb.view.BaseFragment.java
com.remoteyourcam.usb.view.GalleryAdapter.java
com.remoteyourcam.usb.view.GalleryFragment.java
com.remoteyourcam.usb.view.PictureFragment.java
com.remoteyourcam.usb.view.SessionActivity.java
com.remoteyourcam.usb.view.SessionFragment.java
com.remoteyourcam.usb.view.SessionView.java
com.remoteyourcam.usb.view.StorageAdapter.java
com.remoteyourcam.usb.view.TabletSessionFragment.java
com.remoteyourcam.usb.view.ThumbnailAdapter.java
com.remoteyourcam.usb.view.WebViewDialogFragment.java