Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GUI aktualizovan pred novym zadanim #20

Merged
merged 8 commits into from
Feb 9, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
/fw/canshark/*.layout
*.o
*.d
/sw/canshark-gui/bin/Debug
/sw/canshark-gui/obj/Debug
16 changes: 8 additions & 8 deletions dissector/canshark.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- Author: Frantisek Burian <[email protected]>

canshark_proto = Proto("canshark", "bxCAN")
canshark_proto = Proto("canshark", "CAN")

local bit = require("bit");
local band, rshift, tobit, tohex = bit.band, bit.rshift, bit.tobit, bit.tohex
Expand Down Expand Up @@ -33,7 +33,7 @@ f.data = ProtoField.bytes("canshark.datas", "Data")
f.port = ProtoField.uint8("canshark.port", "Port", base.DEC, vs_port, 0x07)
f.dir = ProtoField.uint8("canshark.dir", "Direction", base.DEC, vs_dir, 0x08)
f.mbox = ProtoField.uint8("canshark.mbox", "Mailbox", base.DEC, nil, 0xF0)
f.delay = ProtoField.uint16("canshark.delay", "Delay", base.HEX)
f.timestamp = ProtoField.uint16("canshark.timestamp", "Time", base.HEX)


-------------------------
Expand All @@ -50,14 +50,14 @@ function canshark_proto.dissector(buffer, pinfo, tree)
local peripheral = buffer(5, 1)
local timestamp = buffer(6, 2)
local datas = buffer(8, len:uint())

local addr = {};
addr.ide = rshift(band(mobid:uint(), tobit(0x80000000)), 31)
addr.rtr = rshift(band(mobid:uint(), tobit(0x40000000)), 30)
addr.err = rshift(band(mobid:uint(), tobit(0x20000000)), 29)
addr.std = rshift(band(mobid:uint(), tobit(0x1FFC0000)), 18)
addr.ext = rshift(band(mobid:uint(), tobit(0x0003FFFF)), 0)

local dir = rshift(band(peripheral:uint(), 0x08), 3)
local periph = rshift(band(peripheral:uint(), 0x07), 0)

Expand All @@ -66,17 +66,17 @@ function canshark_proto.dissector(buffer, pinfo, tree)
else
addr.str = tohex(addr.std, 3)
end

t = tree:add(canshark_proto, vs_port[periph] .. "(".. vs_dir[dir] ..")".." COB-ID="..addr.str, buffer())
if len:uint() > 0 then
tree:append_text(" data="..tostring(datas))
end

t:add(f.port, peripheral)
t:add(f.dir, peripheral)
t:add(f.mbox, peripheral)
t:add(f.delay, timestamp)
t:add_le(f.timestamp, timestamp)

if addr.err == 0 then
q = t:add(f.mobid, addr.str)
q:add(f.mobid_ide, mobid)
Expand Down
6 changes: 3 additions & 3 deletions fw/canshark/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ void sys_tick_handler(void)
stick_update();

canopen_sync(CAN1);
canopen_sync(CAN2);
//canopen_sync(CAN2);

uint64_t ticks = stick_get();
can_transmit(CAN1, CAN_ID_STDID(0x100), (uint8_t*)&ticks, 8);
//uint64_t ticks = stick_get();
//can_transmit(CAN2, CAN_ID_STDID(0x100), (uint8_t*)&ticks, 8);
}

uint64_t arp_tmr;
Expand Down
2 changes: 1 addition & 1 deletion fw/canshark/src/modcan.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void modcan_init(void)
can_leave_sleep_mode(CAN2);

struct can_timing ct;
can_timing_init(&ct, CAN_FREQ_1M, CAN_SAMPLE_75);
can_timing_init(&ct, CAN_FREQ_500K, CAN_SAMPLE_75);

//uint32_t canfreq = can_timing_getfreq(&ct);

Expand Down
10 changes: 5 additions & 5 deletions fw/canshark/src/stick.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ uint64_t stick_get(void)
uint64_t stick_get_us(void)
{
CM_ATOMIC_CONTEXT();
uint32_t rld = systick_get_reload() + 1;

uint32_t ss = systick_get_value() >> 8;
uint64_t t = ticks * 65536; // ms->us
uint64_t ss = (rld-systick_get_value()) * 1000 / rld;

if (nvic_get_pending_irq(NVIC_SYSTICK_IRQ) && (ss < 0x7FFFFF)) {
if (nvic_get_pending_irq(NVIC_SYSTICK_IRQ) && (ss < 500)) {
// overflow between atomic and get value?
t += 65536;
ss += 1000;
}

return t + ss;
return ticks * 1000 + ss;
}

void stick_prepare(uint64_t *when, const uint64_t period)
Expand Down
7 changes: 4 additions & 3 deletions sw/canshark-console/CanMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ public static CanMessage DeserializeFrom(BinaryReader br)
br.ReadByte(); /* zero */
byte[] by = br.ReadBytes(8);
msg.Data = new byte[br.ReadByte()];
Array.Copy(by,msg.Data, msg.Data.Length);
Array.Copy(by, msg.Data, msg.Data.Length);

br.ReadBytes(7); /* PAD */
UInt64 ticks = br.ReadUInt64();

msg.Sec = (UInt32)(long)(ticks / (1000 * 65536));
msg.Usec = (UInt32)((long)(ticks % (1000 * 65536)) * 1000 / 65536);
msg.Sec = (UInt32)(long)(ticks / (1000 * 1000));
msg.Usec = (UInt32)((long)(ticks % (1000 * 1000)));

return msg;
}
Expand Down
2 changes: 1 addition & 1 deletion sw/canshark-console/Wireshark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class WiresharkPipe : IDisposable
public const uint DLT_USER0 = 147;

private NamedPipeServerStream _pipe;
static BinaryWriter _bw;
private BinaryWriter _bw;

public WiresharkPipe()
{
Expand Down
82 changes: 82 additions & 0 deletions sw/canshark-gui/Analysis/CanopenCycle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace canshark.Analysis
{
class CanopenMsg
{
public UInt32 COB;
public string COBstr;
public string data;
public UInt32 count;
public double delay;
public double length;
public bool dir;
}

class CanopenCycle
{
private List<CanopenMsg> _temp = new List<CanopenMsg>();

public CanopenMsg[] GetCycleSnapshot()
{
lock (_temp)
return _temp.ToArray();
}

private UInt16 synctime = 0;
private UInt16 oldsynctime = 0;

public int TimeDiff(UInt16 old, UInt16 time1)
{
if (time1 >= old)
return time1 - old;
else
return time1 + 0x10000 - old;
}

public float SyncPeriod { get { return TimeDiff(oldsynctime, synctime) / 1000.0f; } }

public void Analyze(CanMessage m)
{
if (m.GetStdId() == 0x80) // std ID 0x80 = SYNC
{
oldsynctime = synctime;
synctime = m.Time;
}
else
if (_temp.Count == 0) // make the cycle entire from the beginning
return;

CanopenMsg msg = GetOrNew(m.COB);
msg.data = BitConverter.ToString(m.Data);
msg.count++;
msg.delay = TimeDiff(synctime, m.Time) / 1000.0f;
msg.length = m.GetMinFrameLength() / 1000.0f;
msg.dir = ((m.Source & 0x08) != 0);
}

private CanopenMsg GetOrNew(UInt32 ID)
{
lock (_temp)
{
foreach (var p in _temp)
if (p.COB == ID)
return p;

// notfound
CanopenMsg msg = new CanopenMsg();
msg.COB = ID;
msg.COBstr = CanMessage.GetAddrString(ID);
msg.count = 0;
msg.delay = 0;
_temp.Add(msg);
return msg;
}
}

}
}
File renamed without changes.
Loading