protocol.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /* Copyright Statement:
  2. *
  3. * This software/firmware and related documentation ("AutoChips Software") are
  4. * protected under relevant copyright laws. The information contained herein is
  5. * confidential and proprietary to AutoChips Inc. and/or its licensors. Without
  6. * the prior written permission of AutoChips inc. and/or its licensors, any
  7. * reproduction, modification, use or disclosure of AutoChips Software, and
  8. * information contained herein, in whole or in part, shall be strictly
  9. * prohibited.
  10. *
  11. * AutoChips Inc. (C) 2016. All rights reserved.
  12. *
  13. * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  14. * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("AUTOCHIPS SOFTWARE")
  15. * RECEIVED FROM AUTOCHIPS AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
  16. * ON AN "AS-IS" BASIS ONLY. AUTOCHIPS EXPRESSLY DISCLAIMS ANY AND ALL
  17. * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
  19. * NONINFRINGEMENT. NEITHER DOES AUTOCHIPS PROVIDE ANY WARRANTY WHATSOEVER WITH
  20. * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
  21. * INCORPORATED IN, OR SUPPLIED WITH THE AUTOCHIPS SOFTWARE, AND RECEIVER AGREES
  22. * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
  23. * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
  24. * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN AUTOCHIPS
  25. * SOFTWARE. AUTOCHIPS SHALL ALSO NOT BE RESPONSIBLE FOR ANY AUTOCHIPS SOFTWARE
  26. * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
  27. * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND AUTOCHIPS'S
  28. * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE AUTOCHIPS SOFTWARE
  29. * RELEASED HEREUNDER WILL BE, AT AUTOCHIPS'S OPTION, TO REVISE OR REPLACE THE
  30. * AUTOCHIPS SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
  31. * CHARGE PAID BY RECEIVER TO AUTOCHIPS FOR SUCH AUTOCHIPS SOFTWARE AT ISSUE.
  32. */
  33. #ifndef PROTOCOL_H
  34. #define PROTOCOL_H
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif
  38. #include "ac780x.h"
  39. #define Cmd_FirmwareVersion (0x0000)
  40. #define Cmd_HardwareVersion (0x0001)
  41. #define Cmd_DeviceID (0x0002)
  42. #define Cmd_DeviceType (0x0003)
  43. #define Cmd_Reboot (0x0004)
  44. #define Cmd_Reset (0x0005)
  45. #define Cmd_Addr (0x0010)
  46. #define Cmd_Baudrate (0x0011)
  47. #define Cmd_LockStatus (0x0020)
  48. //#define Cmd_FirmwareVersion (0x0000)
  49. #define Cmd_IapUpgrade (0xAABB)
  50. #define MODBUS_FUNC_READ (0x03)
  51. #define MODBUS_FUNC_WRITE (0x06)
  52. #define INVALID_FUNCTION_CODE (0x01)
  53. #define INVALID_COMMAND (0x02)
  54. #define INVALID_DATA (0x03)
  55. #define DEVICE_FAULT (0x04)
  56. //读取时返回,数据长度, 如果返回 0, 说明buf_len 不够, 设备故障
  57. uint16_t Read_FirmwareVersion(uint8_t *pBuf, uint16_t buf_len);
  58. uint16_t Read_HardwareVersion(uint8_t *pBuf, uint16_t buf_len);
  59. uint16_t Read_Deviceid(uint8_t *pBuf, uint16_t buf_len);
  60. uint16_t Read_Devicetype(uint8_t *pBuf, uint16_t buf_len);
  61. uint16_t Read_Addr(uint8_t *pBuf, uint16_t buf_len);
  62. uint16_t Read_Baudrate(uint8_t *pBuf, uint16_t buf_len);
  63. uint16_t Read_LockStatus(uint8_t *pBuf, uint16_t buf_len);
  64. #define RET_ERROR_MASK (0xF0)
  65. #define RET_OK (0x00)
  66. #define RET_NEED_SAVE (0X01)
  67. #define RET_NEED_REBOOT (0X02)
  68. #define RET_DATAINVALID (0x10)
  69. #define RET_CMDINVALID (0x20)
  70. //#define RET_DATAINVALID (3)
  71. //写入成功时返回 RET_OK
  72. //写入不成功时,返回 RET_DATAINVALID
  73. uint8_t Write_Addr(uint8_t *pdata, uint8_t len);
  74. uint8_t Write_Baudrate(uint8_t *pdata, uint8_t len);
  75. uint8_t Write_HardwareVersion(uint8_t *pdata, uint8_t len);
  76. uint8_t Write_Deviceid(uint8_t *pdata, uint8_t len);
  77. uint8_t Write_Devicetype(uint8_t *pdata, uint8_t len);
  78. #ifdef __cplusplus
  79. }
  80. #endif
  81. #endif /* PROTOCOL_H */