static void Handle_TestCallback ( le_msg_MessageRef_t _msgRef ) { // Get the message buffer pointer uint8_t* _msgBufPtr = ((_Message_t*)le_msg_GetPayloadPtr(_msgRef))->buffer; // Needed if we are returning a result or output values uint8_t* _msgBufStartPtr = _msgBufPtr; // Unpack the input parameters from the message uint32_t someParm; _msgBufPtr = UnpackData( _msgBufPtr, &someParm, sizeof(uint32_t) ); size_t dataArrayNumElements; _msgBufPtr = UnpackData( _msgBufPtr, &dataArrayNumElements, sizeof(size_t) ); uint8_t dataArray[dataArrayNumElements]; _msgBufPtr = UnpackData( _msgBufPtr, dataArray, dataArrayNumElements*sizeof(uint8_t) ); void* contextPtr; _msgBufPtr = UnpackData( _msgBufPtr, &contextPtr, sizeof(void*) ); // Create a new server data object and fill it in _ServerData_t* serverDataPtr = le_mem_ForceAlloc(_ServerDataPool); serverDataPtr->clientSessionRef = le_msg_GetSession(_msgRef); serverDataPtr->contextPtr = contextPtr; serverDataPtr->handlerRef = NULL; serverDataPtr->removeHandlerFunc = NULL; contextPtr = serverDataPtr; // Define storage for output parameters // Call the function int32_t _result; _result = TestCallback ( someParm, dataArray, dataArrayNumElements, AsyncResponse_TestCallback, contextPtr ); // Re-use the message buffer for the response _msgBufPtr = _msgBufStartPtr; // Pack the result first _msgBufPtr = PackData( _msgBufPtr, &_result, sizeof(_result) ); // Pack any "out" parameters // Return the response LE_DEBUG("Sending response to client session %p : %ti bytes sent", le_msg_GetSession(_msgRef), _msgBufPtr-_msgBufStartPtr); le_msg_Respond(_msgRef); }
static void Handle_AddTestAHandler ( le_msg_MessageRef_t _msgRef ) { // Get the message buffer pointer uint8_t* _msgBufPtr = ((_Message_t*)le_msg_GetPayloadPtr(_msgRef))->buffer; // Needed if we are returning a result or output values uint8_t* _msgBufStartPtr = _msgBufPtr; // Unpack the input parameters from the message void* contextPtr; _msgBufPtr = UnpackData( _msgBufPtr, &contextPtr, sizeof(void*) ); // Create a new server data object and fill it in _ServerData_t* serverDataPtr = le_mem_ForceAlloc(_ServerDataPool); serverDataPtr->clientSessionRef = le_msg_GetSession(_msgRef); serverDataPtr->contextPtr = contextPtr; serverDataPtr->handlerRef = NULL; serverDataPtr->removeHandlerFunc = NULL; contextPtr = serverDataPtr; // Define storage for output parameters // Call the function TestAHandlerRef_t _result; _result = AddTestAHandler ( AsyncResponse_AddTestAHandler, contextPtr ); // Put the handler reference result and a pointer to the associated remove function // into the server data object. This function pointer is needed in case the client // is closed and the handlers need to be removed. serverDataPtr->handlerRef = (le_event_HandlerRef_t)_result; serverDataPtr->removeHandlerFunc = (RemoveHandlerFunc_t)RemoveTestAHandler; // Return a safe reference to the server data object as the reference. _LOCK _result = le_ref_CreateRef(_HandlerRefMap, serverDataPtr); _UNLOCK // Re-use the message buffer for the response _msgBufPtr = _msgBufStartPtr; // Pack the result first _msgBufPtr = PackData( _msgBufPtr, &_result, sizeof(_result) ); // Pack any "out" parameters // Return the response LE_DEBUG("Sending response to client session %p : %ti bytes sent", le_msg_GetSession(_msgRef), _msgBufPtr-_msgBufStartPtr); le_msg_Respond(_msgRef); }
static void ClientIndicationRecvHandler ( le_msg_MessageRef_t msgRef, void* contextPtr ) { // Get the message payload _Message_t* msgPtr = le_msg_GetPayloadPtr(msgRef); uint8_t* _msgBufPtr = msgPtr->buffer; // Have to partially unpack the received message in order to know which thread // the queued function should actually go to. void* clientContextPtr; _msgBufPtr = UnpackData( _msgBufPtr, &clientContextPtr, sizeof(void*) ); // Pull out the callers thread _ClientData_t* clientDataPtr = clientContextPtr; le_thread_Ref_t callersThreadRef = clientDataPtr->callersThreadRef; // Trigger the appropriate event switch (msgPtr->id) { case _MSGID_AddTestA : le_event_QueueFunctionToThread(callersThreadRef, _Handle_AddTestA, msgRef, NULL); break; case _MSGID_AddBugTest : le_event_QueueFunctionToThread(callersThreadRef, _Handle_AddBugTest, msgRef, NULL); break; default: LE_ERROR("Unknowm msg id = %i for client thread = %p", msgPtr->id, callersThreadRef); } }
//void UART_XB_SPI_UART_ISR_ExitCallback(void) void UART_Read() { uint8_t ReadData; ReadData = UART_XB_UartGetChar(); //UART_PC_PutChar(ReadData); uint32_t ERR; RXSTATUS = 0; ERR = UnpackData(&TX_RESP, ReadData); if (ERR) { char _tmp[15]; sprintf(_tmp, "ERROR: %u\r\n", (unsigned int)ERR); UART_PC_PutString(_tmp); } if (TX_RESP.EndPacket) { uint8_t RespBuff[50]; if (ProcPacket(&TX_RESP, &RXSTATUS, RespBuff)) { if (RXSTATUS == RESP_TO_SEND) { char _tmprecv[50]; PackData(_tmprecv, RespBuff, 0u); //UART_PC_PutString("Data:\r\n"); //UART_PC_PutString(_tmprecv); //UART_PC_PutString("\r\n"); UART_XB_UartPutString(_tmprecv); } //printf("RXSTATUS: %d\n", RXSTATUS); } } UART_XB_ClearRxInterruptSource(UART_XB_INTR_RX_NOT_EMPTY); }
// This function parses the message buffer received from the server, and then calls the user // registered handler, which is stored in a client data object. static void _Handle_AddBugTest ( void* _reportPtr, void* _notUsed ) { le_msg_MessageRef_t _msgRef = _reportPtr; _Message_t* _msgPtr = le_msg_GetPayloadPtr(_msgRef); uint8_t* _msgBufPtr = _msgPtr->buffer; // The clientContextPtr always exists and is always first. void* _clientContextPtr; _msgBufPtr = UnpackData( _msgBufPtr, &_clientContextPtr, sizeof(void*) ); // Pull out additional data from the context pointer _ClientData_t* _clientDataPtr = _clientContextPtr; BugTestFunc_t _handlerRef_AddBugTest = (BugTestFunc_t)_clientDataPtr->handlerPtr; void* contextPtr = _clientDataPtr->contextPtr; // Unpack the remaining parameters // Call the registered handler if ( _handlerRef_AddBugTest != NULL ) { _handlerRef_AddBugTest( contextPtr ); } else { LE_ERROR("ERROR in client _Handle_AddBugTest: no registered handler"); } // Release the message, now that we are finished with it. le_msg_ReleaseMsg(_msgRef); }
static void Handle_allParameters ( le_msg_MessageRef_t _msgRef ) { // Get the message buffer pointer __attribute__((unused)) uint8_t* _msgBufPtr = ((_Message_t*)le_msg_GetPayloadPtr(_msgRef))->buffer; // Unpack the input parameters from the message common_EnumExample_t a; _msgBufPtr = UnpackData( _msgBufPtr, &a, sizeof(common_EnumExample_t) ); size_t dataNumElements; _msgBufPtr = UnpackData( _msgBufPtr, &dataNumElements, sizeof(size_t) ); uint32_t data[dataNumElements]; _msgBufPtr = UnpackData( _msgBufPtr, data, dataNumElements*sizeof(uint32_t) ); size_t outputNumElements; _msgBufPtr = UnpackData( _msgBufPtr, &outputNumElements, sizeof(size_t) ); const char* label; _msgBufPtr = UnpackString( _msgBufPtr, &label ); size_t responseNumElements; _msgBufPtr = UnpackData( _msgBufPtr, &responseNumElements, sizeof(size_t) ); size_t moreNumElements; _msgBufPtr = UnpackData( _msgBufPtr, &moreNumElements, sizeof(size_t) ); // Call the function allParameters ( (ServerCmdRef_t)_msgRef, a, data, dataNumElements, outputNumElements, label, responseNumElements, moreNumElements ); }
static void Handle_RemoveBugTestHandler ( le_msg_MessageRef_t _msgRef ) { // Get the message buffer pointer uint8_t* _msgBufPtr = ((_Message_t*)le_msg_GetPayloadPtr(_msgRef))->buffer; // Needed if we are returning a result or output values uint8_t* _msgBufStartPtr = _msgBufPtr; // Unpack the input parameters from the message BugTestHandlerRef_t addHandlerRef; _msgBufPtr = UnpackData( _msgBufPtr, &addHandlerRef, sizeof(BugTestHandlerRef_t) ); // The passed in handlerRef is a safe reference for the server data object. Need to get the // real handlerRef from the server data object and then delete both the safe reference and // the object since they are no longer needed. _LOCK _ServerData_t* serverDataPtr = le_ref_Lookup(_HandlerRefMap, addHandlerRef); if ( serverDataPtr == NULL ) { _UNLOCK LE_KILL_CLIENT("Invalid reference"); return; } le_ref_DeleteRef(_HandlerRefMap, addHandlerRef); _UNLOCK addHandlerRef = (BugTestHandlerRef_t)serverDataPtr->handlerRef; le_mem_Release(serverDataPtr); // Define storage for output parameters // Call the function RemoveBugTestHandler ( addHandlerRef ); // Re-use the message buffer for the response _msgBufPtr = _msgBufStartPtr; // Pack any "out" parameters // Return the response LE_DEBUG("Sending response to client session %p : %ti bytes sent", le_msg_GetSession(_msgRef), _msgBufPtr-_msgBufStartPtr); le_msg_Respond(_msgRef); }
HRESULT OpenArchive(IInStream *inStream, const CHeader &h, CByteBuffer &xml, CDatabase &db) { RINOK(UnpackData(inStream, h.XmlResource, h.IsLzxMode(), xml, NULL)); RINOK(ReadStreams(inStream, h, db)); bool needBootMetadata = !h.MetadataResource.IsEmpty(); if (h.PartNumber == 1) { int imageIndex = 1; for (int j = 0; j < db.Streams.Size(); j++) { // if (imageIndex > 1) break; const CStreamInfo &si = db.Streams[j]; if (!si.Resource.IsMetadata() || si.PartNumber != h.PartNumber) continue; Byte hash[kHashSize]; CByteBuffer metadata; RINOK(UnpackData(inStream, si.Resource, h.IsLzxMode(), metadata, hash)); if (memcmp(hash, si.Hash, kHashSize) != 0) return S_FALSE; wchar_t sz[32]; ConvertUInt64ToString(imageIndex++, sz); UString s = sz; s += WCHAR_PATH_SEPARATOR; RINOK(ParseDir(metadata, metadata.GetCapacity(), s, db.Items)); if (needBootMetadata) if (h.MetadataResource.Offset == si.Resource.Offset) needBootMetadata = false; } } if (needBootMetadata) { CByteBuffer metadata; RINOK(UnpackData(inStream, h.MetadataResource, h.IsLzxMode(), metadata, NULL)); RINOK(ParseDir(metadata, metadata.GetCapacity(), L"0" WSTRING_PATH_SEPARATOR, db.Items)); } return S_OK; }
HRESULT ReadStreams(IInStream *inStream, const CHeader &h, CDatabase &db) { CByteBuffer offsetBuf; RINOK(UnpackData(inStream, h.OffsetResource, h.IsLzxMode(), offsetBuf, NULL)); for (size_t i = 0; i + kStreamInfoSize <= offsetBuf.GetCapacity(); i += kStreamInfoSize) { CStreamInfo s; GetStream((const Byte *)offsetBuf + i, s); if (s.PartNumber == h.PartNumber) db.Streams.Add(s); } return S_OK; }
/******************************************************************************* * Function Name: ReceiveData ******************************************************************************** * * Summary: * receive data from start in struct "inData" * Return: * NETWORK_CONNECT or NETWORK_DISCONNECT * *******************************************************************************/ uint32_t ReceiveData(void) { if(inData.readStatus == NO_READ && outData.writeStatus == WRITE_OK) { uint32_t result = 0; int i; uint8_t byte; struct Resp recvData; while((UART_XB_SpiUartGetRxBufferSize() > 0) && ((byte=UART_XB_UartGetChar()) != 0)) { result = UnpackData(&recvData, (uint8_t)(byte & 0xFF)); CyDelay(2); if(recvData.EndPacket == 1) { inData.IDpacket = recvData.Seq; /*id packet ok*/ if(outData.IDpacket == inData.IDpacket) { inData.readStatus = READ_OK; outData.writeStatus = NO_WRITE; /*connect network*/ networkStatus = NETWORK_CONNECT; noConnect = 0; /*write data*/ inData.newSkier = (recvData.Data3 & 0xFF00) >> 8; inData.unixStartTime = recvData.Data1; inData.startMsTime = recvData.Data2; inData.reboot = (recvData.Data3 & 0x00FF); /*if new skier on track*/ if(inData.newSkier == NEW_SKIER_IN_TARCK ) { WriteStartTime(inData.unixStartTime, inData.startMsTime); BLE_sendOneSkierTimeStart(inData.unixStartTime, inData.startMsTime,GetIDskierStarted(),SkierOnWay(),MAX_SKIERS_ON_WAY); IncrementID(); } /*next packet*/ outData.IDpacket++; CyDelay(50); } /* if prev packet late*/ else if(outData.IDpacket == (inData.IDpacket + 1))
static void Handle_TriggerCallbackTest ( le_msg_MessageRef_t _msgRef ) { // Get the message buffer pointer __attribute__((unused)) uint8_t* _msgBufPtr = ((_Message_t*)le_msg_GetPayloadPtr(_msgRef))->buffer; // Unpack the input parameters from the message uint32_t data; _msgBufPtr = UnpackData( _msgBufPtr, &data, sizeof(uint32_t) ); // Call the function TriggerCallbackTest ( (ServerCmdRef_t)_msgRef, data ); }
static void Handle_TriggerCallbackTest ( le_msg_MessageRef_t _msgRef ) { // Get the message buffer pointer uint8_t* _msgBufPtr = ((_Message_t*)le_msg_GetPayloadPtr(_msgRef))->buffer; // Needed if we are returning a result or output values uint8_t* _msgBufStartPtr = _msgBufPtr; // Unpack the input parameters from the message uint32_t data; _msgBufPtr = UnpackData( _msgBufPtr, &data, sizeof(uint32_t) ); // Define storage for output parameters // Call the function TriggerCallbackTest ( data ); // Re-use the message buffer for the response _msgBufPtr = _msgBufStartPtr; // Pack any "out" parameters // Return the response LE_DEBUG("Sending response to client session %p : %ti bytes sent", le_msg_GetSession(_msgRef), _msgBufPtr-_msgBufStartPtr); le_msg_Respond(_msgRef); }
static void Handle_allParameters ( le_msg_MessageRef_t _msgRef ) { // Get the message buffer pointer uint8_t* _msgBufPtr = ((_Message_t*)le_msg_GetPayloadPtr(_msgRef))->buffer; // Needed if we are returning a result or output values uint8_t* _msgBufStartPtr = _msgBufPtr; // Unpack the input parameters from the message common_EnumExample_t a; _msgBufPtr = UnpackData( _msgBufPtr, &a, sizeof(common_EnumExample_t) ); size_t dataNumElements; _msgBufPtr = UnpackData( _msgBufPtr, &dataNumElements, sizeof(size_t) ); uint32_t data[dataNumElements]; _msgBufPtr = UnpackData( _msgBufPtr, data, dataNumElements*sizeof(uint32_t) ); size_t outputNumElements; _msgBufPtr = UnpackData( _msgBufPtr, &outputNumElements, sizeof(size_t) ); if ( outputNumElements > 10 ) { LE_DEBUG("Adjusting outputNumElements from %zd to 10", outputNumElements); outputNumElements = 10; } char label[21]; _msgBufPtr = UnpackString( _msgBufPtr, label, 21 ); size_t responseNumElements; _msgBufPtr = UnpackData( _msgBufPtr, &responseNumElements, sizeof(size_t) ); size_t moreNumElements; _msgBufPtr = UnpackData( _msgBufPtr, &moreNumElements, sizeof(size_t) ); // Define storage for output parameters uint32_t b; uint32_t output[outputNumElements]; char response[responseNumElements]; response[0]=0; char more[moreNumElements]; more[0]=0; // Call the function allParameters ( a, &b, data, dataNumElements, output, &outputNumElements, label, response, responseNumElements, more, moreNumElements ); // Re-use the message buffer for the response _msgBufPtr = _msgBufStartPtr; // Pack any "out" parameters _msgBufPtr = PackData( _msgBufPtr, &b, sizeof(uint32_t) ); _msgBufPtr = PackData( _msgBufPtr, &outputNumElements, sizeof(size_t) ); _msgBufPtr = PackData( _msgBufPtr, output, outputNumElements*sizeof(uint32_t) ); _msgBufPtr = PackString( _msgBufPtr, response ); _msgBufPtr = PackString( _msgBufPtr, more ); // Return the response LE_DEBUG("Sending response to client session %p : %ti bytes sent", le_msg_GetSession(_msgRef), _msgBufPtr-_msgBufStartPtr); le_msg_Respond(_msgRef); }
//-------------------------------------------------------------------------------------------------- BugTestRef_t AddBugTest ( const char* newPathPtr, ///< [IN] BugTestFunc_t handlerPtr, ///< [IN] void* contextPtr ///< [IN] ) { le_msg_MessageRef_t _msgRef; le_msg_MessageRef_t _responseMsgRef; _Message_t* _msgPtr; // Will not be used if no data is sent/received from server. __attribute__((unused)) uint8_t* _msgBufPtr; BugTestRef_t _result; // Range check values, if appropriate if ( strlen(newPathPtr) > 512 ) LE_FATAL("strlen(newPathPtr) > 512"); // Create a new message object and get the message buffer _msgRef = le_msg_CreateMsg(GetCurrentSessionRef()); _msgPtr = le_msg_GetPayloadPtr(_msgRef); _msgPtr->id = _MSGID_AddBugTest; _msgBufPtr = _msgPtr->buffer; // Pack the input parameters _msgBufPtr = PackString( _msgBufPtr, newPathPtr ); // The input parameters are stored in the client data object, and it is // a pointer to this object that is passed down. // Create a new client data object and fill it in _ClientData_t* _clientDataPtr = le_mem_ForceAlloc(_ClientDataPool); _clientDataPtr->handlerPtr = (le_event_HandlerFunc_t)handlerPtr; _clientDataPtr->contextPtr = contextPtr; _clientDataPtr->callersThreadRef = le_thread_GetCurrent(); contextPtr = _clientDataPtr; _msgBufPtr = PackData( _msgBufPtr, &contextPtr, sizeof(void*) ); // Send a request to the server and get the response. LE_DEBUG("Sending message to server and waiting for response"); _responseMsgRef = le_msg_RequestSyncResponse(_msgRef); // It is a serious error if we don't get a valid response from the server LE_FATAL_IF(_responseMsgRef == NULL, "Valid response was not received from server"); // Process the result and/or output parameters, if there are any. _msgPtr = le_msg_GetPayloadPtr(_responseMsgRef); _msgBufPtr = _msgPtr->buffer; // Unpack the result first _msgBufPtr = UnpackData( _msgBufPtr, &_result, sizeof(_result) ); // Put the handler reference result into the client data object, and // then return a safe reference to the client data object as the reference. _clientDataPtr->handlerRef = (le_event_HandlerRef_t)_result; _LOCK _result = le_ref_CreateRef(_HandlerRefMap, _clientDataPtr); _UNLOCK // Unpack any "out" parameters // Release the message object, now that all results/output has been copied. le_msg_ReleaseMsg(_responseMsgRef); return _result; }
//-------------------------------------------------------------------------------------------------- void allParameters ( common_EnumExample_t a, ///< [IN] ///< first one-line comment ///< second one-line comment uint32_t* bPtr, ///< [OUT] const uint32_t* dataPtr, ///< [IN] size_t dataNumElements, ///< [IN] uint32_t* outputPtr, ///< [OUT] ///< some more comments here ///< and some comments here as well size_t* outputNumElementsPtr, ///< [INOUT] const char* label, ///< [IN] char* response, ///< [OUT] ///< comments on final parameter, first line ///< and more comments size_t responseNumElements, ///< [IN] char* more, ///< [OUT] ///< This parameter tests a bug fix size_t moreNumElements ///< [IN] ) { le_msg_MessageRef_t _msgRef; le_msg_MessageRef_t _responseMsgRef; _Message_t* _msgPtr; // Will not be used if no data is sent/received from server. __attribute__((unused)) uint8_t* _msgBufPtr; // Range check values, if appropriate if ( dataNumElements > 10 ) LE_FATAL("dataNumElements > 10"); if ( strlen(label) > 20 ) LE_FATAL("strlen(label) > 20"); // Create a new message object and get the message buffer _msgRef = le_msg_CreateMsg(GetCurrentSessionRef()); _msgPtr = le_msg_GetPayloadPtr(_msgRef); _msgPtr->id = _MSGID_allParameters; _msgBufPtr = _msgPtr->buffer; // Pack the input parameters _msgBufPtr = PackData( _msgBufPtr, &a, sizeof(common_EnumExample_t) ); _msgBufPtr = PackData( _msgBufPtr, &dataNumElements, sizeof(size_t) ); _msgBufPtr = PackData( _msgBufPtr, dataPtr, dataNumElements*sizeof(uint32_t) ); _msgBufPtr = PackData( _msgBufPtr, outputNumElementsPtr, sizeof(size_t) ); _msgBufPtr = PackString( _msgBufPtr, label ); _msgBufPtr = PackData( _msgBufPtr, &responseNumElements, sizeof(size_t) ); _msgBufPtr = PackData( _msgBufPtr, &moreNumElements, sizeof(size_t) ); // Send a request to the server and get the response. LE_DEBUG("Sending message to server and waiting for response"); _responseMsgRef = le_msg_RequestSyncResponse(_msgRef); // It is a serious error if we don't get a valid response from the server LE_FATAL_IF(_responseMsgRef == NULL, "Valid response was not received from server"); // Process the result and/or output parameters, if there are any. _msgPtr = le_msg_GetPayloadPtr(_responseMsgRef); _msgBufPtr = _msgPtr->buffer; // Unpack any "out" parameters _msgBufPtr = UnpackData( _msgBufPtr, bPtr, sizeof(uint32_t) ); _msgBufPtr = UnpackData( _msgBufPtr, outputNumElementsPtr, sizeof(size_t) ); _msgBufPtr = UnpackData( _msgBufPtr, outputPtr, *outputNumElementsPtr*sizeof(uint32_t) ); _msgBufPtr = UnpackDataString( _msgBufPtr, response, responseNumElements*sizeof(char) ); _msgBufPtr = UnpackDataString( _msgBufPtr, more, moreNumElements*sizeof(char) ); // Release the message object, now that all results/output has been copied. le_msg_ReleaseMsg(_responseMsgRef); }