diff --git a/constants.go b/constants.go index 9b520b8..fa6b41b 100644 --- a/constants.go +++ b/constants.go @@ -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 diff --git a/irsdk.go b/irsdk.go index 11afb98..6aa7e30 100644 --- a/irsdk.go +++ b/irsdk.go @@ -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 { diff --git a/sessionInfo.go b/sessionInfo.go index 2695b65..980ed6f 100644 --- a/sessionInfo.go +++ b/sessionInfo.go @@ -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, "", " ")