public int Send(byte[] buffer, int offset, int dataLength, BacnetAddress address, bool waitForTransmission, int timeout) { var frameType = BacnetPtpFrameTypes.FRAME_TYPE_DATA0; if (_sequenceCounter) { frameType = BacnetPtpFrameTypes.FRAME_TYPE_DATA1; } _sequenceCounter = !_sequenceCounter; //add header var fullLength = PTP.Encode(buffer, offset - PTP.PTP_HEADER_LENGTH, frameType, dataLength); //wait for send allowed if (!_maySend.WaitOne(timeout)) { return(-BacnetMstpProtocolTransport.ETIMEDOUT); } //debug if (StateLogging) { Trace.WriteLine($" {frameType}", null); } //send SendWithXonXoff(buffer, offset - HeaderLength, fullLength); return(dataLength); }
public override int Send(byte[] buffer, int offset, int dataLength, BacnetAddress address, bool waitForTransmission, int timeout) { var frameType = BacnetPtpFrameTypes.FRAME_TYPE_DATA0; if (_sequenceCounter) { frameType = BacnetPtpFrameTypes.FRAME_TYPE_DATA1; } _sequenceCounter = !_sequenceCounter; //add header var fullLength = PTP.Encode(buffer, offset - PTP.PTP_HEADER_LENGTH, frameType, dataLength); //wait for send allowed if (!_maySend.WaitOne(timeout)) { return(-BacnetMstpProtocolTransport.ETIMEDOUT); } Log.AddCustomEvent(LagoVista.Core.PlatformSupport.LogLevel.Message, "BacnetPtpProtocol", frameType.ToString()); //send SendWithXonXoff(buffer, offset - HeaderLength, fullLength); return(dataLength); }
private void Test() { string dir = @""; var enc = new PersonaEditorLib.PersonaEncoding(@""); string[] files = Directory.GetFiles(dir, "*.*", SearchOption.AllDirectories); foreach (var file in files) { if (new FileInfo(file).Length > 100000000) { continue; } var temp = PersonaEditorLib.GameFormatHelper.OpenFile(Path.GetFileName(file), File.ReadAllBytes(file)); if (temp != null) { foreach (var a in temp.GetAllObjectFiles(PersonaEditorLib.FormatEnum.BMD)) { var bmd = a.GameData as BMD; var ptp = new PTP(bmd); string newPath = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(a.Name.Replace('/', '+')) + ".txt"); File.WriteAllLines(newPath, ptp.ExportTXT(true, enc)); } } } }
public PTPEditorVM(PTP ptp) { int sourceInd = Static.EncodingManager.GetPersonaEncodingIndex(ApplicationSettings.AppSetting.Default.PTPOldDefault); if (sourceInd >= 0) { OldEncoding = sourceInd; } else { OldEncoding = 0; } sourceInd = Static.EncodingManager.GetPersonaEncodingIndex(ApplicationSettings.AppSetting.Default.PTPNewDefault); if (sourceInd >= 0) { NewEncoding = sourceInd; } else { NewEncoding = 0; } sourceInd = Static.BackManager.GetBackgroundIndex(ApplicationSettings.AppSetting.Default.PTPBackgroundDefault); if (sourceInd >= 0) { SelectedBackgroundIndex = sourceInd; } else { SelectedBackgroundIndex = 0; } View = ApplicationSettings.AppSetting.Default.PTPImageView; EncodingManagerEW = new EventWrapperINPC(Static.EncodingManager, this); foreach (var a in ptp.Names) { Names.Add(new PTPNameEditVM(a, OldEncoding, NewEncoding, SelectedBackgroundIndex)); } foreach (var a in ptp.Msg) { var name = Names.FirstOrDefault(x => x.Index == a.CharacterIndex); Tuple <ImageDrawing, ImageDrawing, ImageDrawing, RectangleGeometry> tuple; if (name == null) { tuple = new Tuple <ImageDrawing, ImageDrawing, ImageDrawing, RectangleGeometry>(null, null, BackgroundDrawing, ClipGeometry); } else { tuple = new Tuple <ImageDrawing, ImageDrawing, ImageDrawing, RectangleGeometry>(name.OldNameVisual.TextDrawing, name.NewNameVisual.TextDrawing, BackgroundDrawing, ClipGeometry); } MSG.Add(new PTPMsgVM(a, tuple, ApplicationSettings.AppSetting.Default.PTPOldDefault, ApplicationSettings.AppSetting.Default.PTPNewDefault, SelectedBackgroundIndex)); } }
public static void SavePTPFile(GameFile objectFile, string path, PersonaEncoding oldEncoding = null) { if (objectFile.GameData is BMD bmd) { PTP PTP = new PTP(bmd); if (oldEncoding != null) { PTP.CopyOld2New(oldEncoding); } File.WriteAllBytes(path, PTP.GetData()); } }
static void ExportPTP(GameFile objectFile, string value, string openedFileDir, Parameters parameters) { if (objectFile.GameData is BMD bmd) { string path = Path.Combine(openedFileDir, Path.GetFileNameWithoutExtension(objectFile.Name.Replace('/', '+')) + ".PTP"); PTP PTP = new PTP(bmd); if (parameters.CopyOld2New) { PTP.CopyOld2New(Static.OldEncoding()); } File.WriteAllBytes(path, PTP.GetData()); } }
static void ImportPTP(GameFile objectFile, string value, string openedFileDir, Parameters parameters) { if (objectFile.GameData is BMD bmd) { string path = Path.Combine(openedFileDir, Path.GetFileNameWithoutExtension(objectFile.Name.Replace('/', '+')) + ".PTP"); if (File.Exists(path)) { PTP PTP = new PTP(File.ReadAllBytes(path)); var temp = new BMD(PTP, Static.NewEncoding()); temp.IsLittleEndian = bmd.IsLittleEndian; objectFile.GameData = temp; } } }
public static void FindIncorrectString(string PTPdir, string txtFile) { string temp = PTPdir; byte[] searchArray = new byte[] { 0xF1, 0x25 }; string[] Files = Directory.GetFiles(temp, "*.ptp", SearchOption.AllDirectories); List <string> returned = new List <string>(); string DIRtemp = ""; foreach (var file in Files) { PTP PTP = null; try { PTP = new PTP(File.ReadAllBytes(file)); } catch { continue; } foreach (var msg in PTP.Msg) { foreach (var str in msg.Strings) { var tempPrefix = str.Prefix.FirstOrDefault(x => x.Data.SequenceEqual(searchArray)); if (tempPrefix.Data != null) { string DIR = IOTools.RelativePath(Path.GetDirectoryName(file), temp); if (DIRtemp != DIR) { DIRtemp = DIR; returned.Add(""); } string FILE = Path.GetFileName(file); string MSGINDEX = msg.Index.ToString(); string STRINGINDEX = str.Index.ToString(); returned.Add($"{DIR}\t{FILE}\t{MSGINDEX}\t{STRINGINDEX}\t{str.OldString.GetString(Static.OldEncoding(), false).Replace('\n', ' ')}"); } } } } File.WriteAllLines(txtFile, returned); }
private void SendFrame(BacnetPtpFrameTypes frameType, byte[] buffer = null, int msgLength = 0) { if (_port == null) { return; } var fullLength = PTP.PTP_HEADER_LENGTH + msgLength + (msgLength > 0 ? 2 : 0); if (buffer == null) { buffer = new byte[fullLength]; } PTP.Encode(buffer, 0, frameType, msgLength); Log.AddCustomEvent(LagoVista.Core.PlatformSupport.LogLevel.Message, "BacnetPtpProtocol", frameType.ToString()); //send SendWithXonXoff(buffer, 0, fullLength); }
private void SendFrame(BacnetPtpFrameTypes frameType, byte[] buffer = null, int msgLength = 0) { if (_port == null) { return; } var fullLength = PTP.PTP_HEADER_LENGTH + msgLength + (msgLength > 0 ? 2 : 0); if (buffer == null) { buffer = new byte[fullLength]; } PTP.Encode(buffer, 0, frameType, msgLength); Log.Debug(frameType); //send SendWithXonXoff(buffer, 0, fullLength); }
static void Test(string[] args) { string testPath = @"d:\Persona 5\DATA_PS3_JAP\"; var par = new Parameters(new string[][] { new string[] { "/sub" } }); var files = Directory.EnumerateFiles(testPath, "*.*", SearchOption.AllDirectories).ToArray(); int index = 0; foreach (var filePath in files) { Console.Write($"{index++}/{files.Length}\r"); var OpenedFileDir = Path.GetDirectoryName(filePath); if (new FileInfo(filePath).Length > 10000000) { continue; } GameFile file = GameFormatHelper.OpenFile(Path.GetFileName(filePath), File.ReadAllBytes(filePath)); if (file != null) { SubFileAction((a, b, c, d) => { try { if (a.GameData is BMD bmd) { PTP ptp = new PTP(bmd); var newName = a.Name.Replace('/', '+'); string path = Path.Combine(c, Path.GetFileNameWithoutExtension(newName) + ".TXT"); var exp = ptp.ExportTXT(true, Static.OldEncoding()); File.WriteAllLines(path, exp); } } catch { } }, file, "", OpenedFileDir, par); } } }
private void SendFrame(BacnetPtpFrameTypes frame_type, byte[] buffer = null, int msg_length = 0) { if (m_port == null) { return; } int full_length = PTP.PTP_HEADER_LENGTH + msg_length + (msg_length > 0 ? 2 : 0); if (buffer == null) { buffer = new byte[full_length]; } PTP.Encode(buffer, 0, frame_type, msg_length); //debug if (StateLogging) { Trace.WriteLine(" " + frame_type, null); } //send SendWithXonXoff(buffer, 0, full_length); }
public static void OpenPTPFile(GameFile objectFile, string path, PersonaEncoding newEncoding) { if (objectFile == null) { throw new System.ArgumentNullException(nameof(objectFile)); } if (path == null) { throw new System.ArgumentNullException(nameof(path)); } if (newEncoding == null) { return; } if (objectFile.GameData is BMD bmd) { if (File.Exists(path)) { PTP PTP = new PTP(File.ReadAllBytes(path)); objectFile.GameData = new BMD(PTP, newEncoding); } } }
private BacnetMstpProtocolTransport.GetMessageStatus GetNextMessage(byte[] buffer, ref int offset, int timeoutMs, out BacnetPtpFrameTypes frameType, out int msgLength) { BacnetMstpProtocolTransport.GetMessageStatus status; var timeout = timeoutMs; frameType = BacnetPtpFrameTypes.FRAME_TYPE_HEARTBEAT_XOFF; msgLength = 0; var complimentNext = false; //fetch header while (offset < PTP.PTP_HEADER_LENGTH) { if (_port == null) { return(BacnetMstpProtocolTransport.GetMessageStatus.ConnectionClose); } timeout = offset > 0 ? T_FRAME_ABORT : timeoutMs; //read var rx = _port.Read(buffer, offset, PTP.PTP_HEADER_LENGTH - offset, timeout); status = ProcessRxStatus(buffer, ref offset, rx); if (status != BacnetMstpProtocolTransport.GetMessageStatus.Good) { return(status); } //remove XON/XOFF var newOffset = offset + rx; RemoveXonOff(buffer, offset, ref newOffset, ref complimentNext); offset = newOffset; //remove garbage RemoveGarbage(buffer, ref offset); } //greeting if (IsGreeting(buffer, 0, offset)) { //get last byte var rx = _port.Read(buffer, offset, 1, timeout); status = ProcessRxStatus(buffer, ref offset, rx); if (status != BacnetMstpProtocolTransport.GetMessageStatus.Good) { return(status); } offset += 1; if (IsGreeting(buffer, 0, offset)) { frameType = BacnetPtpFrameTypes.FRAME_TYPE_GREETING; if (StateLogging) { Trace.WriteLine(frameType, null); } return(BacnetMstpProtocolTransport.GetMessageStatus.Good); } //drop message buffer[0] = 0xFF; RemoveGarbage(buffer, ref offset); return(BacnetMstpProtocolTransport.GetMessageStatus.DecodeError); } //decode if (PTP.Decode(buffer, 0, offset, out frameType, out msgLength) < 0) { //drop message buffer[0] = 0xFF; RemoveGarbage(buffer, ref offset); return(BacnetMstpProtocolTransport.GetMessageStatus.DecodeError); } //valid length? var full_msg_length = msgLength + PTP.PTP_HEADER_LENGTH + (msgLength > 0 ? 2 : 0); if (msgLength > MaxBufferLength) { //drop message buffer[0] = 0xFF; RemoveGarbage(buffer, ref offset); return(BacnetMstpProtocolTransport.GetMessageStatus.DecodeError); } //fetch data if (msgLength > 0) { timeout = T_FRAME_ABORT; //set sub timeout while (offset < full_msg_length) { //read var rx = _port.Read(buffer, offset, full_msg_length - offset, timeout); status = ProcessRxStatus(buffer, ref offset, rx); if (status != BacnetMstpProtocolTransport.GetMessageStatus.Good) { return(status); } //remove XON/XOFF var newOffset = offset + rx; RemoveXonOff(buffer, offset, ref newOffset, ref complimentNext); offset = newOffset; } //verify data crc if (PTP.Decode(buffer, 0, offset, out frameType, out msgLength) < 0) { //drop message buffer[0] = 0xFF; RemoveGarbage(buffer, ref offset); return(BacnetMstpProtocolTransport.GetMessageStatus.DecodeError); } } //debug if (StateLogging) { Trace.WriteLine(frameType, null); } //done return(BacnetMstpProtocolTransport.GetMessageStatus.Good); }
public static void Test1() { var symbols = new E6Pos().Parse(new Dictionary <string, object>() { { "file", "" }, { "line", 0 }, { "column", 0 }, { "text", "DECL E6POS XP1={X -132.307266,Y -427.616180,Z 1162.82056,A 95.0179,B -1.98647153,C 1.45468986,S 6,T 50,E1 0.0,E2 0.0,E3 0.0,E4 0.0,E5 0.0,E6 0.0}" } }); Debug.Assert(symbols != null); symbols = new FDAT().Parse(new Dictionary <string, object>() { { "file", "" }, { "line", 0 }, { "column", 0 }, { "text", "DECL FDAT FP1={TOOL_NO 1,BASE_NO 0,IPO_FRAME #BASE,POINT2[] \" \",TQ_STATE FALSE}" } }); Debug.Assert(symbols != null); symbols = new PDAT().Parse(new Dictionary <string, object>() { { "file", "" }, { "line", 0 }, { "column", 0 }, { "text", "DECL PDAT PPDAT3={VEL 100.000,ACC 100.000,APO_DIST 100.000,APO_MODE #CDIS,GEAR_JERK 50.0000,EXAX_IGN 0}" } }); Debug.Assert(symbols != null); symbols = new LDAT().Parse(new Dictionary <string, object>() { { "file", "" }, { "line", 0 }, { "column", 0 }, { "text", "DECL LDAT LCPDAT14={VEL 2.00000,ACC 100.000,APO_DIST 100.000,APO_FAC 50.0000,AXIS_VEL 100.000,AXIS_ACC 100.000,ORI_TYP #VAR,CIRC_TYP #BASE,JERK_FAC 50.0000,GEAR_JERK 50.0000,EXAX_IGN 0}" } }); Debug.Assert(symbols != null); symbols = new SetFDAT().Parse(new Dictionary <string, object>() { { "file", "" }, { "line", 0 }, { "column", 0 }, { "text", "FDAT_ACT=FP38" } }); Debug.Assert(symbols != null); symbols = new SetPDAT().Parse(new Dictionary <string, object>() { { "file", "" }, { "line", 0 }, { "column", 0 }, { "text", "PDAT_ACT=PPDAT36" } }); Debug.Assert(symbols != null); symbols = new SetLDAT().Parse(new Dictionary <string, object>() { { "file", "" }, { "line", 0 }, { "column", 0 }, { "text", "LDAT_ACT=LCPDAT14" } }); Debug.Assert(symbols != null); symbols = new SetPTPParams().Parse(new Dictionary <string, object>() { { "file", "" }, { "line", 0 }, { "column", 0 }, { "text", "BAS(#PTP_PARAMS,30)" } }); Debug.Assert(symbols != null); symbols = new SetCPParams().Parse(new Dictionary <string, object>() { { "file", "" }, { "line", 0 }, { "column", 0 }, { "text", "BAS(#CP_PARAMS,0.2)" } }); Debug.Assert(symbols != null); symbols = new PTP().Parse(new Dictionary <string, object>() { { "file", "" }, { "line", 0 }, { "column", 0 }, { "text", "PTP XP40 C_DIS" } }); Debug.Assert(symbols != null); symbols = new LIN().Parse(new Dictionary <string, object>() { { "file", "" }, { "line", 0 }, { "column", 0 }, { "text", "LIN XP40 C_DIS" } }); Debug.Assert(symbols != null); }
public ObservableVariable() { PTP = new PTP(OldCharList, NewCharList); }