* updated to nbiot driver
This commit is contained in:
parent
f65ffde252
commit
174971097f
@ -1,5 +1,5 @@
|
||||
set(ARDUINO_BASE_LIBDIR /opt/arduino-1.8.5)
|
||||
set(ARDUINO_SAMD_DIR $ENV{HOME}/.arduino15/packages/arduino/hardware/samd/1.6.16)
|
||||
set(ARDUINO_SAMD_DIR $ENV{HOME}/.arduino15/packages/arduino/hardware/samd/1.6.17)
|
||||
|
||||
set(ARDUINO_INCLUDE_DIRS
|
||||
${ARDUINO_SAMD_DIR}/cores/arduino
|
||||
|
||||
@ -17,21 +17,19 @@
|
||||
*******************************************************************************/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <Dns.h>
|
||||
#include <Ethernet.h>
|
||||
#include <IPAddress.h>
|
||||
#include <Sodaq_nbIOT.h>
|
||||
#include "connection.h"
|
||||
|
||||
|
||||
connection_t * connection_find(connection_t * connList,
|
||||
EthernetUDP * udpConnection)
|
||||
int sock)
|
||||
{
|
||||
connection_t * connP;
|
||||
|
||||
connP = connList;
|
||||
while (connP != nullptr)
|
||||
{
|
||||
if (connP->udpConnection == udpConnection)
|
||||
if (connP->sock == sock)
|
||||
{
|
||||
return connP;
|
||||
}
|
||||
@ -43,8 +41,9 @@ connection_t * connection_find(connection_t * connList,
|
||||
|
||||
|
||||
connection_t * connection_new_incoming(connection_t * connList,
|
||||
EthernetUDP * udpConnection,
|
||||
IPAddress * remoteIp,
|
||||
int sock,
|
||||
Sodaq_nbIOT * nbIOT,
|
||||
char * remoteIpStr,
|
||||
uint16_t port)
|
||||
{
|
||||
connection_t * connP;
|
||||
@ -52,32 +51,33 @@ connection_t * connection_new_incoming(connection_t * connList,
|
||||
connP = (connection_t *)malloc(sizeof(connection_t));
|
||||
if (connP != nullptr)
|
||||
{
|
||||
connP->udpConnection = udpConnection;
|
||||
connP->remoteIp = remoteIp;
|
||||
int remoteIpLen = strlen(remoteIpStr)+1;
|
||||
connP->remoteIpStr = (char*)malloc(remoteIpLen);
|
||||
// memset(connP->remoteIpStr, 0, remoteIpLen);
|
||||
strncpy(connP->remoteIpStr, remoteIpStr, remoteIpLen);
|
||||
|
||||
connP->nbIOT = nbIOT;
|
||||
connP->sock = sock;
|
||||
connP->port = port;
|
||||
connP->next = connList;
|
||||
|
||||
SerialUSB.print(F("connP->remoteIpStr: "));
|
||||
SerialUSB.println(connP->remoteIpStr);
|
||||
}
|
||||
|
||||
return connP;
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo add some sort of sanity checking to see if its possible to connect
|
||||
* @param connList
|
||||
* @param udpConnection
|
||||
* @param remoteIp
|
||||
* @param port
|
||||
* @return
|
||||
*/
|
||||
|
||||
connection_t * connection_create(connection_t * connList,
|
||||
EthernetUDP * udpConnection,
|
||||
IPAddress * remoteIp,
|
||||
int sock,
|
||||
Sodaq_nbIOT * nbIOT,
|
||||
char * remoteIpStr,
|
||||
uint16_t port)
|
||||
{
|
||||
connection_t * connP = nullptr;
|
||||
|
||||
if(*remoteIp != 0) {
|
||||
connP = connection_new_incoming(connList, udpConnection, remoteIp, port);
|
||||
if(*remoteIpStr != NULL) {
|
||||
connP = connection_new_incoming(connList, sock, nbIOT, remoteIpStr, port);
|
||||
}
|
||||
return connP;
|
||||
}
|
||||
@ -90,6 +90,7 @@ void connection_free(connection_t * connList)
|
||||
connection_t * nextP;
|
||||
|
||||
nextP = connList->next;
|
||||
free(connList->remoteIpStr);
|
||||
free(connList);
|
||||
|
||||
connList = nextP;
|
||||
@ -101,10 +102,7 @@ int connection_send(connection_t *connP,
|
||||
uint8_t * buffer,
|
||||
size_t length)
|
||||
{
|
||||
SerialOut.println(F("connection_send() start"));
|
||||
connP->udpConnection->beginPacket(*(connP->remoteIp), connP->port);
|
||||
connP->udpConnection->write(buffer, length);
|
||||
connP->udpConnection->endPacket();
|
||||
connP->nbIOT->sendSocket(connP->sock, connP->remoteIpStr, connP->port, buffer, length);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -118,13 +116,11 @@ uint8_t lwm2m_buffer_send(void * sessionH,
|
||||
|
||||
if (connP == nullptr)
|
||||
{
|
||||
// fprintf(stderr, "#> failed sending %lu bytes, missing connection\r\n", length);
|
||||
return COAP_500_INTERNAL_SERVER_ERROR ;
|
||||
}
|
||||
|
||||
if (-1 == connection_send(connP, buffer, length))
|
||||
{
|
||||
// fprintf(stderr, "#> failed sending %lu bytes\r\n", length);
|
||||
return COAP_500_INTERNAL_SERVER_ERROR ;
|
||||
}
|
||||
|
||||
|
||||
@ -23,9 +23,6 @@
|
||||
#include <sys/stat.h>
|
||||
#include <liblwm2m.h>
|
||||
|
||||
#include <EthernetUdp.h>
|
||||
#include <serialout.h>
|
||||
|
||||
#define LWM2M_STANDARD_PORT_STR "5683"
|
||||
#define LWM2M_STANDARD_PORT 5683
|
||||
#define LWM2M_DTLS_PORT_STR "5684"
|
||||
@ -36,26 +33,29 @@
|
||||
typedef struct _connection_t
|
||||
{
|
||||
struct _connection_t * next;
|
||||
EthernetUDP * udpConnection;
|
||||
IPAddress * remoteIp;
|
||||
int sock;
|
||||
Sodaq_nbIOT * nbIOT;
|
||||
char * remoteIpStr;
|
||||
uint16_t port;
|
||||
} connection_t;
|
||||
|
||||
//int create_socket(const char * portStr, int ai_family);
|
||||
|
||||
connection_t * connection_find(connection_t * connList,
|
||||
EthernetUDP * udpConnection);
|
||||
int sock);
|
||||
connection_t * connection_new_incoming(connection_t * connList,
|
||||
EthernetUDP * udpConnection,
|
||||
IPAddress * remoteIp,
|
||||
int sock,
|
||||
Sodaq_nbIOT * nbIOT,
|
||||
char * remoteIp,
|
||||
uint16_t port);
|
||||
connection_t * connection_create(connection_t * connList,
|
||||
EthernetUDP * udpConnection,
|
||||
IPAddress * remoteIp,
|
||||
int sock,
|
||||
Sodaq_nbIOT * nbIOT,
|
||||
char * remoteIp,
|
||||
uint16_t port);
|
||||
|
||||
void connection_free(connection_t * connList);
|
||||
|
||||
int connection_send(connection_t *connP, uint8_t * buffer, size_t length);
|
||||
int connection_send(connection_t *connP, char * buffer, size_t length);
|
||||
|
||||
#endif
|
||||
|
||||
@ -11,7 +11,7 @@ if(DTLS)
|
||||
set(SHARED_SOURCES
|
||||
${SHARED_SOURCES}
|
||||
${TINYDTLS_SOURCES}
|
||||
${SHARED_SOURCES_DIR}/dtlsconnection.c)
|
||||
${SHARED_SOURCES_DIR}/dtlsconnection.cpp)
|
||||
|
||||
set(SHARED_INCLUDE_DIRS
|
||||
${SHARED_SOURCES_DIR}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user