Files
ChanSort/ChanSort.Api/Utils/Tools.cs
hbeham a2ae5583ff Added support for LG's 2013 LA-Series (Sat list only)
Improved LG duplicate channel cleanup (including linked list and allocation bitmap)
2013-04-28 12:44:40 +02:00

43 lines
1.3 KiB
C#

using System.Collections.Generic;
using System.Text;
namespace ChanSort.Api
{
public static class Tools
{
public static V TryGet<K, V>(this IDictionary<K, V> dict, K key)
{
V val;
dict.TryGetValue(key, out val);
return val;
}
public static string GetAnalogChannelNumber(int freq)
{
if (freq < 41) return "";
if (freq <= 68) return ((freq - 41)/7 + 1).ToString("d2"); // Band I (01-04)
if (freq < 105) return "";
if (freq <= 174) return "S" + ((freq - 105)/7 + 1).ToString("d2"); // Midband (S01-S10)
if (freq <= 230) return ((freq - 175)/7 + 5).ToString("d2"); // Band III (05-12)
if (freq <= 300) return "S" + ((freq - 231)/7 + 11); // Superband (S11-S20)
if (freq <= 469) return "S" + ((freq - 303)/8 + 21); // Hyperband (S21-S41)
if (freq <= 1000) return ((freq - 471)/8 + 21).ToString("d2"); // Band IV, V
return "";
}
public static void SetInt16(byte[] data, int offset, int value)
{
data[offset+0] = (byte)value;
data[offset + 1] = (byte) (value >> 8);
}
public static void SetInt32(byte[] data, int offset, int value)
{
data[offset + 0] = (byte)value;
data[offset + 1] = (byte)(value >> 8);
data[offset + 2] = (byte)(value >> 16);
data[offset + 3] = (byte)(value >> 24);
}
}
}