| @@ -112,9 +112,13 @@ func decodeBeacon(adv model.BeaconAdvertisement, appState *appcontext.AppState, | |||||
| if event.ID == "" { | if event.ID == "" { | ||||
| return nil | return nil | ||||
| } | } | ||||
| prevEvent, ok := appState.GetBeaconEvent(id) | prevEvent, ok := appState.GetBeaconEvent(id) | ||||
| appState.UpdateBeaconEvent(id, event) | appState.UpdateBeaconEvent(id, event) | ||||
| if event.Type == "iBeacon" { | |||||
| event.BtnPressed = true | |||||
| } | |||||
| if ok && bytes.Equal(prevEvent.Hash(), event.Hash()) { | if ok && bytes.Equal(prevEvent.Hash(), event.Hash()) { | ||||
| return nil | return nil | ||||
| } | } | ||||
| @@ -39,5 +39,12 @@ | |||||
| "accY": {"offset": 9, "length": 2, "order": "fixedpoint"}, | "accY": {"offset": 9, "length": 2, "order": "fixedpoint"}, | ||||
| "accZ": {"offset": 11, "length": 2, "order": "fixedpoint"} | "accZ": {"offset": 11, "length": 2, "order": "fixedpoint"} | ||||
| } | } | ||||
| }, | |||||
| { | |||||
| "name": "iBeacon", | |||||
| "min": 5, | |||||
| "max": 27, | |||||
| "pattern": ["0xFF", "0x4C", "0x00", "0x02"], | |||||
| "configs": {} | |||||
| } | } | ||||
| ] | ] | ||||
| @@ -77,7 +77,6 @@ func (p *ParserRegistry) Unregister(name string) { | |||||
| func (b *BeaconParser) Parse(name string, ad []byte) (BeaconEvent, bool) { | func (b *BeaconParser) Parse(name string, ad []byte) (BeaconEvent, bool) { | ||||
| flag := false | flag := false | ||||
| event := BeaconEvent{Type: name} | event := BeaconEvent{Type: name} | ||||
| fmt.Printf("parsing: %s\n", name) | |||||
| if cfg, ok := b.configs["battery"]; ok { | if cfg, ok := b.configs["battery"]; ok { | ||||
| event.Battery = uint32(b.extract(ad, cfg).(uint16)) | event.Battery = uint32(b.extract(ad, cfg).(uint16)) | ||||
| flag = true | flag = true | ||||
| @@ -97,7 +96,12 @@ func (b *BeaconParser) Parse(name string, ad []byte) (BeaconEvent, bool) { | |||||
| event.AccZ = int16(val) | event.AccZ = int16(val) | ||||
| flag = true | flag = true | ||||
| } | } | ||||
| fmt.Printf("success: %s, event: %+v\n", flag, event) | |||||
| if cfg, ok := b.configs["temperature"]; ok { | |||||
| val := b.extract(ad, cfg).(float64) | |||||
| event.Temperature = uint16(val) | |||||
| flag = true | |||||
| } | |||||
| return event, flag | return event, flag | ||||
| } | } | ||||
| @@ -87,14 +87,17 @@ type Beacon struct { | |||||
| } | } | ||||
| type BeaconEvent struct { | type BeaconEvent struct { | ||||
| Name string | |||||
| ID string | |||||
| Type string | |||||
| Battery uint32 | |||||
| Event int | |||||
| AccX int16 | |||||
| AccY int16 | |||||
| AccZ int16 | |||||
| Name string | |||||
| ID string | |||||
| Type string | |||||
| Battery uint32 | |||||
| Event int | |||||
| AccX int16 | |||||
| AccY int16 | |||||
| AccZ int16 | |||||
| Temperature uint16 | |||||
| Heart int16 | |||||
| BtnPressed bool | |||||
| } | } | ||||
| type HTTPResult struct { | type HTTPResult struct { | ||||