For RevB MBED Hardware, with the new boot sequence. This example establishes a transparent link between the mbed USB CDC port and the modem (LISA) on the C027. You can use it to use the standard u-blox tools such as m-center or any terminal program. These tools can then connect to the serial port and talk directly to the modem. Baudrate should be set to 115200 baud and is fixed. m-center can be downloaded from u-blox website following this link: http://www.u-blox.com/en/evaluation-tools-a-software/u-center/m-center.html

Dependencies:   C027-REVB UbloxUSBModem mbed

Committer:
dixter1
Date:
Fri Dec 13 00:40:55 2013 +0000
Revision:
0:92ab4f4846f8
Child:
1:15b5edb4a91f
RevB Version of TransparentUSBCDC.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dixter1 0:92ab4f4846f8 1 #include "mbed.h"
dixter1 0:92ab4f4846f8 2 #include "C027.h"
dixter1 0:92ab4f4846f8 3 #include "WANDongle.h"
dixter1 0:92ab4f4846f8 4 #include "USBSerialStream.h"
dixter1 0:92ab4f4846f8 5 #include "UbloxCDMAModemInitializer.h"
dixter1 0:92ab4f4846f8 6 #include "UbloxGSMModemInitializer.h"
dixter1 0:92ab4f4846f8 7
dixter1 0:92ab4f4846f8 8 DigitalOut mdm_activity(LED);
dixter1 0:92ab4f4846f8 9
dixter1 0:92ab4f4846f8 10 int main()
dixter1 0:92ab4f4846f8 11 {
dixter1 0:92ab4f4846f8 12 int led_toggle_count = 5;
dixter1 0:92ab4f4846f8 13
dixter1 0:92ab4f4846f8 14 // the instantiation of the type, calls C027::C027
dixter1 0:92ab4f4846f8 15 C027 c027;
dixter1 0:92ab4f4846f8 16
dixter1 0:92ab4f4846f8 17 c027.mdmPower(true);
dixter1 0:92ab4f4846f8 18
dixter1 0:92ab4f4846f8 19 #if 0
dixter1 0:92ab4f4846f8 20 while(1) {
dixter1 0:92ab4f4846f8 21 mdm_activity = !mdm_activity;
dixter1 0:92ab4f4846f8 22 wait(0.2);
dixter1 0:92ab4f4846f8 23 }
dixter1 0:92ab4f4846f8 24 #else
dixter1 0:92ab4f4846f8 25 while( led_toggle_count-- > 0 )
dixter1 0:92ab4f4846f8 26 {
dixter1 0:92ab4f4846f8 27 mdm_activity = !mdm_activity;
dixter1 0:92ab4f4846f8 28 wait(0.2);
dixter1 0:92ab4f4846f8 29 }
dixter1 0:92ab4f4846f8 30 #endif
dixter1 0:92ab4f4846f8 31
dixter1 0:92ab4f4846f8 32 // open the mdm serial port
dixter1 0:92ab4f4846f8 33 WANDongle mdmDongle;
dixter1 0:92ab4f4846f8 34 USBSerialStream mdmStream(mdmDongle.getSerial(1/* the CDC usually 0 or 1, LISA-C requires CDC1*/));
dixter1 0:92ab4f4846f8 35 USBHost* host = USBHost::getHostInst();
dixter1 0:92ab4f4846f8 36 mdmDongle.addInitializer(new UbloxCDMAModemInitializer(host));
dixter1 0:92ab4f4846f8 37 mdmDongle.addInitializer(new UbloxGSMModemInitializer(host));
dixter1 0:92ab4f4846f8 38
dixter1 0:92ab4f4846f8 39 // open the PC serial port and (use the same baudrate)
dixter1 0:92ab4f4846f8 40 Serial pc(USBTX, USBRX);
dixter1 0:92ab4f4846f8 41 pc.baud(MDMBAUD);
dixter1 0:92ab4f4846f8 42
dixter1 0:92ab4f4846f8 43 while (1)
dixter1 0:92ab4f4846f8 44 {
dixter1 0:92ab4f4846f8 45 uint8_t buf[64];
dixter1 0:92ab4f4846f8 46 size_t len;
dixter1 0:92ab4f4846f8 47 int i;
dixter1 0:92ab4f4846f8 48
dixter1 0:92ab4f4846f8 49 if (!mdmDongle.connected())
dixter1 0:92ab4f4846f8 50 {
dixter1 0:92ab4f4846f8 51 mdmDongle.tryConnect();
dixter1 0:92ab4f4846f8 52 }
dixter1 0:92ab4f4846f8 53 else
dixter1 0:92ab4f4846f8 54 {
dixter1 0:92ab4f4846f8 55
dixter1 0:92ab4f4846f8 56 // transfer data from pc to modem
dixter1 0:92ab4f4846f8 57 len = mdmStream.space();
dixter1 0:92ab4f4846f8 58 if (len>0)
dixter1 0:92ab4f4846f8 59 {
dixter1 0:92ab4f4846f8 60 if (len > sizeof(buf))
dixter1 0:92ab4f4846f8 61 len = sizeof(buf);
dixter1 0:92ab4f4846f8 62 for (i = 0; (i < len) && pc.readable(); )
dixter1 0:92ab4f4846f8 63 buf[i++] = pc.getc();
dixter1 0:92ab4f4846f8 64 if (OK == mdmStream.write(buf, i))
dixter1 0:92ab4f4846f8 65 /* do something? */;
dixter1 0:92ab4f4846f8 66 }
dixter1 0:92ab4f4846f8 67 // transfer data from modem to pc
dixter1 0:92ab4f4846f8 68 len = mdmStream.available();
dixter1 0:92ab4f4846f8 69 if ((len>0) && pc.writeable())
dixter1 0:92ab4f4846f8 70 {
dixter1 0:92ab4f4846f8 71 if (len > sizeof(buf))
dixter1 0:92ab4f4846f8 72 len = sizeof(buf);
dixter1 0:92ab4f4846f8 73 if (OK == mdmStream.read(buf, &len, len))
dixter1 0:92ab4f4846f8 74 {
dixter1 0:92ab4f4846f8 75 for (i = 0; (i < len); )
dixter1 0:92ab4f4846f8 76 {
dixter1 0:92ab4f4846f8 77 mdm_activity=!mdm_activity;
dixter1 0:92ab4f4846f8 78 pc.putc(buf[i++]);
dixter1 0:92ab4f4846f8 79 }
dixter1 0:92ab4f4846f8 80
dixter1 0:92ab4f4846f8 81 // default the led to off
dixter1 0:92ab4f4846f8 82 mdm_activity=0;
dixter1 0:92ab4f4846f8 83 }
dixter1 0:92ab4f4846f8 84 }
dixter1 0:92ab4f4846f8 85 }
dixter1 0:92ab4f4846f8 86 }
dixter1 0:92ab4f4846f8 87 }