Commit aa214d7e authored by Ikram Haq's avatar Ikram Haq
Browse files

Update userInfo table: Add relativeLocationInfo and civicInfo attributes

parent 3b8bd063
Loading
Loading
Loading
Loading
+179 −0
Original line number Diff line number Diff line
@@ -2132,6 +2132,183 @@ components:
        - rel
        - href
      type: object
    CivicAddress:
      description: Indicates a Civic address
      type: object
      required:
        - country
      properties:
        country:
          description: The two-letter ISO 3166 country code in capital ASCII letters, e.g., DE or US 
          type: string
          x-etsi-mec-cardinality: 1
          x-etsi-mec-origin-type: String
        A1:
          description: National subdivisions (state, canton, region, province, prefecture)
          type: string
          x-etsi-mec-cardinality: 0..1
          x-etsi-mec-origin-type: String
        A2:
          description: County, parish, gun (JP), district (IN)
          type: string
          x-etsi-mec-cardinality: 0..1
          x-etsi-mec-origin-type: String
        A3:
          description: City, township, shi (JP) 
          type: string
          x-etsi-mec-cardinality: 0..1
          x-etsi-mec-origin-type: String
        A4:
          description: City division, borough, city district, ward, chou (JP)
          type: string
          x-etsi-mec-cardinality: 0..1
          x-etsi-mec-origin-type: String
        A5:
          description: Neighbourhood, block 
          type: string
          x-etsi-mec-cardinality: 0..1
          x-etsi-mec-origin-type: String
        A6:
          description: Group of streets below the neighbourhood level
          type: string
          x-etsi-mec-cardinality: 0..1
          x-etsi-mec-origin-type: String
        PRD:
          description: Leading street direction
          type: string
          x-etsi-mec-cardinality: 0..1
          x-etsi-mec-origin-type: String
        POD:
          description: Trailing street suffix
          type: string
          x-etsi-mec-cardinality: 0..1
          x-etsi-mec-origin-type: String
        STS:
          description: Street suffix or type
          type: string
          x-etsi-mec-cardinality: 0..1
          x-etsi-mec-origin-type: String
        HNO:
          description: House number
          type: string
          x-etsi-mec-cardinality: 0..1
          x-etsi-mec-origin-type: String
        HNS:
          description: House number suffix
          type: string
          x-etsi-mec-cardinality: 0..1
          x-etsi-mec-origin-type: String
        LMK:
          description: Landmark or vanity address 
          type: string
          x-etsi-mec-cardinality: 0..1
          x-etsi-mec-origin-type: String
        LOC:
          description: Additional location information
          type: string
          x-etsi-mec-cardinality: 0..1
          x-etsi-mec-origin-type: String
        NAM:
          description: Name (residence and office occupant)
          type: string
          x-etsi-mec-cardinality: 0..1
          x-etsi-mec-origin-type: String
        PC:
          description: Postal/zip code 
          type: string
          x-etsi-mec-cardinality: 0..1
          x-etsi-mec-origin-type: String
        BLD:
          description: Building (structure) 
          type: string
          x-etsi-mec-cardinality: 0..1
          x-etsi-mec-origin-type: String
        UNIT:
          description: Unit (apartment, suite)
          type: string
          x-etsi-mec-cardinality: 0..1
          x-etsi-mec-origin-type: String
        FLR:
          description: Floor
          type: string
          x-etsi-mec-cardinality: 0..1
          x-etsi-mec-origin-type: String
        ROOM:
          description: Room
          type: string
          x-etsi-mec-cardinality: 0..1
          x-etsi-mec-origin-type: String
        PLC:
          description: Place-type 
          type: string
          x-etsi-mec-cardinality: 0..1
          x-etsi-mec-origin-type: String
        PCN:
          description: Postal community name
          type: string
          x-etsi-mec-cardinality: 0..1
          x-etsi-mec-origin-type: String
        POBOX:
          description: Post office box (P.O. box) 
          type: string
          x-etsi-mec-cardinality: 0..1
          x-etsi-mec-origin-type: String
        ADDCODE:
          description: Additional code
          type: string
          x-etsi-mec-cardinality: 0..1
          x-etsi-mec-origin-type: String
        SEAT:
          description: Seat (desk, cubicle, workstation)
          type: string
          x-etsi-mec-cardinality: 0..1
          x-etsi-mec-origin-type: String
        RD:
          description: Primary road or street 
          type: string
          x-etsi-mec-cardinality: 0..1
          x-etsi-mec-origin-type: String
        RDSEC:
          description: Road clause 
          type: string
          x-etsi-mec-cardinality: 0..1
          x-etsi-mec-origin-type: String
        RDBR:
          description: Road branch
          type: string
          x-etsi-mec-cardinality: 0..1
          x-etsi-mec-origin-type: String
        RDSUBBR:
          description: Road sub-branch
          type: string
          x-etsi-mec-cardinality: 0..1
          x-etsi-mec-origin-type: String
        PRM:
          description: Road pre-modifier
          type: string
          x-etsi-mec-cardinality: 0..1
          x-etsi-mec-origin-type: String
        POM:
          description: Road post-modifier
          type: string
          x-etsi-mec-cardinality: 0..1
          x-etsi-mec-origin-type: String
        usageRules:
          description: When present, this IE shall carry the value of "usagerules" Element of the PIDL-LO XML document, with UTF-8 encoding.
          type: string
          x-etsi-mec-cardinality: 0..1
          x-etsi-mec-origin-type: String
        method:
          description: When present, this IE shall contain the method token, carried by the "method" Element of the PIDLLO XML document. 
          type: string
          x-etsi-mec-cardinality: 0..1
          x-etsi-mec-origin-type: String
        providedBy:
          description: When present, this IE shall carry the value of "provided-by" Element of the PIDL-LO XML document, with UTF-8 encoding. 
          type: string
          x-etsi-mec-cardinality: 0..1
          x-etsi-mec-origin-type: String

    LocationInfo:
      properties:
        accuracy:
@@ -2566,6 +2743,8 @@ components:
          x-etsi-mec-origin-type: String
        locationInfo:
          $ref: '#/components/schemas/LocationInfo'
        civicInfo:
          $ref: '#/components/schemas/CivicAddress'
        resourceURL:
          description: Self-referring URL, see note 1.
          type: string
+50 −10
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package sbi

import (
	"errors"
	"math"
	"strings"
	"sync"
	"time"
@@ -36,7 +37,7 @@ type SbiCfg struct {
	MepName        string
	RedisAddr      string
	Locality       []string
	UserInfoCb     func(string, string, string, *float32, *float32)
	UserInfoCb     func(string, string, string, *float32, *float32, *string, *string, *float64, *float64, *float32, *float32)
	ZoneInfoCb     func(string, int, int, int)
	ApInfoCb       func(string, string, string, string, int, *float32, *float32)
	ScenarioNameCb func(string)
@@ -55,7 +56,7 @@ type LocServSbi struct {
	activeModel             *mod.Model
	gisCache                *gc.GisCache
	refreshTicker           *time.Ticker
	updateUserInfoCB        func(string, string, string, *float32, *float32)
	updateUserInfoCB        func(string, string, string, *float32, *float32, *string, *string, *float64, *float64, *float32, *float32)
	updateZoneInfoCB        func(string, int, int, int)
	updateAccessPointInfoCB func(string, string, string, string, int, *float32, *float32)
	updateScenarioNameCB    func(string)
@@ -266,7 +267,6 @@ func processActiveScenarioUpdate() {
	// Get all UE & POA positions
	uePositionMap, _ := sbi.gisCache.GetAllPositions(gc.TypeUe)
	poaPositionMap, _ := sbi.gisCache.GetAllPositions(gc.TypePoa)

	// Update UE info
	ueNames := []string{}
	ueNameList := sbi.activeModel.GetNodeNames("UE")
@@ -290,15 +290,26 @@ func processActiveScenarioUpdate() {

		// Add UE to list of valid UEs
		ueNames = append(ueNames, name)

		var id string = "324561243"
		var mapid *string = &id
		var country string = "Monaco"
		var country_name *string = &country
		var longitude *float32
		var latitude *float32
		originLatitude := new(float32)
		*originLatitude = 43.7314
		originLongitude := new(float32)
		*originLongitude = 7.4202
		if position, found := uePositionMap[name]; found {
			longitude = &position.Longitude
			latitude = &position.Latitude
		}

		sbi.updateUserInfoCB(name, zone, netLoc, longitude, latitude)
		}
		// Convert user's geographic coordinates to Cartesian coordinates relative to the origin
		x, y := geographicToCartesian(latitude, longitude, originLatitude, originLongitude)
		var X *float64 = &x
		var Y *float64 = &y
		sbi.updateUserInfoCB(name, zone, netLoc, longitude, latitude, country_name, mapid, X, Y, originLatitude, originLongitude)
		uePerZoneMap[zone]++
		uePerNetLocMap[netLoc]++
	}
@@ -313,7 +324,7 @@ func processActiveScenarioUpdate() {
			}
		}
		if !found {
			sbi.updateUserInfoCB(prevUeName, "", "", nil, nil)
			sbi.updateUserInfoCB(prevUeName, "", "", nil, nil, nil, nil, nil, nil, nil, nil)
			// log.Info("Ue removed : ", prevUeName)
		}
	}
@@ -368,6 +379,26 @@ func processActiveScenarioUpdate() {
	}
}

func geographicToCartesian(userLatitude, userLongitude, originLatitude, originLongitude *float32) (x, y float64) {
	// Earth's radius in meters
	const R = 6371000.0

	// Convert user's latitude and longitude from degrees to radians
	userLatRad := float64(*userLatitude) * (math.Pi / 180.0)
	userLonRad := float64(*userLongitude) * (math.Pi / 180.0)

	// Convert origin latitude and longitude from degrees to radians
	originLatRad := float64(*originLatitude) * (math.Pi / 180.0)
	originLonRad := float64(*originLongitude) * (math.Pi / 180.0)

	// Calculate X coordinate relative to the origin
	x = R * (userLonRad - originLonRad)

	// Calculate Y coordinate relative to the origin (using Mercator projection formula)
	y = R*math.Log(math.Tan((math.Pi/4)+(userLatRad/2))) - R*math.Log(math.Tan((math.Pi/4)+(originLatRad/2)))

	return x, y
}
func getNetworkLocation(name string) (zone string, netLoc string, err error) {
	ctx := sbi.activeModel.GetNodeContext(name)
	if ctx == nil {
@@ -404,16 +435,25 @@ func refreshPositions() {
		if !isInLocality(zone) {
			continue
		}

		var id string = "324561243"
		var mapid *string = &id
		var country string = "Monaco"
		var country_name *string = &country
		// Get position
		var longitude *float32
		var latitude *float32
		originLatitude := new(float32)
		*originLatitude = 43.7314
		originLongitude := new(float32)
		*originLongitude = 7.4202
		if position, found := uePositionMap[name]; found {
			longitude = &position.Longitude
			latitude = &position.Latitude
		}

		sbi.updateUserInfoCB(name, zone, netLoc, longitude, latitude)
		x, y := geographicToCartesian(latitude, longitude, originLatitude, originLongitude)
		var X *float64 = &x
		var Y *float64 = &y
		sbi.updateUserInfoCB(name, zone, netLoc, longitude, latitude, country_name, mapid, X, Y, originLatitude, originLongitude)
	}

	// Update POA Positions
+24 −2
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ import (
)

const moduleName = "meep-loc-serv"
const LocServBasePath = "location/v2/"
const LocServBasePath = "location/v3/"
const locServKey = "loc-serv"
const serviceName = "Location Service"
const serviceCategory = "Location"
@@ -3345,7 +3345,7 @@ func updateStoreName(storeName string) {
	}
}

func updateUserInfo(address string, zoneId string, accessPointId string, longitude *float32, latitude *float32) {
func updateUserInfo(address string, zoneId string, accessPointId string, longitude *float32, latitude *float32, country *string, mapid *string, x *float64, y *float64, originLatitude *float32, originLongitude *float32) {
	var oldZoneId string
	var oldApId string

@@ -3378,7 +3378,29 @@ func updateUserInfo(address string, zoneId string, accessPointId string, longitu
	timeStamp.Seconds = int32(seconds)

	userInfo.Timestamp = &timeStamp
	if mapid != nil {
		if userInfo.RelativeLocationInfo == nil {
			userInfo.RelativeLocationInfo = new(RelativeLocationInfo)
		}
		userInfo.RelativeLocationInfo.X = *x
		userInfo.RelativeLocationInfo.Y = *y
		if userInfo.RelativeLocationInfo.MapInfo == nil {
			userInfo.RelativeLocationInfo.MapInfo = new(MapInfo)
		}
		userInfo.RelativeLocationInfo.MapInfo.MapId = *mapid

		if userInfo.RelativeLocationInfo.MapInfo.Origin == nil {
			userInfo.RelativeLocationInfo.MapInfo.Origin = new(Origin)
			userInfo.RelativeLocationInfo.MapInfo.Origin.Latitude = *originLatitude
			userInfo.RelativeLocationInfo.MapInfo.Origin.Longitude = *originLongitude
		}
	}
	if country != nil {
		if userInfo.CivicInfo == nil {
			userInfo.CivicInfo = new(CivicAddress)
		}
		userInfo.CivicInfo.Country = *country
	}
	// Update position
	if longitude == nil || latitude == nil {
		userInfo.LocationInfo = nil
+82 −0
Original line number Diff line number Diff line
/*
 * AdvantEDGE Location API
 *
 * Location Service is AdvantEDGE's implementation of [ETSI MEC ISG MEC013 Location API](https://www.etsi.org/deliver/etsi_gs/MEC/001_099/013/02.02.01_60/gs_mec013v020201p.pdf) <p>The API is based on the Open Mobile Alliance's specification RESTful Network API for Zonal Presence <p>[Copyright (c) ETSI 2017](https://forge.etsi.org/etsi-forge-copyright-notice.txt) <p>**Micro-service**<br>[meep-loc-serv](https://github.com/InterDigitalInc/AdvantEDGE/tree/master/go-apps/meep-loc-serv) <p>**Type & Usage**<br>Edge Service used by edge applications that want to get information about Users (UE) and Zone locations <p>**Note**<br>AdvantEDGE supports all of Location API endpoints (see below).
 *
 * API version: 2.2.1
 * Contact: AdvantEDGE@InterDigital.com
 * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
 */
package server

// Indicates a Civic address
type CivicAddress struct {
	// The two-letter ISO 3166 country code in capital ASCII letters, e.g., DE or US
	Country string `json:"country"`
	// National subdivisions (state, canton, region, province, prefecture)
	A1 string `json:"A1,omitempty"`
	// County, parish, gun (JP), district (IN)
	A2 string `json:"A2,omitempty"`
	// City, township, shi (JP)
	A3 string `json:"A3,omitempty"`
	// City division, borough, city district, ward, chou (JP)
	A4 string `json:"A4,omitempty"`
	// Neighbourhood, block
	A5 string `json:"A5,omitempty"`
	// Group of streets below the neighbourhood level
	A6 string `json:"A6,omitempty"`
	// Leading street direction
	PRD string `json:"PRD,omitempty"`
	// Trailing street suffix
	POD string `json:"POD,omitempty"`
	// Street suffix or type
	STS string `json:"STS,omitempty"`
	// House number
	HNO string `json:"HNO,omitempty"`
	// House number suffix
	HNS string `json:"HNS,omitempty"`
	// Landmark or vanity address
	LMK string `json:"LMK,omitempty"`
	// Additional location information
	LOC string `json:"LOC,omitempty"`
	// Name (residence and office occupant)
	NAM string `json:"NAM,omitempty"`
	// Postal/zip code
	PC string `json:"PC,omitempty"`
	// Building (structure)
	BLD string `json:"BLD,omitempty"`
	// Unit (apartment, suite)
	UNIT string `json:"UNIT,omitempty"`
	// Floor
	FLR string `json:"FLR,omitempty"`
	// Room
	ROOM string `json:"ROOM,omitempty"`
	// Place-type
	PLC string `json:"PLC,omitempty"`
	// Postal community name
	PCN string `json:"PCN,omitempty"`
	// Post office box (P.O. box)
	POBOX string `json:"POBOX,omitempty"`
	// Additional code
	ADDCODE string `json:"ADDCODE,omitempty"`
	// Seat (desk, cubicle, workstation)
	SEAT string `json:"SEAT,omitempty"`
	// Primary road or street
	RD string `json:"RD,omitempty"`
	// Road clause
	RDSEC string `json:"RDSEC,omitempty"`
	// Road branch
	RDBR string `json:"RDBR,omitempty"`
	// Road sub-branch
	RDSUBBR string `json:"RDSUBBR,omitempty"`
	// Road pre-modifier
	PRM string `json:"PRM,omitempty"`
	// Road post-modifier
	POM string `json:"POM,omitempty"`
	// When present, this IE shall carry the value of \"usagerules\" Element of the PIDL-LO XML document, with UTF-8 encoding.
	UsageRules string `json:"usageRules,omitempty"`
	// When present, this IE shall contain the method token, carried by the \"method\" Element of the PIDLLO XML document.
	Method string `json:"method,omitempty"`
	// When present, this IE shall carry the value of \"provided-by\" Element of the PIDL-LO XML document, with UTF-8 encoding.
	ProvidedBy string `json:"providedBy,omitempty"`
}
+19 −0
Original line number Diff line number Diff line
/*
 * AdvantEDGE Location API
 *
 * Location Service is AdvantEDGE's implementation of [ETSI MEC ISG MEC013 Location API](https://www.etsi.org/deliver/etsi_gs/MEC/001_099/013/02.02.01_60/gs_mec013v020201p.pdf) <p>The API is based on the Open Mobile Alliance's specification RESTful Network API for Zonal Presence <p>[Copyright (c) ETSI 2017](https://forge.etsi.org/etsi-forge-copyright-notice.txt) <p>**Micro-service**<br>[meep-loc-serv](https://github.com/InterDigitalInc/AdvantEDGE/tree/master/go-apps/meep-loc-serv) <p>**Type & Usage**<br>Edge Service used by edge applications that want to get information about Users (UE) and Zone locations <p>**Note**<br>AdvantEDGE supports all of Location API endpoints (see below).
 *
 * API version: 2.2.1
 * Contact: AdvantEDGE@InterDigital.com
 * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
 */
package server

type MapInfo struct {
	// Ancillary map information may be used to convert coordinates between different coordinate systems.
	AncillaryMapInfo *interface{} `json:"ancillaryMapInfo,omitempty"`
	// Indicates the ID of the map.
	MapId string `json:"mapId"`

	Origin *Origin `json:"origin,omitempty"`
}
Loading