1 | #tag Class |
---|
2 | Protected Class ICSSerialPort |
---|
3 | Inherits serial |
---|
4 | #tag Method, Flags = &h0 |
---|
5 | Sub resetCar() |
---|
6 | //This sends the command to reset the car back to a default configuration |
---|
7 | //Defaults are different for each car type |
---|
8 | setDefaultValues |
---|
9 | |
---|
10 | //Send the default values to the car |
---|
11 | writeCar |
---|
12 | End Sub |
---|
13 | #tag EndMethod |
---|
14 | |
---|
15 | #tag Method, Flags = &h0 |
---|
16 | Sub setDefaultValues() |
---|
17 | //Set the defaults for the bytes sent to a car |
---|
18 | |
---|
19 | select case carType |
---|
20 | |
---|
21 | case "MR-03" |
---|
22 | byte01 = chrb(&hD5) |
---|
23 | byte02 = chrb(&h5A) |
---|
24 | byte03 = chrb(&h64) |
---|
25 | byte04 = chrb(&hFF) |
---|
26 | byte05 = chrb(&h02) |
---|
27 | byte06 = chrb(&h02) |
---|
28 | byte07 = chrb(&h01) |
---|
29 | byte08 = chrb(&hFF) |
---|
30 | byte09 = chrb(&hBC) |
---|
31 | byte10 = chrb(&h44) |
---|
32 | byte11 = chrb(&h88) |
---|
33 | byte12 = chrb(&h78) |
---|
34 | byte13 = chrb(&hFF) |
---|
35 | byte14 = chrb(&h2C) |
---|
36 | byte15 = chrb(&h05) |
---|
37 | byte16 = chrb(&h5A) |
---|
38 | byte17 = chrb(&h3C) |
---|
39 | byte18 = chrb(&h87) |
---|
40 | |
---|
41 | case "dNaNo" |
---|
42 | byte01 = chrb(&hD5) |
---|
43 | byte02 = chrb(&h5A) |
---|
44 | byte03 = chrb(&hFF) |
---|
45 | byte04 = chrb(&hFF) |
---|
46 | byte05 = chrb(&h0A) |
---|
47 | byte06 = chrb(&h03) |
---|
48 | byte07 = chrb(&h01) |
---|
49 | byte08 = chrb(&h40) |
---|
50 | byte09 = chrb(&hBC) |
---|
51 | byte10 = chrb(&h44) |
---|
52 | byte11 = chrb(&h88) |
---|
53 | byte12 = chrb(&h78) |
---|
54 | byte13 = chrb(&h03) |
---|
55 | byte14 = chrb(&hFF) |
---|
56 | byte15 = chrb(&hFF) |
---|
57 | byte16 = chrb(&h80) |
---|
58 | byte17 = chrb(&h80) |
---|
59 | byte18 = chrb(&hA7) |
---|
60 | |
---|
61 | case "ASF" |
---|
62 | byte01 = chrb(&hD5) |
---|
63 | byte02 = chrb(&h5A) |
---|
64 | byte03 = chrb(&hFF) |
---|
65 | byte04 = chrb(&hFF) |
---|
66 | byte05 = chrb(&h0A) |
---|
67 | byte06 = chrb(&h03) |
---|
68 | byte07 = chrb(&h01) |
---|
69 | byte08 = chrb(&h78) |
---|
70 | byte09 = chrb(&hBC) |
---|
71 | byte10 = chrb(&h44) |
---|
72 | byte11 = chrb(&h88) |
---|
73 | byte12 = chrb(&h78) |
---|
74 | byte13 = chrb(&h03) |
---|
75 | byte14 = chrb(&hFF) |
---|
76 | byte15 = chrb(&hFF) |
---|
77 | byte16 = chrb(&hFF) |
---|
78 | byte17 = chrb(&hFF) |
---|
79 | byte18 = chrb(&hDD) |
---|
80 | |
---|
81 | else |
---|
82 | //default thing to do |
---|
83 | MsgBox "Error invalid car type" |
---|
84 | return |
---|
85 | end select |
---|
86 | |
---|
87 | //trigger the event definition so main program knows the values changed |
---|
88 | valuesChanged() |
---|
89 | End Sub |
---|
90 | #tag EndMethod |
---|
91 | |
---|
92 | #tag Method, Flags = &h0 |
---|
93 | Sub setCarType(value as string) |
---|
94 | //When setting car type we must reconfigure the serial port |
---|
95 | //Some car types have a different baud rate |
---|
96 | |
---|
97 | select case value |
---|
98 | |
---|
99 | case "MR-03" |
---|
100 | carType = value |
---|
101 | byte15 = chrb(&h05) |
---|
102 | byte16 = chrb(&h5A) |
---|
103 | byte17 = chrb(&h3C) |
---|
104 | case "dNaNo" |
---|
105 | carType = value |
---|
106 | byte15 = chrb(&hFF) |
---|
107 | byte16 = chrb(&h80) |
---|
108 | byte17 = chrb(&h80) |
---|
109 | case "ASF" |
---|
110 | carType = value |
---|
111 | byte15 = chrb(&hFF) |
---|
112 | byte16 = chrb(&hFF) |
---|
113 | byte17 = chrb(&hFF) |
---|
114 | |
---|
115 | else |
---|
116 | MsgBox "Error setting Car Type" |
---|
117 | end select |
---|
118 | |
---|
119 | valuesChanged() |
---|
120 | End Sub |
---|
121 | #tag EndMethod |
---|
122 | |
---|
123 | #tag Method, Flags = &h0 |
---|
124 | Sub writeCar() |
---|
125 | //Send set bytes to the car |
---|
126 | mode = "write" |
---|
127 | |
---|
128 | dim sendstring as string |
---|
129 | |
---|
130 | calculateChecksum() |
---|
131 | |
---|
132 | sendstring = byte01 + byte02 + byte03 + byte04 + byte05 + byte06 + byte07 + byte08 + byte09 + byte10 + byte11 + byte12 + byte13 + byte14 + byte15 + byte16 + byte17 + byte18 |
---|
133 | |
---|
134 | me.Write(sendstring) |
---|
135 | End Sub |
---|
136 | #tag EndMethod |
---|
137 | |
---|
138 | #tag Method, Flags = &h0 |
---|
139 | Sub calculateChecksum() |
---|
140 | //Use this to calculate byte 18, the checksum |
---|
141 | //The checksum is just adding bytes 2-17 together but rounded at each byte |
---|
142 | |
---|
143 | dim i as integer |
---|
144 | |
---|
145 | i = (asc(byte02) + asc(byte03)) mod &h100 |
---|
146 | i = (i + asc(byte04)) mod &h100 |
---|
147 | i = (i + asc(byte05)) mod &h100 |
---|
148 | i = (i + asc(byte06)) mod &h100 |
---|
149 | i = (i + asc(byte07)) mod &h100 |
---|
150 | i = (i + asc(byte08)) mod &h100 |
---|
151 | i = (i + asc(byte09)) mod &h100 |
---|
152 | i = (i + asc(byte10)) mod &h100 |
---|
153 | i = (i + asc(byte11)) mod &h100 |
---|
154 | i = (i + asc(byte12)) mod &h100 |
---|
155 | i = (i + asc(byte13)) mod &h100 |
---|
156 | i = (i + asc(byte14)) mod &h100 |
---|
157 | i = (i + asc(byte15)) mod &h100 |
---|
158 | i = (i + asc(byte16)) mod &h100 |
---|
159 | i = (i + asc(byte17)) mod &h100 |
---|
160 | |
---|
161 | byte18 = chrb(i) |
---|
162 | End Sub |
---|
163 | #tag EndMethod |
---|
164 | |
---|
165 | #tag Method, Flags = &h0 |
---|
166 | Sub readCar() |
---|
167 | //Read values from the currently attached car |
---|
168 | dim sendstring as string |
---|
169 | |
---|
170 | mode = "read" |
---|
171 | |
---|
172 | sendstring = chrb(&hC5) |
---|
173 | |
---|
174 | me.Write(sendstring) |
---|
175 | End Sub |
---|
176 | #tag EndMethod |
---|
177 | |
---|
178 | #tag Method, Flags = &h0 |
---|
179 | Sub Constructor() |
---|
180 | //Make sure we have a database and if not create it |
---|
181 | dim exists as boolean |
---|
182 | |
---|
183 | exists = prepareDB() |
---|
184 | if exists = false then |
---|
185 | //No database available, create one |
---|
186 | createDB() |
---|
187 | else |
---|
188 | //Database exists, connect to it |
---|
189 | if fsicsdb.Connect = false then |
---|
190 | MsgBox "Database connection failed" |
---|
191 | end if |
---|
192 | end if |
---|
193 | |
---|
194 | //Set default byte values |
---|
195 | byte01 = chrb(&hD5) |
---|
196 | byte02 = chrb(&h5A) |
---|
197 | byte03 = chrb(&h64) |
---|
198 | byte04 = chrb(&hFF) |
---|
199 | byte05 = chrb(&h02) |
---|
200 | byte06 = chrb(&h02) |
---|
201 | byte07 = chrb(&h01) |
---|
202 | byte08 = chrb(&hFF) |
---|
203 | byte09 = chrb(&hBC) |
---|
204 | byte10 = chrb(&h44) |
---|
205 | byte11 = chrb(&h88) |
---|
206 | byte12 = chrb(&h78) |
---|
207 | byte13 = chrb(&hFF) |
---|
208 | byte14 = chrb(&h2C) |
---|
209 | byte15 = chrb(&h05) |
---|
210 | byte16 = chrb(&h5A) |
---|
211 | byte17 = chrb(&h3C) |
---|
212 | byte18 = chrb(&h87) |
---|
213 | |
---|
214 | carType = "MR-03" |
---|
215 | End Sub |
---|
216 | #tag EndMethod |
---|
217 | |
---|
218 | #tag Method, Flags = &h21 |
---|
219 | Private Function prepareDB() As Boolean |
---|
220 | //Open the database file |
---|
221 | fsicsdb = new REALSQLDatabase |
---|
222 | dim f as FolderItem = GetFolderItem("fsicsdb") |
---|
223 | fsicsdb.DatabaseFile = f |
---|
224 | |
---|
225 | return f.Exists |
---|
226 | End Function |
---|
227 | #tag EndMethod |
---|
228 | |
---|
229 | #tag Method, Flags = &h21 |
---|
230 | Private Sub createDB() |
---|
231 | //Create a new database |
---|
232 | |
---|
233 | |
---|
234 | //make sure we can create the file |
---|
235 | if fsicsdb.CreateDatabaseFile() then |
---|
236 | if fsicsdb.Connect() then |
---|
237 | dim query as string |
---|
238 | query = "CREATE TABLE carprofiles (id INTEGER PRIMARY KEY, name VARCHAR, cartype VARCHAR, byte01 INTEGER, byte02 INTEGER, byte03 INTEGER, byte04 INTEGER, byte05 INTEGER, byte06 INTEGER"+_ |
---|
239 | ", byte07 INTEGER, byte08 INTEGER, byte09 INTEGER, byte10 INTEGER, byte11 INTEGER, byte12 INTEGER, byte13 INTEGER, byte14 INTEGER, byte15 INTEGER, byte16 INTEGER, byte17 INTEGER"+_ |
---|
240 | ", byte18 INTEGER, UNIQUE(name))" |
---|
241 | fsicsdb.SQLExecute(query) |
---|
242 | if fsicsdb.Error then |
---|
243 | MsgBox "Database Error (carprofiles):" + fsicsdb.ErrorMessage |
---|
244 | fsicsdb.Rollback |
---|
245 | |
---|
246 | else |
---|
247 | fsicsdb.Commit |
---|
248 | end if |
---|
249 | |
---|
250 | |
---|
251 | else |
---|
252 | MsgBox "Failed to connect to new database file" |
---|
253 | end if |
---|
254 | else |
---|
255 | //Failed to create database file |
---|
256 | MsgBox "Failed to create database file" |
---|
257 | end if |
---|
258 | End Sub |
---|
259 | #tag EndMethod |
---|
260 | |
---|
261 | #tag Method, Flags = &h0 |
---|
262 | Function createProfile(theName as String) As Boolean |
---|
263 | dim success as boolean |
---|
264 | success = false |
---|
265 | |
---|
266 | //Make sure we got a name |
---|
267 | if theName = "" then |
---|
268 | return success |
---|
269 | else |
---|
270 | //Build a new database record |
---|
271 | dim rec as DatabaseRecord |
---|
272 | rec = New DatabaseRecord |
---|
273 | |
---|
274 | rec.Column("name") = theName |
---|
275 | rec.Column("cartype") = carType |
---|
276 | rec.IntegerColumn("byte01") = asc(byte01) |
---|
277 | rec.IntegerColumn("byte02") = asc(byte02) |
---|
278 | rec.IntegerColumn("byte03") = asc(byte03) |
---|
279 | rec.IntegerColumn("byte04") = asc(byte04) |
---|
280 | rec.IntegerColumn("byte05") = asc(byte05) |
---|
281 | rec.IntegerColumn("byte06") = asc(byte06) |
---|
282 | rec.IntegerColumn("byte07") = asc(byte07) |
---|
283 | rec.IntegerColumn("byte08") = asc(byte08) |
---|
284 | rec.IntegerColumn("byte09") = asc(byte09) |
---|
285 | rec.IntegerColumn("byte10") = asc(byte10) |
---|
286 | rec.IntegerColumn("byte11") = asc(byte11) |
---|
287 | rec.IntegerColumn("byte12") = asc(byte12) |
---|
288 | rec.IntegerColumn("byte13") = asc(byte13) |
---|
289 | rec.IntegerColumn("byte14") = asc(byte14) |
---|
290 | rec.IntegerColumn("byte15") = asc(byte15) |
---|
291 | rec.IntegerColumn("byte16") = asc(byte16) |
---|
292 | rec.IntegerColumn("byte17") = asc(byte17) |
---|
293 | rec.IntegerColumn("byte18") = asc(byte18) |
---|
294 | |
---|
295 | fsicsdb.InsertRecord("carprofiles", rec) |
---|
296 | |
---|
297 | if fsicsdb.Error = True then |
---|
298 | MsgBox "Error creating profile, " + fsicsdb.ErrorMessage |
---|
299 | fsicsdb.Rollback |
---|
300 | else |
---|
301 | fsicsdb.Commit |
---|
302 | success = true |
---|
303 | end if |
---|
304 | end if |
---|
305 | |
---|
306 | Return success |
---|
307 | End Function |
---|
308 | #tag EndMethod |
---|
309 | |
---|
310 | #tag Method, Flags = &h0 |
---|
311 | Sub deleteProfile(theName as String) |
---|
312 | if theName <> "" then |
---|
313 | |
---|
314 | //Delete the profile selected |
---|
315 | fsicsdb.SQLExecute("DELETE FROM carprofiles WHERE name = '" + theName + "'") |
---|
316 | |
---|
317 | //Check for errors |
---|
318 | if fsicsdb.Error = True then |
---|
319 | MsgBox "Error deleting profile" |
---|
320 | fsicsdb.Rollback |
---|
321 | else |
---|
322 | fsicsdb.Commit |
---|
323 | end if |
---|
324 | |
---|
325 | else |
---|
326 | |
---|
327 | MsgBox "Please select a profile to delete" |
---|
328 | |
---|
329 | end if |
---|
330 | End Sub |
---|
331 | #tag EndMethod |
---|
332 | |
---|
333 | #tag Method, Flags = &h0 |
---|
334 | Sub saveProfile(theName as String) |
---|
335 | if theName <> "" then |
---|
336 | |
---|
337 | dim rs as RecordSet |
---|
338 | dim status as Boolean |
---|
339 | |
---|
340 | //Find a record |
---|
341 | rs = fsicsdb.SQLSelect("SELECT * FROM carprofiles WHERE name= '"+theName+"'") |
---|
342 | |
---|
343 | //Make sure we got a record |
---|
344 | if rs <> nil then |
---|
345 | //delete the record before saving |
---|
346 | deleteProfile(theName) |
---|
347 | end if |
---|
348 | |
---|
349 | rs.Close |
---|
350 | |
---|
351 | status = createProfile(theName) |
---|
352 | |
---|
353 | else |
---|
354 | |
---|
355 | MsgBox "Please select a profile to modify" |
---|
356 | |
---|
357 | end if |
---|
358 | End Sub |
---|
359 | #tag EndMethod |
---|
360 | |
---|
361 | #tag Method, Flags = &h0 |
---|
362 | Function listProfiles() As String() |
---|
363 | dim rs as RecordSet |
---|
364 | dim s() as string |
---|
365 | |
---|
366 | //Find records |
---|
367 | rs = fsicsdb.SQLSelect("SELECT name FROM carprofiles") |
---|
368 | |
---|
369 | if rs <> nil then |
---|
370 | |
---|
371 | while rs.EOF = false |
---|
372 | s.Append rs.Field("name").StringValue |
---|
373 | rs.MoveNext |
---|
374 | wend |
---|
375 | |
---|
376 | end if |
---|
377 | |
---|
378 | rs.Close |
---|
379 | Return s() |
---|
380 | End Function |
---|
381 | #tag EndMethod |
---|
382 | |
---|
383 | #tag Method, Flags = &h0 |
---|
384 | Sub loadProfile(theName as string) |
---|
385 | //Find the profile in the database, update the bytes and fire the event |
---|
386 | dim rs as RecordSet |
---|
387 | |
---|
388 | rs = fsicsdb.SQLSelect("SELECT * FROM carprofiles WHERE name= '"+theName+"'") |
---|
389 | |
---|
390 | //Make sure we got a record to work with |
---|
391 | if rs <> Nil then |
---|
392 | |
---|
393 | if rs.Field("cartype").StringValue <> "" then |
---|
394 | carType = rs.Field("cartype").StringValue |
---|
395 | end if |
---|
396 | |
---|
397 | if rs.Field("byte01").StringValue <> "" then |
---|
398 | byte01 = chrb(rs.Field("byte01").IntegerValue) |
---|
399 | end if |
---|
400 | if rs.Field("byte02").StringValue <> "" then |
---|
401 | byte02 = chrb(rs.Field("byte02").IntegerValue) |
---|
402 | end if |
---|
403 | if rs.Field("byte03").StringValue <> "" then |
---|
404 | byte03 = chrb(rs.Field("byte03").IntegerValue) |
---|
405 | end if |
---|
406 | if rs.Field("byte04").StringValue <> "" then |
---|
407 | byte04 = chrb(rs.Field("byte04").IntegerValue) |
---|
408 | end if |
---|
409 | if rs.Field("byte05").StringValue <> "" then |
---|
410 | byte05 = chrb(rs.Field("byte05").IntegerValue) |
---|
411 | end if |
---|
412 | if rs.Field("byte06").StringValue <> "" then |
---|
413 | byte06 = chrb(rs.Field("byte06").IntegerValue) |
---|
414 | end if |
---|
415 | if rs.Field("byte07").StringValue <> "" then |
---|
416 | byte07 = chrb(rs.Field("byte07").IntegerValue) |
---|
417 | end if |
---|
418 | if rs.Field("byte08").StringValue <> "" then |
---|
419 | byte08 = chrb(rs.Field("byte08").IntegerValue) |
---|
420 | end if |
---|
421 | if rs.Field("byte09").StringValue <> "" then |
---|
422 | byte09 = chrb(rs.Field("byte09").IntegerValue) |
---|
423 | end if |
---|
424 | if rs.Field("byte10").StringValue <> "" then |
---|
425 | byte10 = chrb(rs.Field("byte10").IntegerValue) |
---|
426 | end if |
---|
427 | if rs.Field("byte11").StringValue <> "" then |
---|
428 | byte11 = chrb(rs.Field("byte11").IntegerValue) |
---|
429 | end if |
---|
430 | if rs.Field("byte12").StringValue <> "" then |
---|
431 | byte12 = chrb(rs.Field("byte12").IntegerValue) |
---|
432 | end if |
---|
433 | if rs.Field("byte13").StringValue <> "" then |
---|
434 | byte13 = chrb(rs.Field("byte13").IntegerValue) |
---|
435 | end if |
---|
436 | if rs.Field("byte14").StringValue <> "" then |
---|
437 | byte14 = chrb(rs.Field("byte14").IntegerValue) |
---|
438 | end if |
---|
439 | if rs.Field("byte15").StringValue <> "" then |
---|
440 | byte15 = chrb(rs.Field("byte15").IntegerValue) |
---|
441 | end if |
---|
442 | if rs.Field("byte16").StringValue <> "" then |
---|
443 | byte16 = chrb(rs.Field("byte16").IntegerValue) |
---|
444 | end if |
---|
445 | if rs.Field("byte17").StringValue <> "" then |
---|
446 | byte17 = chrb(rs.Field("byte17").IntegerValue) |
---|
447 | end if |
---|
448 | if rs.Field("byte18").StringValue <> "" then |
---|
449 | byte18 = chrb(rs.Field("byte18").IntegerValue) |
---|
450 | end if |
---|
451 | |
---|
452 | valuesChanged() |
---|
453 | end if |
---|
454 | End Sub |
---|
455 | #tag EndMethod |
---|
456 | |
---|
457 | #tag Method, Flags = &h0 |
---|
458 | Sub exportProfile(theName as string) |
---|
459 | dim xml as XmlDocument |
---|
460 | dim root as XmlNode |
---|
461 | dim rootchild as XmlNode |
---|
462 | dim rs as RecordSet |
---|
463 | dim i as integer |
---|
464 | dim dlg as SaveAsDialog |
---|
465 | dim f as FolderItem |
---|
466 | |
---|
467 | dlg = New SaveAsDialog |
---|
468 | dlg.Title = "Export your profile" |
---|
469 | #if TargetLinux |
---|
470 | dlg.InitialDirectory = SpecialFolder.Home |
---|
471 | #else |
---|
472 | dlg.InitialDirectory = SpecialFolder.Documents |
---|
473 | #endif |
---|
474 | |
---|
475 | dlg.SuggestedFileName = "ics_"+theName+".xml" |
---|
476 | f = dlg.ShowModal() |
---|
477 | |
---|
478 | if f <> Nil then |
---|
479 | //Nothing to see here, move along |
---|
480 | else |
---|
481 | MsgBox "You must choose a file" |
---|
482 | Return |
---|
483 | end if |
---|
484 | |
---|
485 | //Find the record |
---|
486 | rs = fsicsdb.SQLSelect("SELECT * FROM carprofiles WHERE name= '"+theName+"'") |
---|
487 | |
---|
488 | if rs <> Nil then |
---|
489 | //We have a record, so do something |
---|
490 | |
---|
491 | //Create the root element of the XML file |
---|
492 | xml = New XmlDocument |
---|
493 | root = xml.AppendChild(xml.CreateElement("icsprofile")) |
---|
494 | |
---|
495 | //Itterate all available fields and write them to the xml document |
---|
496 | for i = 1 to rs.FieldCount |
---|
497 | if rs.IdxField(i).Name <> "" and rs.IdxField(i).StringValue<> "" then |
---|
498 | |
---|
499 | rootchild = root.AppendChild(xml.CreateElement(rs.IdxField(i).Name)) |
---|
500 | rootchild.AppendChild(xml.CreateTextNode(rs.IdxField(i).StringValue)) |
---|
501 | end if |
---|
502 | next |
---|
503 | |
---|
504 | //Write the document to a file |
---|
505 | xml.SaveXml(f) |
---|
506 | else |
---|
507 | MsgBox "No profile to export" |
---|
508 | Return |
---|
509 | end if |
---|
510 | |
---|
511 | End Sub |
---|
512 | #tag EndMethod |
---|
513 | |
---|
514 | #tag Method, Flags = &h0 |
---|
515 | Function importProfile() As Boolean |
---|
516 | dim success as boolean |
---|
517 | dim dlg as OpenDialog |
---|
518 | dim f as FolderItem |
---|
519 | dim xdoc as XmlDocument |
---|
520 | dim root as XmlNode |
---|
521 | dim i as integer |
---|
522 | dim count as Integer |
---|
523 | dim item as string |
---|
524 | dim rec as DatabaseRecord |
---|
525 | dim theName as string |
---|
526 | |
---|
527 | rec = New DatabaseRecord |
---|
528 | success = False |
---|
529 | |
---|
530 | |
---|
531 | //Get the user to select a file |
---|
532 | dlg = New OpenDialog |
---|
533 | dlg.Title = "Select a profile to import" |
---|
534 | #if TargetLinux |
---|
535 | dlg.InitialDirectory = SpecialFolder.Home |
---|
536 | #else |
---|
537 | dlg.InitialDirectory = SpecialFolder.Documents |
---|
538 | #endif |
---|
539 | f = dlg.ShowModal() |
---|
540 | |
---|
541 | //If we have a valid file we need to read it as an xml file to process it |
---|
542 | //Items are individually specified to prevent the program from trying to insert columns that do not exist |
---|
543 | //All column names should match the database table |
---|
544 | |
---|
545 | if f <> nil then |
---|
546 | |
---|
547 | //Read the XML file |
---|
548 | xdoc = New XmlDocument(f) |
---|
549 | |
---|
550 | count = xdoc.DocumentElement.ChildCount |
---|
551 | |
---|
552 | for i = 0 to count - 1 |
---|
553 | root = xdoc.DocumentElement.Child(i) |
---|
554 | |
---|
555 | item = root.FirstChild.Value |
---|
556 | |
---|
557 | select case root.Name |
---|
558 | |
---|
559 | case "name" |
---|
560 | theName = item |
---|
561 | case "cartype" |
---|
562 | carType = item |
---|
563 | case "byte01" |
---|
564 | byte01 = chrb(val(item)) |
---|
565 | case "byte02" |
---|
566 | byte02 = chrb(val(item)) |
---|
567 | case "byte03" |
---|
568 | byte03 = chrb(val(item)) |
---|
569 | case "byte04" |
---|
570 | byte04 = chrb(val(item)) |
---|
571 | case "byte05" |
---|
572 | byte05 = chrb(val(item)) |
---|
573 | case "byte06" |
---|
574 | byte06 = chrb(val(item)) |
---|
575 | case "byte07" |
---|
576 | byte07 = chrb(val(item)) |
---|
577 | case "byte08" |
---|
578 | byte08 = chrb(val(item)) |
---|
579 | case "byte09" |
---|
580 | byte09 = chrb(val(item)) |
---|
581 | case "byte10" |
---|
582 | byte10 = chrb(val(item)) |
---|
583 | case "byte11" |
---|
584 | byte11 = chrb(val(item)) |
---|
585 | case "byte12" |
---|
586 | byte12 = chrb(val(item)) |
---|
587 | case "byte13" |
---|
588 | byte13 = chrb(val(item)) |
---|
589 | case "byte14" |
---|
590 | byte14 = chrb(val(item)) |
---|
591 | case "byte15" |
---|
592 | byte15 = chrb(val(item)) |
---|
593 | case "byte16" |
---|
594 | byte16 = chrb(val(item)) |
---|
595 | case "byte17" |
---|
596 | byte17 = chrb(val(item)) |
---|
597 | case "byte18" |
---|
598 | byte18 = chrb(val(item)) |
---|
599 | |
---|
600 | end select |
---|
601 | |
---|
602 | next |
---|
603 | |
---|
604 | else |
---|
605 | //File not select we can stop |
---|
606 | success = False |
---|
607 | return success |
---|
608 | end if |
---|
609 | |
---|
610 | //Now check to make sure their is not an existing profile with this name |
---|
611 | dim rs as RecordSet |
---|
612 | |
---|
613 | rs = fsicsdb.SQLSelect("SELECT * FROM carprofiles WHERE name= '"+theName+"'") |
---|
614 | |
---|
615 | if rs <> Nil then |
---|
616 | |
---|
617 | if rs.RecordCount > 0 then |
---|
618 | //we have a duplicate record |
---|
619 | //we need to prompt the user about what to do |
---|
620 | dim d as New MessageDialog |
---|
621 | dim b as MessageDialogButton |
---|
622 | d.Icon = MessageDialog.GraphicCaution |
---|
623 | d.ActionButton.Caption = "Yes" |
---|
624 | d.CancelButton.Visible = True |
---|
625 | d.CancelButton.Caption = "No" |
---|
626 | d.Message = "A profile exists with this name, do you want to overwrite the existing profile?" |
---|
627 | b = d.ShowModal |
---|
628 | |
---|
629 | //Now determine what the user chose |
---|
630 | Select Case b |
---|
631 | case d.ActionButton |
---|
632 | //The user wants to overwrite the record so we can just save what we have |
---|
633 | saveProfile(theName) |
---|
634 | success = True |
---|
635 | //Values changed because of the overwrite |
---|
636 | valuesChanged() |
---|
637 | case d.CancelButton |
---|
638 | //The user chose not to overwrite the record, we need to come up with a new name |
---|
639 | //We will increment the number until we find a name not used or we hit 32 just in case an infinite loop would occur |
---|
640 | dim tempString as string |
---|
641 | dim tempName as string |
---|
642 | i = 0 |
---|
643 | while rs.RecordCount > 0 |
---|
644 | i = i + 1 |
---|
645 | tempString = str(i) |
---|
646 | tempName = theName + tempString |
---|
647 | //Check to make sure we are not in an infinite looooooooop |
---|
648 | //If we are something went wrong |
---|
649 | if i > 31 then |
---|
650 | exit While |
---|
651 | end if |
---|
652 | rs = fsicsdb.SQLSelect("SELECT * FROM carprofiles WHERE name = '"+tempName+"'") |
---|
653 | |
---|
654 | wend |
---|
655 | //OK we have a unique name at this point |
---|
656 | theName = theName + tempString |
---|
657 | saveProfile(theName) |
---|
658 | success = True |
---|
659 | //new profile was imported |
---|
660 | profileImported(theName) |
---|
661 | end select |
---|
662 | |
---|
663 | else |
---|
664 | //No duplicate exists so we can just insert the record |
---|
665 | saveProfile(theName) |
---|
666 | success = True |
---|
667 | //new profile was imported |
---|
668 | profileImported(theName) |
---|
669 | end if |
---|
670 | //Close our record |
---|
671 | rs.Close |
---|
672 | |
---|
673 | end if |
---|
674 | |
---|
675 | Return success |
---|
676 | |
---|
677 | End Function |
---|
678 | #tag EndMethod |
---|
679 | |
---|
680 | |
---|
681 | #tag Hook, Flags = &h0 |
---|
682 | Event valuesChanged() |
---|
683 | #tag EndHook |
---|
684 | |
---|
685 | #tag Hook, Flags = &h0 |
---|
686 | Event profileImported(profileName as string) |
---|
687 | #tag EndHook |
---|
688 | |
---|
689 | |
---|
690 | #tag Note, Name = General |
---|
691 | Car type must be set for this to operate |
---|
692 | Car types supported by this application are |
---|
693 | MR-03 |
---|
694 | dNaNo |
---|
695 | ASF |
---|
696 | #tag EndNote |
---|
697 | |
---|
698 | #tag Note, Name = License |
---|
699 | Copyright 2010 Jeremy Auten |
---|
700 | |
---|
701 | This file is part of Flip Side ICS Software. |
---|
702 | |
---|
703 | Flip Side ICS Software is free software: you can redistribute it and/or modify |
---|
704 | it under the terms of the GNU General Public License as published by |
---|
705 | the Free Software Foundation, either version 3 of the License, or |
---|
706 | (at your option) any later version. |
---|
707 | |
---|
708 | Flip Side ICS Software is distributed in the hope that it will be useful, |
---|
709 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
710 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
711 | GNU General Public License for more details. |
---|
712 | |
---|
713 | You should have received a copy of the GNU General Public License |
---|
714 | along with Flip Side ICS Software. If not, see <http://www.gnu.org/licenses/>. |
---|
715 | |
---|
716 | #tag EndNote |
---|
717 | |
---|
718 | |
---|
719 | #tag Property, Flags = &h0 |
---|
720 | byte01 As String |
---|
721 | #tag EndProperty |
---|
722 | |
---|
723 | #tag Property, Flags = &h0 |
---|
724 | byte11 As String |
---|
725 | #tag EndProperty |
---|
726 | |
---|
727 | #tag Property, Flags = &h0 |
---|
728 | byte12 As String |
---|
729 | #tag EndProperty |
---|
730 | |
---|
731 | #tag Property, Flags = &h0 |
---|
732 | byte13 As String |
---|
733 | #tag EndProperty |
---|
734 | |
---|
735 | #tag Property, Flags = &h0 |
---|
736 | byte14 As String |
---|
737 | #tag EndProperty |
---|
738 | |
---|
739 | #tag Property, Flags = &h0 |
---|
740 | byte15 As String |
---|
741 | #tag EndProperty |
---|
742 | |
---|
743 | #tag Property, Flags = &h0 |
---|
744 | byte16 As String |
---|
745 | #tag EndProperty |
---|
746 | |
---|
747 | #tag Property, Flags = &h0 |
---|
748 | byte17 As String |
---|
749 | #tag EndProperty |
---|
750 | |
---|
751 | #tag Property, Flags = &h0 |
---|
752 | byte18 As String |
---|
753 | #tag EndProperty |
---|
754 | |
---|
755 | #tag Property, Flags = &h0 |
---|
756 | byte02 As String |
---|
757 | #tag EndProperty |
---|
758 | |
---|
759 | #tag Property, Flags = &h0 |
---|
760 | byte03 As String |
---|
761 | #tag EndProperty |
---|
762 | |
---|
763 | #tag Property, Flags = &h0 |
---|
764 | byte04 As String |
---|
765 | #tag EndProperty |
---|
766 | |
---|
767 | #tag Property, Flags = &h0 |
---|
768 | byte05 As String |
---|
769 | #tag EndProperty |
---|
770 | |
---|
771 | #tag Property, Flags = &h0 |
---|
772 | byte06 As String |
---|
773 | #tag EndProperty |
---|
774 | |
---|
775 | #tag Property, Flags = &h0 |
---|
776 | byte07 As String |
---|
777 | #tag EndProperty |
---|
778 | |
---|
779 | #tag Property, Flags = &h0 |
---|
780 | byte08 As String |
---|
781 | #tag EndProperty |
---|
782 | |
---|
783 | #tag Property, Flags = &h0 |
---|
784 | byte09 As String |
---|
785 | #tag EndProperty |
---|
786 | |
---|
787 | #tag Property, Flags = &h0 |
---|
788 | byte10 As String |
---|
789 | #tag EndProperty |
---|
790 | |
---|
791 | #tag Property, Flags = &h0 |
---|
792 | carType As String = "MR-03" |
---|
793 | #tag EndProperty |
---|
794 | |
---|
795 | #tag Property, Flags = &h0 |
---|
796 | fsicsdb As REALSQLDatabase |
---|
797 | #tag EndProperty |
---|
798 | |
---|
799 | #tag Property, Flags = &h0 |
---|
800 | mode As String = "none" |
---|
801 | #tag EndProperty |
---|
802 | |
---|
803 | |
---|
804 | #tag ViewBehavior |
---|
805 | #tag ViewProperty |
---|
806 | Name="Name" |
---|
807 | Visible=true |
---|
808 | Group="ID" |
---|
809 | InheritedFrom="serial" |
---|
810 | #tag EndViewProperty |
---|
811 | #tag ViewProperty |
---|
812 | Name="Index" |
---|
813 | Visible=true |
---|
814 | Group="ID" |
---|
815 | Type="Integer" |
---|
816 | InheritedFrom="serial" |
---|
817 | #tag EndViewProperty |
---|
818 | #tag ViewProperty |
---|
819 | Name="Super" |
---|
820 | Visible=true |
---|
821 | Group="ID" |
---|
822 | InheritedFrom="serial" |
---|
823 | #tag EndViewProperty |
---|
824 | #tag ViewProperty |
---|
825 | Name="Left" |
---|
826 | Visible=true |
---|
827 | Group="Position" |
---|
828 | InheritedFrom="serial" |
---|
829 | #tag EndViewProperty |
---|
830 | #tag ViewProperty |
---|
831 | Name="Top" |
---|
832 | Visible=true |
---|
833 | Group="Position" |
---|
834 | InheritedFrom="serial" |
---|
835 | #tag EndViewProperty |
---|
836 | #tag ViewProperty |
---|
837 | Name="Baud" |
---|
838 | Visible=true |
---|
839 | Group="Behavior" |
---|
840 | InitialValue="13" |
---|
841 | Type="Integer" |
---|
842 | EditorType="Enum" |
---|
843 | InheritedFrom="serial" |
---|
844 | #tag EnumValues |
---|
845 | "0 - 300" |
---|
846 | "1 - 600" |
---|
847 | "2 - 1200" |
---|
848 | "3 - 1800" |
---|
849 | "4 - 2400" |
---|
850 | "5 - 3600" |
---|
851 | "6 - 4800" |
---|
852 | "7 - 7200" |
---|
853 | "8 - 9600" |
---|
854 | "9 - 14400" |
---|
855 | "10 - 19200" |
---|
856 | "11 - 28800" |
---|
857 | "12 - 38400" |
---|
858 | "13 - 57600" |
---|
859 | "14 - 115200" |
---|
860 | "15 - 230400" |
---|
861 | #tag EndEnumValues |
---|
862 | #tag EndViewProperty |
---|
863 | #tag ViewProperty |
---|
864 | Name="Bits" |
---|
865 | Visible=true |
---|
866 | Group="Behavior" |
---|
867 | InitialValue="3" |
---|
868 | Type="Integer" |
---|
869 | EditorType="Enum" |
---|
870 | InheritedFrom="serial" |
---|
871 | #tag EnumValues |
---|
872 | "0 - 5 Data Bits" |
---|
873 | "1 - 6 Data Bits" |
---|
874 | "2 - 7 Data Bits" |
---|
875 | "3 - 8 Data bits" |
---|
876 | #tag EndEnumValues |
---|
877 | #tag EndViewProperty |
---|
878 | #tag ViewProperty |
---|
879 | Name="Parity" |
---|
880 | Visible=true |
---|
881 | Group="Behavior" |
---|
882 | InitialValue="0" |
---|
883 | Type="Integer" |
---|
884 | EditorType="Enum" |
---|
885 | InheritedFrom="serial" |
---|
886 | #tag EnumValues |
---|
887 | "0 - No Parity" |
---|
888 | "1 - Odd Parity" |
---|
889 | "2 - EvenParity" |
---|
890 | #tag EndEnumValues |
---|
891 | #tag EndViewProperty |
---|
892 | #tag ViewProperty |
---|
893 | Name="Stop" |
---|
894 | Visible=true |
---|
895 | Group="Behavior" |
---|
896 | InitialValue="0" |
---|
897 | Type="Integer" |
---|
898 | EditorType="Enum" |
---|
899 | InheritedFrom="serial" |
---|
900 | #tag EnumValues |
---|
901 | "0 - 1 Stop Bit" |
---|
902 | "1 - 1.5 Stop Bits" |
---|
903 | "2 - 2 Stop Bits" |
---|
904 | #tag EndEnumValues |
---|
905 | #tag EndViewProperty |
---|
906 | #tag ViewProperty |
---|
907 | Name="XON" |
---|
908 | Visible=true |
---|
909 | Group="Behavior" |
---|
910 | Type="Boolean" |
---|
911 | InheritedFrom="serial" |
---|
912 | #tag EndViewProperty |
---|
913 | #tag ViewProperty |
---|
914 | Name="CTS" |
---|
915 | Visible=true |
---|
916 | Group="Behavior" |
---|
917 | Type="Boolean" |
---|
918 | InheritedFrom="serial" |
---|
919 | #tag EndViewProperty |
---|
920 | #tag ViewProperty |
---|
921 | Name="DTR" |
---|
922 | Visible=true |
---|
923 | Group="Behavior" |
---|
924 | Type="Boolean" |
---|
925 | InheritedFrom="serial" |
---|
926 | #tag EndViewProperty |
---|
927 | #tag ViewProperty |
---|
928 | Name="byte01" |
---|
929 | Group="Behavior" |
---|
930 | InitialValue="&hFF" |
---|
931 | Type="String" |
---|
932 | EditorType="MultiLineEditor" |
---|
933 | #tag EndViewProperty |
---|
934 | #tag ViewProperty |
---|
935 | Name="byte11" |
---|
936 | Group="Behavior" |
---|
937 | Type="String" |
---|
938 | EditorType="MultiLineEditor" |
---|
939 | #tag EndViewProperty |
---|
940 | #tag ViewProperty |
---|
941 | Name="byte12" |
---|
942 | Group="Behavior" |
---|
943 | Type="String" |
---|
944 | EditorType="MultiLineEditor" |
---|
945 | #tag EndViewProperty |
---|
946 | #tag ViewProperty |
---|
947 | Name="byte13" |
---|
948 | Group="Behavior" |
---|
949 | Type="String" |
---|
950 | EditorType="MultiLineEditor" |
---|
951 | #tag EndViewProperty |
---|
952 | #tag ViewProperty |
---|
953 | Name="byte14" |
---|
954 | Group="Behavior" |
---|
955 | Type="String" |
---|
956 | EditorType="MultiLineEditor" |
---|
957 | #tag EndViewProperty |
---|
958 | #tag ViewProperty |
---|
959 | Name="byte15" |
---|
960 | Group="Behavior" |
---|
961 | Type="String" |
---|
962 | EditorType="MultiLineEditor" |
---|
963 | #tag EndViewProperty |
---|
964 | #tag ViewProperty |
---|
965 | Name="byte16" |
---|
966 | Group="Behavior" |
---|
967 | Type="String" |
---|
968 | EditorType="MultiLineEditor" |
---|
969 | #tag EndViewProperty |
---|
970 | #tag ViewProperty |
---|
971 | Name="byte17" |
---|
972 | Group="Behavior" |
---|
973 | Type="String" |
---|
974 | EditorType="MultiLineEditor" |
---|
975 | #tag EndViewProperty |
---|
976 | #tag ViewProperty |
---|
977 | Name="byte18" |
---|
978 | Group="Behavior" |
---|
979 | Type="String" |
---|
980 | EditorType="MultiLineEditor" |
---|
981 | #tag EndViewProperty |
---|
982 | #tag ViewProperty |
---|
983 | Name="byte02" |
---|
984 | Group="Behavior" |
---|
985 | Type="String" |
---|
986 | EditorType="MultiLineEditor" |
---|
987 | #tag EndViewProperty |
---|
988 | #tag ViewProperty |
---|
989 | Name="byte03" |
---|
990 | Group="Behavior" |
---|
991 | Type="String" |
---|
992 | EditorType="MultiLineEditor" |
---|
993 | #tag EndViewProperty |
---|
994 | #tag ViewProperty |
---|
995 | Name="byte04" |
---|
996 | Group="Behavior" |
---|
997 | Type="String" |
---|
998 | EditorType="MultiLineEditor" |
---|
999 | #tag EndViewProperty |
---|
1000 | #tag ViewProperty |
---|
1001 | Name="byte05" |
---|
1002 | Group="Behavior" |
---|
1003 | Type="String" |
---|
1004 | EditorType="MultiLineEditor" |
---|
1005 | #tag EndViewProperty |
---|
1006 | #tag ViewProperty |
---|
1007 | Name="byte06" |
---|
1008 | Group="Behavior" |
---|
1009 | Type="String" |
---|
1010 | EditorType="MultiLineEditor" |
---|
1011 | #tag EndViewProperty |
---|
1012 | #tag ViewProperty |
---|
1013 | Name="byte07" |
---|
1014 | Group="Behavior" |
---|
1015 | Type="String" |
---|
1016 | EditorType="MultiLineEditor" |
---|
1017 | #tag EndViewProperty |
---|
1018 | #tag ViewProperty |
---|
1019 | Name="byte08" |
---|
1020 | Group="Behavior" |
---|
1021 | Type="String" |
---|
1022 | EditorType="MultiLineEditor" |
---|
1023 | #tag EndViewProperty |
---|
1024 | #tag ViewProperty |
---|
1025 | Name="byte09" |
---|
1026 | Group="Behavior" |
---|
1027 | Type="String" |
---|
1028 | EditorType="MultiLineEditor" |
---|
1029 | #tag EndViewProperty |
---|
1030 | #tag ViewProperty |
---|
1031 | Name="byte10" |
---|
1032 | Group="Behavior" |
---|
1033 | Type="String" |
---|
1034 | EditorType="MultiLineEditor" |
---|
1035 | #tag EndViewProperty |
---|
1036 | #tag ViewProperty |
---|
1037 | Name="carType" |
---|
1038 | Group="Behavior" |
---|
1039 | InitialValue="MR-03" |
---|
1040 | Type="String" |
---|
1041 | #tag EndViewProperty |
---|
1042 | #tag ViewProperty |
---|
1043 | Name="mode" |
---|
1044 | Group="Behavior" |
---|
1045 | InitialValue="read" |
---|
1046 | Type="String" |
---|
1047 | #tag EndViewProperty |
---|
1048 | #tag EndViewBehavior |
---|
1049 | End Class |
---|
1050 | #tag EndClass |
---|