shared.nim 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. discard """
  2. cmd: "nim $target --debuginfo --hints:on --app:lib $options $file"
  3. """
  4. import strutils
  5. # Global state, accessing with threads, no locks. Don't do this at
  6. # home.
  7. var gCounter: uint64
  8. var gTxStatus: bool
  9. var gRxStatus: bool
  10. var gConnectStatus: bool
  11. var gPttStatus: bool
  12. var gComm1Status: bool
  13. var gComm2Status: bool
  14. proc getTxStatus(): string =
  15. result = if gTxStatus: "On" else: "Off"
  16. gTxStatus = not gTxStatus
  17. proc getRxStatus(): string =
  18. result = if gRxStatus: "On" else: "Off"
  19. gRxStatus = not gRxStatus
  20. proc getConnectStatus(): string =
  21. result = if gConnectStatus: "Yes" else: "No"
  22. gConnectStatus = not gConnectStatus
  23. proc getPttStatus(): string =
  24. result = if gPttStatus: "PTT: On" else: "PTT: Off"
  25. gPttStatus = not gPttStatus
  26. proc getComm1Status(): string =
  27. result = if gComm1Status: "On" else: "Off"
  28. gComm1Status = not gComm1Status
  29. proc getComm2Status(): string =
  30. result = if gComm2Status: "On" else: "Off"
  31. gComm2Status = not gComm2Status
  32. proc status() {.exportc: "status", dynlib.} =
  33. var tx_status = getTxStatus()
  34. var rx_status = getRxStatus()
  35. var connected = getConnectStatus()
  36. var ptt_status = getPttStatus()
  37. var str1: string = "[PilotEdge] Connected: $1 TX: $2 RX: $3" % [connected, tx_status, rx_status]
  38. var a = getComm1Status()
  39. var b = getComm2Status()
  40. var str2: string = "$1 COM1: $2 COM2: $3" % [ptt_status, a, b]
  41. # echo(str1)
  42. # echo(str2)
  43. proc count() {.exportc: "count", dynlib.} =
  44. var temp: uint64
  45. for i in 0..100_000:
  46. temp += 1
  47. gCounter += 1
  48. # echo("gCounter: ", gCounter)
  49. proc checkOccupiedMem() {.exportc: "checkOccupiedMem", dynlib.} =
  50. if getOccupiedMem() > 10_000_000:
  51. quit 1
  52. discard