led.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. package protocol
  2. import "time"
  3. //数据上报类:
  4. type QueryType uint8
  5. const (
  6. QT_STATUSINFO QueryType = iota //led内存、磁盘上报(平台主动,终端被动,调试用)
  7. QT_RESOLUTION //led分辨率上报(平台主动,终端被动)
  8. QT_POWERSTATUS //led开关机状态上报(1、有变化才上报;2、平台查询上报)
  9. QT_IFSTATUSS //led接口状态上报(平台主动,终端被动)
  10. QT_NETWORK //led网络状态上报(平台主动,终端被动)
  11. QT_PLAYINGINFO //led当前播放的节目上报(1、节目有变化才上报;2平台查询上报)
  12. QT_BRIGHTNESSCOLORTEMP //led音量、色温、亮度上报(平台主动,终端被动)
  13. QT_VOLUME //led音量、色温、亮度上报(平台主动,终端被动)
  14. QT_NTP //NTP配置上报(平台主动,终端被动)
  15. QT_ACCOUNT //led账户信息上报(平台主动,终端被动)
  16. QT_VSNS //led所有节目上报(平台主动,终端被动)
  17. QT_SCREENSHOT //led截屏(平台主动,终端被动)
  18. QT_LOCALE //led系统区域和语言(平台主动,终端被动)
  19. QT_RTCTIME //ledRTC时间
  20. QT_PGMS //查询节目
  21. QT_SCHEDULE //查询排程
  22. )
  23. type QType struct {
  24. Flag QueryType `json:"flag"` //查询类型标识
  25. State uint8
  26. }
  27. type LedState struct {
  28. Time string `json:"time"`
  29. State uint8 `json:"state"` //0 在线,1离线
  30. }
  31. type Pack_LedState struct {
  32. Header
  33. Data LedState `json:"data"`
  34. }
  35. func (o Pack_LedState) EnCode(id string, gid string, seq uint64, changetime time.Time, state uint8) (string, error) {
  36. o.SetHeaderData(id, gid, seq)
  37. o.Data.Time = changetime.Format("2006-01-02 15:04:05")
  38. o.Data.State = state
  39. return json.MarshalToString(o)
  40. }
  41. func (o *Pack_LedState) DeCode(message string) error {
  42. return json.UnmarshalFromString(message, o)
  43. }
  44. type Pack_QueryInfo struct {
  45. Header
  46. Data QType `json:"data"`
  47. }
  48. func (o *Pack_QueryInfo) EnCode(id, gid string, seq uint64, flag QueryType) (string, error) {
  49. o.SetHeaderData(id, gid, seq)
  50. o.Data.Flag = flag
  51. return json.MarshalToString(o)
  52. }
  53. func (o *Pack_QueryInfo) DeCode(message string) error {
  54. return json.UnmarshalFromString(message, o)
  55. }
  56. type Pack_StatusInfo struct {
  57. Header
  58. Data StatusInfo `json:"data"`
  59. }
  60. func (o *Pack_StatusInfo) EnCode(id, gid string, seq uint64, si *StatusInfo) (string, error) {
  61. o.SetHeaderData(id, gid, seq)
  62. o.Data = *si
  63. return json.MarshalToString(o)
  64. }
  65. func (o *Pack_StatusInfo) DeCode(message string) error {
  66. return json.UnmarshalFromString(message, o)
  67. }
  68. type Pack_Resolution struct {
  69. Header
  70. Data Resolution `json:"data"`
  71. }
  72. func (o *Pack_Resolution) EnCode(id, gid string, seq uint64, r *Resolution) (string, error) {
  73. o.SetHeaderData(id, gid, seq)
  74. o.Data = *r
  75. return json.MarshalToString(o)
  76. }
  77. func (o *Pack_Resolution) DeCode(message string) error {
  78. return json.UnmarshalFromString(message, o)
  79. }
  80. type PowerstatusData struct {
  81. Powerstatus uint8 `json:"powerstatus"`
  82. }
  83. type Pack_PowerStatus struct {
  84. Header
  85. Data PowerstatusData `json:"data"`
  86. }
  87. func (o *Pack_PowerStatus) EnCode(id, gid string, seq uint64, powerstatus int) (string, error) {
  88. o.SetHeaderData(id, gid, seq)
  89. o.Data.Powerstatus = uint8(powerstatus)
  90. return json.MarshalToString(o)
  91. }
  92. func (o *Pack_PowerStatus) DeCode(message string) error {
  93. return json.UnmarshalFromString(message, o)
  94. }
  95. type Pack_IFStatuss struct {
  96. Header
  97. Data IFStatuss `json:"data"`
  98. }
  99. func (o *Pack_IFStatuss) EnCode(id, gid string, seq uint64, ifs *IFStatuss) (string, error) {
  100. o.SetHeaderData(id, gid, seq)
  101. o.Data = *ifs
  102. return json.MarshalToString(o)
  103. }
  104. func (o *Pack_IFStatuss) DeCode(message string) error {
  105. return json.UnmarshalFromString(message, o)
  106. }
  107. type Pack_PlayingInfo struct {
  108. Header
  109. Data PlayingInfo `json:"data"`
  110. }
  111. func (o *Pack_PlayingInfo) EnCode(id, gid string, seq uint64, pi *PlayingInfo) (string, error) {
  112. o.SetHeaderData(id, gid, seq)
  113. o.Data = *pi
  114. return json.MarshalToString(o)
  115. }
  116. func (o *Pack_PlayingInfo) DeCode(message string) error {
  117. return json.UnmarshalFromString(message, o)
  118. }
  119. type Pack_BrightnessColortemp struct {
  120. Header
  121. Data BrightnessColortemp `json:"data"`
  122. }
  123. func (o *Pack_BrightnessColortemp) EnCode(id, gid string, seq uint64, bc *BrightnessColortemp) (string, error) {
  124. o.SetHeaderData(id, gid, seq)
  125. o.Data = *bc
  126. return json.MarshalToString(o)
  127. }
  128. func (o *Pack_BrightnessColortemp) DeCode(message string) error {
  129. return json.UnmarshalFromString(message, o)
  130. }
  131. type VolumeData struct {
  132. Volume uint8 `json:"volume"`
  133. }
  134. type Pack_VolumeData struct {
  135. Header
  136. Data VolumeData `json:"data"`
  137. }
  138. func (o *Pack_VolumeData) EnCode(id, gid string, seq uint64, volume int) (string, error) {
  139. o.SetHeaderData(id, gid, seq)
  140. o.Data.Volume = uint8(volume)
  141. return json.MarshalToString(o)
  142. }
  143. func (o *Pack_VolumeData) DeCode(message string) error {
  144. return json.UnmarshalFromString(message, o)
  145. }
  146. type Pack_Ntp struct {
  147. Header
  148. Data Ntp `json:"data"`
  149. }
  150. func (o *Pack_Ntp) EnCode(id, gid string, seq uint64, ntp *Ntp) (string, error) {
  151. o.SetHeaderData(id, gid, seq)
  152. o.Data = *ntp
  153. return json.MarshalToString(o)
  154. }
  155. func (o *Pack_Ntp) DeCode(message string) error {
  156. return json.UnmarshalFromString(message, o)
  157. }
  158. type Pack_Account struct {
  159. Header
  160. Data Account `json:"data"`
  161. }
  162. func (o *Pack_Account) EnCode(id, gid string, seq uint64, acc *Account) (string, error) {
  163. o.SetHeaderData(id, gid, seq)
  164. o.Data = *acc
  165. return json.MarshalToString(o)
  166. }
  167. func (o *Pack_Account) DeCode(message string) error {
  168. return json.UnmarshalFromString(message, o)
  169. }
  170. type Pack_VSNS struct {
  171. Header
  172. Data VSNS `json:"data"`
  173. }
  174. func (o *Pack_VSNS) EnCode(id, gid string, seq uint64, vsns *VSNS) (string, error) {
  175. o.SetHeaderData(id, gid, seq)
  176. o.Data = *vsns
  177. return json.MarshalToString(o)
  178. }
  179. func (o *Pack_VSNS) DeCode(message string) error {
  180. return json.UnmarshalFromString(message, o)
  181. }
  182. type Pack_Locale struct {
  183. Header
  184. Data Locale `json:"data"`
  185. }
  186. func (o *Pack_Locale) EnCode(id, gid string, seq uint64, lc *Locale) (string, error) {
  187. o.SetHeaderData(id, gid, seq)
  188. o.Data = *lc
  189. return json.MarshalToString(o)
  190. }
  191. func (o *Pack_Locale) DeCode(message string) error {
  192. return json.UnmarshalFromString(message, o)
  193. }
  194. type Pack_RTCTime struct {
  195. Header
  196. Data RTCTime `json:"data"`
  197. }
  198. func (o *Pack_RTCTime) EnCode(id, gid string, seq uint64, rtc *RTCTime) (string, error) {
  199. o.SetHeaderData(id, gid, seq)
  200. o.Data = *rtc
  201. return json.MarshalToString(o)
  202. }
  203. func (o *Pack_RTCTime) DeCode(message string) error {
  204. return json.UnmarshalFromString(message, o)
  205. }
  206. type BrightnessData struct {
  207. Brightness uint8 `json:"brightness"`
  208. }
  209. type Pack_BrightnessData struct {
  210. Header
  211. Data BrightnessData `json:"data"`
  212. }
  213. func (o *Pack_BrightnessData) EnCode(id, gid string, seq uint64, brightness int) (string, error) {
  214. o.SetHeaderData(id, gid, seq)
  215. o.Data.Brightness = uint8(brightness)
  216. return json.MarshalToString(o)
  217. }
  218. func (o *Pack_BrightnessData) DeCode(message string) error {
  219. return json.UnmarshalFromString(message, o)
  220. }
  221. type ShowtoastData struct {
  222. Showtoast uint8 `json:"showtoast"`
  223. }
  224. type Pack_ShowtoastData struct {
  225. Header
  226. Data ShowtoastData `json:"data"`
  227. }
  228. func (o *Pack_ShowtoastData) EnCode(id, gid string, seq uint64, showtoast int) (string, error) {
  229. o.SetHeaderData(id, gid, seq)
  230. o.Data.Showtoast = uint8(showtoast)
  231. return json.MarshalToString(o)
  232. }
  233. func (o *Pack_ShowtoastData) DeCode(message string) error {
  234. return json.UnmarshalFromString(message, o)
  235. }
  236. type CmdData struct {
  237. Cmd string `json:"cmd"`
  238. }
  239. type Pack_CmdData struct {
  240. Header
  241. Data CmdData `json:"data"`
  242. }
  243. func (o *Pack_CmdData) EnCode(id, gid string, seq uint64, cmd string) (string, error) {
  244. o.SetHeaderData(id, gid, seq)
  245. o.Data.Cmd = cmd
  246. return json.MarshalToString(o)
  247. }
  248. func (o *Pack_CmdData) DeCode(message string) error {
  249. return json.UnmarshalFromString(message, o)
  250. }
  251. type ProgramData struct {
  252. Flag uint8 `json:"flag"` //flag=4清除缓存;flag=3清除节目缓存;flag=2清除节目;flag=1删除节目;flag=0切换节目
  253. Source string `json:"source"` //flag = 1或0时有效
  254. Vsn string `json:"vsn"` //flag = 1或0时有效
  255. }
  256. type Pack_ProgramData struct {
  257. Header
  258. Data ProgramData `json:"data"`
  259. }
  260. func (o *Pack_ProgramData) EnCode(id, gid string, seq uint64, flag uint8, source, vsn string) (string, error) {
  261. o.SetHeaderData(id, gid, seq)
  262. o.Data.Flag = flag
  263. o.Data.Source = source
  264. o.Data.Vsn = vsn
  265. return json.MarshalToString(o)
  266. }
  267. func (o *Pack_ProgramData) DeCode(message string) error {
  268. return json.UnmarshalFromString(message, o)
  269. }
  270. type Host struct {
  271. Host string `json:"host"`
  272. }
  273. type Pack_Host struct {
  274. Header
  275. Data Host `json:"data"`
  276. }
  277. func (o *Pack_Host) EnCode(id, gid string, seq uint64, host string) (string, error) {
  278. o.SetHeaderData(id, gid, seq)
  279. o.Data.Host = host
  280. return json.MarshalToString(o)
  281. }
  282. func (o *Pack_Host) DeCode(message string) error {
  283. return json.UnmarshalFromString(message, o)
  284. }
  285. type RetHost struct {
  286. StateError
  287. Host string `json:"host"`
  288. TTL float64 `json:"ttl"`
  289. }
  290. type Pack_RetHost struct {
  291. Header
  292. Data RetHost `json:"data"`
  293. }
  294. func (o *Pack_RetHost) EnCode(id, gid string, seq uint64, err error, host string, ttl float64) (string, error) {
  295. o.SetHeaderData(id, gid, seq)
  296. o.Data.SetStateErrorData(err)
  297. o.Data.Host = host
  298. o.Data.TTL = ttl
  299. return json.MarshalToString(o)
  300. }
  301. func (o *Pack_RetHost) DeCode(message string) error {
  302. return json.UnmarshalFromString(message, o)
  303. }
  304. type PubGPMS struct {
  305. Name string `json:"name"`
  306. Files []string `json:"files"`
  307. }
  308. type Pack_PubGPMS struct {
  309. Header
  310. Data []PubGPMS `json:"data"`
  311. }
  312. func (o *Pack_PubGPMS) EnCode(id, gid string, seq uint64, pgms []PubGPMS) (string, error) {
  313. o.SetHeaderData(id, gid, seq)
  314. o.Data = pgms
  315. return json.MarshalToString(o)
  316. }
  317. func (o *Pack_PubGPMS) DeCode(message string) error {
  318. return json.UnmarshalFromString(message, o)
  319. }
  320. //排程
  321. type CmdOperation struct {
  322. AuthorUrl string `json:"author_url,omitempty"`
  323. Method int `json:"method,omitempty"`
  324. Content string `json:"content,omitempty"`
  325. Source string `json:"source,omitempty"`
  326. Vsn string `json:"vsn,omitempty"`
  327. }
  328. type LimitDateTime struct {
  329. Start string `json:"start,omitempty"`
  330. End string `json:"end,omitempty"`
  331. StartTime string `json:"start_time,omitempty"`
  332. EndTime string `json:"end_time,omitempty"`
  333. }
  334. type CommandSchedule struct {
  335. Operation CmdOperation `json:"operation"`
  336. OpTime []string `json:"op_time"`
  337. IfLimitDate bool `json:"if_limit_date"`
  338. LimitDate LimitDateTime `json:"limit_date"`
  339. IfLimitWeekday bool `json:"if_limit_weekday"`
  340. LimitWeekday []bool `json:"limit_weekday"`
  341. Type string `json:"type"`
  342. }
  343. type Pack_CommandSchedule struct {
  344. Header
  345. Data []CommandSchedule `json:"data"`
  346. }
  347. func (o *Pack_CommandSchedule) EnCode(id, gid string, seq uint64, cmdSchedule []CommandSchedule) (string, error) {
  348. o.SetHeaderData(id, gid, seq)
  349. o.Data = cmdSchedule
  350. return json.MarshalToString(o)
  351. }
  352. func (o *Pack_CommandSchedule) DeCode(message string) error {
  353. return json.UnmarshalFromString(message, o)
  354. }
  355. //info
  356. type Storage struct {
  357. Total uint `json:"total"`
  358. Free uint `json:"free"`
  359. }
  360. type PlayingInfo struct {
  361. Name string `json:"name"`
  362. Path string `json:"path"`
  363. Source string `json:"source"`
  364. }
  365. type InfoTag struct {
  366. Serialno string `json:"serialno"`
  367. Model string `json:"model"`
  368. Mem Storage `json:"mem"`
  369. Storage Storage `json:"storage"`
  370. Playing PlayingInfo `json:"playing"`
  371. }
  372. type StatusInfo struct {
  373. Info InfoTag `json:"info"`
  374. }
  375. //ifstatus
  376. type Peer struct {
  377. Ip string `json:"ip,omitempty"`
  378. Mac string `json:"mac,omitempty"`
  379. }
  380. type IPS struct {
  381. Broadcast string `json:"broadcast,omitempty"`
  382. Ip string `json:"ip,omitempty"`
  383. Mask string `json:"mask,omitempty"`
  384. Dns1 string `json:"dns1,omitempty"`
  385. Dns2 string `json:"dns2,omitempty"`
  386. Gateway string `json:"gateway,omitempty"`
  387. }
  388. type SSID struct {
  389. SSID string `json:"SSID,omitempty"`
  390. Pass string `json:"pass,omitempty"`
  391. Priority int `json:"priority,omitempty"`
  392. }
  393. type IFStatus struct {
  394. Type string `json:"type,omitempty"`
  395. Connected int `json:"connected,omitempty"`
  396. Enabled int `json:"enabled,omitempty"`
  397. Ips *IPS `json:"ips,omitempty"`
  398. Peers []Peer `json:"peers,omitempty"`
  399. SSID string `json:"SSID,omitempty"`
  400. Ssids []SSID `json:"ssids,omitempty"`
  401. Operstate string `json:"operstate,omitempty"`
  402. Pass string `json:"pass,omitempty"`
  403. Channel int `json:"channel,omitempty"`
  404. Carrier int `json:"carrier,omitempty"`
  405. Mode string `json:"mode,omitempty"`
  406. Mac string `json:"mac,omitempty"`
  407. Currentap string `json:"currentap,omitempty"`
  408. State string `json:"state,omitempty"`
  409. Speed int `json:"speed,omitempty"`
  410. Strength int `json:"strength,omitempty"`
  411. Log int `json:"log,omitempty"`
  412. Isstatic int `json:"isstatic,omitempty"`
  413. }
  414. type IFStatuss struct {
  415. Types []IFStatus `json:"types,omitempty"`
  416. }
  417. type RTCTime struct {
  418. Time string `json:"time"`
  419. Timezone string `json:"timezone"`
  420. Isautotimezone int `json:"isautotimezone"`
  421. Isautotime int `json:"isautotime"`
  422. }
  423. type Locale struct {
  424. Language string `json:"language"`
  425. Country string `json:"country"`
  426. }
  427. type Resolution struct {
  428. Width int `json:"width"`
  429. Height int `json:"height"`
  430. Hsync int `json:"hsync"`
  431. Dclk int `json:"dclk"`
  432. RealWidth int `json:"real_width"`
  433. RealHeight int `json:"real_height"`
  434. RealDclk int `json:"real_dclk"`
  435. Fps int `json:"fps"`
  436. }
  437. type BrightnessColortemp struct {
  438. Brightness int `json:"brightness"`
  439. Colortemp int `json:"colortemperature"`
  440. }
  441. type Ntp struct {
  442. Ntpserver string `json:"ntpserver"`
  443. Ntpinterval int `json:"ntpinterval"`
  444. Ntpthreshold int `json:"ntpthreshold"`
  445. }
  446. type Account struct {
  447. Name string `json:"name"`
  448. Password string `json:"password"`
  449. Url string `json:"url"`
  450. Devicestatus string `json:"devicestatus"`
  451. Internet bool `json:"internet"`
  452. Login bool `json:"login"`
  453. Reason string `json:"reason"`
  454. }
  455. //vsn
  456. type ContentTag struct {
  457. Md5 string `json:"md5,omitempty"`
  458. Name string `json:"name,omitempty"`
  459. Publishedmd5 string `json:"publishedmd5,omitempty"`
  460. Size uint `json:"size,omitempty"`
  461. }
  462. type Contents struct {
  463. Content []ContentTag `json:"content"`
  464. Ressize uint `json:"ressize,omitempty"`
  465. Type string `json:"type,omitempty"`
  466. Unused uint `json:"unused,omitempty"`
  467. }
  468. type Playing_Vsn struct {
  469. Name string `json:"name,omitempty"`
  470. Type string `json:"type,omitempty"`
  471. }
  472. type VSNS struct {
  473. Contents []Contents `json:"contents,omitempty"`
  474. Playing Playing_Vsn `json:"playing,omitempty"`
  475. }
  476. // CltledData 信息屏 数据
  477. type CltledData struct {
  478. Powerstatus int `json:"powerstatus"` //电源状态 1 0
  479. Musicvolume int `json:"musicvolume"` //音量
  480. Brightness int `json:"brightness"` //亮度
  481. Playing string `json:"playing"` //当前播放节目
  482. Colortemperature int `json:"colortemperature"` //色温
  483. SleepTime string `json:"sleepTime"` //关机时间
  484. WakeupTime string `json:"wakeupTime"` //开机时间
  485. RebootTime string `json:"rebootTime"` //重启时间
  486. RealWidth int `json:"real_width"` //宽度
  487. RealHeight int `json:"real_height"` //高度
  488. }
  489. type Pack_LedCltledData struct {
  490. Header
  491. Data CltledData `json:"data"`
  492. }
  493. func (o *Pack_LedCltledData) EnCode(id, gid string, seq uint64, r *CltledData) (string, error) {
  494. o.SetHeaderData(id, gid, seq)
  495. o.Data = *r
  496. return json.MarshalToString(o)
  497. }
  498. func (o *Pack_LedCltledData) DeCode(message string) error {
  499. return json.UnmarshalFromString(message, o)
  500. }