Пример #1
0
uint32_t NDEFPushProtocol::pushPayload(uint8_t *NDEFMessage, uint32_t length)
{
    NPP_MESSAGE *nppMessage = (NPP_MESSAGE *) ALLOCATE_HEADER_SPACE(NDEFMessage, NPP_MESSAGE_HDR_LEN);
    
    nppMessage->version = NPP_SUPPORTED_VERSION;
    nppMessage->numNDEFEntries = MODIFY_ENDIAN((uint32_t)0x00000001);
    nppMessage->actionCode = NPP_ACTION_CODE;
    nppMessage->NDEFLength = MODIFY_ENDIAN(length);
 
    
    /*uint8_t *buf = (uint8_t *) nppMessage;
    Serial.println(F("NPP + NDEF Message")); 
    for (uint16_t i = 0; i < length + NPP_MESSAGE_HDR_LEN; ++i)
    {
        Serial.print(F("0x")); 
        Serial.print(buf[i], HEX);
        Serial.print(F(" "));
    }*/
    uint32_t result = _linkLayer->openNPPClientLink();
  
    if(RESULT_OK(result)) //if connection is error-free
    { 
        result =  _linkLayer->clientLinkTxData((uint8_t *)nppMessage, length + NPP_MESSAGE_HDR_LEN);
    } 
    
    return result;       
}
Пример #2
0
uint32_t NDEFMessage::createNDEFShortRecord(uint8_t *&NDEFMessage ,uint8_t payloadLen)
{
   //Serial.print("Message: ");
   //Serial.println((char *)message);
   uint8_t * NDEFMessageHdr = ALLOCATE_HEADER_SPACE(NDEFMessage, NDEF_SHORT_RECORD_MESSAGE_HDR_LEN);
   
   NDEFMessageHdr[0] =  NDEF_MESSAGE_BEGIN_FLAG | NDEF_MESSAGE_END_FLAG | NDEF_MESSAGE_SHORT_RECORD | TYPE_FORMAT_MEDIA_TYPE; 
   NDEFMessageHdr[1] =  SHORT_RECORD_TYPE_LEN;
   NDEFMessageHdr[2] =  payloadLen;
   memcpy(&NDEFMessageHdr[3], TYPE_STR, SHORT_RECORD_TYPE_LEN);
   //Serial.print("NDEF Message: ");
   //Serial.println((char *)NDEFMessage);   
   NDEFMessage = NDEFMessageHdr;
   return (payloadLen + NDEF_SHORT_RECORD_MESSAGE_HDR_LEN);   
}
Пример #3
0
uint32_t SNEP::pushPayload(uint8_t *NDEFMessage, uint32_t length)
{
   SNEP_MESSAGE *snepMessage = (SNEP_MESSAGE *) ALLOCATE_HEADER_SPACE(NDEFMessage, SNEP_MESSAGE_HDR_LEN);
   
   snepMessage->version = 0x10;
   snepMessage->action  = 0x02;
   snepMessage->length  = MODIFY_ENDIAN(length);
  
    uint32_t result = _linkLayer->openSNEPClientLink();
    
    

    if(RESULT_OK(result)) //if connection is error-free
    {
        result =  _linkLayer->clientLinkTxData((uint8_t *)snepMessage, length + SNEP_MESSAGE_HDR_LEN);
    }
    
    

    return result;
}
Пример #4
0
// Transmits a SNEP request to the server. A link must have been established before this function is called
// Arguments: NDEFMessage is the NDEF message to be sent
//            length is the length of the NDEF message to be sent
//            request[0] is the the SNEP request type and request[1] is the acceptable length if SNEP request type is Get
// Returns the length of the received NDEF message
//why *& as argument?
uint32_t SNEP::transmitPutRequest(uint8_t *NDEFMessage, uint32_t length){
  
  uint32_t result;
  
  //Opening link to server.  
  result = _linkLayer->openLinkToServer(true);
  
  //if data-link was succesfully established continue, else abort.
  if(RESULT_OK(result)){
       
      //If a data-link was established send the request, else abort.
          SNEP_PDU *snepRequest;
          snepRequest = (SNEP_PDU *) ALLOCATE_HEADER_SPACE(NDEFMessage, SNEP_PDU_HEADER_LEN);          
          snepRequest -> version =  SNEP_SUPPORTED_VERSION;
          snepRequest -> type = SNEP_PUT_REQUEST;
          snepRequest -> length = length;
         
          //caller must check the result
          result = _linkLayer -> transmitToServer((uint8_t *)snepRequest, length + SNEP_PDU_HEADER_LEN, true);
      
  } 
  return result;  
}