Skip to content

Commit

Permalink
*slightly updated API structures
Browse files Browse the repository at this point in the history
*fixed a bug in ATQT in API mode
  • Loading branch information
KillingJacky committed Jan 22, 2016
1 parent 7e9a1f0 commit 364a02e
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 26 deletions.
Binary file modified build/output/COO_JN5168.bin
Binary file not shown.
Binary file modified build/output/END_JN5168.bin
Binary file not shown.
Binary file modified build/output/ROU_JN5168.bin
Binary file not shown.
10 changes: 5 additions & 5 deletions include/firmware_at_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,11 @@
#define AT_REQ_PARAM_LEN 4 //maximal size of AT parameter
#define AT_RESP_PARAM_LEN 20 //maximal size of AT response hex value
#define API_DATA_LEN 32 //maximal size of each API data frame
#define AT_CMD_LEN 8 //AT command length

#define API_START_DELIMITER 0x7e //API special frame start delimiter

#define OPTION_CAST_MASK 0x40 //option unicast or broadcast MASK
#define OPTION_ACK_MASK 0x80 //option ACK or not MASK
#define OPTION_ACK_MASK 0x01 //option ACK or not
#define OPTION_CAST_MASK 0x02 //option unicast or broadcast

/*
API mode index
Expand Down Expand Up @@ -98,7 +97,6 @@ typedef enum
API_REMOTE_AT_RESP = 0x97, //remote At response
API_DATA_PACKET = 0x02, //indicate that's a data packet,data packet is certainly remote packet.
API_TEST = 0x8f, //Test
/* recently */
API_OTA_NTC = 0xd3,
API_OTA_REQ = 0xb0,
API_OTA_RESP = 0x06,
Expand Down Expand Up @@ -152,6 +150,7 @@ typedef struct
typedef struct
{
uint8 frameId; //identifies the UART data frame to correlate with subsequent ACK
uint8 option;
uint8 atCmdId; //AT Command index
uint8 value[AT_REQ_PARAM_LEN]; //if present,indicates the requested parameter value to set
//the given register,if no character present,register is queried
Expand All @@ -164,6 +163,7 @@ typedef struct
uint8 frameId; //identifies the UART data frame to correlate with subsequent ACK
uint8 atCmdId; //AT Command index
uint8 eStatus; //OK,ERROR,Invalid command,Invalid Parameter
uint8 valueLen;
uint8 value[AT_RESP_PARAM_LEN]; //value returned in hex format
}__attribute__ ((packed)) tsLocalAtResp;

Expand All @@ -172,7 +172,7 @@ typedef struct
typedef struct
{
uint8 frameId;
uint8 option; //0x01 Disable ACK,default: 0x00 Enable ACK
uint8 option;
uint8 atCmdId;
uint8 value[AT_REQ_PARAM_LEN];
uint16 unicastAddr;
Expand Down
36 changes: 23 additions & 13 deletions src/firmware_at_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ int assembleLocalAtResp(tsLocalAtResp *resp, uint8 frm_id, uint8 cmd_id, uint8 s
resp->frameId = frm_id;
resp->atCmdId = cmd_id;
resp->eStatus = status;
resp->valueLen = len;
memcpy(resp->value, value, len);
return sizeof(tsLocalAtResp);
}
Expand Down Expand Up @@ -475,7 +476,7 @@ void assembleApiSpec(tsApiSpec *api, uint8 idtf, uint8 *payload, int payload_len
api->startDelimiter = API_START_DELIMITER;
api->length = payload_len;
api->teApiIdentifier = idtf;
memcpy((uint8 *)&api->payload.localAtReq, payload, payload_len);
memcpy((uint8 *)&api->payload.dummyByte, payload, payload_len);
api->checkSum = calCheckSum(payload, payload_len);
}

Expand Down Expand Up @@ -1241,7 +1242,6 @@ int API_QueryOnChipTemper_CallBack(tsApiSpec *reqApiSpec, tsApiSpec *respApiSpec
40ppm limit specified by the IEEE 802.15. 4 standard.
*/
vHAL_PullXtal((int32)i16ChipTemperature);
uint8 val = (uint8)i16ChipTemperature;

if (API_LOCAL_AT_REQ == reqApiSpec->teApiIdentifier)
{
Expand All @@ -1253,8 +1253,8 @@ int API_QueryOnChipTemper_CallBack(tsApiSpec *reqApiSpec, tsApiSpec *respApiSpec
reqApiSpec->payload.localAtReq.frameId,
ATQT,
AT_OK,
&val,
sizeof(uint8));
(uint8*)&i16ChipTemperature,
sizeof(int16));

/* Assemble apiSpec */
assembleApiSpec(respApiSpec,
Expand All @@ -1271,8 +1271,8 @@ int API_QueryOnChipTemper_CallBack(tsApiSpec *reqApiSpec, tsApiSpec *respApiSpec
reqApiSpec->payload.remoteAtReq.frameId,
ATQT,
AT_OK,
&val,
sizeof(uint8));
(uint8*)&i16ChipTemperature,
sizeof(int16));

/* Assemble apiSpec */
assembleApiSpec(respApiSpec,
Expand Down Expand Up @@ -1706,11 +1706,12 @@ int API_i32ApiFrmProc(tsApiSpec *apiSpec)
}
}

/* UART ACK,if frameId ==0,No ACK(implement in v1003) */
if (0 != apiSpec->payload.localAtReq.frameId)
/* UART ACK */
if (0 == (apiSpec->payload.localAtReq.option & OPTION_ACK_MASK))
{
CMI_vLocalAckDistributor(&retApiSpec);
}
result = OK;
break;
}

Expand Down Expand Up @@ -1864,11 +1865,20 @@ int API_i32AdsStackEventProc(ZPS_tsAfEvent *sStackEvent)
}
}
}
/* ACK unicast to u16SrcAddr */
size = i32CopyApiSpec(&respApiSpec, tmp);
ret = API_bSendToAirPort(UNICAST, u16SrcAddr, tmp, size);
if (!ret) result = ERR;
else result = OK;

if (0 == ((apiSpec.payload.remoteAtReq.option) & OPTION_ACK_MASK))
{
/* ACK unicast to u16SrcAddr */
size = i32CopyApiSpec(&respApiSpec, tmp);
ret = API_bSendToAirPort(UNICAST, u16SrcAddr, tmp, size);
if (!ret) result = ERR;
else result = OK;
}else
{
/* the caller doesn't need response */
result = OK;
}

break;
}

Expand Down
4 changes: 2 additions & 2 deletions src/firmware_aups.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ PRIVATE uint32 _loopInterval = 0;
/****************************************************************************/
/*** Exported Functions ***/
/****************************************************************************/
extern uint32 SPM_u32PullData(void *data, int len);
extern uint32 SPM_u32PushData(void *data, int len);

/****************************************************************************
*
Expand Down Expand Up @@ -240,7 +240,7 @@ PUBLIC uint8 aupsAirPortRead(void *dst, int len)
****************************************************************************/
PUBLIC uint8 aupsSendApiFrm(void *data, int len)
{
uint32 avlb_cnt = SPM_u32PullData(data, len);
uint32 avlb_cnt = SPM_u32PushData(data, len);
if (avlb_cnt >= THRESHOLD_READ)
{
OS_eActivateTask(APP_taskHandleUartRx); //Activate SPM immediately
Expand Down
8 changes: 4 additions & 4 deletions src/firmware_cmi.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
/****************************************************************************/
/*** External Function Prototypes ***/
/****************************************************************************/
extern uint32 SPM_u32PullData(void *data, int len);
extern uint32 SPM_u32PushData(void *data, int len);

/****************************************************************************/
/*** Exported Variables ***/
Expand Down Expand Up @@ -89,17 +89,17 @@ void CMI_vUrtRevDataDistributor(void *data, int len)
{
/* AT mode */
case E_MODE_AT:
avlb_cnt = SPM_u32PullData(data, len);
avlb_cnt = SPM_u32PushData(data, len);
break;

/* API mode */
case E_MODE_API:
avlb_cnt = SPM_u32PullData(data, len);
avlb_cnt = SPM_u32PushData(data, len);
break;

/* DATA mode */
case E_MODE_DATA:
avlb_cnt = SPM_u32PullData(data, len);
avlb_cnt = SPM_u32PushData(data, len);
break;

/* Arduino-ful MCU mode */
Expand Down
4 changes: 2 additions & 2 deletions src/firmware_spm.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void SPM_vInit()

/****************************************************************************
*
* NAME: SPM_u32PullData
* NAME: SPM_u32PushData
*
* DESCRIPTION:
* SPM pull some data into data pool
Expand All @@ -93,7 +93,7 @@ void SPM_vInit()
* available data size of SPM
*
****************************************************************************/
uint32 SPM_u32PullData(void *data, int len)
uint32 SPM_u32PushData(void *data, int len)
{
uint32 free_cnt = 0;
uint32 min_cnt = 0;
Expand Down

0 comments on commit 364a02e

Please sign in to comment.