FlyCube/FlieOperate/JsonBase.cs
2022-04-11 15:19:08 +08:00

81 lines
3.1 KiB
C#
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections.Generic;
using Newtonsoft.Json;
namespace FlieOperate
{
/// <summary>
/// 飞行魔方地面站 fcgm Json文件层级 结构模型
/// </summary>
public class FcgmJsonModel
{
public string ID { get; set; }
public string ver { get; set; }
public int coptercount { get; set; }
public int taskcount { get; set; }
public List<Groups> groups { get; set; }
public class Groups
{
public string groupName { get; set; }
public List<int> copterIndexList { get; set; }
}
public List<List<double>> locate { get; set; }
public List<Tasks> tasks { get; set; }
public class Tasks
{
public int type { get; set; }//100起飞 0普通航点 6降落
public int takeoffnumber { get; set; }//起飞任务独有
public int takeoffTime { get; set; }//起飞任务独有
public bool staggerRoutes { get; set; }
public int flytoTime { get; set; }
public int loiterTime { get; set; }
public string taskname { get; set; }
public List<SingleCopterInfos> singleCopterInfos { get; set; }
public class SingleCopterInfos
{
public int waitTime { get; set; }//起飞降落 独有
public double x { get; set; }
public double y { get; set; }
public double targetAlt { get; set; }
public List<LedInfos> ledInfos { get; set; }
public class LedInfos
{
public double Delay { get; set; }
public int LEDMode { get; set; }
public double LEDInterval { get; set; }
public int LEDRate { get; set; }
public int LEDTimes { get; set; }
public string LEDRGB { get; set; }
}
public bool isLandWaypoint { get; set; }//返航点
public bool isChangeSpeed { get; set; }//改变速度
public double levelSpeed { get; set; }
public double upSpeed { get; set; }
public double downSpeed { get; set; }
}
}
}
public class JsonBase
{
/// <summary>
/// 航点文件转存到FcgmJsonModel对象里面 反序列化
/// </summary>
/// <param name="FliePath">航点文件路径</param>
/// <returns>航点FcgmJsonModel对象</returns>
public static FcgmJsonModel JsonToModel(string FliePath)
{
string str = FileBase.ReadFlieToStr(FliePath);
FcgmJsonModel fcgmModel = JsonConvert.DeserializeObject<FcgmJsonModel>(str);//反系列化
return fcgmModel;
}
/// <summary>
/// FcgmJsonModel对象 序列化 成 json
/// </summary>
/// <param name="fcgmJsonModel"></param>
/// <returns></returns>
public static string ModelTojson(FcgmJsonModel fcgmJsonModel)
{
return JsonConvert.SerializeObject(fcgmJsonModel);    //转为字符串
}
}
}