package org.josast.ApplicationAmicalsat;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.Date;
import java.util.Vector;

import org.josast.amicalsat.FactoryConsumer;
import org.josast.amicalsat.Frame;

 


public class ModelReceivedData {
    
    long numberFrame = 0;
    Vector<ReceivedData> vecRawData =  new Vector<ReceivedData>();
    Vector<Frame> vecDecodedData=  new Vector<Frame>();
    FactoryConsumer ff = new  FactoryConsumer();
    
    
    private PropertyChangeSupport listenerList = new PropertyChangeSupport(this);
    
    public void addPropertyChangeListener(PropertyChangeListener listener) {
        listenerList.addPropertyChangeListener(listener);
    }
    
    public void removePropertyChangeListener(PropertyChangeListener listener) {
        listenerList.removePropertyChangeListener(listener);
    }
    
    public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
        listenerList.addPropertyChangeListener(propertyName, listener);
    }
    
    public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
        listenerList.removePropertyChangeListener(propertyName, listener);
    }

    public long getNumberFrame() {
        return numberFrame;
    }

    public ReceivedData getLastReceivedData() {
        return vecRawData.lastElement();
    }
    
    public Frame getLastDecodedData() {
        return vecDecodedData.lastElement();
    }



    @Deprecated
    public void addFrame(int size, byte[] data) {
//        long oldNumberFrame = numberFrame;
//        numberFrame++;
//        try {
//            // try to decode 
//            FrameTlmEntrySat frame = new FrameTlmEntrySat(new ByteBufferKaitaiStream (cbuf) );
//            Ax25Frame ax = frame.frameTlmEntrySat();
//         //   System.out.println(ax.ax25Header().srcCallsignRaw().srcCallsignRor().srcCallsign());
//            vect.addElement(frame);
//            EntryFrame EntryFrame = new EntryFrame(new Date(), new KissData(cbuf, nb));
//            vecKiss.addElement(EntryFrame);
//
//            
//        } catch (Exception e)
//        {
//            e.printStackTrace();
//        }
        
    }

    public void addFrame(byte[] received) {
        long oldNumberFrame = numberFrame;
        numberFrame++;
        vecRawData.add(new ReceivedData(new Date(),received));
        Frame framereceived =  ff.getFrame(received);
        vecDecodedData.add(framereceived);
        listenerList.firePropertyChange("numberFrame", oldNumberFrame, numberFrame);
        
    }



}
