bridge.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package mcu_ctrl_board
  2. /*
  3. #include "mcu_ctrl_board.h"
  4. */
  5. import "C"
  6. import (
  7. "fmt"
  8. )
  9. type WorkState byte
  10. const (
  11. Idle WorkState = 0x00 // 空闲(默认)
  12. AppUpgrading WorkState = 0x01 // 应用程序-升级中
  13. TakingPhoto WorkState = 0x01 // 相机数据-拍照中
  14. PhotoUploading WorkState = 0x10 // 相机数据-上传中
  15. ParsingEnvData WorkState = 0x01 // 环境数据-收集中
  16. EnvDataUploading WorkState = 0x10 // 环境数据-上传中
  17. )
  18. // 打开与MCU控制板的串口通讯
  19. func mcuCtrlBoard_ComInit() (int, error) {
  20. ret := int(C.MCBComInit())
  21. if ret != 0 {
  22. return ret, fmt.Errorf("an error occurred while calling the C.MCBComInit function(%d)", ret)
  23. }
  24. return 0, nil
  25. }
  26. // 关闭与MCU控制板的串口通讯
  27. func mcuCtrlBoard_ComExit() error {
  28. ret := int(C.MCBComExit())
  29. if ret != 0 {
  30. return fmt.Errorf("an error occurred while calling the C.MCBComExit function(%d)", ret)
  31. }
  32. return nil
  33. }
  34. // 配置单片机控制板-运行参数
  35. func mcuCtrlBoard_ConfParameters(version uint32, ctrl_mode uint8, light_duration uint8, start_hour uint8, end_hour uint8, tp_intvl_min uint16) {
  36. C.MCBConfParameters(C.uint32_t(version), C.uint8_t(ctrl_mode), C.uint8_t(light_duration), C.uint8_t(start_hour), C.uint8_t(end_hour), C.uint16_t(tp_intvl_min))
  37. }
  38. // 设置工作状态位图-固件运维
  39. func MCBSetMNTStateBit(state WorkState) error {
  40. ret := int(C.MCBSetMNTStateBit(C.uint8_t(state)))
  41. if ret != 0 {
  42. return fmt.Errorf("an error occurred while calling the C.MCBSetMNTState function(%d)", ret)
  43. }
  44. return nil
  45. }
  46. // 设置工作状态位图-相机拍照
  47. func MCBSetCamStateBit(state WorkState) error {
  48. ret := int(C.MCBSetCamStateBit(C.uint8_t(state)))
  49. if ret != 0 {
  50. return fmt.Errorf("an error occurred while calling the C.MCBSetCamState function(%d)", ret)
  51. }
  52. return nil
  53. }
  54. // 设置工作状态位图-环境数据
  55. func MCBSetEnvStateBit(state WorkState) error {
  56. ret := int(C.MCBSetEnvStateBit(C.uint8_t(state)))
  57. if ret != 0 {
  58. return fmt.Errorf("an error occurred while calling the C.MCBSetEnvState function(%d)", ret)
  59. }
  60. return nil
  61. }
  62. // 请求获取当前实时-环境数据
  63. func MCBReqEnvCurData() error {
  64. ret := int(C.MCBReqEnvCurData())
  65. if ret != 0 {
  66. return fmt.Errorf("an error occurred while calling the C.MCBReqEnvCurData function(%d)", ret)
  67. }
  68. return nil
  69. }