config.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package main
  2. import (
  3. "errors"
  4. "strings"
  5. "github.com/go-ini/ini"
  6. )
  7. var CheckOfflineInterval = 1
  8. var OfflineInterval float64 = 5
  9. func GetVagueTopic(devtype, topic string) string {
  10. return "+/" + devtype + "/+/" + topic
  11. }
  12. func GetCltledTopic(topic string) string {
  13. return "+/cltled/+/up/" + topic + "/+"
  14. }
  15. func GetTopic(tenant, devtype, id, topic string) string {
  16. return tenant + "/" + devtype + "/" + id + "/" + topic
  17. }
  18. func GetHLTopicDown(tenant, devType, id, topic string) string {
  19. return "hllk/113/lamp/longchi/down"
  20. }
  21. func GetHLTopicUp() string {
  22. return "hllk/113/lamp/longchi/up"
  23. }
  24. // ParseTopic 获取租户、设备类型、设备编码、MQTT协议topic固定部分(定义在topic.go文件)
  25. func ParseTopic(topic string) (string, string, string, string, error) {
  26. strList := strings.Split(topic, "/")
  27. if len(strList) < 4 {
  28. return "", "", "", "", errors.New("不支持的topic")
  29. }
  30. topic = strings.Join(strList[3:], "/")
  31. return strList[0], strList[1], strList[2], topic, nil
  32. }
  33. // ParseTopicHL 获取租户、设备类型、设备编码、MQTT协议topic固定部分(定义在topic.go文件)
  34. func ParseTopicHL(topic string) (string, string, error) {
  35. strList := strings.Split(topic, "/")
  36. if len(strList) < 4 {
  37. return "", "", errors.New("不支持的topic")
  38. }
  39. if strList[3] == "longchi" {
  40. strList[0] = "100000"
  41. }
  42. return strList[0], topic, nil
  43. }
  44. // ParseTopicHL 获取租户、设备类型、设备编码、MQTT协议topic固定部分, request(定义在topic.go文件)
  45. func ParseTopicCltLed(topic string) (string, string, string, string, string, error) {
  46. strList := strings.Split(topic, "/")
  47. if len(strList) < 6 {
  48. return "", "", "", "", "", errors.New("不支持的topic")
  49. }
  50. //+/cltled/+/up/query/+
  51. return strList[0], strList[1], strList[2], strList[4], strList[5], nil
  52. }
  53. type MainConfig struct {
  54. GB28181API string
  55. SRSLIVEDIR string
  56. SRSLIVEMP4 int
  57. SDKAppId string
  58. SecretId string
  59. SecretKey string
  60. SMSKey string
  61. SMSTemplateId string
  62. SMSReceiver []string
  63. }
  64. func (o *MainConfig) ReadConfig(path, sec string) bool {
  65. var ret = false
  66. fini, err := ini.Load(path + "main.ini")
  67. if err == nil {
  68. fsec := fini.Section(sec)
  69. if fsec != nil {
  70. err := fsec.StrictMapTo(&o)
  71. if err != nil {
  72. panic(path + " ReadConfig MainConfig err = " + err.Error())
  73. return false
  74. }
  75. //o.GB28181API = fsec.Key("GB28181API").String()
  76. //o.SRSLIVEDIR = fsec.Key("SRSLIVEDIR").String()
  77. //o.SRSLIVEMP4, _ = fsec.Key("SRSLIVEMP4").Int()
  78. //o.SDKAppId = fsec.Key("SDKAppId").String()
  79. //o.SecretId = fsec.Key("SecretId").String()
  80. //o.SecretKey = fsec.Key("SecretKey").String()
  81. //o.SMSTemplateId = fsec.Key("SMSTemplateId").String()
  82. //o.SMSKey = fsec.Key("SMSKey").String()
  83. //o.SMSReceiver = fsec.Key("SMSReceiver").
  84. if o.SRSLIVEMP4 <= 0 || o.SRSLIVEMP4 > 8640 {
  85. o.SRSLIVEMP4 = 48
  86. }
  87. ret = true
  88. }
  89. }
  90. return ret
  91. }