test
Dependencies: MTS-Serial libmDot mbed-rtos mbed
Fork of mDot_LoRa_Connect_Example by
Revision 6:f87d57498fd0, committed 2017-11-08
- Comitter:
- hmiot
- Date:
- Wed Nov 08 12:10:51 2017 +0000
- Parent:
- 5:f16b067257b6
- Commit message:
- Updated for Zigo Demo
Changed in this revision
lora-task.cpp | Show annotated file Show diff for this revision Revisions of this file |
spi_write.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/lora-task.cpp Fri Oct 13 10:30:14 2017 +0000 +++ b/lora-task.cpp Wed Nov 08 12:10:51 2017 +0000 @@ -18,8 +18,8 @@ extern int ble_flag; extern int zigbee_flag; char gateway_buffer[128]; -int device_buffer[8]; - +int device_buffer[16]; +int temp =0; int process_gateway_data(const char *device_type, int *device_buffer, char *data_buffer) { const char *pBuf; @@ -37,9 +37,10 @@ return false; } - pBuf += 13; - - len = strstr((const char *)pBuf, ",") - (char *)pBuf - 1; /* ends with / */ + pBuf += 12; + //pBuf += 11; + //len = strstr((const char *)pBuf, ",") - (char *)pBuf - 1; /* ends with / */ + len = strstr((const char *)pBuf, ",") - (char *)pBuf; /* ends with / */ if (len <= 0) { my_mutex.unlock(); return false; @@ -47,8 +48,9 @@ strncpy ((char *)device_type, (const char *)pBuf, len); printf("device type is %s\r\n", device_type); if (!strcmp(device_type, "ble_bulbs")) { - device_buffer[0] = 0xB3; - device_buffer[1] = 0x01; + device_buffer[0] = 0x04; + device_buffer[1] = 0xCE; + device_buffer[2] = 0x01; pBuf = strstr((const char *)pBuf, "powered"); if (!pBuf) { @@ -56,7 +58,7 @@ my_mutex.unlock(); return false; } - + pBuf += 9; len = strstr((const char *)pBuf, ",") - (char *)pBuf; /* ends with / */ if (len <= 0) { @@ -65,13 +67,13 @@ } if (!strncmp ((char *)pBuf, "true", len)) { - device_buffer[2] = 0x01; + device_buffer[3] = 0x01; } else if (!strncmp ((char *)pBuf, "false", len)) { - device_buffer[2] = 0x00; + device_buffer[3] = 0x00; } else { - device_buffer[2] = 0x02; + device_buffer[3] = 0x02; } pBuf = strstr((const char *)pBuf, "color"); @@ -81,33 +83,34 @@ return false; } - pBuf += 8; - len = strstr((const char *)pBuf, ",") - (char *)pBuf - 1; /* ends with / */ + pBuf += 7; + //len = strstr((const char *)pBuf, ",") - (char *)pBuf - 1; /* ends with / */ + len = strstr((const char *)pBuf, ",") - (char *)pBuf; /* ends with / */ if (len <= 0) { my_mutex.unlock(); return false; } if (!strncmp ((char *)pBuf, "red", len)) { - device_buffer[3] = 0x00; + device_buffer[4] = 0x00; } else if (!strncmp ((char *)pBuf, "green", len)) { - device_buffer[3] = 0x01; + device_buffer[4] = 0x01; } else if (!strncmp ((char *)pBuf, "blue", len)){ - device_buffer[3] = 0x02; + device_buffer[4] = 0x02; } else if (!strncmp ((char *)pBuf, "yellow", len)){ - device_buffer[3] = 0x03; + device_buffer[4] = 0x03; } else if (!strncmp ((char *)pBuf, "cyan", len)){ - device_buffer[3] = 0x04; + device_buffer[4] = 0x04; } else if (!strncmp ((char *)pBuf, "magenta", len)){ - device_buffer[3] = 0x05; + device_buffer[4] = 0x05; } else { - device_buffer[3] = 0x06; + device_buffer[4] = 0x06; } pBuf = strstr((const char *)pBuf, "dim"); if (!pBuf) { @@ -117,7 +120,7 @@ } pBuf += 5; - device_buffer[4] = atoi(pBuf); + device_buffer[5] = atoi(pBuf); my_mutex.unlock(); return true; } @@ -218,13 +221,37 @@ osDelay(1000); //continue; } - //strcpy(gateway_buffer, "{\"DeviceType\":\"ble_bulbs\",\"DeviceName\":\"bulb1\",\"DeviceCommand\":\"desired_state\": {\"powered\":true,\"color\":\"red\",\"dim\":50}}"); + /* + if(temp == 0) + { + strcpy(gateway_buffer, "{\"DeviceType\":\"ble_bulbs\",\"DeviceName\":\"bulb1\",\"DeviceCommand\":\"desired_state\": {\"powered\":false,\"color\":\"red\",\"dim\":50}}"); + temp++; + } + else if(temp == 1) + { + strcpy(gateway_buffer, "{\"DeviceType\":\"ble_bulbs\",\"DeviceName\":\"bulb1\",\"DeviceCommand\":\"desired_state\": {\"powered\":true,\"color\":\"red\",\"dim\":50}}"); + temp++; + } + else if(temp == 2) + { + strcpy(gateway_buffer, "{\"DeviceType\":\"ble_bulbs\",\"DeviceName\":\"bulb1\",\"DeviceCommand\":\"desired_state\": {\"powered\":any,\"color\":\"red\",\"dim\":50}}"); + temp++; + } + else if(temp == 3) + { + strcpy(gateway_buffer, "{\"DeviceType\":\"ble_bulbs\",\"DeviceName\":\"bulb1\",\"DeviceCommand\":\"desired_state\": {\"powered\":any,\"color\":\"green\",\"dim\":50}}"); + temp++; + } + else if(temp ==4) + { + temp =0; + }*/ printf("data received in mdot from gateway: %s\r\n", gateway_buffer); memset(device_type, 0, 16); res = process_gateway_data(device_type, device_buffer, gateway_buffer); if (res == true) { - printf("device_buffer data is: %X, %X, %X, %X, %d\r\n", device_buffer[0], device_buffer[1], device_buffer[2], device_buffer[3], device_buffer[4]); + printf("device_buffer data is: %X, %X, %X, %X, %d %d\r\n", device_buffer[0], device_buffer[1], device_buffer[2], device_buffer[3], device_buffer[4], device_buffer[5]); if (strcmp(device_type, "ble_bulbs") == 0) { printf("sending data to BLE\r\n");
--- a/spi_write.cpp Fri Oct 13 10:30:14 2017 +0000 +++ b/spi_write.cpp Wed Nov 08 12:10:51 2017 +0000 @@ -44,11 +44,26 @@ pc.baud(9600); printf("SPI test..\n\r"); //int temp; - //size = strlen(buf); - + printf("buff[0] = %d\r\n", buf[0]); + int size = buf[0] + 2; + printf("size = %d\r\n", size); + int k, index = 0; + int write_buff[16]; // Chip must be deselected cs = 1; - + write_buff[index] = 0x86; + index++; + for (k =0 ; k< size ; k++, index++) + { + write_buff[index] = buf[k]; + printf("index = %d, size=%d\r\n", index, size); + } + + printf("index = %d, size=%d\r\n", index, size); + write_buff[index] = 0x88; + printf("index = %d, size=%d\r\n", index, size); + printf("index value = %d \r\n", index); + //printf("spi data length is:%d\r\n", size); // Setup the spi for 8 bit data, high steady state clock, // second edge capture, with a 1MHz clock rate @@ -56,16 +71,18 @@ spimaster.frequency(1000000); int i = 0; - while(i < 5) + + while(i <= index) { //osDelay(1000); // Select the device by seting chip select low cs = 0; - response[i] = spimaster.write(buf[i]); + response[i] = spimaster.write(write_buff[i]); cs = 1; - printf("buf[i] = %X\r\n", buf[i]); - printf("response[i] = %X\r\n", response[i]); + printf("buf[%d] = %X\r\n", i ,write_buff[i]); + printf("response[%d] = %X\r\n", i , response[i]); i++; + //printf("\r\nSlave response = 0x%X, 0x%X, 0x%X, 0x%X", response[0], response[1], response[2], response[3]); } @@ -79,15 +96,19 @@ void ble_task(void const *args) { printf("started ble task\r\n"); - int ble_buffer[8]; + int ble_buffer[16]; int i; while (true) { if (ble_flag) { my_mutex.lock(); - for (i = 0; i < 5; i++) + // printf("Device buff Length %d \r\n",); + printf("send Size %d\r\n", device_buffer[0]); + memset(ble_buffer,'\0', 16); + for (i = 0; i <= device_buffer[0] + 2; i++) ble_buffer[i] = device_buffer[i]; my_mutex.unlock(); printf("spi write called\r\n"); + spi_write(ble_buffer); ble_flag = 0; }