Exemplo n.º 1
0
void CoapRequest::get()
{
    CoapPDU pdu;
    pdu.setCode(CoapPDU::Code::Get);
    pdu.setType(CoapPDU::Type::Confirmable);
    pdu.addOption(CoapPDU::OptionType::UriPath, "/");
    CoapExchange::send(pdu);
}
Exemplo n.º 2
0
void testOptionInsertion(void) {
	CoapPDU *pdu = NULL;
	uint8_t *buffer[64];
	
	for(int constructorType=0; constructorType<4; constructorType++) {
		DBG("New iteration: constructorType: %d",constructorType);
		switch(constructorType) {
			case 0:
				pdu = new CoapPDU((uint8_t*)buffer,64,0);
			break;
			case 1:
				pdu->reset();
			break;
			case 2:
				pdu = new CoapPDU();
			break;
			case 3:
				pdu->reset();
			break;
		}
		pdu->setVersion(1);
		pdu->setType(CoapPDU::COAP_CONFIRMABLE);
		pdu->setCode(CoapPDU::COAP_CHANGED);
		CU_ASSERT_NSTRING_EQUAL_FATAL(optionInsertionTestA,pdu->getPDUPointer(),pdu->getPDULength());
		pdu->addOption(11,3,(uint8_t*)"\x55\x55\x55");
		CU_ASSERT_NSTRING_EQUAL_FATAL(optionInsertionTestB,pdu->getPDUPointer(),pdu->getPDULength());
		pdu->addOption(11,3,(uint8_t*)"\xff\xff\xff");
		CU_ASSERT_NSTRING_EQUAL_FATAL(optionInsertionTestC,pdu->getPDUPointer(),pdu->getPDULength());
		pdu->addOption(7,3,(uint8_t*)"\xf7\xf7\xf7");
		CU_ASSERT_NSTRING_EQUAL_FATAL(optionInsertionTestD,pdu->getPDUPointer(),pdu->getPDULength());
		pdu->addOption(200,3,(uint8_t*)"\x01\x02\x03");
		CU_ASSERT_NSTRING_EQUAL_FATAL(optionInsertionTestE,pdu->getPDUPointer(),pdu->getPDULength());
		pdu->addOption(190,3,(uint8_t*)"\x03\x02\x01");
		CU_ASSERT_NSTRING_EQUAL_FATAL(optionInsertionTestF,pdu->getPDUPointer(),pdu->getPDULength());
		pdu->addOption(300,3,(uint8_t*)"\x01\x02\x03");
		CU_ASSERT_NSTRING_EQUAL_FATAL(optionInsertionTestG,pdu->getPDUPointer(),pdu->getPDULength());
		pdu->addOption(195,3,(uint8_t*)"\x03\x02\x01");
		CU_ASSERT_NSTRING_EQUAL_FATAL(optionInsertionTestH,pdu->getPDUPointer(),pdu->getPDULength());
		pdu->addOption(1950,3,(uint8_t*)"\x03\x02\x01");
		CU_ASSERT_NSTRING_EQUAL_FATAL(optionInsertionTestI,pdu->getPDUPointer(),pdu->getPDULength());
		if(constructorType%2) {
			DBG("%d DELETE",constructorType);
			delete pdu;
		}
	}
}