JLC test
Dependencies: PinDetect libmDot mbed-rtos mbed
Diff: main.cpp
- Revision:
- 1:96c429800568
- Parent:
- 0:6aa743a332ae
- Child:
- 2:376af6a70e8a
--- a/main.cpp Fri Jan 22 00:33:38 2016 +0000 +++ b/main.cpp Wed Jan 27 00:57:12 2016 +0000 @@ -15,6 +15,7 @@ #include <vector> #include <algorithm> #include "PinDetect.h" +#include "common.h" #define I2C_TIME 5 #define LED_TIME 1 @@ -53,7 +54,7 @@ uint8_t lastPowerOn; //Function prototypes -void ledWrite(); +void timeOfDay(); void periodicSendTock(); void batteryRead(); void killStatusRead(); @@ -68,14 +69,9 @@ bool setAck(uint8_t retries); bool joinNetwork(); bool send(const std::string text); -char latestData[100]; I2C i2c_mem(PTB3,PTB2); //SPI spi_rf(PTD6, PTD7, PTD5, PTD4); SPI spi_rf(PTD6, PTD7, PTD5); -int myI2CWrite(int addr, char *data, int length); -int myI2CRead(int addr, char *data, int length); -int mySPIWrite(int addr, char *data, int length); -int mySPIRead(int addr, char *data, int length); int i2cAddr = 0xAA; char data[0x10]; @@ -104,18 +100,17 @@ spi_cs = 1; //Start LED startup sequence - ledTimer.attach(&ledWrite, LED_TIME); + ledTimer.attach(&timeOfDay, LED_TIME); pc.baud(115200); - pc.printf("\r\n\r\n"); - pc.printf("=====================================\r\n"); - pc.printf("I2C Demo \r\n"); - pc.printf("=====================================\r\n"); + // pc.printf("\r\n\r\n"); + // pc.printf("=====================================\r\n"); +// pc.printf("JLC MT Demo \r\n"); +// pc.printf("=====================================\r\n"); // get the mDot handle // dot = mDot::getInstance(); - printVersion(); -/* dot->setLogLevel(mts::MTSLog::INFO_LEVEL); + /* dot->setLogLevel(mts::MTSLog::INFO_LEVEL); //******************************************* // configuration @@ -160,9 +155,24 @@ // batteryTimer.attach(batteryRead, BATTERY_TIME); // killStatusTimer.attach(killStatusRead, KILL_STATUS_TIME); // powerOnTimer.attach(powerOnRead, POWER_ON_TIME); + + /* initialize time and date */ + epoch =0; + + /* Send message to verify UART is connected properly */ + printVersion(); + sprintf(TransmitBuffer,"%s cmd>",time_string); + pc.printf(TransmitBuffer); while (1) { + if (getLine() == 1) /* wait until command line complete */ + { + executeCmd(); + sprintf(TransmitBuffer,"%s cmd> ",time_string); + pc.printf("%s",TransmitBuffer); + } + #if 0 // is there anything to send if(readyToSendI2C) { @@ -179,9 +189,9 @@ #if 1 // Send 0x8f, the command to read the WHOAMI register data[0] = 0x12; -// mySPIWrite(0x0A,data,1); -// mySPIRead(0x0A,data1,1); - mySPIRead(0x42,data1,1); + mySPIWrite(0x0A,data,1); + mySPIRead(0x0A,data1,1); + mySPIRead(0x42,data1,2); // int spiData = spi_rf.write(0x0600 | 0x0000); sprintf(latestData,"SPI %02X %02X",data1[0], data1[1]); pc.printf("%s\r\n",latestData); @@ -211,38 +221,41 @@ send(latestData); readyToSendPowerOn = false; } + #endif } } -int myI2CWrite(int addr, char *data, int length) +void I2CWrite(uint16 addr, uint8 *data, int length) { int i; char bytes[3]; for(i=0; i< length; i++,addr++) { - bytes[0] = addr << 8; + bytes[0] = addr >> 8; bytes[1] = addr & 0xFF; bytes[2] = data[i]; i2c_mem.write(i2cAddr, bytes, 3); /* write address and one byte */ while(i2c_mem.write(i2cAddr, bytes, 0) != 0); /* wait till write complete */ } - return 0; + return; } -int myI2CRead(int addr, char *data, int length) +void I2CRead(uint16 addr, uint8 *data, int length) { char bytes[2]; - bytes[0] = addr << 8; + bytes[0] = addr >> 8; bytes[1] = addr & 0xFF; +// sprintf(TransmitBuffer,"read I2C %04X %02X %04X\r\n",regAddress, bytes[0], bytes[1]); +// pc.printf(TransmitBuffer); i2c_mem.write(i2cAddr, bytes, 2,true); /* write address with repeated start */ - i2c_mem.read(i2cAddr, data, length); /* read all bytes */ - return 0; + i2c_mem.read(i2cAddr, (char *)data, length); /* read all bytes */ + return; } -int mySPIWrite(int addr, char *data, int length) +void SPIWrite(uint16 addr, uint8 *data, int length) { int i; @@ -252,10 +265,9 @@ data[i] = spi_rf.write( (addr << 8) | data[i] | 0x8000); spi_cs = 1; } - return 0; } -int mySPIRead(int addr, char *data, int length) +void SPIRead(uint16 addr, uint8 *data, int length) { int i; @@ -265,11 +277,11 @@ data[i] = spi_rf.write( (addr << 8) | data[i] | 0x0000); spi_cs = 1; } - return 0; - } + } -void ledWrite() +void timeOfDay() { + epoch++; /* update time of day */ led_red = !led_red; // led_green = !led_green; // led_blue = !led_blue; @@ -294,12 +306,6 @@ readyToSendPowerOn = true; } -void printVersion() -{ - // pc.printf("%s Built on: %s %s\r\n\r\n", dot->getId().c_str(),__DATE__,__TIME__); - pc.printf("Built on: %s %s\r\n\r\n", __DATE__,__TIME__); -} - bool setFrequencySubBand(uint8_t subBand) { /* int32_t returnCode;