shared.nim 1.6 KB

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