protocol.go 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. package clt_client
  2. import (
  3. "encoding/json"
  4. "github.com/sirupsen/logrus"
  5. "lc/common/util"
  6. "os"
  7. "path"
  8. )
  9. var textVsn TextVsn
  10. type ProgramInfo struct {
  11. Type string `json:"type"` //节目类型
  12. Name string `json:"name"` //节目名
  13. ImageInfo ImageInfo `json:"imageinfo"` //图片,视频资源url
  14. TextInfo TextInfo `json:"textinfo"` //文本内容
  15. }
  16. type TextInfo struct {
  17. Content string `json:"content"`
  18. LfFaceName string `json:"lfFaceName"`
  19. BackColor string `json:"backcolor"`
  20. TextColor string `json:"textcolor"`
  21. Duration string `json:"duration"`
  22. IsScroll string `json:"IsScroll"`
  23. Speed string `json:"Speed"` //滚动速度pixels/秒
  24. }
  25. type ImageInfo struct {
  26. Urls []string `json:"urls"`
  27. Duration string `json:"duration"`
  28. InEffect InEffect `json:"inEffect"`
  29. }
  30. // ListResp 查所有节目的响应结构体(只包含当前播放节目)
  31. type ListResp struct {
  32. Playing playing `json:"playing"`
  33. }
  34. type playing struct {
  35. Name string `json:"name"`
  36. Type string `json:"type"`
  37. }
  38. // LoadVsn 加载 vsn文件->结构体
  39. func (c cltClient) LoadVsn() {
  40. text, _ := os.ReadFile(util.GetPath(0) + "text.vsn")
  41. json.Unmarshal(text, &textVsn)
  42. }
  43. func NewPVsn(pro ProgramInfo) []byte {
  44. var marshal []byte
  45. switch pro.Type {
  46. case "2":
  47. var v = NewVsn()
  48. v.Programs.Program.Pages[0].Regions[0].Items[0].Type = "2"
  49. v.Programs.Program.Pages[0].Regions[0].Items[0].FileSource.FilePath = ".\\" + pro.Name + ".files\\" + path.Base(pro.ImageInfo.Urls[0])
  50. v.Programs.Program.Pages[0].Regions[0].Items[0].FileSource.IsRelative = "1"
  51. items := v.Programs.Program.Pages[0].Regions[0].Items
  52. for i, va := range pro.ImageInfo.Urls {
  53. if i > 0 {
  54. item := Items{}
  55. item.Type = "2"
  56. item.FileSource.IsRelative = "1"
  57. item.FileSource.FilePath = ".\\" + pro.Name + ".files\\" + path.Base(va)
  58. if pro.ImageInfo.Duration != "" {
  59. item.Duration = pro.ImageInfo.Duration
  60. }
  61. if pro.ImageInfo.InEffect.Type != "" {
  62. item.InEffect.Type = pro.ImageInfo.InEffect.Type
  63. }
  64. if pro.ImageInfo.InEffect.Time != "" {
  65. item.InEffect.Time = pro.ImageInfo.InEffect.Time
  66. }
  67. items = append(items, item)
  68. v.Programs.Program.Pages[0].Regions[0].Items = items
  69. }
  70. }
  71. marshal, _ = json.Marshal(v)
  72. case "3":
  73. var v = NewVsn()
  74. v.Programs.Program.Pages[0].Regions[0].Items[0].Type = "3"
  75. v.Programs.Program.Pages[0].Regions[0].Items[0].Volume = "1.000000"
  76. v.Programs.Program.Pages[0].Regions[0].Items[0].FileSource.IsRelative = "1"
  77. v.Programs.Program.Pages[0].Regions[0].Items[0].ReserveAS = "0"
  78. v.Programs.Program.Pages[0].Regions[0].Rect.Width = "256"
  79. v.Programs.Program.Pages[0].Regions[0].Rect.Height = "256"
  80. v.Programs.Program.Pages[0].Regions[0].Items[0].FileSource.FilePath = ".\\" + pro.Name + ".files\\" + path.Base(pro.ImageInfo.Urls[0])
  81. marshal, _ = json.Marshal(v)
  82. case "4":
  83. fallthrough
  84. case "5":
  85. v := textVsn
  86. v.Programs.Program.Pages[0].Regions[0].Items[0].Type = "5"
  87. if pro.TextInfo.BackColor != "" {
  88. v.Programs.Program.Pages[0].Regions[0].Items[0].BackColor = pro.TextInfo.BackColor
  89. }
  90. if pro.TextInfo.TextColor != "" {
  91. v.Programs.Program.Pages[0].Regions[0].Items[0].TextColor = pro.TextInfo.TextColor
  92. }
  93. if pro.TextInfo.LfFaceName != "" {
  94. v.Programs.Program.Pages[0].Regions[0].Items[0].LogFont.LfFaceName = pro.TextInfo.LfFaceName
  95. }
  96. if pro.TextInfo.Duration != "" {
  97. v.Programs.Program.Pages[0].Regions[0].Items[0].MultiPicInfo.OnePicDuration = pro.TextInfo.Duration
  98. }
  99. if pro.TextInfo.IsScroll != "" {
  100. v.Programs.Program.Pages[0].Regions[0].Items[0].IsScroll = pro.TextInfo.IsScroll
  101. }
  102. if pro.TextInfo.Speed != "" {
  103. v.Programs.Program.Pages[0].Regions[0].Items[0].Speed = pro.TextInfo.Speed
  104. }
  105. v.Programs.Program.Pages[0].Regions[0].Items[0].Text = pro.TextInfo.Content
  106. marshal, _ = json.Marshal(v)
  107. case "27":
  108. //v.Programs.Program.Pages[0].Regions[0].Items[0].Type = "27"
  109. //v.Programs.Program.Pages[0].Regions[0].Items[0].URL = pro.URL
  110. //v.Programs.Program.Pages[0].Name = pro.Name + ".vsn"
  111. //v.Programs.Program.Pages[0].AppointDuration = "3600000"
  112. //v.Programs.Program.Information.Width = "256"
  113. //v.Programs.Program.Information.Height = "256"
  114. //v.Programs.Program.Pages[0].Regions[0].Rect.Width = "128"
  115. //v.Programs.Program.Pages[0].Regions[0].Rect.Height = "128"
  116. //v.Programs.Program.Pages[0].LoopType = "1"
  117. default:
  118. logrus.Errorf("不支持的类型:%v", pro.Type)
  119. return nil
  120. }
  121. return marshal
  122. }
  123. // 图片/视频
  124. // Vsn vsn文件结构体
  125. type Vsn struct {
  126. Programs Programs `json:"Programs"`
  127. }
  128. type Rect struct {
  129. X string `json:"X"`
  130. Y string `json:"Y"`
  131. Width string `json:"Width"`
  132. Height string `json:"Height"`
  133. BorderWidth string `json:"BorderWidth"`
  134. BorderColor string `json:"BorderColor"`
  135. }
  136. type FileSource struct {
  137. IsRelative string `json:"IsRelative"`
  138. FilePath string `json:"FilePath"`
  139. }
  140. type InEffect struct {
  141. Type string `json:"Type"` //0- No transition, 1-Random, 2-Left unveil, 3-Right unveil
  142. Time string `json:"DateTime"`
  143. }
  144. type Items struct {
  145. Type string `json:"Type"`
  146. Volume string `json:"Volume"`
  147. Duration string `json:"Duration"`
  148. FileSource FileSource `json:"FileSource"`
  149. ReserveAS string `json:"ReserveAS"`
  150. InEffect InEffect `json:"inEffect"`
  151. URL string `json:"URL"`
  152. }
  153. type Regions struct {
  154. Layer int `json:"Layer"`
  155. Rect Rect `json:"Rect"`
  156. Items []Items `json:"Items"`
  157. }
  158. type Pages struct {
  159. Regions []Regions `json:"Regions"`
  160. }
  161. type Program struct {
  162. Pages []Pages `json:"Pages"`
  163. }
  164. type Programs struct {
  165. Program Program `json:"Program"`
  166. }
  167. func NewVsn() Vsn {
  168. return Vsn{Programs: Programs{
  169. Program: Program{
  170. Pages: []Pages{
  171. {Regions: []Regions{
  172. {Layer: 1,
  173. Rect: Rect{
  174. X: "0",
  175. Y: "0",
  176. Width: "128",
  177. Height: "256",
  178. BorderWidth: "0",
  179. BorderColor: "0xFFFFFF00",
  180. },
  181. Items: []Items{
  182. {
  183. Type: "",
  184. FileSource: FileSource{},
  185. },
  186. },
  187. },
  188. }},
  189. },
  190. },
  191. }}
  192. }
  193. // 文本vsn
  194. type TextVsn struct {
  195. Programs struct {
  196. Program struct {
  197. Pages []struct {
  198. Regions []struct {
  199. Rect struct {
  200. X string `json:"X"`
  201. Y string `json:"Y"`
  202. Width string `json:"Width"`
  203. Height string `json:"Height"`
  204. } `json:"Rect"`
  205. Items []struct {
  206. Type string `json:"Type"`
  207. BackColor string `json:"BackColor"`
  208. TextColor string `json:"TextColor"`
  209. Alpha string `json:"Alpha"`
  210. BeGlaring string `json:"BeGlaring"`
  211. MultiPicInfo struct {
  212. OnePicDuration string `json:"OnePicDuration"`
  213. } `json:"MultiPicInfo"`
  214. VerticalAlign int `json:"VerticalAlign"`
  215. CenteralAlign int `json:"CenteralAlign"`
  216. LogFont struct {
  217. LfHeight string `json:"lfHeight"`
  218. LfWeight string `json:"lfWeight"`
  219. LfItalic string `json:"lfItalic"`
  220. LfUnderline string `json:"lfUnderline"`
  221. LfStrikeOut string `json:"lfStrikeOut"`
  222. LfFaceName string `json:"lfFaceName"`
  223. } `json:"LogFont"`
  224. RepeatCount string `json:"RepeatCount"`
  225. Speed string `json:"Speed"`
  226. IsScrollByTime string `json:"IsScrollByTime"`
  227. IsScroll string `json:"IsScroll"`
  228. PlayLenth string `json:"PlayLenth"`
  229. Text string `json:"Text"`
  230. } `json:"Items"`
  231. } `json:"Regions"`
  232. } `json:"Pages"`
  233. } `json:"Program"`
  234. } `json:"Programs"`
  235. }
  236. type SSchedule struct {
  237. Sleep string `json:"sleep"`
  238. Wakeup string `json:"wakeup"`
  239. Reboot string `json:"reboot"`
  240. }