Skip to content

Commit

Permalink
Thead comm refactoring done
Browse files Browse the repository at this point in the history
Signed-off-by: Ulf Bjorkengren <[email protected]>
  • Loading branch information
UlfBj committed Jan 6, 2025
1 parent f17245a commit b207aea
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 15 deletions.
4 changes: 2 additions & 2 deletions client/client-1.0/requests.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{"request":[{"action":"get","path":"Vehicle/Cabin/Door/Row1/DriverSide/IsOpen","requestId":"232"},
{"action":"get","path":"Incorrect/Path","requestId":"1957"},
{"action":"get","path":"Vehicle.Acceleration.Longitudinal","requestId":"233"},
{"action":"get","path":"Vehicle/ADAS","filter":{"type":"paths","parameter":["ABS/*","CruiseControl/Error"]},"requestId":"237"},
{"action":"get","path":"Vehicle/ADAS","filter":{"variant":"paths","parameter":["ABS/*","CruiseControl/IsError"]},"requestId":"237"},
{"action":"set", "path":"Vehicle/Cabin/Door/Row1/DriverSide/IsOpen", "value":"true", "requestId":"245"},
{"action":"subscribe","path":"Vehicle/Cabin/Door/Row1/DriverSide/IsOpen","filter":{"type":"timebased","parameter":{"period":"3"}},"requestId":"246"}]}
{"action":"subscribe","path":"Vehicle/Cabin/Door/Row1/DriverSide/IsOpen","filter":{"variant":"timebased","parameter":{"period":"3"}},"requestId":"246"}]}
40 changes: 33 additions & 7 deletions server/vissv2server/serviceMgr/serviceMgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ type FeederPathElem struct {
Reference int
}
var feederPathList []FeederPathElem
var feederConnected bool

//var feederConn net.Conn
//var hostIp string
Expand Down Expand Up @@ -617,6 +618,9 @@ func setVehicleData(path string, value string) string {
utils.Error.Printf("setVehicleData:Write failed, err = %s", err)
return ""
}*/
if !feederConnected {
return ""
}
message := `{"action": "set", "data": {"path":"` + path + `", "dp":{"value":"` + value + `", "ts":"` + ts + `"}}}`
toFeeder <- message
return ts
Expand Down Expand Up @@ -917,6 +921,26 @@ func getDataPack(pathArray []string, filterList []utils.FilterObject) string {
return dataPack
}

func getDataPackMap(pathArray []string) map[string]interface{} {
dataPack := make(map[string]interface{}, 0)
if len(pathArray) > 1 {
dataPackElement := make([]interface{}, len(pathArray))
for i := 0; i < len(pathArray); i++ {
dataPackElement[i] = map[string]interface{}{
"path": pathArray[i],
"dp": string2Map(getVehicleData(pathArray[i]))["s2m"],
}
}
dataPack["dpack"] = dataPackElement
} else {
dataPack["dpack"] = map[string]interface{}{
"path": pathArray[0],
"dp": string2Map(getVehicleData(pathArray[0]))["s2m"],
}
}
return dataPack
}

func getVssPathList(host string, port int, path string) []byte {
url := "http://" + host + ":" + strconv.Itoa(port) + path
utils.Info.Printf("url = %s", url)
Expand Down Expand Up @@ -1007,11 +1031,12 @@ func feederFrontend(toFeeder chan string, fromFeederRorC chan string, fromFeeder
udsConn = utils.GetUdsConn("*", "serverFeeder")
if udsConn == nil && attempts >= 10-1 {
utils.Error.Printf("feederFrontend:Failed to UDS connect to feeder.")
return // ???
return
}
attempts++
time.Sleep(3 * time.Second)
}
feederConnected = true
utils.Info.Printf("feederFrontend:Connected to feeder.")
configureDefault(udsConn)
fromFeeder := make(chan string)
Expand Down Expand Up @@ -1224,6 +1249,7 @@ func feederReader(udsConn net.Conn, fromFeeder chan string) {
func ServiceMgrInit(mgrId int, serviceMgrChan chan map[string]interface{}, stateStorageType string, histSupport bool, dbFile string) {
stateDbType = stateStorageType
historySupport = histSupport
feederConnected = false

utils.ReadUdsRegistrations("uds-registration.json")

Expand Down Expand Up @@ -1401,14 +1427,14 @@ func ServiceMgrInit(mgrId int, serviceMgrChan chan map[string]interface{}, state
break
}
}
dataPack := getDataPack(pathArray, filterList)
if len(dataPack) == 0 {
dataPack := getDataPackMap(pathArray)
/* if len(dataPack) == 0 {
utils.Info.Printf("No historic data available")
utils.SetErrorResponse(requestMap, errorResponseMap, 6, "") //unavailable_data
dataChan <- errorResponseMap
break
}
responseMap["data"] = string2Map(dataPack)["s2m"]
}*/
responseMap["data"] = dataPack["dpack"]
dataChan <- responseMap
case "subscribe":
var subscriptionState SubscriptionState
Expand Down Expand Up @@ -1488,7 +1514,7 @@ func ServiceMgrInit(mgrId int, serviceMgrChan chan map[string]interface{}, state
subscriptionMap["ts"] = utils.GetRfcTime()
subscriptionMap["subscriptionId"] = strconv.Itoa(subscriptionState.SubscriptionId)
subscriptionMap["RouterId"] = subscriptionState.RouterId
subscriptionMap["data"] = string2Map(getDataPack(subscriptionState.Path, nil))["s2m"]
subscriptionMap["data"] = getDataPackMap(subscriptionState.Path)["dpack"]
backendChan <- subscriptionMap
case clPack := <-CLChannel: // curve logging notification
index := getSubcriptionStateIndex(clPack.SubscriptionId, subscriptionList)
Expand Down Expand Up @@ -1537,7 +1563,7 @@ func checkRCFilterAndIssueMessages(triggeredPath string, subscriptionList []Subs
subscriptionMap["ts"] = utils.GetRfcTime()
subscriptionMap["subscriptionId"] = strconv.Itoa(subscriptionState.SubscriptionId)
subscriptionMap["RouterId"] = subscriptionState.RouterId
subscriptionMap["data"] = string2Map(getDataPack(subscriptionList[i].Path, nil))["s2m"]
subscriptionMap["data"] = getDataPackMap(subscriptionList[i].Path)["dpack"]
backendChan <- subscriptionMap
}
}
Expand Down
12 changes: 6 additions & 6 deletions server/vissv2server/vissv2server.go
Original file line number Diff line number Diff line change
Expand Up @@ -644,16 +644,16 @@ func issueServiceRequest(requestMap map[string]interface{}, tDChanIndex int, sDC
pathLen := getPathLen(string(searchData[i].NodePath[:]))
paths += "\"" + string(searchData[i].NodePath[:pathLen]) + "\", "
}
if matches == 0 {
utils.SetErrorResponse(requestMap, errorResponseMap, 6, "") //unavailable_data
backendChan[tDChanIndex] <- errorResponseMap
return
}
totalMatches += matches
maxValidation = utils.GetMaxValidation(int(validation), maxValidation)
}
if totalMatches == 0 {
utils.SetErrorResponse(requestMap, errorResponseMap, 6, "") //unavailable_data
backendChan[tDChanIndex] <- errorResponseMap
return
}
nodeType := utils.VSSgetType(searchData[0].NodeHandle)
if strings.Contains (utils.VSSgetDatatype(searchData[0].NodeHandle), ".FileDescriptor") {
if strings.Contains (utils.VSSgetDatatype(searchData[0].NodeHandle), ".FileDescriptor") { // path to struct def
response := initiateFileTransfer(requestMap, nodeType, searchPath[0])
backendChan[tDChanIndex] <- response
return
Expand Down

0 comments on commit b207aea

Please sign in to comment.