/* Includes ---------------------------------------------------------------- */
#include "aisg_vendor.h"
#include "aisg.h"
#include "aisg_layer7.h"
//#include "aisg3_layer7.h"
#include "aisg_commands.h"
#include "version.h"
#include "motor.h"
#include "flashdb_api.h"
#include <string.h>
/* Internal define --------------------------------------------------------- */
/* Internal variables ------------------------------------------------------ */
const uint8_t AISG_DefaultVendorCode[ AISG_DATA_VENDORCODE_LENGTH ] = {'N', 'T'};
const uint8_t AISG_NewDefaultVendorCode[ AISG_DATA_VENDORCODE_LENGTH ] = {'R', 'B'};
const uint8_t MRET_DefaultID[] = "M";
const uint8_t SizeOfMRET_DefaultID = sizeof(MRET_DefaultID) - 1;
const uint8_t VSRET_DefaultID[] = "S";
const uint8_t SizeOfVSRET_DefaultID = sizeof(VSRET_DefaultID) - 1;
/* Function declarations --------------------------------------------------- */
// vendor special command handler
static void AISGVendor_V3_Cmd_SetUniqueID(uint8_t node, uint16_t PrimaryCommandSequence, uint8_t *pData, uint16_t dataLength);
static void AISGVerdor_V3_Cmd_Flashdb_Write(uint8_t node, uint16_t PrimaryCommandSequence, uint8_t *pData, uint8_t dataLength);
static void AISGVerdor_V3_Cmd_Flashdb_Read(uint8_t node, uint16_t PrimaryCommandSequence, uint8_t *pData, uint8_t dataLength);
static void AISGVendor_V3_Cmd_SetProductNumber(uint8_t node, uint16_t PrimaryCommandSequence, uint8_t *pData, uint8_t dataLength);
static void AISGVendor_V3_Cmd_SetNumberOfAntennas(uint8_t node, uint16_t PrimaryCommandSequence, uint8_t *pData, uint8_t dataLength);
static void AISGVendor_V3_Cmd_SetADB_ANT_INFO(uint8_t node, uint16_t PrimaryCommandSequence, uint8_t *pData, uint8_t dataLength);
/* Function implements ----------------------------------------------------- */
//
// Vendor Special Command
// Command : 0x90 <LengthLowByte> <LengthHighByte> <VendorCode> <VendorCommandCode> <Data>(if any)
// Response : 0x90 <LengthLowByte> <LengthHighByte> <OK> <Data>(if any)
// 0x90 <LengthLowByte> <LengthHighByte> <FAIL> <ReturnCode>
//
#if 1
//uint8_t vendor[2] = {0};
//void AISGVendor_ProcessCommand( uint8_t node, uint8_t *pData, uint16_t dataLength )
void AISG_V3_Cmd_Vendor_Process(uint8_t node, uint16_t PrimaryCommandSequence, uint16_t SubunitNumber, uint8_t *pData, uint16_t dataLength)
{
// vendor[0] = *pData;
// vendor[1] = *(pData + 1);
// pData += 2;
uint16_t vendorcommand = MKWORD(*(pData + 2), *(pData + 3));
if (pData == NULL) {
return;
}
if (*pData != 0x52 || *(pData + 1) != 0x42) {
AISGL7_V3_BeginResponseWithSubunitNo(node, AISG_CMD_VENDOR, PrimaryCommandSequence, AISG_V3_RTN_FORMAT_ERROR, true);
AISGL7_V3_WriteResponse(node, AISG_State.Node[ node ].VendorCode[ 0 ]);
AISGL7_V3_WriteResponse(node, AISG_State.Node[ node ].VendorCode[ 1 ]);
AISGL7_V3_SendBuiltResponse(node);
}
DEBUG_PRINTF("vendorcommand:0x%x\n",vendorcommand);
switch (vendorcommand) {
case AISG_VENDOR_CMD_SET_UNIQUE_ID:
AISGVendor_V3_Cmd_SetUniqueID(node, PrimaryCommandSequence, pData + 5, dataLength - 5);
break;
case AISG_VENDOR_CMD_GET_RELEASE_ID:
AISGL7_V3_BeginResponseWithSubunitNo(node, AISG_CMD_VENDOR, PrimaryCommandSequence, AISG_V3_RTN_OK, true);
AISGL7_V3_WriteResponse(node, AISG_State.Node[ node ].VendorCode[ 0 ]);
AISGL7_V3_WriteResponse(node, AISG_State.Node[ node ].VendorCode[ 1 ]);
// AISGL7_V3_WriteResponse(node, AISG_VENDOR_CMD_GET_RELEASE_ID);
AISGL7_V3_WriteStringData(node, (uint8_t *)&SoftwareReleaseID[0], SizeOfSoftwareReleaseID);
AISGL7_V3_WriteStringData(node, (uint8_t *)&SoftwareReleaseID[0], SizeOfSoftwareReleaseID);
AISGL7_V3_SendBuiltResponse(node);
break;
case AISG_VENDOR_CMD_ADB_SET_ANTENNA_INFO:
AISGVendor_V3_Cmd_SetADB_ANT_INFO(node, PrimaryCommandSequence, pData + 5, dataLength - 5); //set model number
break;
case AISG_VENDOR_CMD_SET_NUMBER_OF_ANTENNAS:
AISGVendor_V3_Cmd_SetNumberOfAntennas(node, PrimaryCommandSequence, pData + 5, dataLength - 5);
break;
case AISG_VENDOR_CMD_SET_PRODUCT_NUMBER:
AISGVendor_V3_Cmd_SetProductNumber(node, PrimaryCommandSequence, pData + 5, dataLength - 5);
break;
case AISG_VENDOR_CMD_FLASHDB_WRITE:
AISGVerdor_V3_Cmd_Flashdb_Write(node, PrimaryCommandSequence, pData + 4, dataLength);
break;
case AISG_VENDOR_CMD_FLASHDB_READ:
AISGVerdor_V3_Cmd_Flashdb_Read(node, PrimaryCommandSequence, pData + 4, dataLength);
break;
default:
AISGL7_V3_BeginResponseWithSubunitNo(node, AISG_CMD_VENDOR, PrimaryCommandSequence, AISG_V3_RTN_UNSUPPORT_VALUE, true);
AISGL7_V3_WriteResponse(node, AISG_State.Node[ node ].VendorCode[ 0 ]);
AISGL7_V3_WriteResponse(node, AISG_State.Node[ node ].VendorCode[ 1 ]);
AISGL7_V3_SendBuiltResponse(node);
break;
}
}
#endif
static void AISGVendor_V3_Cmd_SetUniqueID(uint8_t node, uint16_t PrimaryCommandSequence, uint8_t *pData, uint16_t dataLength)
{
uint8_t i = 0;
node = 0;
char kv_uid[KV_NAME_L];
#if 0
if (AISG_DEVICE_TYPE_MRET == AISG_State.Node[0].DeviceType) {
node = 0;
} else {
for (i = 0; i < AISG_State.aisg_subunit_count; i++) {
if (memcmp(pData + 2, (void *)AISG_State.Node[ i ].SerialNumber, AISG_DATA_SERIALNUMBER_LENGTH) == 0) {
AISGL7_BeginResponse(node, AISG_CMD_VENDOR, false);
AISGL7_WriteResponse(node, AISG_RTN_FORMAT_ERROR);
AISGL7_SendBuiltResponse(node);
return;
}
}
}
#endif
#ifndef FDB_USING_KVDB
I2C_WriteData(I2C_NODE_STR19_UNIQUE_ID, pData, AISG_DATA_UNIQUEID_LENGTH);
#else
for (uint8_t i = 0; i < AISG_NODE_COUNT; i++) {
//check length.
if (memcmp(pData + 2, (void *)AISG_State.Node[i].SerialNumber, AISG_DATA_SERIALNUMBER_LENGTH) == 0 /*|| dataLength != AISG_DATA_UNIQUEID_LENGTH */ || NULL == pData || \
(pData[ 0 ] < 'A') || (pData[ 0 ] > 'Z') || (pData[ 1 ] < 'A') || (pData[ 1 ] > 'Z')) {
AISGL7_V3_BeginResponseWithSubunitNo(node, AISG_CMD_VENDOR, PrimaryCommandSequence, AISG_V3_RTN_FORMAT_ERROR, true);
AISGL7_V3_WriteResponse(node, AISG_State.Node[ i ].VendorCode[ 0 ]);
AISGL7_V3_WriteResponse(node, AISG_State.Node[ i ].VendorCode[ 1 ]);
// AISGL7_V3_WriteResponse(node, AISG_VENDOR_CMD_SET_UNIQUE_ID);
AISGL7_V3_SendBuiltResponse(node);
return;
}
rt_sprintf(kv_uid, "%s%d", SET_UNIQUE_ID, i);
fdb_err_t Status = flashdb_KV_WriteMultiData(&kvdb[Automatic_config], kv_uid, pData, AISG_DATA_UNIQUEID_LENGTH);
if (Status != FDB_NO_ERR) {
AISGL7_V3_BeginResponseWithSubunitNo(node, AISG_CMD_VENDOR, PrimaryCommandSequence, AISG_V3_RTN_GENERAL_ERROR, true);
AISGL7_V3_WriteResponse(node, AISG_State.Node[ i ].VendorCode[ 0 ]);
AISGL7_V3_WriteResponse(node, AISG_State.Node[ i ].VendorCode[ 1 ]);
AISGL7_V3_SendBuiltResponse(node);
return;
}
#endif
AISG_State.Node[ i ].VendorCode[ 0 ] = pData[ 0 ];
AISG_State.Node[ i ].VendorCode[ 1 ] = pData[ 1 ];
pData += 2;
// add the serial number
for (i = 0; i < AISG_DATA_SERIALNUMBER_LENGTH; ++i) {
AISG_State.Node[i].SerialNumber[ i ] = *pData++;
}
pData += AISG_DATA_UNIQUEID_LENGTH;
}
// response
AISGL7_V3_BeginResponseWithSubunitNo(node, AISG_CMD_VENDOR, PrimaryCommandSequence, AISG_V3_RTN_OK, true);
AISGL7_V3_WriteResponse(node, AISG_State.Node[ node ].VendorCode[ 0 ]);
AISGL7_V3_WriteResponse(node, AISG_State.Node[ node ].VendorCode[ 1 ]);
// AISGL7_V3_WriteResponse(node,
2301_81122825
- 粉丝: 0
- 资源: 4
最新资源
- Sigrity-XtractIM User Guide.rar
- MicrosoftIgnite2024_ConvinceYourManager.docx
- Sigrity-XPIDME User Guide.rar
- Sigrity-XcitePI What’s New in Sigrity 2018.rar
- Sigrity-XcitePI User Guide.rar
- Sigrity-What's New in Sigrity Translators.rar
- Sigrity-Translators User Guide.rar
- Sigrity-CAD Interfaces Translator Notes.rar
- 一些模型数据 关于live2d得到
- CPT102 Data Structure and Algorithm 数据结构和算法 学习大纲
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈