shared.nim 1.7 KB

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