public int getCount(canMessage cm)
        {
            messageState ms = (messageState)incommingMessages[cm.getIdent()];

            if (ms == null) return 0;
            return ms.count;
        }
Beispiel #2
0
        public addMessage(main m, canMessage cmEdit)
        {
            InitializeComponent();
            idBoxes[0] = txt_id0;
            idBoxes[1] = txt_id1;
            idBoxes[2] = txt_id2;
            idBoxes[3] = txt_id3;

            dataBoxes[0] = txt_d0;
            dataBoxes[1] = txt_d1;
            dataBoxes[2] = txt_d2;
            dataBoxes[3] = txt_d3;
            dataBoxes[4] = txt_d4;
            dataBoxes[5] = txt_d5;
            dataBoxes[6] = txt_d6;
            dataBoxes[7] = txt_d7;

            this.m = m;
            this.cmEdit = cmEdit;
            if (cmEdit != null)
            {
                cmd_add.Text = "Save";
                this.Text = "Edit message";
                loadCm(cmEdit);
            }
            else if(m.addLastCm!=null)
            {
                loadCm(m.addLastCm);
                txt_period.Text = "1000";
            }
        }
        public DateTime getTime(canMessage cm)
        {
            messageState ms = (messageState)outgoingMessages[cm];

            if (ms == null) return new DateTime();
            return ms.timestamp;
        }
        public DateTime getTime(canMessage cm)
        {
            messageState ms = (messageState)incommingMessages[cm.getIdent()];

            if (ms == null) return new DateTime();
            return ms.timestamp;
        }
        public void flagAsSent(canMessage cm)
        {
            messageState ms = (messageState)outgoingMessages[cm];
            if (ms == null) return;

            ms.flagAsSent();
        }
 public dataHistoryViewer(main m, canMessage cm)
 {
     InitializeComponent();
     this.cm = cm;
     this.m = m;
     lab_status.Text = "Last 0 data for "+cm.getIdent().ToString("X").PadLeft(8,'0')+"h";
     this.Text = cm.getIdent().ToString("X").PadLeft(8, '0') + "h history";
 }
Beispiel #7
0
        public void createHistory(canMessage cm)
        {
            identHistory ih = (identHistory)allIdents[cm.getIdent()];
            if (ih == null) ih = new identHistory(cm.getIdent());

            ih.addData(cm);
            allIdents[cm.getIdent()] = ih;
        }
 private void stamp(canMessage cm)
 {
     messageState ms = (messageState)incommingMessages[cm.getIdent()];
     if (ms == null)
     {
         ms = new messageState();
     }
     ms.stamp();
     incommingMessages[cm.getIdent()] = ms;
 }
Beispiel #9
0
 private void loadCm(canMessage cmEdit)
 {
     chk_extended.Checked = cmEdit.getExtended();
     chk_remote_request.Checked = cmEdit.getRemoteRequest();
     txt_period.Text = m.mtOut.getPeriod(cmEdit).ToString();
     uint ident = cmEdit.getIdent();
     data_length.Value = cmEdit.getDataLength();
     byte[] data = cmEdit.getData();
     for (int i = 0; i < 4; i++)
     {
         uint er = (ident >> (8 * i));
         byte b = ((byte)(er&0x000000FF));
         idBoxes[i].Text = b.ToString("X").PadLeft(2, '0');
     }
     for (int i = 0; i < 8; i++) dataBoxes[i].Text = data[i].ToString("X").PadLeft(2, '0');
 }
Beispiel #10
0
 public long getPeriod(canMessage cm)
 {
     messageState ms = (messageState)incommingMessages[cm.getIdent()];
     if (ms == null) return 0;
     return ms.period;
 }
Beispiel #11
0
 internal void addMessage(canMessage newcm)
 {
     lst_raw_log.BeginUpdate();
     if (doLog) lst_raw_log.Items.Insert(1, newcm);
     lst_raw_log.EndUpdate();
 }
Beispiel #12
0
 public void addMessage(canMessage cm)
 {
     allMessages[cm.getIdent()] = cm;
     stamp(cm);
 }
Beispiel #13
0
 public bool timeToSend(canMessage cm)
 {
     messageState ms = (messageState)outgoingMessages[cm];
     if (ms == null) return false;
     return (Environment.TickCount > ms.nextTimeToSend);
 }
 public bool sendMessage(canMessage cm)
 {
     if (serial_conn.IsOpen)
     {
         byte[] b = new byte[PACKET_LENGTH];
         b[0] = UART_START_BYTE;
         Array.Copy(cm.getRaw(), 0, b, 1, PACKET_LENGTH-2);
         b[PACKET_LENGTH-1] = UART_END_BYTE;
         serial_conn.Write(b, 0, PACKET_LENGTH);
         return true;
     }
     return false;
 }
Beispiel #15
0
 public long getPeriod(canMessage cm)
 {
     messageState ms = (messageState)outgoingMessages[cm];
     if (ms == null) return 0;
     return ms.period;
 }
Beispiel #16
0
        private void cmd_add_Click(object sender, EventArgs e)
        {
            byte[] id = new byte[4];
            byte[] data = new byte[8];
            long period = 0;

            if (checkID(out id) && checkData(out data) && checkPeriod(out period))
            {
                // Add message
                canMessage cm = new canMessage(BitConverter.ToUInt32(id,0),chk_extended.Checked,chk_remote_request.Checked,(byte)data_length.Value,data);
                if (cmEdit != null) m.mtOut.deleteMessage(cmEdit);
                if (cmEdit == null) m.addLastCm = cm.clone();
                m.mtOut.addMessage(cm, period);
                m.refreshOutgoing();
                this.Close();
            }
        }
Beispiel #17
0
 public void deleteMessage(canMessage cm)
 {
     outgoingMessages.Remove(cm);
 }
Beispiel #18
0
 public void addMessage(canMessage cm, long period)
 {
     outgoingMessages[cm] = new messageState(period);
 }
        private void serial_conn_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
        {
            System.IO.Ports.SerialPort port = (System.IO.Ports.SerialPort)sender;
            byte[] data = new byte[port.BytesToRead];

            int bytesToRead = port.BytesToRead;

            // Fyll på array hela tiden i slutet.
            port.Read(data, 0, data.Length);
            Array.Copy(data, 0, iBuff, iBuffPointer, data.Length);
            iBuffPointer += bytesToRead;

            // När array större eller lika med PACKET_LENGTH...
            while (iBuffPointer >= PACKET_LENGTH)
            {
                int startIndex = 0;

                // Sök igenom efter start byte från början.
                for (int i = 0; i < iBuffPointer; i++)
                {
                    // Poppa alla bytes som inte är startbyte.
                    if (iBuff[i] != UART_START_BYTE) startIndex++;
                    else
                    {
                        // När startbyte hittas, kolla om återstående längd är större eller lika med PACKET_LENGTH (inkl startbyte)
                        if ((iBuffPointer - startIndex) >= PACKET_LENGTH)
                        {
                            //om så, kolla PACKET_LENGTH-1 byte fram.
                            if (iBuff[startIndex + PACKET_LENGTH-1] == UART_END_BYTE)
                            {
                                // Om byte PACKET_LENGTH-1 är slutbyte så extraktas startIndex till slutbyteindex.
                                canMessage cm = new canMessage(iBuff, startIndex + 1);
                                cmQueue.Enqueue(cm);

                                newIncommingCanMessage.Invoke(this, EventArgs.Empty);

                                // Sätt ny startindex och avsluta loop.
                                startIndex += PACKET_LENGTH;
                                break;
                            }
                        }
                    }
                }
                // och i slutet göra en array copy.
                // Flytta ner allt efter slutbyte till index 0 i array.
                Array.Copy(iBuff, startIndex, iBuff, 0, iBuffPointer - PACKET_LENGTH);
                iBuffPointer -= startIndex;
            }
        }
Beispiel #20
0
 public void addData(canMessage cm)
 {
     lst.AddLast(new dataStamp(cm.getData(),cm.getDataLength()));
        while(lst.Count>MAX_LOG) lst.RemoveFirst();
 }
Beispiel #21
0
 public int getCount(canMessage cm)
 {
     messageState ms = (messageState)outgoingMessages[cm];
     if (ms == null) return 0;
     return ms.count;
 }