Android Open Source - FlashTransmitter Manchester Line Coder






From Project

Back to project page FlashTransmitter.

License

The source code is released under:

GNU General Public License

If you think the Android project FlashTransmitter 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

package com.catinthedark.flash_transmitter.lib.algorithm;
//from  w  w w. j av a2  s  .  c om
import java.util.ArrayList;

/**
 * Created by Ilya on 15.04.2014.
 */
public class ManchesterLineCoder implements LineCoder {
    private final Synchronizer manchesterSynchronizer = new ManchesterSynchronizer();

    @Override
    public Byte[] pack(final Byte[] bits) {
        ArrayList<Byte> rawData = new ArrayList<Byte>(bits.length * 2);

        for (byte b: bits) {
            if (b == 0) {
                rawData.add((byte) 0);
                rawData.add((byte) 1);
            } else {
                rawData.add((byte) 1);
                rawData.add((byte) 0);
            }
        }

        return manchesterSynchronizer.addSynchroImpuls(rawData.toArray(new Byte[rawData.size()]));
    }

    @Override
    public Byte[] unpack(final Byte[] bits) {
        ArrayList<Byte> data = new ArrayList<Byte>();
        Byte[] synchBits = manchesterSynchronizer.removeSynchroImpuls(bits);

        ArrayList<Byte> manchesterizedData = new ArrayList<Byte>();
        for (int i = 0; i < synchBits.length - 1; i += 2) {
            if (!synchBits[i].equals(synchBits[i + 1])) {
                manchesterizedData.add(synchBits[i]);
                manchesterizedData.add(synchBits[i + 1]);
            } else {
                i -= 1;
            }
        }

        for (int i = 0; i < manchesterizedData.size(); i += 2) {
            if (manchesterizedData.get(i) == (manchesterizedData.get(i + 1) ^ 1)) {
                data.add(manchesterizedData.get(i));
            }
        }

        return data.toArray(new Byte[data.size()]);
    }
}




Java Source Code List

com.catinthedark.activity.ReceiveActivity.java
com.catinthedark.activity.StartActivity.java
com.catinthedark.activity.TransmitActivity.java
com.catinthedark.flash_transmitter.lib.algorithm.ASCIIScheme.java
com.catinthedark.flash_transmitter.lib.algorithm.CompressedScheme.java
com.catinthedark.flash_transmitter.lib.algorithm.Converter.java
com.catinthedark.flash_transmitter.lib.algorithm.EmptyErrorCorrectionLayer.java
com.catinthedark.flash_transmitter.lib.algorithm.EmptyLogicalCodeLayer.java
com.catinthedark.flash_transmitter.lib.algorithm.EncodingScheme.java
com.catinthedark.flash_transmitter.lib.algorithm.ErrorCorrectionLayer.java
com.catinthedark.flash_transmitter.lib.algorithm.Filter.java
com.catinthedark.flash_transmitter.lib.algorithm.LineCoder.java
com.catinthedark.flash_transmitter.lib.algorithm.LogicalCodeLayer.java
com.catinthedark.flash_transmitter.lib.algorithm.ManchesterLineCoder.java
com.catinthedark.flash_transmitter.lib.algorithm.ManchesterSynchronizer.java
com.catinthedark.flash_transmitter.lib.algorithm.RawDataTranslator.java
com.catinthedark.flash_transmitter.lib.algorithm.Synchronizer.java
com.catinthedark.flash_transmitter.lib.factories.EncodingSchemeFactory.java
com.catinthedark.flash_transmitter.lib.factories.ErrorCorrectionFactory.java
com.catinthedark.flash_transmitter.lib.factories.LineCoderFactory.java
com.catinthedark.flash_transmitter.lib.factories.LogicalCodeFactory.java
com.catinthedark.task.SubmitDataTask.java