📄 zkbsensor.c
字号:
if ( srcAddressMod.u8EndPoint == WKB_ENDPOINT_LCD
&& srcAddressMod.u16Address == 0x0000
&& srcAddressMod.hAddrMode == DEV_16BIT_ADDR
&& commandTypeIdentifier == SET_RESPONSE
&& dstEndPoint == WKB_ENDPOINT_PS2
&& clusterID == WKB_CLUSTER_ID
&& attributeIdentifier == WKB_PS2_DISPLAY
)
{
if (transactionSequenceNum == ais.u8AfTransactionSequence)
{
/* received ACK, increment outstanding ACK counter */
vAHI_WakeTimerStop(E_AHI_WAKE_TIMER_0);
sKeybStatus.sSystem.boAckPending = FALSE;
ais.u8AfTransactionSequence++;
/* indicate ack pending period over */
vLedControl(LED_SENSOR_ACK_PENDING, FALSE);
}
else
{
/* Received earlier packet again - last ACK was missed, ignore this packet. */
/* An ACK for this packet will be sent automatically by the ZigBee network layer. */
}
}
else
{
/* Received unexpected KVPresponse - could add a handler here for this situation */
}
}
/****************************************************************************
*
* NAME: JZA_pu8AfMsgObject
*
* DESCRIPTION:
* Called when a MSG transaction has been received with a matching endpoint.
* Not used in this example application.
*
* PARAMETERS: Name RW Usage
* afSrcAddr R Address of sender device
* dstEndPoint R Endpoint at receiver
* clusterID R Pointer to cluster ID
* afduLength R Pointer to length of data
* pAfdu R Data array
*
* RETURNS:
* NULL
*
****************************************************************************/
PUBLIC uint8 JZA_u8AfMsgObject(AF_ADDRTYPE sAfSrcAddr,
uint8 u8ClusterID,
uint8 u8DstEndPoint,
uint8 u8LQI,
uint8 *pau8AfduInd,
uint8 *pu8ClusterIDRsp,
uint8 *pau8AfduRsp)
{
return 0;
}
/****************************************************************************
*
* NAME: JZA_vZdpResponse
*
* DESCRIPTION:
* Called when a ZDP response frame has been received.
* Not used in this example application.
*
* PARAMETERS: Name RW Usage
* u8Type R ZDP response type
* pu8Payload R Payload buffer
* u8PayloadLen R Length of payload
*
****************************************************************************/
PUBLIC void JZA_vZdpResponse(uint8 u8Type,
uint8 u8LQI,
uint8 *pu8Payload,
uint8 u8PayloadLen)
{
}
/****************************************************************************
*
* NAME: JZA_vAppEventHandler
*
* DESCRIPTION:
* Called regularly by the task scheduler.
* This is the application task, where the PS2 keyboard is scanned and
* keycodes are sent to the coordinator keyboard display application.
*
****************************************************************************/
PUBLIC void JZA_vAppEventHandler(void)
{
uint16 u16Key;
if (!bNwkJoined)
{
return;
}
/* first check if we are waiting for an ack */
if (sKeybStatus.sSystem.boAckPending)
{
/* no ack received, have we timed-out waiting ? */
if (u8AHI_WakeTimerFiredStatus() & E_AHI_WAKE_TIMER_MASK_0)
{
/* timed-out, send keycode again */
vSendData(sKeybStatus.sSystem.u8CurrentKeyCode);
/* restart ack timer */
vAHI_WakeTimerEnable(E_AHI_WAKE_TIMER_0, FALSE);
vAHI_WakeTimerStart (E_AHI_WAKE_TIMER_0, ACK_TIMEOUT_VALUE);
}
}
else /* ready for a new keyboard scan */
{
/* look for a new keycode from PS2 port */
u16Key = u16ZKBgetKey();
if (u16Key != KBD_NO_KEY_PRESS)
{
/* key found, so send it to the display device */
vSendData((uint8) u16Key);
/* turn on an LED to indicate ack pending - useful */
/* visual aid to packet latency. */
vLedControl(LED_SENSOR_ACK_PENDING, TRUE);
/* prepare for an application level retransmit */
sKeybStatus.sSystem.boAckPending = TRUE;
sKeybStatus.sSystem.u8CurrentKeyCode = (uint8) u16Key;
/* start ACK time-out */
vAHI_WakeTimerEnable(E_AHI_WAKE_TIMER_0, FALSE);
vAHI_WakeTimerStart (E_AHI_WAKE_TIMER_0, ACK_TIMEOUT_VALUE);
}
else
{
/* This would be an appropriate place to enter low power mode. */
/* If no keyboard activity has been seen for a while, then a wakeup */
/* interrupt could be enabled on the PS2 clock line after which the */
/* JN5121 could be put into sleep mode. */
}
}
}
/****************************************************************************
*
* NAME: JZA_vPeripheralEvent
*
* DESCRIPTION:
* Called when a hardware event causes an interrupt. This function is called
* from within the interrupt context so should be brief. In this case, the
* information is placed on a simple FIFO queue to be processed later.
*
* PARAMETERS: Name RW Usage
* u32Device R Peripheral generating interrupt
* u32ItemBitmap R Bitmap of interrupt sources within peripheral
*
****************************************************************************/
PUBLIC void JZA_vPeripheralEvent(uint32 u32Device, uint32 u32ItemBitmap)
{
tsHwIntData *psHwIntData;
uint8 u8WriteNextPtr;
u8WriteNextPtr = (sKeybStatus.sQueue.u8WritePtr + 1) & HW_INT_Q_PTR_MASK;
if (u8WriteNextPtr != sKeybStatus.sQueue.u8ReadPtr)
{
/* There is space on queue */
psHwIntData = &sKeybStatus.sQueue.asHwIntData[sKeybStatus.sQueue.u8WritePtr];
psHwIntData->u32Device = u32Device;
psHwIntData->u32ItemBitmap = u32ItemBitmap;
sKeybStatus.sQueue.u8WritePtr = u8WriteNextPtr;
}
/* If no space on queue, interrupt is silently discarded */
}
/****************************************************************************
*
* NAME: JZA_vStackEvent
*
* DESCRIPTION:
* Used to receive additional stack events such as Data Request confirm
*
* PARAMETERS: Name RW Usage
* eEventId R ID number of stack event
* *puStackEvent R Pointer to union containing
* stack event data
*
* RETURNS:
* void
*
****************************************************************************/
PUBLIC void JZA_vStackEvent(teJZS_EventIdentifier eEventId,
tuJZS_StackEvent *puStackEvent)
{
if (eEventId == JZS_EVENT_NWK_JOINED_AS_ROUTER)
{
bNwkJoined = TRUE;
}
}
/****************************************************************************/
/*** Local Functions ***/
/****************************************************************************/
/****************************************************************************
*
* NAME: vInitKeyboardDemo
*
* DESCRIPTION:
* Initialises the ZigBee stack and JN5121 devices. Initialises the PS2 socket
* service. Finally calls the BOS task switcher, doesn't return from this call.
*
* RETURNS: No return - enters BOS task switcher.
* void
*
****************************************************************************/
PRIVATE void vInitKeyboardDemo(void)
{
/* Initialise Zigbee stack */
JZS_u32InitSystem(TRUE);
/* Calibrate 32kHz clock wakeup timer */
sKeybStatus.sSystem.u32CalibOffset = 10000 / u32AHI_WakeTimerCalibrate();
/* initialise the PS2 bus and disable the keyboard */
(void) u16PS2socketInit();
vPS2socketBusDisable();
/* Set DIO for scroll lock LED */
vLedControl(LED_SENSOR_ACK_PENDING, FALSE);
vLedControl(LED_SENSOR_UNUSED_1, FALSE);
vLedInitRfd();
/* Initialise keyboard control structures */
sKeybStatus.sQueue.u8ReadPtr = 0;
sKeybStatus.sQueue.u8WritePtr = 0;
sKeybStatus.sSystem.boAckPending = FALSE;
/* Start BOS */
(void)bBosRun(TRUE);
}
/****************************************************************************
*
* NAME: vSendData
*
* DESCRIPTION:
* Sends keyboard codes to the coordinator application, packaged in a KVP object.
*
* PARAMETERS: Name R/W Usage
* u8datum R PS2 keycode (part of keycode sequence)
*
****************************************************************************/
PRIVATE void vSendData(uint8 u8datum)
{
uint8 u8SrcEP;
AFDE_DATA_REQ_INFO asAfdeDataReq[1];
AF_ADDRTYPE hDstAddr;
uint8 au8Afdu[2];
uint8 transCount = 1;
u8SrcEP = WKB_ENDPOINT_PS2;
hDstAddr.hAddrMode = DEV_16BIT_ADDR;
hDstAddr.u16Address = 0x0000;
hDstAddr.u8EndPoint = WKB_ENDPOINT_LCD;
asAfdeDataReq[0].u8SequenceNum = ais.u8AfTransactionSequence;
asAfdeDataReq[0].hCommandTypeID = SET_ACKNOWLEDGMENT;
asAfdeDataReq[0].hAttributeDataType = UNSIGNED_8BIT_INTEGER;
asAfdeDataReq[0].u16AttributeID = WKB_PS2_DISPLAY;
asAfdeDataReq[0].hErrorCode = KVP_SUCCESS;
asAfdeDataReq[0].u8DividedAfduLen = 2;
/* API fix - application data field seq number, currently not available to JZA_eAfKvpObject */
au8Afdu[0] = ais.u8AfTransactionSequence;
au8Afdu[1] = u8datum;
/* Build a KVP data message */
afdeDataRequest(hDstAddr,
u8SrcEP,
WKB_PROFILE_ID,
WKB_CLUSTER_ID,
KVP,
transCount,
asAfdeDataReq,
au8Afdu,
APS_TXOPTION_NONE,
SUPPRESS_ROUTE_DISCOVERY,
0);
}
/****************************************************************************/
/*** END OF FILE ***/
/****************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -