レンタルサーバーと連携したsakura.ioの運用例
Dependencies: mbed SakuraIO MPU9250_SPI BME280 gps AQM0802A
main.cpp@0:d2c4ee597498, 2018-11-21 (annotated)
- Committer:
- punix
- Date:
- Wed Nov 21 08:54:34 2018 +0000
- Revision:
- 0:d2c4ee597498
- Child:
- 1:11957db1faa5
TEST 20181121
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
punix | 0:d2c4ee597498 | 1 | #include <mbed.h> |
punix | 0:d2c4ee597498 | 2 | #include <AQM0802A.h> |
punix | 0:d2c4ee597498 | 3 | #include <BME280.h> |
punix | 0:d2c4ee597498 | 4 | #include <MPU9250.h> |
punix | 0:d2c4ee597498 | 5 | #include <SakuraIO.h> |
punix | 0:d2c4ee597498 | 6 | #include "SakuraPinNames.h" |
punix | 0:d2c4ee597498 | 7 | #include "sensors.h" |
punix | 0:d2c4ee597498 | 8 | #include "gps.h" |
punix | 0:d2c4ee597498 | 9 | |
punix | 0:d2c4ee597498 | 10 | #define MESG_NORMAL 0 |
punix | 0:d2c4ee597498 | 11 | #define MESG_INIT 1 |
punix | 0:d2c4ee597498 | 12 | |
punix | 0:d2c4ee597498 | 13 | |
punix | 0:d2c4ee597498 | 14 | // Serial over CMSIS_DAP |
punix | 0:d2c4ee597498 | 15 | Serial pc(DAP_UART_TX, DAP_UART_RX, 9600); |
punix | 0:d2c4ee597498 | 16 | |
punix | 0:d2c4ee597498 | 17 | // GPS |
punix | 0:d2c4ee597498 | 18 | Serial gps(GPS_TX, GPS_RX, 9600); |
punix | 0:d2c4ee597498 | 19 | DigitalOut gps_en(GPS_EN); |
punix | 0:d2c4ee597498 | 20 | |
punix | 0:d2c4ee597498 | 21 | // LED |
punix | 0:d2c4ee597498 | 22 | DigitalOut led_1(LED1); |
punix | 0:d2c4ee597498 | 23 | DigitalOut led_2(LED2); |
punix | 0:d2c4ee597498 | 24 | DigitalOut led_3(LED3); |
punix | 0:d2c4ee597498 | 25 | DigitalOut led_4(LED4); |
punix | 0:d2c4ee597498 | 26 | |
punix | 0:d2c4ee597498 | 27 | // LCD backlight |
punix | 0:d2c4ee597498 | 28 | DigitalOut lcd_led(LED_LCD); |
punix | 0:d2c4ee597498 | 29 | |
punix | 0:d2c4ee597498 | 30 | // Switch |
punix | 0:d2c4ee597498 | 31 | DigitalIn sw_1(SW1); |
punix | 0:d2c4ee597498 | 32 | DigitalIn sw_2(SW2); |
punix | 0:d2c4ee597498 | 33 | DigitalIn sw_3(SW3); |
punix | 0:d2c4ee597498 | 34 | DigitalIn sw_4(SW4); |
punix | 0:d2c4ee597498 | 35 | DigitalIn sw_5(SW5); |
punix | 0:d2c4ee597498 | 36 | DigitalIn sw_6(SW6); |
punix | 0:d2c4ee597498 | 37 | |
punix | 0:d2c4ee597498 | 38 | // Internal I2C |
punix | 0:d2c4ee597498 | 39 | I2C internal_i2c(I2C_INTERNAL_SDA, I2C_INTERNAL_SCL); |
punix | 0:d2c4ee597498 | 40 | AQM0802A lcd(internal_i2c); |
punix | 0:d2c4ee597498 | 41 | BME280 bme280(internal_i2c); |
punix | 0:d2c4ee597498 | 42 | |
punix | 0:d2c4ee597498 | 43 | // SPI |
punix | 0:d2c4ee597498 | 44 | SPI internal_mpu9250_spi(SPI_MPU_MOSI, SPI_MPU_MISO, SPI_MPU_SCK); |
punix | 0:d2c4ee597498 | 45 | mpu9250_spi mpu9250(internal_mpu9250_spi, SPI_MPU_CS); |
punix | 0:d2c4ee597498 | 46 | |
punix | 0:d2c4ee597498 | 47 | // sakura.io |
punix | 0:d2c4ee597498 | 48 | SakuraIO_I2C sakuraio(I2C_SDA, I2C_SCL); |
punix | 0:d2c4ee597498 | 49 | |
punix | 0:d2c4ee597498 | 50 | SensorData sensor_data; |
punix | 0:d2c4ee597498 | 51 | |
punix | 0:d2c4ee597498 | 52 | // GPS UART buffer |
punix | 0:d2c4ee597498 | 53 | char uart_buffer[128] = {0}; |
punix | 0:d2c4ee597498 | 54 | int uart_buffer_index = 0; |
punix | 0:d2c4ee597498 | 55 | int connected_now = 0; |
punix | 0:d2c4ee597498 | 56 | |
punix | 0:d2c4ee597498 | 57 | // NMEA Decoder |
punix | 0:d2c4ee597498 | 58 | GPSDecoder gps_decoder; |
punix | 0:d2c4ee597498 | 59 | |
punix | 0:d2c4ee597498 | 60 | void gps_uart_buffering_handler(); |
punix | 0:d2c4ee597498 | 61 | |
punix | 0:d2c4ee597498 | 62 | const int SEND_INTERVAL_TICKS_PAR_COUNT = 25; |
punix | 0:d2c4ee597498 | 63 | |
punix | 0:d2c4ee597498 | 64 | const int RETRY_INTERVAL_TICKS_PAR_COUNT = 25; |
punix | 0:d2c4ee597498 | 65 | |
punix | 0:d2c4ee597498 | 66 | void setup() |
punix | 0:d2c4ee597498 | 67 | { |
punix | 0:d2c4ee597498 | 68 | lcd_led = 1; |
punix | 0:d2c4ee597498 | 69 | pc.printf("Hello World !\r\n"); |
punix | 0:d2c4ee597498 | 70 | lcd.cls(); |
punix | 0:d2c4ee597498 | 71 | lcd.printf("Hello"); |
punix | 0:d2c4ee597498 | 72 | connected_now = 0; |
punix | 0:d2c4ee597498 | 73 | |
punix | 0:d2c4ee597498 | 74 | // Initialize sensors |
punix | 0:d2c4ee597498 | 75 | bme280.initialize(); |
punix | 0:d2c4ee597498 | 76 | pc.printf("BME280 ok.\r\n"); |
punix | 0:d2c4ee597498 | 77 | mpu9250.init(1, BITS_DLPF_CFG_188HZ); |
punix | 0:d2c4ee597498 | 78 | pc.printf("MPU9250 ok. WHOAMI=%02x\r\n", mpu9250.whoami()); |
punix | 0:d2c4ee597498 | 79 | if (mpu9250.whoami() != 0x71) { |
punix | 0:d2c4ee597498 | 80 | pc.printf("[ERROR] MPU9250 init fail.\r\n"); |
punix | 0:d2c4ee597498 | 81 | } |
punix | 0:d2c4ee597498 | 82 | |
punix | 0:d2c4ee597498 | 83 | mpu9250.set_gyro_scale(BITS_FS_2000DPS); //Set full scale range for gyros |
punix | 0:d2c4ee597498 | 84 | mpu9250.set_acc_scale(BITS_FS_16G); //Set full scale range for accs |
punix | 0:d2c4ee597498 | 85 | mpu9250.calib_acc(); |
punix | 0:d2c4ee597498 | 86 | mpu9250.AK8963_calib_Magnetometer(); |
punix | 0:d2c4ee597498 | 87 | |
punix | 0:d2c4ee597498 | 88 | // active high |
punix | 0:d2c4ee597498 | 89 | gps_en = 1; |
punix | 0:d2c4ee597498 | 90 | gps.attach(&gps_uart_buffering_handler, Serial::RxIrq); |
punix | 0:d2c4ee597498 | 91 | |
punix | 0:d2c4ee597498 | 92 | led_1 = 1; |
punix | 0:d2c4ee597498 | 93 | led_2 = 0; |
punix | 0:d2c4ee597498 | 94 | |
punix | 0:d2c4ee597498 | 95 | pc.printf("Send par %d seconds.\r\n", (SEND_INTERVAL_TICKS_PAR_COUNT * 200) / 1000); |
punix | 0:d2c4ee597498 | 96 | } |
punix | 0:d2c4ee597498 | 97 | |
punix | 0:d2c4ee597498 | 98 | void read_sensor_data() |
punix | 0:d2c4ee597498 | 99 | { |
punix | 0:d2c4ee597498 | 100 | sensor_data.bme280.temperature = bme280.getTemperature(); |
punix | 0:d2c4ee597498 | 101 | sensor_data.bme280.pressure = bme280.getPressure(); |
punix | 0:d2c4ee597498 | 102 | sensor_data.bme280.humidity = bme280.getHumidity(); |
punix | 0:d2c4ee597498 | 103 | |
punix | 0:d2c4ee597498 | 104 | mpu9250.read_all(); |
punix | 0:d2c4ee597498 | 105 | sensor_data.mpu9250.temperature = mpu9250.Temperature; |
punix | 0:d2c4ee597498 | 106 | for (int cnt_send = 0; cnt_send < 3; cnt_send++) { |
punix | 0:d2c4ee597498 | 107 | sensor_data.mpu9250.accelerometer[cnt_send] = mpu9250.accelerometer_data[cnt_send]; |
punix | 0:d2c4ee597498 | 108 | sensor_data.mpu9250.gyroscope[cnt_send] = mpu9250.gyroscope_data[cnt_send]; |
punix | 0:d2c4ee597498 | 109 | sensor_data.mpu9250.magnetometer[cnt_send] = mpu9250.Magnetometer[cnt_send]; |
punix | 0:d2c4ee597498 | 110 | } |
punix | 0:d2c4ee597498 | 111 | } |
punix | 0:d2c4ee597498 | 112 | |
punix | 0:d2c4ee597498 | 113 | void enqueue_sensor_data(int counter) |
punix | 0:d2c4ee597498 | 114 | { |
punix | 0:d2c4ee597498 | 115 | sakuraio.enqueueTx(0, (int32_t)counter); |
punix | 0:d2c4ee597498 | 116 | sakuraio.enqueueTx(1, sensor_data.bme280.temperature); |
punix | 0:d2c4ee597498 | 117 | sakuraio.enqueueTx(2, sensor_data.bme280.pressure); |
punix | 0:d2c4ee597498 | 118 | sakuraio.enqueueTx(3, sensor_data.bme280.humidity); |
punix | 0:d2c4ee597498 | 119 | sakuraio.enqueueTx(4, sensor_data.mpu9250.accelerometer[0]); |
punix | 0:d2c4ee597498 | 120 | sakuraio.enqueueTx(5, sensor_data.mpu9250.accelerometer[1]); |
punix | 0:d2c4ee597498 | 121 | sakuraio.enqueueTx(6, sensor_data.mpu9250.accelerometer[2]); |
punix | 0:d2c4ee597498 | 122 | sakuraio.enqueueTx(7, sensor_data.mpu9250.gyroscope[0]); |
punix | 0:d2c4ee597498 | 123 | sakuraio.enqueueTx(8, sensor_data.mpu9250.gyroscope[1]); |
punix | 0:d2c4ee597498 | 124 | sakuraio.enqueueTx(9, sensor_data.mpu9250.gyroscope[2]); |
punix | 0:d2c4ee597498 | 125 | sakuraio.enqueueTx(10, sensor_data.mpu9250.magnetometer[0]); |
punix | 0:d2c4ee597498 | 126 | sakuraio.enqueueTx(11, sensor_data.mpu9250.magnetometer[1]); |
punix | 0:d2c4ee597498 | 127 | sakuraio.enqueueTx(12, sensor_data.mpu9250.magnetometer[2]); |
punix | 0:d2c4ee597498 | 128 | sakuraio.enqueueTx(13, gps_decoder.get_longitude()); |
punix | 0:d2c4ee597498 | 129 | sakuraio.enqueueTx(14, gps_decoder.get_latitude()); |
punix | 0:d2c4ee597498 | 130 | sakuraio.enqueueTx(15, gps_decoder.get_unixtime()); |
punix | 0:d2c4ee597498 | 131 | } |
punix | 0:d2c4ee597498 | 132 | |
punix | 0:d2c4ee597498 | 133 | void gps_uart_buffering_handler() |
punix | 0:d2c4ee597498 | 134 | { |
punix | 0:d2c4ee597498 | 135 | while (gps.readable() == 1) { |
punix | 0:d2c4ee597498 | 136 | char c = gps.getc(); |
punix | 0:d2c4ee597498 | 137 | if (c == '\r') { |
punix | 0:d2c4ee597498 | 138 | continue; |
punix | 0:d2c4ee597498 | 139 | } |
punix | 0:d2c4ee597498 | 140 | uart_buffer[uart_buffer_index] = c; |
punix | 0:d2c4ee597498 | 141 | uart_buffer_index++; |
punix | 0:d2c4ee597498 | 142 | if (c == '\n') { |
punix | 0:d2c4ee597498 | 143 | uart_buffer[uart_buffer_index - 1] = '\0'; |
punix | 0:d2c4ee597498 | 144 | gps_decoder.set_nmea_message(uart_buffer); |
punix | 0:d2c4ee597498 | 145 | gps_decoder.decode(); |
punix | 0:d2c4ee597498 | 146 | uart_buffer_index = 0; |
punix | 0:d2c4ee597498 | 147 | } |
punix | 0:d2c4ee597498 | 148 | } |
punix | 0:d2c4ee597498 | 149 | } |
punix | 0:d2c4ee597498 | 150 | |
punix | 0:d2c4ee597498 | 151 | |
punix | 0:d2c4ee597498 | 152 | void loop() |
punix | 0:d2c4ee597498 | 153 | { |
punix | 0:d2c4ee597498 | 154 | static int cnt_send = 1; |
punix | 0:d2c4ee597498 | 155 | static int tick_by_200ms = 0; |
punix | 0:d2c4ee597498 | 156 | static int stat_sw5 = -1; |
punix | 0:d2c4ee597498 | 157 | uint8_t rx_available = 0; |
punix | 0:d2c4ee597498 | 158 | uint8_t rx_queued = 0; |
punix | 0:d2c4ee597498 | 159 | uint8_t rx_ch=0; |
punix | 0:d2c4ee597498 | 160 | uint8_t rx_type=0; |
punix | 0:d2c4ee597498 | 161 | uint8_t rx_value[8]; |
punix | 0:d2c4ee597498 | 162 | int64_t rx_offset=0; |
punix | 0:d2c4ee597498 | 163 | int64_t rx_val; |
punix | 0:d2c4ee597498 | 164 | uint32_t tx_tmp; |
punix | 0:d2c4ee597498 | 165 | uint8_t ch20_ctrl; |
punix | 0:d2c4ee597498 | 166 | uint32_t ch20_id; |
punix | 0:d2c4ee597498 | 167 | uint8_t ch20_mesg; |
punix | 0:d2c4ee597498 | 168 | |
punix | 0:d2c4ee597498 | 169 | if((sakuraio.getConnectionStatus() & 0x80) == 0x00) { |
punix | 0:d2c4ee597498 | 170 | //Offline |
punix | 0:d2c4ee597498 | 171 | lcd.cls(); |
punix | 0:d2c4ee597498 | 172 | lcd.printf("Offline"); |
punix | 0:d2c4ee597498 | 173 | pc.printf("Network is offline.\r\n(After 1 sec to running retry.)\r\n"); |
punix | 0:d2c4ee597498 | 174 | wait(1); |
punix | 0:d2c4ee597498 | 175 | connected_now = 0; |
punix | 0:d2c4ee597498 | 176 | return; |
punix | 0:d2c4ee597498 | 177 | } |
punix | 0:d2c4ee597498 | 178 | else { |
punix | 0:d2c4ee597498 | 179 | if(0 == connected_now){ |
punix | 0:d2c4ee597498 | 180 | tx_tmp = (MESG_INIT << 8) | (lcd_led & 0xFF); |
punix | 0:d2c4ee597498 | 181 | sakuraio.enqueueTx(20, tx_tmp); |
punix | 0:d2c4ee597498 | 182 | sakuraio.send(); |
punix | 0:d2c4ee597498 | 183 | connected_now = 1; |
punix | 0:d2c4ee597498 | 184 | stat_sw5 = -1; |
punix | 0:d2c4ee597498 | 185 | } |
punix | 0:d2c4ee597498 | 186 | if(1 == connected_now){ |
punix | 0:d2c4ee597498 | 187 | if((tick_by_200ms % RETRY_INTERVAL_TICKS_PAR_COUNT) == 0){ |
punix | 0:d2c4ee597498 | 188 | tx_tmp = (MESG_INIT<<8) | (lcd_led & 0xFF); |
punix | 0:d2c4ee597498 | 189 | sakuraio.enqueueTx(20, tx_tmp); |
punix | 0:d2c4ee597498 | 190 | sakuraio.send(); |
punix | 0:d2c4ee597498 | 191 | } |
punix | 0:d2c4ee597498 | 192 | } |
punix | 0:d2c4ee597498 | 193 | } |
punix | 0:d2c4ee597498 | 194 | |
punix | 0:d2c4ee597498 | 195 | |
punix | 0:d2c4ee597498 | 196 | |
punix | 0:d2c4ee597498 | 197 | |
punix | 0:d2c4ee597498 | 198 | if (stat_sw5 != sw_5) { |
punix | 0:d2c4ee597498 | 199 | stat_sw5 = sw_5; |
punix | 0:d2c4ee597498 | 200 | led_3 = stat_sw5; //State: `Send Enable' |
punix | 0:d2c4ee597498 | 201 | if (stat_sw5 == 0) { |
punix | 0:d2c4ee597498 | 202 | lcd.cls(); |
punix | 0:d2c4ee597498 | 203 | lcd.printf("Send:OFF"); |
punix | 0:d2c4ee597498 | 204 | } else { |
punix | 0:d2c4ee597498 | 205 | cnt_send = 1; |
punix | 0:d2c4ee597498 | 206 | tick_by_200ms = 0; |
punix | 0:d2c4ee597498 | 207 | lcd.cls(); |
punix | 0:d2c4ee597498 | 208 | lcd.printf("Send:ON"); |
punix | 0:d2c4ee597498 | 209 | } |
punix | 0:d2c4ee597498 | 210 | } |
punix | 0:d2c4ee597498 | 211 | |
punix | 0:d2c4ee597498 | 212 | if (stat_sw5 == 1) { |
punix | 0:d2c4ee597498 | 213 | if ((tick_by_200ms % SEND_INTERVAL_TICKS_PAR_COUNT) == 0) { //Send data intarval is 5 minutes. |
punix | 0:d2c4ee597498 | 214 | pc.printf("\r\n\r\n--------------------\r\n"); |
punix | 0:d2c4ee597498 | 215 | read_sensor_data(); |
punix | 0:d2c4ee597498 | 216 | pc.printf("BME280\r\n"); |
punix | 0:d2c4ee597498 | 217 | pc.printf("\tTemp: %.2fC\r\n", sensor_data.bme280.temperature); |
punix | 0:d2c4ee597498 | 218 | pc.printf("\tPres: %.2fhPa\r\n", sensor_data.bme280.pressure); |
punix | 0:d2c4ee597498 | 219 | pc.printf("\tHum: %.2f%%\r\n", sensor_data.bme280.humidity); |
punix | 0:d2c4ee597498 | 220 | pc.printf("MPU9250\r\n"); |
punix | 0:d2c4ee597498 | 221 | pc.printf("\tTemp: %.2fC\r\n", sensor_data.mpu9250.temperature); |
punix | 0:d2c4ee597498 | 222 | for (int j = 0; j < 3; j++) { |
punix | 0:d2c4ee597498 | 223 | pc.printf("\tacc[%d]: %.2f\r\n", j, sensor_data.mpu9250.accelerometer[j]); |
punix | 0:d2c4ee597498 | 224 | pc.printf("\tgyro[%d]: %.2f\r\n", j, sensor_data.mpu9250.gyroscope[j]); |
punix | 0:d2c4ee597498 | 225 | pc.printf("\tmag[%d]: %.2f\r\n", j, sensor_data.mpu9250.magnetometer[j]); |
punix | 0:d2c4ee597498 | 226 | } |
punix | 0:d2c4ee597498 | 227 | pc.printf("GPS\r\n"); |
punix | 0:d2c4ee597498 | 228 | pc.printf("\tlat: %f%c\r\n", |
punix | 0:d2c4ee597498 | 229 | gps_decoder.get_latitude(), |
punix | 0:d2c4ee597498 | 230 | gps_decoder.get_latitude() >= 0 ? 'N' : 'S'); |
punix | 0:d2c4ee597498 | 231 | pc.printf("\tlon: %f%c\r\n", |
punix | 0:d2c4ee597498 | 232 | gps_decoder.get_longitude(), |
punix | 0:d2c4ee597498 | 233 | gps_decoder.get_longitude() >= 0 ? 'E' : 'W'); |
punix | 0:d2c4ee597498 | 234 | pc.printf("\tspeed: %fkm/h\r\n", gps_decoder.get_speed()); |
punix | 0:d2c4ee597498 | 235 | pc.printf("\tmove_direction: %f\r\n", gps_decoder.get_move_direction()); |
punix | 0:d2c4ee597498 | 236 | pc.printf("\tdate: %d/%02d/%02d %02d:%02d:%02d (UTC)\r\n", |
punix | 0:d2c4ee597498 | 237 | gps_decoder.get_year(), gps_decoder.get_month(), gps_decoder.get_day(), |
punix | 0:d2c4ee597498 | 238 | gps_decoder.get_hour(), gps_decoder.get_min(), gps_decoder.get_sec()); |
punix | 0:d2c4ee597498 | 239 | pc.printf("\tUNIX time: %d\r\n", gps_decoder.get_unixtime()); |
punix | 0:d2c4ee597498 | 240 | led_2 = 1; |
punix | 0:d2c4ee597498 | 241 | pc.printf("Send:%d\r\n", cnt_send); |
punix | 0:d2c4ee597498 | 242 | lcd.setCursor(0, 1); |
punix | 0:d2c4ee597498 | 243 | lcd.printf("%d", cnt_send); |
punix | 0:d2c4ee597498 | 244 | enqueue_sensor_data(cnt_send); |
punix | 0:d2c4ee597498 | 245 | sakuraio.send(); |
punix | 0:d2c4ee597498 | 246 | cnt_send++; |
punix | 0:d2c4ee597498 | 247 | led_2 = 0; |
punix | 0:d2c4ee597498 | 248 | pc.printf("After %d sec to send.\r\n", (int)(SEND_INTERVAL_TICKS_PAR_COUNT * 0.2)); |
punix | 0:d2c4ee597498 | 249 | } |
punix | 0:d2c4ee597498 | 250 | } |
punix | 0:d2c4ee597498 | 251 | |
punix | 0:d2c4ee597498 | 252 | do { |
punix | 0:d2c4ee597498 | 253 | rx_available = 0; |
punix | 0:d2c4ee597498 | 254 | if ( CMD_ERROR_NONE == sakuraio.getRxQueueLength(&rx_available, &rx_queued)) { |
punix | 0:d2c4ee597498 | 255 | if (0 < rx_queued) { |
punix | 0:d2c4ee597498 | 256 | if ( CMD_ERROR_NONE == sakuraio.dequeueRx(&rx_ch, &rx_type, rx_value, &rx_offset)) { |
punix | 0:d2c4ee597498 | 257 | if ( (20 == rx_ch) && (0x49 == rx_type) ) { |
punix | 0:d2c4ee597498 | 258 | rx_val = ( (int64_t)rx_value[3] << 24) + ( (int64_t)rx_value[2] << 16) + ( (int64_t)rx_value[1] << 8) + ( (int64_t)rx_value[0] << 0); |
punix | 0:d2c4ee597498 | 259 | ch20_ctrl = rx_val & 0xFF; |
punix | 0:d2c4ee597498 | 260 | ch20_mesg = (rx_val>>8) & 0xFF; |
punix | 0:d2c4ee597498 | 261 | ch20_id = (rx_val>>16) & 0xFFFF; |
punix | 0:d2c4ee597498 | 262 | if ( (1 == ch20_ctrl) && (MESG_NORMAL == ch20_mesg)) { |
punix | 0:d2c4ee597498 | 263 | tx_tmp = (ch20_id<<16) | (MESG_NORMAL<<8) | (lcd_led & 0xFF); |
punix | 0:d2c4ee597498 | 264 | sakuraio.enqueueTx(20, tx_tmp); |
punix | 0:d2c4ee597498 | 265 | sakuraio.send(); |
punix | 0:d2c4ee597498 | 266 | } |
punix | 0:d2c4ee597498 | 267 | if ( (1 == ch20_ctrl) && (MESG_INIT == ch20_mesg)) { |
punix | 0:d2c4ee597498 | 268 | connected_now = 2; |
punix | 0:d2c4ee597498 | 269 | } |
punix | 0:d2c4ee597498 | 270 | } |
punix | 0:d2c4ee597498 | 271 | if ( (21 == rx_ch) && (0x49 == rx_type) ) { |
punix | 0:d2c4ee597498 | 272 | rx_val = ( (int64_t)rx_value[3] << 24) + ( (int64_t)rx_value[2] << 16) + ( (int64_t)rx_value[1] << 8) + ( (int64_t)rx_value[0] << 0); |
punix | 0:d2c4ee597498 | 273 | ch20_ctrl = rx_val & 0xFF; |
punix | 0:d2c4ee597498 | 274 | ch20_mesg = (rx_val>>8) & 0xFF; |
punix | 0:d2c4ee597498 | 275 | ch20_id = (rx_val>>16) & 0xFFFF; |
punix | 0:d2c4ee597498 | 276 | if ( 1 == ch20_ctrl || 0 == ch20_ctrl ) { |
punix | 0:d2c4ee597498 | 277 | lcd_led = ch20_ctrl; |
punix | 0:d2c4ee597498 | 278 | tx_tmp = (ch20_id<<16) | (MESG_NORMAL<<8) | (lcd_led & 0xFF); |
punix | 0:d2c4ee597498 | 279 | sakuraio.enqueueTx(20, tx_tmp); |
punix | 0:d2c4ee597498 | 280 | sakuraio.send(); |
punix | 0:d2c4ee597498 | 281 | } |
punix | 0:d2c4ee597498 | 282 | } |
punix | 0:d2c4ee597498 | 283 | } |
punix | 0:d2c4ee597498 | 284 | } |
punix | 0:d2c4ee597498 | 285 | } |
punix | 0:d2c4ee597498 | 286 | }while(0 < rx_queued); |
punix | 0:d2c4ee597498 | 287 | |
punix | 0:d2c4ee597498 | 288 | |
punix | 0:d2c4ee597498 | 289 | |
punix | 0:d2c4ee597498 | 290 | led_1 = !led_1; |
punix | 0:d2c4ee597498 | 291 | led_4 = !sw_4; |
punix | 0:d2c4ee597498 | 292 | tick_by_200ms++; |
punix | 0:d2c4ee597498 | 293 | wait(0.2); |
punix | 0:d2c4ee597498 | 294 | } |
punix | 0:d2c4ee597498 | 295 | |
punix | 0:d2c4ee597498 | 296 | |
punix | 0:d2c4ee597498 | 297 | int main() |
punix | 0:d2c4ee597498 | 298 | { |
punix | 0:d2c4ee597498 | 299 | setup(); |
punix | 0:d2c4ee597498 | 300 | while(1) { |
punix | 0:d2c4ee597498 | 301 | loop(); |
punix | 0:d2c4ee597498 | 302 | } |
punix | 0:d2c4ee597498 | 303 | } |