From 28a2732bbee7adb6a71782e1ea3015f2a9064283 Mon Sep 17 00:00:00 2001 From: Tomoki Date: Thu, 1 Dec 2022 14:47:36 +0900 Subject: [PATCH] add SECONDARY_OBC compo --- Program.cs | 8 ++++ .../SecondaryObcTcPacketHandler.cs | 13 +++++ .../SecondaryObcTmPacketExtractor.cs | 48 +++++++++++++++++++ appsettings.json | 2 + 4 files changed, 71 insertions(+) create mode 100644 Services/UserDefined/SECONDARY_OBC/SecondaryObcTcPacketHandler.cs create mode 100644 Services/UserDefined/SECONDARY_OBC/SecondaryObcTmPacketExtractor.cs diff --git a/Program.cs b/Program.cs index bc61e0a..e74ee97 100644 --- a/Program.cs +++ b/Program.cs @@ -4,6 +4,7 @@ using Microsoft.Extensions.Configuration; using WINGS_TMTC_IF.Services; using WINGS_TMTC_IF.Services.MOBC; +using WINGS_TMTC_IF.Services.SECONDARY_OBC; using WINGS_TMTC_IF.Services.IsslCommon; namespace WINGS_TMTC_IF @@ -63,6 +64,13 @@ private static void ConfigureUserDefinedServices(IServiceCollection services, IC services.AddSingleton(); configuration["SerialPort:BaudRate:Using"] = configuration["SerialPort:BaudRate:MOBC_RF"]; break; + + case "SECONDARY_OBC": + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + configuration["SerialPort:BaudRate:Using"] = configuration["SerialPort:BaudRate:SECONDARY_OBC"]; + break; case "ISSL_COMMON": services.AddSingleton(); diff --git a/Services/UserDefined/SECONDARY_OBC/SecondaryObcTcPacketHandler.cs b/Services/UserDefined/SECONDARY_OBC/SecondaryObcTcPacketHandler.cs new file mode 100644 index 0000000..af89390 --- /dev/null +++ b/Services/UserDefined/SECONDARY_OBC/SecondaryObcTcPacketHandler.cs @@ -0,0 +1,13 @@ +using System; +using System.Linq; +using WINGS_TMTC_IF.Models; + +namespace WINGS_TMTC_IF.Services.SECONDARY_OBC +{ + public class SecondaryObcTcPacketHandler : TcPacketHandlerBase, ITcPacketHandler + { + public SecondaryObcTcPacketHandler(IPortManager portManager) : base(portManager) + { + } + } +} diff --git a/Services/UserDefined/SECONDARY_OBC/SecondaryObcTmPacketExtractor.cs b/Services/UserDefined/SECONDARY_OBC/SecondaryObcTmPacketExtractor.cs new file mode 100644 index 0000000..3adc281 --- /dev/null +++ b/Services/UserDefined/SECONDARY_OBC/SecondaryObcTmPacketExtractor.cs @@ -0,0 +1,48 @@ +using System; +using System.Linq; +using WINGS_TMTC_IF.Models; + +namespace WINGS_TMTC_IF.Services.SECONDARY_OBC +{ + public class SecondaryObcTmPacketExtractor : TmPacketExtractorBase, ITmPacketExtractor + { + private static readonly byte[] STX = new byte[]{0xeb, 0x90}; + private static readonly byte[] ETX = new byte[]{0xc5, 0x79}; + + public SecondaryObcTmPacketExtractor(IPortManager portManager) + : base(portManager, new ReceivedDataConfig { + HeaderLength = 4, + BodyLength = 6 + 7 + 223, + FooterLength = 4 + }) + { + } + + protected override bool AnalyzeHeader() + { + if (!_buffer.GetRange(0, STX.Count()).SequenceEqual(STX)) + { + return false; + } + byte[] packet_tmp = _buffer.GetRange(2, 2).ToArray(); + if (BitConverter.IsLittleEndian) + { + Array.Reverse(packet_tmp); + } + _config.BodyLength = BitConverter.ToUInt16(packet_tmp); + + return true; + } + + protected override bool AnalyzeFooter() + { + return _buffer.GetRange(_config.TotalLength - ETX.Count(), ETX.Count()).SequenceEqual(ETX); + } + + protected override TmPacketData ConvertToTmPacketData(byte[] receivedDataInByteArray) + { + Console.WriteLine("Received"); + return base.ConvertToTmPacketData(receivedDataInByteArray); + } + } +} diff --git a/appsettings.json b/appsettings.json index f4a08e3..09430c3 100644 --- a/appsettings.json +++ b/appsettings.json @@ -9,6 +9,7 @@ "Using": 0, "MOBC_UART": 115200, "MOBC_RF": 115200, + "SECONDARY_OBC": 115200, "ISSL_COMMON": 115200 } }, @@ -25,6 +26,7 @@ "ComponentList": [ "MOBC_UART", "MOBC_RF", + "SECONDARY_OBC", "ISSL_COMMON" ] }