Commit d8a22bf3 authored by Kotaro Terada's avatar Kotaro Terada

Update source files

parent e3dd9624
......@@ -385,6 +385,12 @@ public class ARDrone implements ARDroneInterface {
manager.setSpeed(speed);
}
@Override
public void parallel(int lr,int fb) {
if (manager != null)
manager.parallel(lr, fb);
}
@Override
public void stop() {
if (manager != null)
......@@ -492,4 +498,4 @@ public class ARDrone implements ARDroneInterface {
}
return inetaddr;
}
}
\ No newline at end of file
}
This diff is collapsed.
......@@ -82,6 +82,8 @@ public interface ARDroneInterface {
public void goLeft(int speed);
public void parallel(int lr,int fb);
public void stop();
public void move3D(int speedX, int speedY, int speedZ, int speedSpin);
......@@ -94,4 +96,4 @@ public interface ARDroneInterface {
public void setMaxAltitude(int altitude);
// set min altitude
public void setMinAltitude(int altitude);
}
\ No newline at end of file
}
/**
ARDroneForP5
https://github.com/shigeodayo/ARDroneForP5
Copyright (C) 2013, Shigeo YOSHIDA.
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.shigeodayo.ardrone;
public interface ARDroneInterface {
// connection
public boolean connect();
public boolean connectVideo();
public boolean connectNav();
public void disconnect();
public void start();
// camera
public void setHorizontalCamera();// setFrontCameraStreaming()
public void setVerticalCamera();// setBellyCameraStreaming()
public void setHorizontalCameraWithVertical();// setFrontCameraWithSmallBellyStreaming()
public void setVerticalCameraWithHorizontal();// setBellyCameraWithSmallFrontStreaming()
public void toggleCamera();
// control command
public void landing();
public void takeOff();
public void reset();
public void forward();
public void forward(int speed);
public void backward();
public void backward(int speed);
public void spinRight();
public void spinRight(int speed);
public void spinLeft();
public void spinLeft(int speed);
public void up();
public void up(int speed);
public void down();
public void down(int speed);
public void goRight();
public void goRight(int speed);
public void goLeft();
public void goLeft(int speed);
public void stop();
public void move3D(int speedX, int speedY, int speedZ, int speedSpin);
// speed
public int getSpeed();
public void setSpeed(int speed);
// set max altitude
public void setMaxAltitude(int altitude);
// set min altitude
public void setMinAltitude(int altitude);
}
\ No newline at end of file
......@@ -191,6 +191,19 @@ public abstract class CommandManager extends AbstractManager {
goLeft();
}
public void parallel(int lr,int fb){ //original
float lr_speed=(float)(lr/100.0);
float fb_speed=(float)(fb/100.0);
command = "AT*PCMD=" + SEQ + ",1," + intOfFloat(lr_speed) +","+ intOfFloat(fb_speed) +",0,0"
+ "\r" + "AT*REF=" + SEQ + ",290718208";
continuance = true;
}
public void stop() {
command = "AT*PCMD=" + SEQ + ",1,0,0,0,0";
continuance = true;
......@@ -250,7 +263,7 @@ public abstract class CommandManager extends AbstractManager {
}
/*
* Thank you Tarqunio !!
*
*/
public void move3D(int speedX, int speedY, int speedZ, int speedSpin) {
if (speedX > 100)
......@@ -349,4 +362,4 @@ public abstract class CommandManager extends AbstractManager {
fb.put(0, f);
return ib.get(0);
}
}
\ No newline at end of file
}
/**
ARDroneForP5
https://github.com/shigeodayo/ARDroneForP5
Copyright (C) 2013, Shigeo YOSHIDA.
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.shigeodayo.ardrone.command;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import com.shigeodayo.ardrone.manager.AbstractManager;
import com.shigeodayo.ardrone.utils.ARDroneConstants;
public abstract class CommandManager extends AbstractManager {
protected static final String CR = "\r";
protected static final String SEQ = "$SEQ$";
private static int seq = 1;
private FloatBuffer fb = null;
private IntBuffer ib = null;
private boolean landing = true;
private boolean continuance = false;
private String command = null;
/** speed */
private float speed = 0.05f; // 0.01f - 1.0f
protected String VIDEO_CODEC;
public CommandManager(InetAddress inetaddr) {
this.inetaddr = inetaddr;
ByteBuffer bb = ByteBuffer.allocate(4);
fb = bb.asFloatBuffer();
ib = bb.asIntBuffer();
}
public void setHorizontalCamera() {
command = "AT*CONFIG=" + SEQ + ",\"video:video_channel\",\"0\"";
continuance = false;
}
public void setVerticalCamera() {
command = "AT*CONFIG=" + SEQ + ",\"video:video_channel\",\"1\"";
continuance = false;
}
public void setHorizontalCameraWithVertical() {
command = "AT*CONFIG=" + SEQ + ",\"video:video_channel\",\"2\"";
continuance = false;
}
public void setVerticalCameraWithHorizontal() {
command = "AT*CONFIG=" + SEQ + ",\"video:video_channel\",\"3\"";
continuance = false;
}
public void toggleCamera() {
command = "AT*CONFIG=" + SEQ + ",\"video:video_channel\",\"4\"";
continuance = false;
}
public void landing() {
command = "AT*REF=" + SEQ + ",290717696";
continuance = false;
landing = true;
//System.out.println("landing");
}
public void takeOff() {
sendCommand("AT*FTRIM=" + SEQ);
command = "AT*REF=" + SEQ + ",290718208";
continuance = false;
landing = false;
//System.out.println("take off");
}
public void reset() {
command = "AT*REF=" + SEQ + ",290717952";
continuance = true;
landing = true;
}
/*public void forward() {
command = "AT*PCMD=" + SEQ + ",1,0," + intOfFloat(-speed) + ",0,0"
+ "\r" + "AT*REF=" + SEQ + ",290718208";
continuance = true;
}*/
public void forward(int speed) {
setSpeed(speed);
forward();
}
public void backward() {
command = "AT*PCMD=" + SEQ + ",1,0," + intOfFloat(speed) + ",0,0"
+ "\r" + "AT*REF=" + SEQ + ",290718208";
continuance = true;
}
public void backward(int speed) {
setSpeed(speed);
backward();
}
public void spinRight() {
command = "AT*PCMD=" + SEQ + ",1,0,0,0," + intOfFloat(speed) + "\r"
+ "AT*REF=" + SEQ + ",290718208";
continuance = true;
}
public void spinRight(int speed) {
setSpeed(speed);
spinRight();
}
public void spinLeft() {
command = "AT*PCMD=" + SEQ + ",1,0,0,0," + intOfFloat(-speed) + "\r"
+ "AT*REF=" + SEQ + ",290718208";
continuance = true;
}
public void spinLeft(int speed) {
setSpeed(speed);
spinLeft();
}
public void up() {
command = "AT*PCMD=" + SEQ + ",1," + intOfFloat(0) + ","
+ intOfFloat(0) + "," + intOfFloat(speed) + "," + intOfFloat(0)
+ "\r" + "AT*REF=" + SEQ + ",290718208";
continuance = true;
}
public void up(int speed) {
setSpeed(speed);
up();
}
public void down() {
command = "AT*PCMD=" + SEQ + ",1," + intOfFloat(0) + ","
+ intOfFloat(0) + "," + intOfFloat(-speed) + ","
+ intOfFloat(0) + "\r" + "AT*REF=" + SEQ + ",290718208";
continuance = true;
}
public void down(int speed) {
setSpeed(speed);
down();
}
public void goRight() {
command = "AT*PCMD=" + SEQ + ",1," + intOfFloat(speed) + ",0,0,0"
+ "\r" + "AT*REF=" + SEQ + ",290718208";
continuance = true;
}
public void goRight(int speed) {
setSpeed(speed);
goRight();
}
public void goLeft() {
command = "AT*PCMD=" + SEQ + ",1," + intOfFloat(-speed) + ",0,0,0"
+ "\r" + "AT*REF=" + SEQ + ",290718208";
continuance = true;
}
public void goLeft(int speed) {
setSpeed(speed);
goLeft();
}
public void parallel(int lr,int fb){ //original
float lr_speed=(float)(lr/100.0);
float fb_speed=(float)(fb/100.0);
command = "AT*PCMD=" + SEQ + ",1," + intOfFloat(lr_speed) +","+ intOfFloat(fb_speed) +",0,0"
+ "\r" + "AT*REF=" + SEQ + ",290718208";
continuance = true;
}
public void stop() {
command = "AT*PCMD=" + SEQ + ",1,0,0,0,0";
continuance = true;
}
public void setSpeed(int speed) {
if (speed > 100)
speed = 100;
else if (speed < 1)
speed = 1;
this.speed = (float) (speed / 100.0);
}
public void enableVideoData() {
command = "AT*CONFIG=" + SEQ + ",\"general:video_enable\",\"TRUE\""
+ CR + "AT*FTRIM=" + SEQ;
continuance = false;
}
public void enableDemoData() {
command = "AT*CONFIG=" + SEQ + ",\"general:navdata_demo\",\"TRUE\""
+ CR + "AT*FTRIM=" + SEQ;
continuance = false;
}
public void disableBootStrap() {
command = "AT*CONFIG_IDS=" + SEQ + ",\"" + ARDroneConstants.SESSION_ID
+ "\",\"" + ARDroneConstants.PROFILE_ID + "\",\""
+ ARDroneConstants.APPLICATION_ID + "\"" + CR;
}
public void sendControlAck() {
command = "AT*CTRL=" + SEQ + ",0";
continuance = false;
}
public int getSpeed() {
return (int) (speed * 100);
}
public void disableAutomaticVideoBitrate() {
command = "AT*CONFIG=" + SEQ + ",\"video:bitrate_ctrl_mode\",\"0\"";
continuance = false;
}
public void setMaxAltitude(int altitude) {
command = "AT*CONFIG=" + SEQ + ",\"control:altitude_max\",\""
+ altitude + "\"";
continuance = false;
}
public void setMinAltitude(int altitude) {
command = "AT*CONFIG=" + SEQ + ",\"control:altitude_min\",\""
+ altitude + "\"";
continuance = false;
}
/*
*
*/
public void move3D(int speedX, int speedY, int speedZ, int speedSpin) {
if (speedX > 100)
speedX = 100;
else if (speedX < -100)
speedX = -100;
if (speedY > 100)
speedY = 100;
else if (speedY < -100)
speedY = -100;
if (speedZ > 100)
speedZ = 100;
else if (speedZ < -100)
speedZ = -100;
command = "AT*PCMD=" + SEQ + ",1," + intOfFloat(-speedY / 100.0f) + ","
+ intOfFloat(-speedX / 100.0f) + ","
+ intOfFloat(-speedZ / 100.0f) + ","
+ intOfFloat(-speedSpin / 100.0f) + "\r" + "AT*REF=" + SEQ
+ ",290718208";
continuance = true;
}
@Override
public void run() {
initializeDrone();
while (true) {
if (this.command != null) {
// sendCommand();
sendCommand(this.command);
if (!continuance) {
command = null;
}
} else {
if (landing) {
sendCommand("AT*PCMD=" + SEQ + ",1,0,0,0,0" + CR
+ "AT*REF=" + SEQ + ",290717696");
} else {
sendCommand("AT*PCMD=" + SEQ + ",1,0,0,0,0" + CR
+ "AT*REF=" + SEQ + ",290718208");
}
}
try {
Thread.sleep(20); // < 50ms
} catch (InterruptedException e) {
e.printStackTrace();
}
if (seq % 5 == 0) { // < 2000ms
sendCommand("AT*COMWDG=" + SEQ);
}
}
}
protected abstract void initializeDrone();
/*
* private void initializeDrone() { sendCommand("AT*CONFIG=" + SEQ +
* ",\"general:navdata_demo\",\"TRUE\"" + CR + "AT*FTRIM=" + SEQ); // 1
* sendCommand("AT*PMODE=" + SEQ + ",2" + CR + "AT*MISC=" + SEQ +
* ",2,20,2000,3000" + CR + "AT*FTRIM=" + SEQ + CR + "AT*REF=" + SEQ +
* ",290717696"); // 2-5 sendCommand("AT*PCMD=" + SEQ + ",1,0,0,0,0" + CR +
* "AT*REF=" + SEQ + ",290717696" + CR + "AT*COMWDG=" + SEQ); // 6-8
* sendCommand("AT*PCMD=" + SEQ + ",1,0,0,0,0" + CR + "AT*REF=" + SEQ +
* ",290717696" + CR + "AT*COMWDG=" + SEQ); // 6-8 sendCommand("AT*FTRIM=" +
* SEQ); //System.out.println("Initialize completed!"); }
*/
/*
* Thank you Dirk !!
*/
protected synchronized void sendCommand(String command) {
int seqIndex = -1;
while ((seqIndex = command.indexOf(SEQ)) != -1)
command = command.substring(0, seqIndex) + (seq++)
+ command.substring(seqIndex + SEQ.length());
byte[] buffer = (command + CR).getBytes();
//System.out.println(command);
DatagramPacket packet = new DatagramPacket(buffer, buffer.length,
inetaddr, ARDroneConstants.PORT);
try {
socket.send(packet);
//Thread.sleep(20); // < 50ms
} catch (IOException e) {
e.printStackTrace();
} /*catch (InterruptedException e) {
e.printStackTrace();
}*/
}
private int intOfFloat(float f) {
fb.put(0, f);
return ib.get(0);
}
}
......@@ -4,7 +4,6 @@ import java.nio.ByteBuffer;
//#region Copyright Notice
//Copyright 2007-2011, PARROT SA, all rights reserved.
//DISCLAIMER
//The APIs is provided by PARROT and contributors "AS IS" and any express or implied warranties, including, but not limited to, the implied warranties of merchantability
......
This diff is collapsed.
package com.shigeodayo.ardrone.video;
//Copyright © 2007-2011, PARROT SA, all rights reserved.
//DISCLAIMER
//The APIs is provided by PARROT and contributors "AS IS" and any express or implied warranties, including, but not limited to, the implied warranties of merchantability
......@@ -29,4 +29,4 @@ public class ImageSlice {
MacroBlocks[index] = new MacroBlock();
}
}
}
\ No newline at end of file
}
package com.shigeodayo.ardrone.video;
//Copyright © 2007-2011, PARROT SA, all rights reserved.
//DISCLAIMER
//The APIs is provided by PARROT and contributors "AS IS" and any express or implied warranties, including, but not limited to, the implied warranties of merchantability
//and fitness for a particular purpose are disclaimed. In no event shall PARROT and contributors be liable for any direct, indirect, incidental, special, exemplary, or
//consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data, or profits; or business interruption) however
//caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this
//software, even if advised of the possibility of such damage.
//Author : Daniel Schmidt
//Publishing date : 2010-01-06
//based on work by : Wilke Jansoone
//Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions
//are met:
//- Redistributions of source code must retain the above copyright notice, this list of conditions, the disclaimer and the original author of the source code.
//- Neither the name of the PixVillage Team, nor the names of its contributors may be used to endorse or promote products derived from this software without
//specific prior written permission.
public class ImageSlice {
MacroBlock[] MacroBlocks;
ImageSlice(int macroBlockCount) {
MacroBlocks = new MacroBlock[macroBlockCount];
for (int index = 0; index < macroBlockCount; index++) {
MacroBlocks[index] = new MacroBlock();
}
}
}
\ No newline at end of file
package com.shigeodayo.ardrone.video;
//Copyright © 2007-2011, PARROT SA, all rights reserved.
//DISCLAIMER
//The APIs is provided by PARROT and contributors "AS IS" and any express or implied warranties, including, but not limited to, the implied warranties of merchantability
......@@ -44,4 +44,4 @@ public class MacroBlock {
}
// //#endregion
}
\ No newline at end of file
}
package com.shigeodayo.ardrone.video;
//Copyright © 2007-2011, PARROT SA, all rights reserved.
//DISCLAIMER
//The APIs is provided by PARROT and contributors "AS IS" and any express or implied warranties, including, but not limited to, the implied warranties of merchantability
//and fitness for a particular purpose are disclaimed. In no event shall PARROT and contributors be liable for any direct, indirect, incidental, special, exemplary, or
//consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data, or profits; or business interruption) however
//caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this
//software, even if advised of the possibility of such damage.
//Author : Daniel Schmidt
//Publishing date : 2010-01-06
//based on work by : Wilke Jansoone
//Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions
//are met:
//- Redistributions of source code must retain the above copyright notice, this list of conditions, the disclaimer and the original author of the source code.
//- Neither the name of the PixVillage Team, nor the names of its contributors may be used to endorse or promote products derived from this software without
//specific prior written permission.
public class MacroBlock {
// /#//#region ants
// private int _BlockWidth = 8;
// private int _BlockSize = 64;
// //#endregion
// //#region Properties
short[][] DataBlocks;
// //#endregion
// //#region ruction
MacroBlock() {
DataBlocks = new short[6][];
for (int index = 0; index < 6; index++) {
DataBlocks[index] = new short[64];
}
}
// //#endregion
}
\ No newline at end of file
package com.shigeodayo.ardrone.video;
//Copyright © 2007-2011, PARROT SA, all rights reserved.
//DISCLAIMER
//The APIs is provided by PARROT and contributors "AS IS" and any express or implied warranties, including, but not limited to, the implied warranties of merchantability
......
package com.shigeodayo.ardrone.video;
//DISCLAIMER
//The APIs is provided by PARROT and contributors "AS IS" and any express or implied warranties, including, but not limited to, the implied warranties of merchantability
//and fitness for a particular purpose are disclaimed. In no event shall PARROT and contributors be liable for any direct, indirect, incidental, special, exemplary, or
//consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data, or profits; or business interruption) however
//caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this
//software, even if advised of the possibility of such damage.
//Author : Daniel Schmidt
//Publishing date : 2010-01-06
//based on work by : Wilke Jansoone
//Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions
//are met:
//- Redistributions of source code must retain the above copyright notice, this list of conditions, the disclaimer and the original author of the source code.
//- Neither the name of the PixVillage Team, nor the names of its contributors may be used to endorse or promote products derived from this software without
//specific prior written permission.
public class PictureFormats {
// / <summary>
// / 176px x 144px
// / </summary>
public static final int Cif = 1;
// / <summary>
// / 320px x 240px
// / </summary>
public static final int Vga = 2;
}
//Copyright 2007-2011, PARROT SA, all rights reserved.
//DISCLAIMER
//The APIs is provided by PARROT and contributors "AS IS" and any express or implied warranties, including, but not limited to, the implied warranties of merchantability
......
//DISCLAIMER
//The APIs is provided by PARROT and contributors "AS IS" and any express or implied warranties, including, but not limited to, the implied warranties of merchantability
//and fitness for a particular purpose are disclaimed. In no event shall PARROT and contributors be liable for any direct, indirect, incidental, special, exemplary, or
//consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data, or profits; or business interruption) however
//caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this
//software, even if advised of the possibility of such damage.
//Author : Daniel Schmidt
//Publishing date : 2010-01-06
//based on work by : Wilke Jansoone
//Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions
//are met:
//- Redistributions of source code must retain the above copyright notice, this list of conditions, the disclaimer and the original author of the source code.
//- Neither the name of the PixVillage Team, nor the names of its contributors may be used to endorse or promote products derived from this software without
// specific prior written permission.
//modified :Shigeo Yoshida, 2011-02-23
package com.shigeodayo.ardrone.video;
import java.awt.image.BufferedImage;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.ByteBuffer;
public class ReadRawFileImage {
public ReadRawFileImage() {
}
public BufferedImage readUINT_RGBImage(byte[] rawData)
throws FileNotFoundException, IOException {
int length = 0;
try {
byte[] processedData = process(rawData);
int[] pixelData = new int[processedData.length / 3];
int raw, pixel = 0, j = 0;
for (int i = 0; i < pixelData.length; i++) {
pixel = 0;
raw = processedData[j++] & 0xFF;
pixel |= (raw << 16);
raw = processedData[j++] & 0xFF;
pixel |= (raw << 8);
raw = processedData[j++] & 0xFF;
pixel |= (raw << 0);
pixelData[i] = pixel;
}
// System.out.println(pixelData.length);
length = pixelData.length;
if (length == 76800) {
BufferedImage image = new BufferedImage(320, 240,
BufferedImage.TYPE_INT_RGB);
image.setRGB(0, 0, 320, 240, pixelData, 0, 320);
return image;
} else if (length == 25344) {
BufferedImage image = new BufferedImage(176, 144,
BufferedImage.TYPE_INT_RGB);
image.setRGB(0, 0, 176, 144, pixelData, 0, 176);
return image;
}
/*
* BufferedImage image = new BufferedImage(640, 480,
* BufferedImage.TYPE_INT_RGB);
*
* image.setRGB(0, 0, 640, 480, pixelData, 0, 480);
*/
} catch (ArrayIndexOutOfBoundsException e) {
e.printStackTrace();
// System.out.println(length);
}
return null;
}
private byte[] process(final byte[] rawData) {
final BufferedVideoImage image = new BufferedVideoImage();
image.AddImageStream(ByteBuffer.wrap(rawData));
final uint[] outData = image.getPixelData();
ByteBuffer buffer = ByteBuffer.allocate(outData.length * 3);
for (int i = 0; i < outData.length; i++) {
int myInt = outData[i].intValue();
buffer.put((byte) ((myInt >> 16) & 0xFF));
buffer.put((byte) ((myInt >> 8) & 0xFF));
buffer.put((byte) (myInt & 0xFF));
}
return buffer.array();
}
}
......@@ -2,7 +2,6 @@ package com.shigeodayo.ardrone.video;
//#region Copyright Notice
//Copyright 2007-2011, PARROT SA, all rights reserved.
//DISCLAIMER
//The APIs is provided by PARROT and contributors "AS IS" and any express or implied warranties, including, but not limited to, the implied warranties of merchantability
......
This diff is collapsed.
......@@ -7,7 +7,7 @@ import java.io.DataInputStream;
import java.nio.ByteBuffer;
//import java.security.AllPermission;
//Copyright 2007-2011, PARROT SA, all rights reserved.
//DISCLAIMER
//The APIs is provided by PARROT and contributors "AS IS" and any express or implied warranties, including, but not limited to, the implied warranties of merchantability
......
package com.shigeodayo.ardrone.video;
import java.io.ByteArrayInputStream;
//import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
//import java.io.DataOutputStream;
import java.nio.ByteBuffer;
//import java.security.AllPermission;
//DISCLAIMER
//The APIs is provided by PARROT and contributors "AS IS" and any express or implied warranties, including, but not limited to, the implied warranties of merchantability
//and fitness for a particular purpose are disclaimed. In no event shall PARROT and contributors be liable for any direct, indirect, incidental, special, exemplary, or
//consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data, or profits; or business interruption) however
//caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this
//software, even if advised of the possibility of such damage.
//Author : Daniel Schmidt
//Publishing date : 2010-01-06
//based on work by : Wilke Jansoone
//Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions
//are met:
//- Redistributions of source code must retain the above copyright notice, this list of conditions, the disclaimer and the original author of the source code.
//- Neither the name of the PixVillage Team, nor the names of its contributors may be used to endorse or promote products derived from this software without
//specific prior written permission.
public class uint {
public String toString() {
return Integer.toString(base2, 2);
}
public uint(int base) {
this.base2 = base;
}
public uint(uint that) {
this.base2 = that.base2;
}
public uint(byte[] bp, int start) {
try {
byte[] b = new byte[4];
b[0] = bp[start + 3];
b[1] = bp[start + 2];
b[2] = bp[start + 1];
b[3] = bp[start + 0];
ByteArrayInputStream bas = new ByteArrayInputStream(b);
DataInputStream din = new DataInputStream(bas);
this.base2 = din.readInt();
} catch (Exception e) {
throw new RuntimeException("error creating uint", e);
}
}
public uint(ByteBuffer bp, int start) {
try {
ByteBuffer bb = ByteBuffer.allocate(4);
bb.put(bp.array()[start + 3]);
bb.put(bp.array()[start + 2]);
bb.put(bp.array()[start + 1]);
bb.put(bp.array()[start + 0]);
bb.flip();
this.base2 = bb.getInt();
} catch (Exception e) {
throw new RuntimeException("error creating uint", e);
}
}
private int base2;
public short times(short i) {
return (short) (intValue() * i);
}
public uint shiftRight(int i) {
// System.out.println("shiftRight[0] " + base2 + " " + i);
// String str = Integer.toBinaryString(base);
int base = base2;
// System.out.println("shiftRight[n][1] " + uint.toBinaryString(base));
base = base >>> i;
// System.out.println("shiftRight[n][2] " + uint.toBinaryString(base));
return new uint(base);
}
public uint shiftLeft(int i) {
int base = base2;
base <<= i;
return new uint(base);
// return Integer.parseInt(base, 2);
}
public int flipBits() {
int base = ~base2;
return base;
}
public int intValue() {
return base2;
}
public uint and(int andval) {
int retval = base2 & andval;
return new uint(retval);
}
public void shiftLeftEquals(int i) {
int base = base2;
base <<= i;
base2 = base;
}
public void shiftRightEquals(int i) {
int base = base2;
base >>>= i;
base2 = base;
}
public uint or(uint orval) {
int retval = base2 | orval.base2;
return new uint(retval);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment