4 Commits
Author SHA1 Message Date
esilva 7a210af58d Fix the stateinvalid logic 2026-09-08 16:02:38 +01:00
esilva 78ec6a1e86 This is not pretty 2026-09-08 15:52:49 +01:00
esilva 6070620713 hammer a stupid fix 2026-09-08 15:48:44 +01:00
esilva 1ad9dd4ab7 IsConnected logic 2026-09-08 15:41:44 +01:00
3 changed files with 33 additions and 19 deletions
+22 -6
View File
@@ -20,7 +20,6 @@ const (
IRSDK_BROADCASTMSGNAME string = "IRSDK_BROADCASTMSG"
fileMapSize uint32 = 1164 * 1024
connTimeout int64 = 30
stConnected int = 1
)
const (
@@ -117,6 +116,22 @@ const (
csFocusAtDriver int = 0 // ctFocusAtDriver + car number...
)
// StatusField - START
const (
irsdk_stConnected = 0x01
)
func (i *IBT) SessionStatusConnected() bool {
return i.Headers.Status == irsdk_stConnected
}
// NOTE: move this away from here
// func (i *IBT) SessionTimedOut() bool {
// return sdk.lastValidData+connTimeout > time.Now().Unix()
// }
// StatusField - END
// Camera positions
type bitfieldValue struct {
Value int
@@ -262,17 +277,18 @@ const (
func (i *IBT) SessionStateInvalid() bool {
val, ok := i.Vars.Vars["SessionState"]
if !ok {
log.Fatal("no SessionState")
return true
}
bitfield, err := strconv.ParseInt(val.Value.(string), 0, 64)
if err != nil {
log.Fatal("unable to get SessionState: " + err.Error())
value, ok := val.Value.(int)
if !ok {
return true
}
return bitfield == irsdk_StateInvalid
return value == irsdk_StateInvalid
}
// BUG: Need to fix all of these functions, they are all wrong
func (i *IBT) SessionStateGetInCar() bool {
val, ok := i.Vars.Vars["SessionState"]
if !ok {
+11 -8
View File
@@ -59,16 +59,19 @@ type IBT struct {
}
func (i *IBT) IsConnected() bool {
if i.Headers != nil {
if sessionStatusOK(int(i.Headers.Status)) {
return true
}
// if sessionStatusOK(int(i.Headers.Status)) && (sdk.lastValidData+connTimeout > time.Now().Unix()) {
// return true
// }
if i.Headers == nil {
return false
}
return false
if !i.SessionStatusConnected() {
return false
}
if i.SessionStateInvalid() {
return false
}
return true
}
func (i *IBT) exportYAML() error {
-5
View File
@@ -370,11 +370,6 @@ func parseSessionInfo(buf []byte, len int32) (*SessionInfoYAML, error) {
return &sessionInfo, nil
}
// sessionStatusOK will tell us if we are connected to the live data
func sessionStatusOK(status int) bool {
return (status & stConnected) > 0
}
// ToString will return a readable string of the struct
func (s *SessionInfoYAML) ToString() string {
stringified, _ := json.MarshalIndent(s, "", " ")