Ejemplo n.º 1
0
void pppDialing(void const*) {
    HuaweiUSBCDMAModem modem(NC, true);

    NetLED_ticker.attach(&toggle_NetLed, 3);	//net is disconnect
    while (true) {
        osEvent evt = redial.get();
        char *ch;
        if (evt.status == osEventMessage) {
            ch = (char *)evt.value.p;
            INFO("Get redial osEventMessage value id is %d\n", *ch);
        }

        if (*ch == 1) {
            while(pppRedialingSuccessFlag == false) {
                // connect to redial cellular network
                if (modem.connect(MODEM_APN, MODEM_USERNAME, MODEM_PASSWORD) != OK) {
                    INFO("Could connect the mobile gprs server, please check the Huawei modem or sim card.");
                    Thread::wait(5000);
                }
            }
        } else {
            // connect to cellular network
            if (modem.connect(MODEM_APN, MODEM_USERNAME, MODEM_PASSWORD) != OK) {
                INFO("Could connect the mobile gprs server, please check the Huawei modem or sim card.");
            } else {
                pppDialingSuccessFlag = 1;
            }
        }
    }
}
Ejemplo n.º 2
0
bool pppDialing(void) {
	INFO("Start the pppDialing thread,Thread ID is %d.\n", (int)Thread::gettid());
    HuaweiUSBCDMAModem modem(NC, true);

	Thread::wait(1000);
	// connect to cellular network
    int ret = modem.connect(MODEM_APN, MODEM_USERNAME, MODEM_PASSWORD);
	if(ret)
    {
		ERR("PPP dialing failure, Could not connect!");
		return false;
    }

	return true;
}
Ejemplo n.º 3
0
int main() {
    DBG_INIT();
    DBG_SET_SPEED(115200);
    DBG_SET_NEWLINE("\r\n");

    // structure for getting address of incoming packets
    sockaddr_in fromAddr;
    socklen_t fromAddrLen = sizeof(struct sockaddr_in);
    memset(&fromAddr,0x00,fromAddrLen);
    
    // connect to cellular network
	HuaweiUSBCDMAModem modem(NC, true);
    modem.connect(APN,APN_USERNAME,APN_PASSWORD);

    // setup socket to remote server
    int sockfd = NULL;
//    if(!connectToSocketUDP("109.74.199.96", 5683, &sockfd)) {
    if(!connectToSocketUDP("123.57.235.186", 5683, &sockfd)) {
       DBG("Error connecting to socket");
       fail(1);
    }
    DBG("\"Connected\" to UDP socket");

    // construct CoAP packet
    CoapPDU *pdu = new CoapPDU();
    pdu->setVersion(1);
    pdu->setType(CoapPDU::COAP_CONFIRMABLE);
    pdu->setCode(CoapPDU::COAP_POST);
    pdu->setToken((uint8_t*)"\3\2\1\1",4);
    pdu->setURI((char*)"register",8);

    #define BUFLEN 128
    short messageID = 0;
    char buffer[BUFLEN];

	MbedJSONValue json;
	json["devType"] = "T1";
	json["firmwareNo"] = "F1";
	json["softVerNo"] = "S4";
	json["userDevType"] = "UT1";
	json["userSoftVerNo"] = "US2";
	json["mobile"] = "15811112222";
	json["userHardVerNo"] = "UH1";
	json["hardVerNo"] = "H1";
	json["devUniqId"] = "q1w2e3r4t5";

	string jsonStr = json.serialize();
	printf("serialized content = %s\r\n" ,  jsonStr.c_str());

	char *payload = (char *)jsonStr.c_str();
	pdu->setPayload((uint8_t*)payload,strlen(payload));

	int num = 3;
    // send packets to server
    while(num--) {
        // set PDU parameters
        pdu->setMessageID(messageID++);
    
        // send packet 
        int ret = send(sockfd,pdu->getPDUPointer(),pdu->getPDULength(),0);
        if(ret!=pdu->getPDULength()) {
            INFO("Error sending packet.");
            perror(NULL);
            fail(2);
        }
        INFO("Packet sent");

        // receive response
        ret = recvfrom(sockfd,&buffer,BUFLEN,0,(struct sockaddr *)&fromAddr,&fromAddrLen);
        if(ret==-1) {
            INFO("Error receiving data");
            fail(3);
        }
        INFO("Received %d bytes from %s:%d",ret,inet_ntoa(fromAddr.sin_addr),ntohs(fromAddr.sin_port));

        if(ret>BUFLEN) {
            INFO("PDU too large to fit in pre-allocated buffer");
            continue;
        }

		// reuse the below coap object
		CoapPDU *recvPDU = new CoapPDU((uint8_t*)buffer,BUFLEN,BUFLEN);
        // validate packet
        recvPDU->setPDULength(ret);
        if(recvPDU->validate()!=1) {
            INFO("Malformed CoAP packet");
            fail(4);
        }
        INFO("Valid CoAP PDU received");
        recvPDU->printHuman();
        
        Thread::wait(5000);
    }
	
    modem.disconnect();
    return true;
}
void CDStarRepeaterConfigModemSet::onConfigure(wxCommandEvent& event)
{
	int n = m_type->GetSelection();
	if (n == wxNOT_FOUND)
		return;

	wxString type = m_type->GetStringSelection();

	if (type.IsSameAs(wxT("DVAP"))) {
		wxString port;
		unsigned int frequency;
		int power, squelch;
		m_config->getDVAP(port, frequency, power, squelch);
		CDStarRepeaterConfigDVAPSet modem(this, -1, port, frequency, power, squelch);
		if (modem.ShowModal() == wxID_OK) {
			if (modem.Validate()) {
				port      = modem.getPort();
				frequency = modem.getFrequency();
				power     = modem.getPower();
				squelch   = modem.getSquelch();
				m_config->setDVAP(port, frequency, power, squelch);
			}
		}
	} else if (type.IsSameAs(wxT("GMSK Modem"))) {
		USB_INTERFACE modemType;
		unsigned int modemAddress;
		m_config->getGMSK(modemType, modemAddress);
		CDStarRepeaterConfigGMSKSet modem(this, -1, modemType, modemAddress);
		if (modem.ShowModal() == wxID_OK) {
			if (modem.Validate()) {
				modemType    = modem.getType();
				modemAddress = modem.getAddress();
				m_config->setGMSK(modemType, modemAddress);
			}
		}
	} else if (type.IsSameAs(wxT("DV-RPTR V1"))) {
		wxString port;
		bool txInvert, rxInvert, channel;
		unsigned int modLevel, txDelay;
		m_config->getDVRPTR1(port, rxInvert, txInvert, channel, modLevel, txDelay);
		CDStarRepeaterConfigDVRPTR1Set modem(this, -1, port, rxInvert, txInvert, channel, modLevel, txDelay);
		if (modem.ShowModal() == wxID_OK) {
			if (modem.Validate()) {
				port     = modem.getPort();
				rxInvert = modem.getRXInvert();
				txInvert = modem.getTXInvert();
				channel  = modem.getChannel();
				modLevel = modem.getModLevel();
				txDelay  = modem.getTXDelay();
				m_config->setDVRPTR1(port, rxInvert, txInvert, channel, modLevel, txDelay);
			}
		}
	} else if (type.IsSameAs(wxT("DV-RPTR V2"))) {
		CONNECTION_TYPE connType;
		wxString usbPort, address;
		bool txInvert;
		unsigned int port, modLevel, txDelay;
		m_config->getDVRPTR2(connType, usbPort, address, port, txInvert, modLevel, txDelay);
		CDStarRepeaterConfigDVRPTR2Set modem(this, -1, connType, usbPort, address, port, txInvert, modLevel, txDelay);
		if (modem.ShowModal() == wxID_OK) {
			if (modem.Validate()) {
				connType = modem.getConnectionType();
				usbPort  = modem.getUSBPort();
				address  = modem.getAddress();
				port     = modem.getPort();
				txInvert = modem.getTXInvert();
				modLevel = modem.getModLevel();
				txDelay  = modem.getTXDelay();
				m_config->setDVRPTR2(connType, usbPort, address, port, txInvert, modLevel, txDelay);
			}
		}
	} else if (type.IsSameAs(wxT("DV-RPTR V3"))) {
		CONNECTION_TYPE connType;
		wxString usbPort, address;
		bool txInvert;
		unsigned int port, modLevel, txDelay;
		m_config->getDVRPTR3(connType, usbPort, address, port, txInvert, modLevel, txDelay);
		CDStarRepeaterConfigDVRPTR3Set modem(this, -1, connType, usbPort, address, port, txInvert, modLevel, txDelay);
		if (modem.ShowModal() == wxID_OK) {
			if (modem.Validate()) {
				connType = modem.getConnectionType();
				usbPort  = modem.getUSBPort();
				address  = modem.getAddress();
				port     = modem.getPort();
				txInvert = modem.getTXInvert();
				modLevel = modem.getModLevel();
				txDelay  = modem.getTXDelay();
				m_config->setDVRPTR3(connType, usbPort, address, port, txInvert, modLevel, txDelay);
			}
		}
	} else if (type.IsSameAs(wxT("DVMEGA"))) {
		wxString port;
		DVMEGA_VARIANT variant;
		bool txInvert, rxInvert;
		unsigned int txDelay, frequency;
		m_config->getDVMEGA(port, variant, rxInvert, txInvert, txDelay, frequency);
		CDStarRepeaterConfigDVMegaSet modem(this, -1, port, variant, rxInvert, txInvert, txDelay, frequency);
		if (modem.ShowModal() == wxID_OK) {
			if (modem.Validate()) {
				port      = modem.getPort();
				variant   = modem.getVariant();
				rxInvert  = modem.getRXInvert();
				txInvert  = modem.getTXInvert();
				txDelay   = modem.getTXDelay();
				frequency = modem.getFrequency();
				m_config->setDVMEGA(port, variant, rxInvert, txInvert, txDelay, frequency);
			}
		}
	} else if (type.IsSameAs(wxT("Sound Card"))) {
		wxString rxDevice, txDevice;
		bool txInvert, rxInvert;
		wxFloat32 rxLevel, txLevel;
		unsigned int txDelay;
		m_config->getSoundCard(rxDevice, txDevice, rxInvert, txInvert, rxLevel, txLevel, txDelay);
		CDStarRepeaterConfigSoundCardSet modem(this, -1, rxDevice, txDevice, rxInvert, txInvert, rxLevel, txLevel, txDelay);
		if (modem.ShowModal() == wxID_OK) {
			if (modem.Validate()) {
				rxDevice = modem.getRXDevice();
				txDevice = modem.getTXDevice();
				rxInvert = modem.getRXInvert();
				txInvert = modem.getTXInvert();
				rxLevel  = modem.getRXLevel();
				txLevel  = modem.getTXLevel();
				txDelay  = modem.getTXDelay();
				m_config->setSoundCard(rxDevice, txDevice, rxInvert, txInvert, rxLevel, txLevel, txDelay);
			}
		}
	} else if (type.IsSameAs(wxT("Split"))) {
		wxString localAddress, transmitter1Address, transmitter2Address, transmitter3Address, receiver1Address, receiver2Address, receiver3Address;
		unsigned int localPort, transmitter1Port, transmitter2Port, transmitter3Port, receiver1Port, receiver2Port, receiver3Port, timeout;
		m_config->getSplit(localAddress, localPort, transmitter1Address, transmitter1Port, transmitter2Address, transmitter2Port, transmitter3Address, transmitter3Port, receiver1Address, receiver1Port, receiver2Address, receiver2Port, receiver3Address, receiver3Port, timeout);
		CDStarRepeaterConfigSplitSet modem(this, -1, localAddress, localPort, transmitter1Address, transmitter1Port, transmitter2Address, transmitter2Port, transmitter3Address, transmitter3Port, receiver1Address, receiver1Port, receiver2Address, receiver2Port, receiver3Address, receiver3Port, timeout);
		if (modem.ShowModal() == wxID_OK) {
			if (modem.Validate()) {
				localAddress        = modem.getLocalAddress();
				localPort           = modem.getLocalPort();
				transmitter1Address = modem.getTransmitter1Address();
				transmitter1Port    = modem.getTransmitter1Port();
				transmitter2Address = modem.getTransmitter2Address();
				transmitter2Port    = modem.getTransmitter2Port();
				transmitter3Address = modem.getTransmitter3Address();
				transmitter3Port    = modem.getTransmitter3Port();
				receiver1Address    = modem.getReceiver1Address();
				receiver1Port       = modem.getReceiver1Port();
				receiver2Address    = modem.getReceiver2Address();
				receiver2Port       = modem.getReceiver2Port();
				receiver3Address    = modem.getReceiver3Address();
				receiver3Port       = modem.getReceiver3Port();
				timeout             = modem.getTimeout();
				m_config->setSplit(localAddress, localPort, transmitter1Address, transmitter1Port, transmitter2Address, transmitter2Port, transmitter3Address, transmitter3Port, receiver1Address, receiver1Port, receiver2Address, receiver2Port, receiver3Address, receiver3Port, timeout);
			}
		}
	}
}