protocol.go 7.6 KB

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