public object[] TryCallFunction(string name, params object[] parameters) { if (!Running) { return(null); } try { return(LuaHelpers.CallFunction(_LuaVm, name, parameters)); } catch (Exception ex) { } return(null); }
public object[] CallFunction(string name, params object[] parameters) { if (!Running || name == null || name == "") { return(null); } try { return(LuaHelpers.CallFunction(LuaVm, name, parameters)); } catch (Exception ex) { Running = false; Log.AddMessage("Failed to call " + name + " (Reason: " + ex.Message + "). Stopping."); } return(null); }
public void Handle(GSMParameters param, NormalBurst source, L3Handler l3, byte[] l2Data, int startOffset) { if (param.PacketDumper != null) { param.PacketDumper.WriteL2Data(l2Data); } Builder.Length = 0; /* BCCH and CCCH packets have pseudo L2 headers (GSM 04.07 11.3.1) */ if (source.GetType() == typeof(BCCHBurst) || source.GetType() == typeof(CCCHBurst)) { Builder.Append("Pseudo L2 Header").Append(Environment.NewLine); if (source.ChannelEncrypted) { Builder.Append("======= encrypted =======").Append(Environment.NewLine); } /* call LUA script */ if (param.LuaVm != null) { LuaHelpers.CallFunction(param.LuaVm, "L2DataReceived", true, source, null, param); } /* pass to L3 handler if not empty and skip pseudo length */ if (!PacketIsEmpty(l2Data, 1)) { l3.Handle(l2Data, 1, param); } } else { /* always show empty/multiframe messages if requested */ ShowMessage = ShowAllMessages; /* show if encrypted */ if (source.ChannelEncrypted) { ShowMessage |= ShowCryptedMessages; Builder.Append("======= encrypted =======").Append(Environment.NewLine); } L2Data.Payload = l2Data; L2Data.StartOffset = startOffset; /* call LUA script */ if (param.LuaVm != null) { LuaHelpers.CallFunction(param.LuaVm, "L2DataReceived", true, source, L2Data, param); } if (L3Handler.ExceptFieldsEnabled || ShowMessage) { Builder.Append("SAPI: ").Append(L2Data.SAPI).Append(" C/R: ").Append((L2Data.CR ? "1" : "0")).Append(" EA: ").Append((L2Data.EA ? "1" : "0")).Append(" "); Builder.Append("M: ").Append((L2Data.M ? "1" : "0")).Append(" "); Builder.Append("EL: ").Append((L2Data.EL ? "1" : "0")).Append(" "); Builder.Append("L: ").Append(L2Data.Length).Append(" "); switch (L2Data.FrameFormat) { case eFrameFormat.S_Format: Builder.Append("S Format, N(R)=").Append(L2Data.NR).Append(" S=").Append(L2Data.S).Append(" ").Append((eSupervisory)L2Data.S); break; case eFrameFormat.U_Format: Builder.Append("U Format, U=").Append(L2Data.U).Append(" ").Append((eUnnumbered)L2Data.U); break; case eFrameFormat.I_Format: Builder.Append("I Format, N(R)=").Append(L2Data.NR).Append(" N(S)=").Append(L2Data.NS).Append(" "); break; } } /* check if there is enough space in the buffer */ if (L2Data.Length + packetBufferOffset <= packetBuffer.Length && L2Data.Length + L2Data.DataStart <= L2Data.Payload.Length) { /* dont buffer when its the same frame number (retransmission) */ if (!L2Data.M || LastNS < L2Data.NS) { Array.Copy(L2Data.Payload, L2Data.DataStart, packetBuffer, packetBufferOffset, L2Data.Length); packetBufferOffset += L2Data.Length; LastNS = L2Data.NS; } else { if (L3Handler.ExceptFieldsEnabled || ShowMessage) { Builder.Append("!! Retransmission !! "); } } } else { if (DumpFaulty) { Builder.Append("Faulty length?! Length = ").Append((packetBufferOffset + L2Data.Length)).Append(Environment.NewLine); Builder.Append("Raw L2 data").Append(Environment.NewLine); Builder.Append(" ").Append(DumpBytes(l2Data)).Append(Environment.NewLine); ShowMessage = true; } } /* that counter is just for convinience */ NumPackets++; /* when reached the last packet, pass it to L3 handler */ if (!L2Data.M) { if (L3Handler.ExceptFieldsEnabled || ShowMessage) { if (NumPackets > 1) { Builder.Append("(packet ").Append(NumPackets).Append(", total ").Append(packetBufferOffset).Append(" bytes)").Append(Environment.NewLine); } else { Builder.Append(Environment.NewLine); } } /* but only pass it through when there is any data */ if (packetBufferOffset > 0) { /* allocate a new array with the correct size */ byte[] buf = new byte[packetBufferOffset]; Array.Copy(packetBuffer, buf, buf.Length); if (!PacketIsEmpty(buf)) { l3.Handle(buf, 0, param); } } /* reset the buffer etc */ packetBufferOffset = 0; for (int pos = 0; pos < packetBuffer.Length; pos++) { packetBuffer[pos] = 0xCC; } NumPackets = 0; LastNS = -1; } else if (L3Handler.ExceptFieldsEnabled || ShowMessage) { Builder.Append("(packet ").Append(NumPackets).Append(")").Append(Environment.NewLine); } } if (DumpRawData && (L3Handler.ExceptFieldsEnabled || ShowMessage)) { Builder.Append("Raw L2 data").Append(Environment.NewLine); Builder.Append(" ").Append(DumpBytes(l2Data)).Append(Environment.NewLine); } StatusMessage = Builder.ToString(); }