Skip to content

Commit

Permalink
Merge pull request #4 from ut-issl/feature/add_secondary_obc_compo
Browse files Browse the repository at this point in the history
WINGSのSECONDARY_OBCコンポの作成に伴った改修
  • Loading branch information
TomokiMochizuki authored Dec 7, 2022
2 parents 24d9f9b + 28a2732 commit ba04c7c
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -63,6 +64,13 @@ private static void ConfigureUserDefinedServices(IServiceCollection services, IC
services.AddSingleton<ITcPacketHandler, MobcRfTcPacketHandler>();
configuration["SerialPort:BaudRate:Using"] = configuration["SerialPort:BaudRate:MOBC_RF"];
break;

case "SECONDARY_OBC":
services.AddSingleton<IPortManager, SerialPortManager>();
services.AddSingleton<ITmPacketExtractor, SecondaryObcTmPacketExtractor>();
services.AddSingleton<ITcPacketHandler, SecondaryObcTcPacketHandler>();
configuration["SerialPort:BaudRate:Using"] = configuration["SerialPort:BaudRate:SECONDARY_OBC"];
break;

case "ISSL_COMMON":
services.AddSingleton<IPortManager, SerialPortManager>();
Expand Down
13 changes: 13 additions & 0 deletions Services/UserDefined/SECONDARY_OBC/SecondaryObcTcPacketHandler.cs
Original file line number Diff line number Diff line change
@@ -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)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
2 changes: 2 additions & 0 deletions appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"Using": 0,
"MOBC_UART": 115200,
"MOBC_RF": 115200,
"SECONDARY_OBC": 115200,
"ISSL_COMMON": 115200
}
},
Expand All @@ -25,6 +26,7 @@
"ComponentList": [
"MOBC_UART",
"MOBC_RF",
"SECONDARY_OBC",
"ISSL_COMMON"
]
}

0 comments on commit ba04c7c

Please sign in to comment.