Newer
Older
' Copyright 2014 European Union.
' Licensed under the EUPL (the 'Licence');
'
' * You may not use this work except in compliance with the Licence.
' * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl
' * Unless required by applicable law or agreed to in writing,
' software distributed under the Licence is distributed on an "AS IS" basis,
' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
'
' See the LICENSE.txt for the specific language governing permissions and limitations.

Michael KRISPER
committed
Imports System.ComponentModel
Imports System.IO
Imports System.Text

Michael KRISPER
committed
Imports TUGraz.VectoCommon.Models

Michael KRISPER
committed
Imports vectolic
Public Module VECTO_Global

Michael KRISPER
committed
Public COREvers As String = "NOT FOUND"
Public Const LicSigAppCode As String = "VECTO-Release-0093C61E0A2E4BFA9A7ED7E729C56AE4"
Public MyAppPath As String
Public MyConfPath As String
Public MyDeclPath As String

Michael KRISPER
committed
'to ensure correct format for backgroundworker thread
Public SetCulture As Boolean
Public VECTOworker As BackgroundWorker
Public VECTOworkerV3 As BackgroundWorker
Public MSGerror As Integer
Public MSGwarn As Integer

Michael KRISPER
committed
Public Cfg As Configuration

Michael KRISPER
committed
Public FileFormat As Encoding = Encoding.UTF8
Public VEC As cVECTO
Public VEH As cVEH
Public ENG As cENG
Public GBX As cGBX
Public MAP As cMAP
Public DRI As cDRI
'Public MODdata As cMOD

Michael KRISPER
committed
Public Lic As cLicense
'Public VSUM As cVSUM

Michael KRISPER
committed
''' <summary>
''' Converts engine speed and torque to power.
''' </summary>
''' <param name="nU">engine speed</param>
''' <param name="M">Torque</param>
''' <returns>Power</returns>
''' <remarks></remarks>
Public Function nMtoPe(nU As Double, M As Double) As Double
Return (nU * 2 * Math.PI / 60) * M / 1000

Michael KRISPER
committed
''' <summary>
''' Convert engine speed and power to torque.
''' </summary>
''' <param name="nU">engine speed</param>
''' <param name="Pe">Power</param>
''' <returns>Torque</returns>
''' <remarks></remarks>
Public Function nPeToM(nU As Single, Pe As Double) As Single
Return Pe * 1000 / (nU * 2 * Math.PI / 60)
#Region "sKey > Typ Umwandlung"

Michael KRISPER
committed
Public Function GearboxConv(Gearbox As tGearbox) As String
Select Case Gearbox
Case tGearbox.Manual
Return "MT"
Case tGearbox.AutomaticSerial
Return "ATSerial"
Case tGearbox.AutomaticPowerSplit
Return "ATPowerSplit"
Case tGearbox.SemiAutomatic
Return "AMT"
Case Else 'tGearbox.Custom
Return "Custom"
End Select
End Function

Michael KRISPER
committed
Public Function GearboxConv(Gearbox As String) As tGearbox
Select Case UCase(Trim(Gearbox))
Case "MT"
Return tGearbox.Manual
Case "AT"
Return tGearbox.AutomaticSerial
Case "ATSERIAL"
Return tGearbox.AutomaticSerial
Case "ATPOWERSPLIT"
Return tGearbox.AutomaticPowerSplit
Case "AMT"
Return tGearbox.SemiAutomatic
Case Else '"Custom"
Return tGearbox.Custom
End Select
End Function

Michael KRISPER
committed
Public Function fDriComp(sK As String) As tDriComp
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
sK = Trim(UCase(sK))
Select Case sK
Case sKey.DRI.t
Return tDriComp.t
Case sKey.DRI.V
Return tDriComp.V
Case sKey.DRI.Grad
Return tDriComp.Grad
Case sKey.DRI.nU
Return tDriComp.nU
Case sKey.DRI.Gears
Return tDriComp.Gears
Case sKey.DRI.Padd
Return tDriComp.Padd
Case sKey.DRI.Pe
Return tDriComp.Pe
Case sKey.DRI.VairVres
Return tDriComp.VairVres
Case sKey.DRI.VairBeta
Return tDriComp.VairBeta
Case sKey.DRI.s
Return tDriComp.s
Case sKey.DRI.StopTime
Return tDriComp.StopTime
Case sKey.DRI.Torque
Return tDriComp.Torque
Case sKey.DRI.Alt
Return tDriComp.Alt
Case sKey.DRI.Pwheel
Return tDriComp.Pwheel
Case Else
Return tDriComp.Undefined
End Select
End Function

Michael KRISPER
committed
Public Function fAuxComp(sK As String) As tAuxComp
Dim x As Integer
sK = Trim(UCase(sK))
x = sK.IndexOf("_")

Michael KRISPER
committed
If x = -1 Then Return tAuxComp.Undefined
sK = Left(sK, x + 1)
Select Case sK
Case sKey.PauxSply
Return tAuxComp.Psupply
Case Else
Return tAuxComp.Undefined
End Select
End Function

Michael KRISPER
committed
Public Function fCompSubStr(sK As String) As String
Dim x As Integer
sK = Trim(UCase(sK))
x = sK.IndexOf("_")

Michael KRISPER
committed
If x = -1 Then Return ""
sK = Right(sK, Len(sK) - x - 1)
x = CShort(sK.IndexOf(">"))

Michael KRISPER
committed
If x = -1 Then Return ""
sK = Left(sK, x)
Return sK
End Function

Michael KRISPER
committed
Public Function ConvLoading(load As tLoading) As String
Select Case load
Case tLoading.FullLoaded
Return "Full Loading"
Case tLoading.RefLoaded
Return "Reference Loading"
Case tLoading.EmptyLoaded
Return "Empty Loading"
Case Else ' tLoading.UserDefLoaded
Return "User-defined Loading"
End Select
End Function

Michael KRISPER
committed
Public Function ConvVehCat(VehCat As tVehCat, NiceName As Boolean) As String
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
Select Case VehCat
Case tVehCat.Citybus
Return "Citybus"
Case tVehCat.Coach
Return "Coach"
Case tVehCat.InterurbanBus
If NiceName Then
Return "Interurban Bus"
Else
Return "InterurbanBus"
End If
Case tVehCat.RigidTruck
If NiceName Then
Return "Rigid Truck"
Else
Return "RigidTruck"
End If
Case tVehCat.Tractor
If NiceName Then
Return "Semitrailer Truck"
Else
Return "Tractor"
End If
Case Else ' tVehCat.Undef
Return "not defined"
End Select
End Function

Michael KRISPER
committed
Public Function ConvVehCat(VehCat As String) As tVehCat
Select Case UCase(Trim(VehCat))
Case "CITYBUS"
Return tVehCat.Citybus
Case "COACH"
Return tVehCat.Coach
Case "INTERURBANBUS"
Return tVehCat.InterurbanBus
Case "RIGIDTRUCK"
Return tVehCat.RigidTruck
Case "TRACTOR"
Return tVehCat.Tractor
Case Else
Return tVehCat.Undef
End Select
End Function

Michael KRISPER
committed
Public Function ConvAxleConf(AxleConf As tAxleConf) As String
Select Case AxleConf
Case tAxleConf.a4x2
Return "4x2"
Case tAxleConf.a4x4
Return "4x4"
Case tAxleConf.a6x2
Return "6x2"
Case tAxleConf.a6x4
Return "6x4"
Case tAxleConf.a6x6
Return "6x6"
Case tAxleConf.a8x2
Return "8x2"
Case tAxleConf.a8x4
Return "8x4"
Case tAxleConf.a8x6
Return "8x6"
Case Else 'tAxleConf.a8x8
Return "8x8"
End Select
End Function

Michael KRISPER
committed
Public Function ConvAxleConf(AxleConf As String) As tAxleConf
Select Case UCase(Trim(AxleConf))
Case "4X2"
Return tAxleConf.a4x2
Case "4X4"
Return tAxleConf.a4x4
Case "6X2"
Return tAxleConf.a6x2
Case "6X4"
Return tAxleConf.a6x4
Case "6X6"
Return tAxleConf.a6x6
Case "8X2"
Return tAxleConf.a8x2
Case "8X4"
Return tAxleConf.a8x4
Case "8X6"
Return tAxleConf.a8x6
Case Else '"8X8"
Return tAxleConf.a8x8
End Select
End Function

Michael KRISPER
committed
Public Function ConvMission(Mission As tMission) As String
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
Select Case Mission
Case tMission.LongHaul
Return "LongHaul"
Case tMission.RegionalDelivery
Return "RegionalDelivery"
Case tMission.UrbanDelivery
Return "UrbanDelivery"
Case tMission.MunicipalUtility
Return "MunicipalUtility"
Case tMission.Construction
Return "Construction"
Case tMission.HeavyUrban
Return "HeavyUrban"
Case tMission.Urban
Return "Urban"
Case tMission.Suburban
Return "Suburban"
Case tMission.Interurban
Return "Interurban"
Case tMission.Coach
Return "Coach"
Case Else
Return "not defined"
End Select
End Function

Michael KRISPER
committed
Public Function ConvMission(Mission As String) As tMission
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
Select Case Mission
Case "LongHaul"
Return tMission.LongHaul
Case "RegionalDelivery"
Return tMission.RegionalDelivery
Case "UrbanDelivery"
Return tMission.UrbanDelivery
Case "MunicipalUtility"
Return tMission.MunicipalUtility
Case "Construction"
Return tMission.Construction
Case "HeavyUrban"
Return tMission.HeavyUrban
Case "Urban"
Return tMission.Urban
Case "Suburban"
Return tMission.Suburban
Case "Interurban"
Return tMission.Interurban
Case "Coach"
Return tMission.Coach
Case Else
Return tMission.Undef
End Select
End Function

Michael KRISPER
committed
Public Function CdModeConv(CdMode As tCdMode) As String
Select Case CdMode
Case tCdMode.CdOfBeta
Return "CdOfBeta"
Case tCdMode.CdOfVeng
Return "CdOfVeng"
Case tCdMode.CdOfVdecl
Return "CdOfVdecl"
Case Else 'tCdMode.ConstCd0
Return "Off"
End Select
End Function

Michael KRISPER
committed
Public Function CdModeConv(CdMode As String) As tCdMode
Select Case UCase(Trim(CdMode))
Case "CDOFBETA"
Return tCdMode.CdOfBeta
Case "CDOFV", "CDOFVENG"
Return tCdMode.CdOfVeng
Case "CDOFVDECL"
Return tCdMode.CdOfVdecl
Case Else '"OFF"
Return tCdMode.ConstCd0
End Select
End Function

Michael KRISPER
committed
Public Function RtTypeConv(RtType As tRtType) As String
Select Case RtType
Case tRtType.Primary
Return "Primary"
Case tRtType.Secondary
Return "Secondary"
Case Else 'tRtType.None
Return "None"
End Select
End Function
Public Function RtTypeConv(rtType As String) As tRtType
Select Case UCase(Trim(rtType))
Case "PRIMARY"
Return tRtType.Primary
Case "SECONDARY"
Return tRtType.Secondary
Case Else '"NONE"
Return tRtType.None
End Select
End Function

Michael KRISPER
committed
Private LOGstream As StreamWriter
Public Function StartLog() As Boolean
Try
LOGstream = My.Computer.FileSystem.OpenTextFileWriter(MyAppPath & "LOG.txt", True, FileFormat)
LOGstream.AutoFlush = True
WriteToLog(tMsgID.Normal, "Starting Session " & Now)
WriteToLog(tMsgID.Normal, "VECTO " & VECTOvers)
Catch ex As Exception
Return False
End Try
Public Function SizeCheck() As Boolean

Michael KRISPER
committed
Dim logfDetail As FileInfo
'Start new log if file size limit reached

Michael KRISPER
committed
If File.Exists(MyAppPath & "LOG.txt") Then
'File size check
logfDetail = My.Computer.FileSystem.GetFileInfo(MyAppPath & "LOG.txt")

Michael KRISPER
committed
If logfDetail.Length / (2 ^ 20) > Cfg.LogSize Then
WriteToLog(tMsgID.Normal, "Starting new logfile")
LOGstream.Close()

Michael KRISPER
committed
If File.Exists(MyAppPath & "LOG_backup.txt") Then File.Delete(MyAppPath & "LOG_backup.txt")
File.Move(MyAppPath & "LOG.txt", MyAppPath & "LOG_backup.txt")
Catch ex As Exception
BackUpError = True
End Try
If BackUpError Then
WriteToLog(tMsgID.Err, "Failed to backup logfile! (" & MyAppPath & "LOG_backup.txt)")
Else
WriteToLog(tMsgID.Normal, "Logfile restarted. Old log saved to LOG_backup.txt")
End If
Public Function CloseLog() As Boolean
Try
WriteToLog(tMsgID.Normal, "Closing Session " & Now)
LOGstream.Close()
Catch ex As Exception
Return False
End Try

Michael KRISPER
committed
Public Function WriteToLog(MsgType As tMsgID, Msg As String) As Boolean
Select Case MsgType
Case tMsgID.Err
MsgTypeStr = "Error"
Case tMsgID.Warn
MsgTypeStr = "Warning"
Case Else
MsgTypeStr = "-"
End Select
Try
LOGstream.WriteLine(Now.ToString("yyyy/MM/dd-HH:mm:ss") & vbTab & MsgTypeStr & vbTab & Msg)
Return True
Catch ex As Exception
Return False
End Try
End Function
End Class
#Region "File path functions"
'When no path is specified, then insert either HomeDir or MainDir Special-folders

Michael KRISPER
committed
Public Function fFileRepl(file As String, Optional ByVal MainDir As String = "") As String
Dim ReplPath As String
'Trim Path
file = Trim(file)
'If empty file => Abort
If file = "" Then Return ""

Michael KRISPER
committed
file = Replace(file, sKey.DefVehPath & "\", MyAppPath & "Default Vehicles\", 1, -1,
CompareMethod.Text)
file = Replace(file, sKey.HomePath & "\", MyAppPath, 1, -1, CompareMethod.Text)
'Replace - Determine folder
If MainDir = "" Then
ReplPath = MyAppPath
Else
ReplPath = MainDir
End If
' "..\" => One folder-level up
Do While ReplPath.Length > 0 AndAlso Left(file, 3) = "..\"
ReplPath = fPathUp(ReplPath)
file = file.Substring(3)
Loop
'Supplement Path, if not available
If fPATH(file) = "" Then
Else
Return file
End If
End Function
'Path one-level-up "C:\temp\ordner1\" >> "C:\temp\"

Michael KRISPER
committed
Private Function fPathUp(Pfad As String) As String
Pfad = Pfad.Substring(0, Pfad.Length - 1)

Michael KRISPER
committed
If x = -1 Then Return ""
Return Pfad.Substring(0, x + 1)
End Function
'File name without the path "C:\temp\TEST.txt" >> "TEST.txt" oder "TEST"

Michael KRISPER
committed
Public Function fFILE(Pfad As String, MitEndung As Boolean) As String
Dim x As Int16
x = Pfad.LastIndexOf("\") + 1

Michael KRISPER
committed
Pfad = Right(Pfad, Len(Pfad) - x)
If Not MitEndung Then
x = Pfad.LastIndexOf(".")

Michael KRISPER
committed
If x > 0 Then Pfad = Left(Pfad, x)
End If
Return Pfad
End Function
'Filename without extension "C:\temp\TEST.txt" >> "C:\temp\TEST"

Michael KRISPER
committed
Public Function fFileWoExt(Path As String) As String
Return fPATH(Path) & fFILE(Path, False)
End Function
'Filename without path if Path = WorkDir or MainDir

Michael KRISPER
committed
Public Function fFileWoDir(file As String, Optional ByVal MainDir As String = "") As String
If MainDir = "" Then
path = MyAppPath
Else
path = MainDir
End If
If UCase(fPATH(file)) = UCase(path) Then file = fFILE(file, True)
'Path alone "C:\temp\TEST.txt" >> "C:\temp\"
' "TEST.txt" >> ""

Michael KRISPER
committed
Public Function fPATH(Pfad As String) As String
Dim x As Int16
If Pfad Is Nothing OrElse Pfad.Length < 3 OrElse Pfad.Substring(1, 2) <> ":\" Then Return ""
x = Pfad.LastIndexOf("\")

Michael KRISPER
committed
Return Left(Pfad, x + 1)
'Extension alone "C:\temp\TEST.txt" >> ".txt"

Michael KRISPER
committed
Public Function fEXT(Pfad As String) As String
Dim x As Int16
x = Pfad.LastIndexOf(".")

Michael KRISPER
committed
If x = -1 Then

Michael KRISPER
committed
Return Right(Pfad, Len(Pfad) - x)
End Module
Public Class csKey
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
Public DRI As csKeyDRI
Public AUX As csKeyAux
Public HomePath As String = "<HOME>"
Public JobPath As String = "<JOBPATH>"
Public DefVehPath As String = "<VEHDIR>"
Public NoFile As String = "<NOFILE>"
Public EmptyString As String = "<EMPTYSTRING>"
Public Break As String = "<//>"
Public Normed As String = "NORM"
Public PauxSply As String = "<AUX_"
Public EngDrag As String = "<DRAG>"
Public Sub New()
DRI = New csKeyDRI
AUX = New csKeyAux
End Sub
Public Class csKeyDRI
Public t As String = "<T>"
Public V As String = "<V>"
Public Grad As String = "<GRAD>"
Public Alt As String = "<ALT>"
Public Gears As String = "<GEAR>"
Public nU As String = "<N>"
Public Pe As String = "<PE>"
Public Padd As String = "<PADD>"
Public VairVres As String = "<VAIR_RES>"
Public VairBeta As String = "<VAIR_BETA>"
Public s As String = "<S>"
Public StopTime As String = "<STOP>"
Public Torque As String = "<ME>"
Public Pwheel As String = "<PWHEEL>"
End Class
Public Class csKeyAux
Public Fan As String = "FAN"
Public SteerPump As String = "STP"
Public HVAC As String = "AC"
Public ElecSys As String = "ES"
Public PneumSys As String = "PS"
End Class