fork allowing use of the latest official mbed networking library

Dependents:   SNMPv1UDPExmaple

Fork of Agentbed by Suga koubou

Revision:
3:81f25e337afc
Parent:
2:9e4369522e03
--- a/Agentbed.cpp	Fri Jan 28 09:17:03 2011 +0000
+++ b/Agentbed.cpp	Tue Apr 02 19:53:28 2013 +0000
@@ -28,7 +28,7 @@
 
 #include "Agentbed.h"
 
-SNMP_API_STAT_CODES AgentbedClass::begin(EthernetNetIf *eth)
+SNMP_API_STAT_CODES SNMP::init()
 {
     // set community names
     _getCommName = "public";
@@ -38,15 +38,10 @@
     _setSize = strlen(_setCommName);
     _getSize = strlen(_getCommName);
     //
-    // init UDP socket
-    udpsock = new UDPSocket;
-    udpsock->setOnEvent(this, &AgentbedClass::listen);
-    udpsock->bind(Host(eth->getIp(), SNMP_DEFAULT_PORT));
-    //
     return SNMP_API_STAT_SUCCESS;
 }
 
-SNMP_API_STAT_CODES AgentbedClass::begin(char *getCommName, char *setCommName, uint16_t port, EthernetNetIf *eth)
+SNMP_API_STAT_CODES SNMP::init(char *getCommName, char *setCommName)
 {
     // set community name set/get sizes
     _setSize = strlen(setCommName);
@@ -61,29 +56,11 @@
     _getCommName = getCommName;
     _setCommName = setCommName;
     //
-    // validate session port number
-    if ( port == NULL || port == 0 ) port = SNMP_DEFAULT_PORT;
-    //
-    // init UDP socket
-    udpsock = new UDPSocket;
-    udpsock->setOnEvent(this, &AgentbedClass::listen);
-    udpsock->bind(Host(eth->getIp(), port));
-    //
+    
     return SNMP_API_STAT_SUCCESS;
 }
 
-void AgentbedClass::listen (UDPSocketEvent e)
-{
-    // if bytes available in receive buffer
-    // and pointer to a function (delegate function)
-    // isn't null, trigger the function
-    if (e == UDPSOCKET_READABLE && _callback != NULL ) {
-        (*_callback)();
-    }
-}
-
-
-SNMP_API_STAT_CODES AgentbedClass::requestPdu(SNMP_PDU *pdu)
+SNMP_API_STAT_CODES SNMP::toPdu(SNMP_PDU *pdu,char *_packet,uint16_t _packetSize)
 {
     char *community;
     // sequence length
@@ -102,15 +79,14 @@
     byte obiLen, obiEnd;
     byte __attribute__((__unused__)) valTyp, valLen, valEnd;
     byte i;
-    Host dest;
     //
     // set packet packet size (skip UDP header)
 //    _packetSize = Udp.available()-8;
     //
-    memset(_packet, 0, SNMP_MAX_PACKET_LEN);
+ //   memset(_packet, 0, SNMP_MAX_PACKET_LEN);
     //
     // get UDP packet
-    _packetSize = udpsock->recvfrom((char*)_packet, SNMP_MAX_PACKET_LEN, &_dst);
+ ///  _packetSize = udpsock->recvfrom((char*)_packet, SNMP_MAX_PACKET_LEN, &_dst);
     //
     // validate packet
     if ( _packetSize != 0 && _packetSize > SNMP_MAX_PACKET_LEN ) {
@@ -298,9 +274,10 @@
     return SNMP_API_STAT_SUCCESS;
 }
 
-SNMP_API_STAT_CODES AgentbedClass::responsePdu(SNMP_PDU *pdu)
+uint16_t SNMP::fromPdu(SNMP_PDU *pdu,char *_packet)
 {
     int32_u u;
+    uint16_t _packetSize;
     byte i;
     //
     // Length of entire SNMP packet
@@ -399,21 +376,16 @@
         _packet[_packetPos++] = pdu->VALUE.data[i];
     }
     //
-    udpsock->sendto((char*)_packet, _packetPos, &_dst);
     //
     //SNMP_FREE(_packet);
     //
-    return SNMP_API_STAT_SUCCESS;
+    return _packetSize;
 }
 
 
 
-void AgentbedClass::onPduReceive(onPduReceiveCallback pduReceived)
-{
-    _callback = pduReceived;
-}
 
-void AgentbedClass::freePdu(SNMP_PDU *pdu)
+void SNMP::freePdu(SNMP_PDU *pdu)
 {
     //SNMP_FREE(pdu->OID.oid);
     //SNMP_FREE(pdu->VALUE.value);
@@ -423,4 +395,4 @@
 }
 
 // Create one global object
-//AgentbedClass Agentbed;
+//SNMP Agentbed;