its.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. package protocol
  2. import "time"
  3. type Pack_ITSDev struct {
  4. Header
  5. Data ITSDevConfig `json:"data"`
  6. }
  7. func (o *Pack_ITSDev) EnCode(gid string, seq uint64, itsdevconfig *ITSDevConfig) (string, error) {
  8. o.SetHeaderData(gid, gid, seq)
  9. o.Data = *itsdevconfig
  10. return json.MarshalToString(o)
  11. }
  12. func (o *Pack_ITSDev) DeCode(message string) error {
  13. return json.UnmarshalFromString(message, o)
  14. }
  15. type VehicleSpeed struct {
  16. Plate string `json:"plate"`
  17. Time BJTime `json:"time"`
  18. Type int8 `json:"type"`
  19. Speed int `json:"speed"`
  20. Direction uint `json:"direction"`
  21. }
  22. type Pack_VehicleSpeed struct {
  23. Header
  24. Data VehicleSpeed `json:"data"`
  25. }
  26. func (o *Pack_VehicleSpeed) EnCode(id, gid string, seq uint64, vs *VehicleSpeed) (string, error) {
  27. o.SetHeaderData(id, gid, seq)
  28. o.Data = *vs
  29. return json.MarshalToString(o)
  30. }
  31. func (o *Pack_VehicleSpeed) DeCode(message string) error {
  32. return json.UnmarshalFromString(message, o)
  33. }
  34. //卡口行车统计信息
  35. type VehicleStatic struct {
  36. StaticTime time.Time `json:"statictime"`
  37. TollgateID string `json:"tollgateid"`
  38. SliceVehicleSpeed []*VehicleSpeed `json:"vehiclespeed"` //车速度
  39. MapDirection map[int8]uint `json:"direction"` //按照方向统计
  40. MapProvince map[string]uint `json:"province"` //按照省份统计,如湘
  41. MapProvinceCity map[string]uint `json:"provincecity"` //按照省市统计,如湘A
  42. MapVehicleType map[int8]uint `json:"vehicletype"` //按照车辆类型统计,如大客车、小客车等
  43. }
  44. func NewVehicleStatic() *VehicleStatic {
  45. obj := VehicleStatic{
  46. SliceVehicleSpeed: make([]*VehicleSpeed, 0, 1024),
  47. MapDirection: make(map[int8]uint),
  48. MapProvince: make(map[string]uint),
  49. MapProvinceCity: make(map[string]uint),
  50. MapVehicleType: make(map[int8]uint),
  51. }
  52. return &obj
  53. }
  54. func (o *VehicleStatic) Reset() {
  55. o.StaticTime = time.Time{}
  56. o.TollgateID = ""
  57. o.SliceVehicleSpeed = make([]*VehicleSpeed, 0, 1024)
  58. o.MapDirection = make(map[int8]uint)
  59. o.MapProvince = make(map[string]uint)
  60. o.MapProvinceCity = make(map[string]uint)
  61. o.MapVehicleType = make(map[int8]uint)
  62. }
  63. func (o *VehicleStatic) AddDirection(direction int8) {
  64. increInt8Key(o.MapDirection, direction)
  65. }
  66. func (o *VehicleStatic) AddProvince(province string) {
  67. increStringKey(o.MapProvince, province)
  68. }
  69. func (o *VehicleStatic) AddProvinceCity(provincecity string) {
  70. increStringKey(o.MapProvinceCity, provincecity)
  71. }
  72. func (o *VehicleStatic) AddVehicleSpeed(data *VehicleSpeed) {
  73. o.SliceVehicleSpeed = append(o.SliceVehicleSpeed, data)
  74. }
  75. func (o *VehicleStatic) AddVehicleType(vtype int8) {
  76. increInt8Key(o.MapVehicleType, vtype)
  77. }
  78. func increInt8Key(m map[int8]uint, k int8) {
  79. if a, ok := m[k]; ok {
  80. m[k] = a + 1
  81. } else {
  82. m[k] = 1
  83. }
  84. }
  85. func increStringKey(m map[string]uint, k string) {
  86. if a, ok := m[k]; ok {
  87. m[k] = a + 1
  88. } else {
  89. m[k] = 1
  90. }
  91. }
  92. type Pack_VehicleStatic struct {
  93. Header
  94. Data VehicleStatic `json:"data"`
  95. }
  96. func (o *Pack_VehicleStatic) EnCode(id, gid string, seq uint64, vs *VehicleStatic) (string, error) {
  97. o.SetHeaderData(id, gid, seq)
  98. o.Data = *vs
  99. return json.MarshalToString(o)
  100. }
  101. func (o *Pack_VehicleStatic) DeCode(message string) error {
  102. return json.UnmarshalFromString(message, o)
  103. }
  104. type ITSState struct {
  105. Time string `json:"time"`
  106. State uint8 `json:"state"` //0 在线,1离线
  107. }
  108. type Pack_ITSState struct {
  109. Header
  110. Data ITSState `json:"data"`
  111. }
  112. func (o *Pack_ITSState) EnCode(id, gid string, seq uint64, changetime time.Time, state uint8) (string, error) {
  113. o.SetHeaderData(id, gid, seq)
  114. o.Data.Time = changetime.Format("2006-01-02 15:04:05")
  115. o.Data.State = state
  116. return json.MarshalToString(o)
  117. }
  118. func (o *Pack_ITSState) DeCode(message string) error {
  119. return json.UnmarshalFromString(message, o)
  120. }