Blame view

go/src/fullcycle/analog-kernel/parser/parse.go 18.3 KB
1ed17e94b   김태훈   전주기 시연용 응용 프로그램 추가
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  package parser
  
  import (
  	"regexp"
  	"strconv"
  	"strings"
  )
  
  var parseFuncList = []func(chan string, chan jsonObject){
  	parseMemory,
  	parseMemoryLayout,
  	parseTimestamps,
  	parseStatus,
  	parseHashTables,
  	parseLinux,
  	parseCpu,
  	parseModel,
  	parseDeviceFound,
  	parseKernelCommandLine,
  	parseCma,
  	parseSlub,
  	parsePidMax,
  	parseWorkingset,
9937fc682   김태훈   부트로더 정보 추가
24
25
26
27
28
29
30
31
32
  	parseBootloaderDram,
  	parseBootloaderMmc,
  	parseBootloaderConsole,
  	parseBootloaderGadgetDriver,
  	parseBootloaderSetupSize,
  	parseBootloaderCpu,
  	parseBootloaderBoard,
  	parseBootloaderRstStat,
  	parseBootloaderNet,
1ed17e94b   김태훈   전주기 시연용 응용 프로그램 추가
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
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
334
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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
  }
  
  var reTimestamp = regexp.MustCompile(`^\[[[:blank:]]*[[:digit:]]+\.[[:digit:]]+[[:blank:]]*\]`)
  var reAddress = regexp.MustCompile(`0x[[:xdigit:]]+`)
  
  func parseMemory(lines chan string, chanOutput chan jsonObject) {
  	m := make(jsonObject)
  	m["type"] = "memory"
  
  	rLine := regexp.MustCompile("Memory: [[:ascii:]]+ available")
  	rBytes := regexp.MustCompile("[[:digit:]]+[Kk]")
  	for line := range lines {
  		if found := rLine.FindString(line); found != "" {
  			r := rBytes.FindAllString(line, 2)
  			m["available"] = r[0]
  			m["total"] = r[1]
  			chanOutput <- m
  			return
  		}
  	}
  
  	m["available"] = ""
  	m["total"] = ""
  
  	chanOutput <- m
  }
  
  func parseMemoryLayout(lines chan string, chanOutput chan jsonObject) {
  	rHeaderArm := regexp.MustCompile("Virtual kernel memory layout:")
  	rHeaderX86 := regexp.MustCompile("Zone ranges:")
  	for line := range lines {
  		if rHeaderArm.MatchString(line) {
  			parseMemoryLayoutArm(lines, chanOutput)
  			return
  		}
  
  		if rHeaderX86.MatchString(line) {
  			parseMemoryLayoutX86(lines, chanOutput)
  			return
  		}
  	}
  
  	m := make(jsonObject)
  	m["type"] = "memory_layout"
  	m["layout"] = make([]jsonObject, 0)
  
  	chanOutput <- m
  }
  
  func parseMemoryLayoutArm(lines chan string, chanOutput chan jsonObject) {
  	m := make(jsonObject)
  	m["type"] = "memory_layout"
  	m["layout"] = make([]jsonObject, 0)
  
  	rLine := regexp.MustCompile(`[[:print:]]+:[[:blank:]]*0x[[:xdigit:]]+[[:blank:]]*-[[:blank:]]*0x[[:xdigit:]]+`)
  	rLabel := regexp.MustCompile(`[[:graph:]]+`)
  
  	for line := range lines {
  		line = removeTimestamp(line)
  		if rLine.MatchString(line) {
  			item := make(jsonObject)
  			item["label"] = rLabel.FindString(line)
  
  			r := reAddress.FindAllString(line, 2)
  			item["from"] = r[0]
  			item["to"] = r[1]
  
  			m["layout"] = append(m["layout"].([]jsonObject), item)
  		} else {
  			break
  		}
  	}
  
  	chanOutput <- m
  }
  
  func parseMemoryLayoutX86(lines chan string, chanOutput chan jsonObject) {
  	m := make(jsonObject)
  	m["type"] = "memory_layout"
  	m["layout"] = make([]jsonObject, 0)
  
  	rLine := regexp.MustCompile(`[[:print:]]+\[mem[[:blank:]]+0x[[:xdigit:]]+-0x[[:xdigit:]]+\]`)
  	rLabel := regexp.MustCompile(`[[:graph:]]+`)
  
  	for line := range lines {
  		line = removeTimestamp(line)
  		if rLine.MatchString(line) {
  			item := make(jsonObject)
  			item["label"] = rLabel.FindString(line)
  
  			r := reAddress.FindAllString(line, 2)
  			item["from"] = r[0]
  			item["to"] = r[1]
  
  			m["layout"] = append(m["layout"].([]jsonObject), item)
  		} else {
  			break
  		}
  	}
  
  	chanOutput <- m
  }
  
  func parseTimestamps(lines chan string, chanOutput chan jsonObject) {
  	rVal := regexp.MustCompile(`[[:digit:]]+\.[[:digit:]]+`)
  
  	list := make(jsonArray, 0)
  	for line := range lines {
  		if reTimestamp.MatchString(line) {
  			t := reTimestamp.FindString(line)
  			v := rVal.FindString(t)
  			f, _ := strconv.ParseFloat(v, 64)
  			list = append(list, f)
  		}
  	}
  
  	m := make(jsonObject)
  	m["type"] = "timestamps"
  	m["timestamps"] = list
  
  	chanOutput <- m
  }
  
  func parseStatus(lines chan string, chanOutput chan jsonObject) {
  	rLine := regexp.MustCompile(`^\[[[:blank:]]*(OK|FAIL)[[:blank:]]*\][[:blank:]]+`)
  	rOk := regexp.MustCompile(`^\[[[:blank:]]*OK[[:blank:]]*\]`)
  
  	list := make([]jsonObject, 0)
  	for line := range lines {
  		if rLine.MatchString(line) {
  			item := make(jsonObject)
  			if rOk.MatchString(line) {
  				item["status"] = "ok"
  			} else {
  				item["status"] = "fail"
  			}
  
  			prefix := rLine.FindString(line)
  			label := strings.TrimPrefix(line, prefix)
  			item["label"] = label
  
  			list = append(list, item)
  		}
  	}
  
  	m := make(jsonObject)
  	m["type"] = "status"
  	m["list"] = list
  
  	chanOutput <- m
  }
  
  func parseHashTables(lines chan string, chanOutput chan jsonObject) {
  	rLine := regexp.MustCompile(`[[:graph:]]+ hash table entries:`)
  
  	list := make([]jsonObject, 0)
  	for line := range lines {
  		if rLine.MatchString(line) {
  			line = removeTimestamp(line)
  
  			item := make(jsonObject)
  
  			label := regexp.MustCompile(`[[:print:]]+ hash table entries:`).FindString(line)
  
  			item["label"] = strings.TrimSuffix(label, " hash table entries:")
  
  			entries := regexp.MustCompile(`hash table entries: [[:digit:]]+`).FindString(line)
  			entries = strings.TrimPrefix(entries, "hash table entries: ")
  
  			item["entries"], _ = strconv.ParseInt(entries, 10, 64)
  
  			order := regexp.MustCompile(`order:? [[:digit:]-]+`).FindString(line)
  			orderPrefix := regexp.MustCompile(`order:? `).FindString(order)
  			order = strings.TrimPrefix(order, orderPrefix)
  
  			item["order"], _ = strconv.ParseInt(order, 10, 64)
  
  			size := regexp.MustCompile(`[[:digit:]]+ bytes`).FindString(line)
  			size = strings.TrimSuffix(size, " bytes")
  
  			item["size"], _ = strconv.ParseInt(size, 10, 64)
  
  			list = append(list, item)
  		}
  	}
  
  	m := make(jsonObject)
  	m["type"] = "hash_tables"
  	m["list"] = list
  
  	chanOutput <- m
  }
  
  func parseLinux(lines chan string, chanOutput chan jsonObject) {
  	m := make(jsonObject)
  	m["type"] = "linux"
  	m["version"] = ""
  	m["builder"] = ""
  	m["toolchain"] = ""
  	m["label"] = ""
  
  	rLine := regexp.MustCompile(`Linux version[[:blank:]]+[[:graph:]]+[[:blank:]]+([[:print:]]+)[[:blank:]]+([[:print:]]+)[[:blank:]]+#[[:print:]]+`)
  	for line := range lines {
  		if rLine.MatchString(line) {
  			line = rLine.FindString(line)
  			line = strings.TrimPrefix(line, "Linux version ")
  
  			m["version"] = regexp.MustCompile(`[[:graph:]]+`).FindString(line)
  			m["os"] = "linux"
  
  			bracketed := regexp.MustCompile(`\([[:print:]]+?\)`).FindAllString(line, 2)
  			for i, s := range bracketed {
  				switch i {
  				case 0:
  					m["builder"] = removeBrackets(s)
  				case 1:
  					m["toolchain"] = removeBrackets(s)
  				}
  			}
  
  			m["label"] = regexp.MustCompile(`#[[:print:]]+`).FindString(line)
  
  			break
  		}
  	}
  
  	chanOutput <- m
  }
  
  func parseCpu(lines chan string, chanOutput chan jsonObject) {
  	m := make(jsonObject)
  	m["type"] = "cpu"
  	m["name"] = ""
  	m["id"] = ""
  	m["revision"] = ""
  	m["arch"] = ""
  	m["cr"] = ""
  	m["data_cache"] = ""
  	m["instruction_cache"] = ""
  
  	rLine1 := regexp.MustCompile(`CPU:[[:blank:]]+[[:print:]]+[[:blank:]]+\[[[:xdigit:]]+\][[:blank:]]+revision[[:blank:]]+[[:digit:]][[:blank:]]+\([[:print:]]+\), cr=[[:xdigit:]]+`)
  	rLine2 := regexp.MustCompile(`CPU:[[:blank:]]+[[:print:]]+[[:blank:]]+data cache,[[:blank:]]+[[:print:]]+[[:blank:]]+instruction cache`)
  	for line := range lines {
  		if rLine1.MatchString(line) {
  			line = rLine1.FindString(line)
  			line = strings.TrimPrefix(line, "CPU: ")
  
  			name := regexp.MustCompile(`[[:print:]]+\[`).FindString(line)
  			name = strings.TrimSuffix(name, "[")
  			name = strings.TrimSpace(name)
  
  			m["name"] = name
  
  			id := regexp.MustCompile(`\[[[:xdigit:]]+\]`).FindString(line)
  			id = strings.TrimPrefix(id, "[")
  			id = strings.TrimSuffix(id, "]")
  
  			m["id"] = id
  
  			revision := regexp.MustCompile(`revision[[:blank:]]+[[:digit:]]+`).FindString(line)
  			revision = strings.TrimPrefix(revision, "revision")
  			revision = strings.TrimSpace(revision)
  
  			m["revision"] = revision
  
  			arch := regexp.MustCompile(`\([[:print:]]+\)`).FindString(line)
  			arch = strings.TrimPrefix(arch, "(")
  			arch = strings.TrimSuffix(arch, ")")
  			arch = strings.TrimSpace(arch)
  
  			m["arch"] = arch
  
  			cr := regexp.MustCompile(`cr=[[:xdigit:]]+`).FindString(line)
  			cr = strings.TrimPrefix(cr, "cr=")
  
  			m["cr"] = cr
  		} else if rLine2.MatchString(line) {
  			line = rLine2.FindString(line)
  			line = strings.TrimPrefix(line, `CPU: `)
  
  			dataCache := regexp.MustCompile(`[[:print:]]+data cache`).FindString(line)
  			dataCache = strings.TrimSuffix(dataCache, "data cache")
  			dataCache = strings.TrimSpace(dataCache)
  
  			m["data_cache"] = dataCache
  
  			instructionCache := regexp.MustCompile(`,[[:print:]]+instruction cache`).FindString(line)
  			instructionCache = strings.TrimPrefix(instructionCache, ",")
  			instructionCache = strings.TrimSuffix(instructionCache, "instruction cache")
  			instructionCache = strings.TrimSpace(instructionCache)
  
  			m["instruction_cache"] = instructionCache
  		}
  	}
  
  	chanOutput <- m
  }
  
  func parseModel(lines chan string, chanOutput chan jsonObject) {
  	m := make(jsonObject)
  	m["type"] = "model"
  	m["model"] = ""
  
  	rLine := regexp.MustCompile(`(Machine model: [[:print:]]+)|(Machine: [[:print:]]+)`)
  	rLineEdison := regexp.MustCompile(`Linux version[[:print:]]+edison`)
  	rLineARTIK := regexp.MustCompile(`CPU EXYNOS3250`)
  	for line := range lines {
  		if rLine.MatchString(line) {
  			line = rLine.FindString(line)
  			line = strings.TrimPrefix(line, "Machine model: ")
  			line = strings.TrimPrefix(line, "Machine: ")
  
  			m["model"] = strings.TrimSpace(line)
  
  			break
  		} else if rLineEdison.MatchString(line) {
  			m["model"] = "Intel Edison"
  
  			break
  		} else if rLineARTIK.MatchString(line) {
  			m["model"] = "SAMSUNG ARTIK5"
  
  			break
  		}
  	}
  
  	chanOutput <- m
  }
  
  func parseDeviceFound(lines chan string, chanOutput chan jsonObject) {
  	list := make([]string, 0)
  	for line := range lines {
  		for _, e := range deviceTable {
  			if e.re.MatchString(line) {
  				list = append(list, e.name)
  			}
  		}
  	}
  
  	m := make(jsonObject)
  	m["type"] = "device_found"
  	m["list"] = list
  
  	chanOutput <- m
  }
  
  func parseKernelCommandLine(lines chan string, chanOutput chan jsonObject) {
  	m := make(jsonObject)
  	m["type"] = "kernel_command_line"
  	m["kernel_command_line"] = ""
  
  	rLine := regexp.MustCompile("Kernel command line: [[:print:]]+")
  	for line := range lines {
  		if rLine.MatchString(line) {
  			line = rLine.FindString(line)
  
  			cmdline := strings.TrimPrefix(line, "Kernel command line: ")
  			cmdline = strings.TrimSpace(cmdline)
  			if strings.HasPrefix(cmdline, `"`) && strings.HasSuffix(cmdline, `"`) {
  				cmdline = strings.TrimPrefix(cmdline, `"`)
  				cmdline = strings.TrimSuffix(cmdline, `"`)
  			}
  
  			m["kernel_command_line"] = cmdline
  
  			break
  		}
  	}
  
  	chanOutput <- m
  }
  
  func parseCma(lines chan string, chanOutput chan jsonObject) {
  	m := make(jsonObject)
  	m["type"] = "cma"
  	m["size"] = ""
  	m["address"] = ""
  
  	rLine := regexp.MustCompile("cma: Reserved [[:print:]]+ at [[:print:]]+")
  	for line := range lines {
  		if rLine.MatchString(line) {
  			line = rLine.FindString(line)
  			line = strings.TrimPrefix(line, "cma: Reserved ")
  
  			size := regexp.MustCompile(`[[:print:]]+ at`).FindString(line)
  			size = strings.TrimSuffix(size, "at")
  			size = strings.TrimSpace(size)
  
  			m["size"] = size
  
  			address := regexp.MustCompile(`at [[:print:]]+`).FindString(line)
  			address = strings.TrimPrefix(address, "at")
  			address = strings.TrimSpace(address)
  
  			m["address"] = address
  
  			break
  		}
  	}
  
  	chanOutput <- m
  }
  
  func parseSlub(lines chan string, chanOutput chan jsonObject) {
  	m := make(jsonObject)
  	m["type"] = "slub"
  	m["hw_align"] = ""
  	m["order"] = ""
  	m["min_objects"] = ""
  	m["cpus"] = ""
  	m["nodes"] = ""
  
  	rLine := regexp.MustCompile("SLUB: HWalign=[[:digit:]]+, Order=[[:digit:]]+-[[:digit:]]+, MinObjects=[[:digit:]]+, CPUs=[[:digit:]]+, Nodes=[[:digit:]]+")
  	for line := range lines {
  		if rLine.MatchString(line) {
  			line = rLine.FindString(line)
  
  			hwAlign := regexp.MustCompile(`HWalign=[[:digit:]]+`).FindString(line)
  			hwAlign = strings.TrimPrefix(hwAlign, `HWalign=`)
  
  			m["hw_align"] = hwAlign
  
  			order := regexp.MustCompile(`Order=[[:digit:]]+-[[:digit:]]+`).FindString(line)
  			order = strings.TrimPrefix(order, `Order=`)
  
  			m["order"] = order
  
  			minObjects := regexp.MustCompile(`MinObjects=[[:digit:]]+`).FindString(line)
  			minObjects = strings.TrimPrefix(minObjects, `MinObjects=`)
  
  			m["min_objects"] = minObjects
  
  			cpus := regexp.MustCompile(`CPUs=[[:digit:]]+`).FindString(line)
  			cpus = strings.TrimPrefix(cpus, `CPUs=`)
  
  			m["cpus"] = cpus
  
  			nodes := regexp.MustCompile(`Nodes=[[:digit:]]+`).FindString(line)
  			nodes = strings.TrimPrefix(nodes, `Nodes=`)
  
  			m["nodes"] = nodes
  
  			break
  		}
  	}
  
  	chanOutput <- m
  }
  
  func parsePidMax(lines chan string, chanOutput chan jsonObject) {
  	m := make(jsonObject)
  	m["type"] = "pid_max"
  	m["default"] = ""
  	m["min"] = ""
  
  	rLine := regexp.MustCompile("pid_max:[[:blank:]]+default:[[:blank:]]*[[:digit:]]+[[:blank:]]+minimum:[[:blank:]]*[[:digit:]]+")
  	for line := range lines {
  		if rLine.MatchString(line) {
  			line = rLine.FindString(line)
  
  			m["default"] = extract(line,
  				`default:[[:blank:]]*[[:digit:]]+`,
  				`default:[[:blank:]]*`,
  				``)
  
  			m["min"] = extract(line,
  				`minimum:[[:blank:]]*[[:digit:]]+`,
  				`minimum:[[:blank:]]*`,
  				``)
  
  			break
  		}
  	}
  
  	chanOutput <- m
  }
  
  func parseWorkingset(lines chan string, chanOutput chan jsonObject) {
  	m := make(jsonObject)
  	m["type"] = "workingset"
  	m["timestamp bits"] = ""
  	m["max_order"] = ""
  	m["bucket_order"] = ""
  
  	rLine := regexp.MustCompile("workingset: timestamp_bits=[[:digit:]]+ max_order=[[:digit:]]+ bucket_order=[[:digit:]]+")
  	for line := range lines {
  		if rLine.MatchString(line) {
  			line = rLine.FindString(line)
  
  			m["timestamp_bits"] = extract(line,
  				`timestamp_bits=[[:digit:]]+`,
  				`timestamp_bits=`,
  				``)
  
  			m["max_order"] = extract(line,
  				`max_order=[[:digit:]]+`,
  				`max_order=`,
  				``)
  
  			m["bucket_order"] = extract(line,
  				`bucket_order=[[:digit:]]+`,
  				`bucket_order=`,
  				``)
  
  			break
  		}
  	}
  
  	chanOutput <- m
  }
9937fc682   김태훈   부트로더 정보 추가
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
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
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
  func parseBootloaderDram(lines chan string, chanOutput chan jsonObject) {
  	m := make(jsonObject)
  	m["type"] = "bootloader_dram"
  	m["value"] = ""
  
  	rLine := regexp.MustCompile(`^DRAM:\s+([[:print:]]+)`)
  	for line := range lines {
  		if rLine.MatchString(line) {
  			if sub := rLine.FindStringSubmatch(line); len(sub) > 1 {
  				m["value"] = sub[1]
  				break
  			}
  		}
  	}
  
  	chanOutput <- m
  }
  
  func parseBootloaderMmc(lines chan string, chanOutput chan jsonObject) {
  	m := make(jsonObject)
  	m["type"] = "bootloader_mmc"
  	m["value"] = ""
  
  	rLine := regexp.MustCompile(`^MMC:\s+([[:print:]]+)`)
  	for line := range lines {
  		if rLine.MatchString(line) {
  			if sub := rLine.FindStringSubmatch(line); len(sub) > 1 {
  				m["value"] = sub[1]
  				break
  			}
  		}
  	}
  
  	chanOutput <- m
  }
  
  func parseBootloaderConsole(lines chan string, chanOutput chan jsonObject) {
  	m := make(jsonObject)
  	m["type"] = "bootloader_console"
  	m["in"] = ""
  	m["out"] = ""
  	m["err"] = ""
  
  	const (
  		FIND_IN = iota
  		FIND_OUT
  		FIND_ERR
  		FIN
  	)
  
  	state := FIND_IN
  
  	rIn := regexp.MustCompile(`^In:\s+([[:print:]]+)`)
  	rOut := regexp.MustCompile(`^Out:\s+([[:print:]]+)`)
  	rErr := regexp.MustCompile(`^Err:\s+([[:print:]]+)`)
  	for line := range lines {
  		switch state {
  		case FIND_IN:
  			if sub := rIn.FindStringSubmatch(line); len(sub) > 1 {
  				m["in"] = sub[1]
  				state = FIND_OUT
  			}
  		case FIND_OUT:
  			if sub := rOut.FindStringSubmatch(line); len(sub) > 1 {
  				m["out"] = sub[1]
  				state = FIND_ERR
  			}
  		case FIND_ERR:
  			if sub := rErr.FindStringSubmatch(line); len(sub) > 1 {
  				m["err"] = sub[1]
  				state = FIN
  			}
  		}
  
  		if state == FIN {
  			break
  		}
  	}
  
  	chanOutput <- m
  }
  
  func parseBootloaderGadgetDriver(lines chan string, chanOutput chan jsonObject) {
  	m := make(jsonObject)
  	m["type"] = "bootloader_gadget_driver"
  	m["value"] = ""
  
  	rLine := regexp.MustCompile(`^GADGET DRIVER:\s+([[:print:]]+)`)
  	for line := range lines {
  		if rLine.MatchString(line) {
  			if sub := rLine.FindStringSubmatch(line); len(sub) > 1 {
  				m["value"] = sub[1]
  				break
  			}
  		}
  	}
  
  	chanOutput <- m
  }
  
  func parseBootloaderSetupSize(lines chan string, chanOutput chan jsonObject) {
  	m := make(jsonObject)
  	m["type"] = "bootloader_setup_size"
  	m["value"] = ""
  
  	rLine := regexp.MustCompile(`^Setup Size =\s+([[:print:]]+)`)
  	for line := range lines {
  		if rLine.MatchString(line) {
  			if sub := rLine.FindStringSubmatch(line); len(sub) > 1 {
  				m["value"] = sub[1]
  				break
  			}
  		}
  	}
  
  	chanOutput <- m
  }
  
  func parseBootloaderCpu(lines chan string, chanOutput chan jsonObject) {
  	m := make(jsonObject)
  	m["type"] = "bootloader_cpu"
  	m["value"] = ""
  
  	rLine := regexp.MustCompile(`^CPU:\s+([[:print:]]+)`)
  	for line := range lines {
  		if rLine.MatchString(line) {
  			if sub := rLine.FindStringSubmatch(line); len(sub) > 1 {
  				m["value"] = sub[1]
  				break
  			}
  		}
  	}
  
  	chanOutput <- m
  }
  
  func parseBootloaderBoard(lines chan string, chanOutput chan jsonObject) {
  	m := make(jsonObject)
  	m["type"] = "bootloader_board"
  	m["value"] = ""
  
  	rLine := regexp.MustCompile(`^Board:\s+([[:print:]]+)`)
  	for line := range lines {
  		if rLine.MatchString(line) {
  			if sub := rLine.FindStringSubmatch(line); len(sub) > 1 {
  				m["value"] = sub[1]
  				break
  			}
  		}
  	}
  
  	chanOutput <- m
  }
  
  func parseBootloaderRstStat(lines chan string, chanOutput chan jsonObject) {
  	m := make(jsonObject)
  	m["type"] = "bootloader_rst_stat"
  	m["value"] = ""
  
  	rLine := regexp.MustCompile(`^rst_stat\s+:\s+([[:print:]]+)`)
  	for line := range lines {
  		if rLine.MatchString(line) {
  			if sub := rLine.FindStringSubmatch(line); len(sub) > 1 {
  				m["value"] = sub[1]
  				break
  			}
  		}
  	}
  
  	chanOutput <- m
  }
  
  func parseBootloaderNet(lines chan string, chanOutput chan jsonObject) {
  	m := make(jsonObject)
  	m["type"] = "bootloader_net"
  	m["value"] = ""
  
  	rLine := regexp.MustCompile(`^Net:\s+([[:print:]]+)`)
  	for line := range lines {
  		if rLine.MatchString(line) {
  			if sub := rLine.FindStringSubmatch(line); len(sub) > 1 {
  				m["value"] = sub[1]
  				break
  			}
  		}
  	}
  
  	chanOutput <- m
  }
1ed17e94b   김태훈   전주기 시연용 응용 프로그램 추가
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
  func removeBrackets(s string) string {
  	for strings.HasPrefix(s, "(") && strings.HasSuffix(s, ")") {
  		openCount := strings.Count(s, "(")
  		closeCount := strings.Count(s, ")")
  
  		if openCount > closeCount {
  			s = strings.TrimPrefix(s, "(")
  		} else if openCount < closeCount {
  			s = strings.TrimSuffix(s, ")")
  		} else {
  			s = strings.TrimPrefix(s, "(")
  			s = strings.TrimSuffix(s, ")")
  		}
  	}
  
  	return s
  }
  
  func removeTimestamp(s string) string {
  	if reTimestamp.MatchString(s) {
  		t := reTimestamp.FindString(s)
  		s = strings.TrimPrefix(s, t)
  	}
  	return strings.TrimSpace(s)
  }
  
  func extract(from string, chunk, prefix, suffix string) string {
  	reChunk, err := regexp.Compile(chunk)
  	if err != nil {
  		return ""
  	}
  
  	rePrefix, err := regexp.Compile(prefix)
  	if err != nil {
  		return ""
  	}
  
  	reSuffix, err := regexp.Compile(suffix)
  	if err != nil {
  		return ""
  	}
  
  	b := reChunk.FindString(from)
  
  	p := rePrefix.FindString(b)
  	b = strings.TrimPrefix(b, p)
  
  	s := reSuffix.FindString(b)
  	b = strings.TrimSuffix(b, s)
  
  	return b
  }