Skip to content

Commit

Permalink
Updated application logic and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
edward62740 committed Jun 15, 2023
1 parent 6cee562 commit 1136094
Show file tree
Hide file tree
Showing 25 changed files with 57,736 additions and 57,310 deletions.
7 changes: 5 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# Auto detect text files and perform LF normalization
* text=auto
/Code/co2sn/gecko_sdk_4.3.0/* linguist-vendored
/Code/co2sn/"GNU[[:space]]ARM[[:space]]v10.2.1[[:space]]-[[:space]]Default"/* linguist-vendored
/Code/co2sn/autogen/* linguist-vendored
/Code/co2sn/config/* linguist-vendored
/Code/co2sn/gecko_sdk_4.3.0/* linguist-vendored
2 changes: 1 addition & 1 deletion Code/co2sn/.projectlinkstore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"data":[{"hit":9,"alias":"Software Components","type":"NAVIGATION","data":"softwarecomponents"},{"hit":8,"alias":"app_thread.cpp","type":"FILE","data":"C:/Users/Workstation/Documents/GitHub/ot-CO2/Code/co2sn/app_thread.cpp"},{"hit":9,"alias":"Stack (MTD)","type":"COMPONENT","data":"{\"componentId\":\"ot_stack_mtd\"}"},{"hit":7,"alias":"main.cpp","type":"FILE","data":"C:/Users/Workstation/Documents/GitHub/ot-CO2/Code/co2sn/main.cpp"},{"hit":6,"alias":"app_main.cpp","type":"FILE","data":"C:/Users/Workstation/Documents/GitHub/ot-CO2/Code/co2sn/app_main.cpp"},{"hit":3,"alias":"Configuration","type":"COMPONENT","data":"{\"componentId\":\"mbedtls_config\"}"},{"hit":2,"alias":"app_coap.cpp","type":"FILE","data":"C:/Users/Workstation/Documents/GitHub/ot-CO2/Code/co2sn/app_coap.cpp"},{"hit":0,"alias":"README.md","type":"FILE","data":"C:/Users/Workstation/Documents/GitHub/ot-CO2/Code/co2sn/README.md"},{"hit":0,"alias":"Pin Tool","type":"TOOL","data":"pintool"},{"hit":0,"alias":"Memory Editor","type":"TOOL","data":"memoryeditor"},{"hit":0,"alias":"docs.silabs.com","type":"EXTERNAL_URL","data":"https://docs.silabs.com/"},{"hit":0,"alias":"Simple Button (btn0)","type":"COMPONENT","data":"{\"componentId\":\"simple_button\",\"instanceName\":\"btn0\"}"},{"hit":0,"alias":"Simple Button (btn1)","type":"COMPONENT","data":"{\"componentId\":\"simple_button\",\"instanceName\":\"btn1\"}"}]}
{"data":[{"hit":116,"alias":"app_dns.cpp","type":"FILE","data":"C:/Users/Workstation/Documents/GitHub/ot-CO2/Code/co2sn/app_dns.cpp"},{"hit":39,"alias":"app_main.cpp","type":"FILE","data":"C:/Users/Workstation/Documents/GitHub/ot-CO2/Code/co2sn/app_main.cpp"},{"hit":14,"alias":"app_thread.cpp","type":"FILE","data":"C:/Users/Workstation/Documents/GitHub/ot-CO2/Code/co2sn/app_thread.cpp"},{"hit":13,"alias":"main.cpp","type":"FILE","data":"C:/Users/Workstation/Documents/GitHub/ot-CO2/Code/co2sn/main.cpp"},{"hit":11,"alias":"Software Components","type":"NAVIGATION","data":"softwarecomponents"},{"hit":13,"alias":"Stack (MTD)","type":"COMPONENT","data":"{\"componentId\":\"ot_stack_mtd\"}"},{"hit":3,"alias":"Configuration","type":"COMPONENT","data":"{\"componentId\":\"mbedtls_config\"}"},{"hit":2,"alias":"app_coap.cpp","type":"FILE","data":"C:/Users/Workstation/Documents/GitHub/ot-CO2/Code/co2sn/app_coap.cpp"},{"hit":2,"alias":"UARTDRV USART (vcom)","type":"COMPONENT","data":"{\"componentId\":\"uartdrv_usart\",\"instanceName\":\"vcom\"}"},{"hit":0,"alias":"README.md","type":"FILE","data":"C:/Users/Workstation/Documents/GitHub/ot-CO2/Code/co2sn/README.md"},{"hit":0,"alias":"Pin Tool","type":"TOOL","data":"pintool"},{"hit":0,"alias":"Memory Editor","type":"TOOL","data":"memoryeditor"},{"hit":0,"alias":"docs.silabs.com","type":"EXTERNAL_URL","data":"https://docs.silabs.com/"},{"hit":0,"alias":"Simple Button (btn0)","type":"COMPONENT","data":"{\"componentId\":\"simple_button\",\"instanceName\":\"btn0\"}"},{"hit":0,"alias":"Simple Button (btn1)","type":"COMPONENT","data":"{\"componentId\":\"simple_button\",\"instanceName\":\"btn1\"}"},{"hit":1,"alias":"NVM3 Default Config","type":"COMPONENT","data":"{\"componentId\":\"nvm3_default_config\"}"}]}
2 changes: 2 additions & 0 deletions Code/co2sn/.uceditor/.co2sn.nvm3_default_config.cedit
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
C:\Users\Workstation\Documents\GitHub\ot-CO2\Code\co2sn\co2sn.slcp
nvm3_default_config
3 changes: 3 additions & 0 deletions Code/co2sn/.uceditor/.co2sn.uartdrv_usartvcom.cedit
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
C:\Users\Workstation\Documents\GitHub\ot-CO2\Code\co2sn\co2sn.slcp
uartdrv_usart
vcom
Binary file modified Code/co2sn/GNU ARM v10.2.1 - Default/co2sn.axf
Binary file not shown.
Binary file modified Code/co2sn/GNU ARM v10.2.1 - Default/co2sn.bin
Binary file not shown.
44,532 changes: 22,257 additions & 22,275 deletions Code/co2sn/GNU ARM v10.2.1 - Default/co2sn.hex

Large diffs are not rendered by default.

25,055 changes: 12,625 additions & 12,430 deletions Code/co2sn/GNU ARM v10.2.1 - Default/co2sn.map

Large diffs are not rendered by default.

44,532 changes: 22,257 additions & 22,275 deletions Code/co2sn/GNU ARM v10.2.1 - Default/co2sn.s37

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Code/co2sn/app_coap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ void appCoapCheckConnection(void)
{
otThreadBecomeDetached(otGetInstance());
//otInstanceErasePersistentInfo();
sleepyInit();
//sleepyInit();
setNetworkConfiguration();
otIp6SetEnabled(otGetInstance(), true);
otThreadSetEnabled(otGetInstance(), true);
Expand Down
242 changes: 175 additions & 67 deletions Code/co2sn/app_dns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,68 @@
#include "stdio.h"
#include "string.h"

static otDnsQueryConfig config;
#define APP_DNS_DEBUG_PRINT

dns::dns(otInstance* (*getotInst)(void), uint8_t max_dns, uint8_t max_addr) {
getInst = getotInst;
browseRespInfo = new otDnsServiceInfo[max_dns];
for (uint8_t i = 0; i < max_dns; i++) {
browseRespInfo[i].mHostNameBuffer = new char[OT_DNS_MAX_NAME_SIZE]();
browseRespInfo[i].mHostNameBufferSize = OT_DNS_MAX_NAME_SIZE;

browseRespInfo[i].mTxtData =
new uint8_t[OPENTHREAD_CONFIG_CLI_TXT_RECORD_MAX_SIZE]();
browseRespInfo[i].mTxtDataSize =
OPENTHREAD_CONFIG_CLI_TXT_RECORD_MAX_SIZE;

}
serviceRespInfo.mHostNameBuffer = new char[OT_DNS_MAX_NAME_SIZE]();
serviceRespInfo.mHostNameBufferSize = OT_DNS_MAX_NAME_SIZE;

serviceRespInfo.mTxtData =
new uint8_t[OPENTHREAD_CONFIG_CLI_TXT_RECORD_MAX_SIZE]();
serviceRespInfo.mTxtDataSize = OPENTHREAD_CONFIG_CLI_TXT_RECORD_MAX_SIZE;

browseRespInfoCount = max_dns;
addrRespInfo = new otIp6Address[max_addr];
addrRespInfoCount = max_addr;
}

static void outputPrintDnsTextData(const uint8_t *aTxtData,
uint16_t aTxtDataLength) {
otDnsTxtEntry entry;
otDnsTxtEntryIterator iterator;
bool isFirst = true;

otDnsInitTxtEntryIterator(&iterator, aTxtData, aTxtDataLength);

while (otDnsGetNextTxtEntry(&iterator, &entry) == OT_ERROR_NONE) {
if (!isFirst) {
otCliOutputFormat(", ");
}

char label[OT_DNS_MAX_LABEL_SIZE];
if (entry.mKey == nullptr) {
// A null `mKey` indicates that the key in the entry is
// longer than the recommended max key length, so the entry
// could not be parsed. In this case, the whole entry is
// returned encoded in `mValue`.

static void outputPrintDnsInfo(uint8_t aIndentSize,
otCliOutputFormat("[");
otCliOutputBytes(entry.mValue, entry.mValueLength);
otCliOutputFormat("]");
} else {
otCliOutputFormat("%s", entry.mKey);

if (entry.mValue != nullptr) {
otCliOutputFormat("=");
otCliOutputBytes(entry.mValue, entry.mValueLength);
}
}
isFirst = false;
}
}

static void outputPrintDnsServiceInfo(uint8_t aIndentSize,
const otDnsServiceInfo &aServiceInfo) {
otCliOutputFormat("Port:%d, Priority:%d, Weight:%d, TTL:%lu\n",
aServiceInfo.mPort, aServiceInfo.mPriority, aServiceInfo.mWeight,
Expand All @@ -38,41 +95,11 @@ static void outputPrintDnsInfo(uint8_t aIndentSize,

if (!aServiceInfo.mTxtDataTruncated) {

otDnsTxtEntry entry;
otDnsTxtEntryIterator iterator;
bool isFirst = true;

otDnsInitTxtEntryIterator(&iterator, aServiceInfo.mTxtData,
aServiceInfo.mTxtDataSize);

otCliOutputFormat("[");

while (otDnsGetNextTxtEntry(&iterator, &entry) == OT_ERROR_NONE) {
if (!isFirst) {
otCliOutputFormat(", ");
}

if (entry.mKey == nullptr) {
// A null `mKey` indicates that the key in the entry is
// longer than the recommended max key length, so the entry
// could not be parsed. In this case, the whole entry is
// returned encoded in `mValue`.

otCliOutputFormat("[");
otCliOutputBytes(entry.mValue, entry.mValueLength);
otCliOutputFormat("]");
} else {
otCliOutputFormat("%s", entry.mKey);

if (entry.mValue != nullptr) {
otCliOutputFormat("=");
otCliOutputBytes(entry.mValue, entry.mValueLength);
}
}
isFirst = false;
}

outputPrintDnsTextData(aServiceInfo.mTxtData,
aServiceInfo.mTxtDataSize);
otCliOutputFormat("]");
otCliOutputBytes(aServiceInfo.mTxtData, aServiceInfo.mTxtDataSize);
} else {
otCliOutputFormat("[");
otCliOutputBytes(aServiceInfo.mTxtData, aServiceInfo.mTxtDataSize);
Expand All @@ -88,28 +115,116 @@ void dns::browseRespHandler(otError aError,
uint16_t index = 0;

while (otDnsBrowseResponseGetServiceInstance(aResponse, index, label,
sizeof(label)) == OT_ERROR_NONE) {
sizeof(label)) == OT_ERROR_NONE && index < browseRespInfoCount) {

if (otDnsBrowseResponseGetServiceInfo(aResponse, label,
&browseRespInfo[index]) == OT_ERROR_NONE) {

#define APP_DNS_DEBUG_PRINT
#ifdef APP_DNS_DEBUG_PRINT
outputPrintDnsInfo(4, browseRespInfo[index]);
outputPrintDnsServiceInfo(4, browseRespInfo[index]);
#endif // APP_DNS_DEBUG_PRINT
}

index++;
}
if (index >= browseRespInfoCount)
browseRespInfoOverflow = true;
else
browseRespInfoOverflow = false;
browseRespInfoValid = index;
browseRespInfoReady = true;
}

}

void dns::resolveHostRespHandler(otError aError,
const otDnsServiceResponse *aResponse, void *aContext) {

if (aError == OT_ERROR_NONE) {

if (otDnsServiceResponseGetServiceInfo(aResponse, &serviceRespInfo)
== OT_ERROR_NONE) {

#ifdef APP_DNS_DEBUG_PRINT
outputPrintDnsServiceInfo(0, serviceRespInfo);
#endif // APP_DNS_DEBUG_PRINT
}
}
}

void dns::resolveIpRespHandler(otError aError,
const otDnsAddressResponse *aResponse, void *aContext) {

if (aError == OT_ERROR_NONE) {
uint16_t index = 0;
uint32_t ttl;
while (otDnsAddressResponseGetAddress(aResponse, index,
&addrRespInfo[index], &ttl) == OT_ERROR_NONE
&& index < addrRespInfoCount) {

#ifdef APP_DNS_DEBUG_PRINT
char string[OT_IP6_ADDRESS_STRING_SIZE];
otIp6AddressToString(&addrRespInfo[index], string, sizeof(string));

otCliOutputFormat("%s\n ", string);
otCliOutputFormat(" TTL:%lu ", (ttl));
outputPrintDnsServiceInfo(0, serviceRespInfo);
#endif // APP_DNS_DEBUG_PRINT

index++;
}
if (index >= addrRespInfoCount)
addrRespInfoOverflow = true;
else
addrRespInfoOverflow = false;
addrRespInfoValid = index;
addrRespInfoReady = true;
}

}

otError dns::browse(char *name) {
otInstance *inst = getInst();
if (inst == NULL)
return OT_ERROR_INVALID_STATE;
browseRespInfoReady = false;
if (otDnsClientBrowse(inst, name, &dns::browseRespHandlerWrapper, this,
&config) != OT_ERROR_NONE)
return OT_ERROR_NO_BUFS;
return OT_ERROR_PENDING;

}

otError dns::resolveHost(char *label, char *name) {
otInstance *inst = getInst();
if (inst == NULL)
return OT_ERROR_INVALID_STATE;
browseRespInfoReady = false;
if (otDnsClientResolveService(inst, label, name,
&dns::resolveHostRespHandlerWrapper, this, &config)
!= OT_ERROR_NONE)
return OT_ERROR_NO_BUFS;
return OT_ERROR_PENDING;

}

otError dns::resolve4(char *name) {
otInstance *inst = getInst();
if (inst == NULL)
return OT_ERROR_INVALID_STATE;
browseRespInfoReady = false;
if (otDnsClientResolveIp4Address(inst, name,
&dns::resolveIpRespHandlerWrapper, this, &config) != OT_ERROR_NONE)
return OT_ERROR_NO_BUFS;
return OT_ERROR_PENDING;

}
otError dns::resolve6(char *name) {
otInstance *inst = getInst();
if (inst == NULL)
return OT_ERROR_INVALID_STATE;
browseRespInfoReady = false;
if (otDnsClientBrowse(otGetInstance(), name, &dns::browseRespHandlerWrapper,
if (otDnsClientResolveAddress(inst, name, &dns::resolveIpRespHandlerWrapper,
this, &config) != OT_ERROR_NONE)
return OT_ERROR_NO_BUFS;
return OT_ERROR_PENDING;
Expand All @@ -125,35 +240,28 @@ bool dns::browseResultReady(otDnsServiceInfo **info, uint8_t *num) {
return true;
}

#ifdef APP_DNS_RESOLVE_IMPLEMENTED
void dns::resolveRespHandler(otError aError,
const otDnsAddressResponse *aResponse, void *aContext) {
char hostName[OT_DNS_MAX_NAME_SIZE];
otIp6Address address;
uint32_t ttl;

// IgnoreError(otDnsAddressResponseGetHostName(aResponse, hostName, sizeof(hostName)));

//OutputFormat("DNS response for %s - ", hostName);

if (aError == OT_ERROR_NONE) {
uint16_t index = 0;

while (otDnsAddressResponseGetAddress(aResponse, index, &address, &ttl)
== OT_ERROR_NONE) {
// OutputIp6Address(address);
// OutputFormat(" TTL:%lu ", ToUlong(ttl));
index++;
}
}

bool dns::resolveHostResultReady(otDnsServiceInfo *info) {
if (!serviceRespInfoReady)
return false;
info = browseRespInfo;
serviceRespInfoReady = false;
return true;
}

otError dns::resolveHost(char *host) {
bool dns::resolveIpResultReady(otIp6Address **info, uint8_t *num) {
if (!addrRespInfoReady)
return false;
*info = addrRespInfo;
*num = addrRespInfoValid;
addrRespInfoReady = false;
return true;
}

//assert(otDnsClientResolveAddress(otGetInstance(), host, &(this->resolveRespHandler),
// NULL, &config) == OT_ERROR_NONE);
return OT_ERROR_PENDING;
bool dns::browseResultIsOverflow(void) {
return addrRespInfoOverflow;
}

bool dns::resolveIpResultReadyIsOverflow(void) {
return browseRespInfoOverflow;
}
#endif // APP_DNS_RESOLVE_IMPLEMENTED

Loading

0 comments on commit 1136094

Please sign in to comment.