180718 HJM : 8 Count sensing data RF send, certTest, temp(cold)Test_ take over and turn over

Dependencies:   1_cubebite_ev-cog-ad3029lz_433MHz_1nd_certTest stm-spirit1-rf-driver_for_cubebite2

Fork of cubebite_ev-cog-ad3029lz_433MHz_1nd_certTest by JunMo Hong

Committer:
jmhong
Date:
Fri Jun 22 03:43:49 2018 +0000
Revision:
1:04f46755f8af
Parent:
0:c2a57b2f934e
Child:
2:8861d01a78e4
180622 HJM : 10 Count sensing data RF send

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jmhong 1:04f46755f8af 1 //HJM : 선풍기 에이징 테스트 용 소스임.
jmhong 1:04f46755f8af 2 //180615 HJM : 선풍기 에이징 용 온도 1개 진동 10개 전송용 테스트 임.
jmhong 1:04f46755f8af 3 // CUBEBITE_TEMPERATURE_DISABLE define 값으로 온도 센서 (연결 및 미연결) 시 설정을 할 수 있음.
jmhong 1:04f46755f8af 4
jmhong 1:04f46755f8af 5
jmhong 1:04f46755f8af 6
jmhong 1:04f46755f8af 7 #include "mbed.h"
jmhong 0:c2a57b2f934e 8 #include "ADXL362.h"
jmhong 1:04f46755f8af 9 #include "SimpleSpirit1.h"
jmhong 0:c2a57b2f934e 10 #include "main.h"
jmhong 0:c2a57b2f934e 11
jmhong 0:c2a57b2f934e 12
jmhong 1:04f46755f8af 13
jmhong 0:c2a57b2f934e 14 //*************************************************************************************
jmhong 0:c2a57b2f934e 15 //Define : Test, Compile
jmhong 0:c2a57b2f934e 16 //*************************************************************************************
jmhong 1:04f46755f8af 17 //#define CUBEBITE_DEBUG
jmhong 1:04f46755f8af 18 //#define HEAVY_DEBUG
jmhong 1:04f46755f8af 19
jmhong 1:04f46755f8af 20
jmhong 0:c2a57b2f934e 21 /* 180108 cubebite HJM : cubebite Testing define, 1개씩만 켜야 함. */
jmhong 0:c2a57b2f934e 22 #define CUBEBITE_RF_SPEED_TEST_SEND_ON
jmhong 0:c2a57b2f934e 23 //#define CUBEBITE_RF_SPEED_TEST_RECV_ON
jmhong 1:04f46755f8af 24 //#define CUBEBITE_RF_SPEED_TEST_SEND_AND_RECV_ON //HJM : 추후 만들 예정..
jmhong 0:c2a57b2f934e 25
jmhong 0:c2a57b2f934e 26 /* 180109 cubebite HJM : cubebite Compile define, 1개씩만 켜야 함. */
jmhong 0:c2a57b2f934e 27 #define CUBEBITE_BOARD_AD3029LZ
jmhong 0:c2a57b2f934e 28
jmhong 0:c2a57b2f934e 29
jmhong 0:c2a57b2f934e 30 #define CUBEBITE_RF_SETTING_VALUE_PRINT
jmhong 1:04f46755f8af 31 //#define CUBEBITE_TEMPERATURE_DISABLE
jmhong 1:04f46755f8af 32
jmhong 1:04f46755f8af 33
jmhong 1:04f46755f8af 34 //180411 HJM : 현재 1~3 까지 3대까지 가능 -> 게이트웨이에서 3대까지만 처리하게끔 되어있
jmhong 1:04f46755f8af 35 #define CUBEBITE_SENSOR_UUID 1 //180621 HJM : 온도 및 진동 테스트 용
jmhong 1:04f46755f8af 36 //#define CUBEBITE_SENSOR_UUID 2 //180621 HJM : 철기연 테스트 용
jmhong 0:c2a57b2f934e 37 //*************************************************************************************
jmhong 0:c2a57b2f934e 38
jmhong 1:04f46755f8af 39
jmhong 1:04f46755f8af 40
jmhong 1:04f46755f8af 41
jmhong 1:04f46755f8af 42 //HJM : 타이머 인터럽트 테스트 용
jmhong 1:04f46755f8af 43 #ifdef CUBEBITE_DEBUG
jmhong 1:04f46755f8af 44 DigitalOut led1(LED1);
jmhong 1:04f46755f8af 45 #endif
jmhong 1:04f46755f8af 46
jmhong 1:04f46755f8af 47
jmhong 1:04f46755f8af 48
jmhong 1:04f46755f8af 49
jmhong 1:04f46755f8af 50 //*************************************************************************************
jmhong 1:04f46755f8af 51 //HJM SUDO code : 3개 객체 생성->RF, 온도, 진동
jmhong 1:04f46755f8af 52 //*************************************************************************************
jmhong 1:04f46755f8af 53 //RF 객체
jmhong 1:04f46755f8af 54 static SimpleSpirit1 &myspirit = SimpleSpirit1::CreateInstance(P0_01, P0_02, P0_00, P1_12 ,P2_08, P1_14);
jmhong 1:04f46755f8af 55 // P0_01[SPI0_MOSI]
jmhong 1:04f46755f8af 56 // P0_02[SPI0_MISO],
jmhong 1:04f46755f8af 57 // P0_00[SPI0_CLK],
jmhong 1:04f46755f8af 58 // P1_12[GPIO 28, RF(GPIO 0)]->IRQ로 설정,
jmhong 1:04f46755f8af 59 // P2_08[SPI0_CS2],
jmhong 1:04f46755f8af 60 // P1_14[GPIO 30, RF (SDN)]
jmhong 1:04f46755f8af 61
jmhong 1:04f46755f8af 62
jmhong 1:04f46755f8af 63 //온도 객체
jmhong 1:04f46755f8af 64 #ifndef CUBEBITE_TEMPERATURE_DISABLE
jmhong 1:04f46755f8af 65 I2C i2c(I2C_SDA, I2C_SCL); //HJM : 테스트 용 임, 서대리님이 클래스 정리해서 줄 예정
jmhong 1:04f46755f8af 66 #endif
jmhong 1:04f46755f8af 67
jmhong 1:04f46755f8af 68 //진동 객체(Accelerometer (mosi, miso, sclk, cs), SPI 1)
jmhong 1:04f46755f8af 69 ADXL362 adxl362(P1_07, P1_08, P1_06, P1_10); //HJM : 테스트 용 임, 서대리님이 클래스 정리해서 줄 예정
jmhong 1:04f46755f8af 70
jmhong 1:04f46755f8af 71 //*************************************************************************************
jmhong 1:04f46755f8af 72
jmhong 1:04f46755f8af 73
jmhong 1:04f46755f8af 74
jmhong 1:04f46755f8af 75
jmhong 1:04f46755f8af 76
jmhong 1:04f46755f8af 77
jmhong 1:04f46755f8af 78 //*************************************************************************************
jmhong 1:04f46755f8af 79 //HJM SUDO code : main 사용자 함수 선언
jmhong 1:04f46755f8af 80 //*************************************************************************************
jmhong 1:04f46755f8af 81
jmhong 1:04f46755f8af 82
jmhong 1:04f46755f8af 83 static void callback_func(int event); //RF user callback 함수임.
jmhong 1:04f46755f8af 84 void UserTimerInterrupt(void); //1초, 타이머 인터럽트 임
jmhong 1:04f46755f8af 85 int UserTimerInterrupt_Execution(void);
jmhong 1:04f46755f8af 86 static int SendData(SimpleSpirit1& myspirit);
jmhong 1:04f46755f8af 87
jmhong 1:04f46755f8af 88
jmhong 1:04f46755f8af 89 //*************************************************************************************
jmhong 1:04f46755f8af 90
jmhong 1:04f46755f8af 91
jmhong 1:04f46755f8af 92
jmhong 1:04f46755f8af 93
jmhong 1:04f46755f8af 94
jmhong 0:c2a57b2f934e 95
jmhong 0:c2a57b2f934e 96
jmhong 0:c2a57b2f934e 97
jmhong 1:04f46755f8af 98 //*************************************************************************************
jmhong 1:04f46755f8af 99 //(테스트용)HJM SUDO code : 전역 변수, 진동, 온도 쪽 테스트용임. 추후 서대리님이 클래스 재 정의시 없어질 예정
jmhong 1:04f46755f8af 100 //*************************************************************************************
jmhong 1:04f46755f8af 101
jmhong 1:04f46755f8af 102
jmhong 1:04f46755f8af 103
jmhong 1:04f46755f8af 104
jmhong 1:04f46755f8af 105 //진동
jmhong 1:04f46755f8af 106 uint16_t vCnt = 0;
jmhong 1:04f46755f8af 107 uint8_t iCnt = 0;
jmhong 1:04f46755f8af 108
jmhong 1:04f46755f8af 109 //int16_t x16 = 0;
jmhong 1:04f46755f8af 110 //int16_t y16 = 0;
jmhong 1:04f46755f8af 111 //int16_t z16 = 0;
jmhong 1:04f46755f8af 112 int8_t x8 = 0;
jmhong 1:04f46755f8af 113 int8_t y8 = 0;
jmhong 1:04f46755f8af 114 int8_t z8 = 0;
jmhong 1:04f46755f8af 115
jmhong 1:04f46755f8af 116
jmhong 1:04f46755f8af 117 int8_t int8tX8Result = 0;
jmhong 1:04f46755f8af 118 int8_t int8tY8Result = 0;
jmhong 1:04f46755f8af 119 int8_t int8tZ8Result = 0;
jmhong 0:c2a57b2f934e 120
jmhong 0:c2a57b2f934e 121
jmhong 1:04f46755f8af 122 int16_t temp_x16[3] = {0,};
jmhong 1:04f46755f8af 123 int16_t temp_y16[3] = {0,};
jmhong 1:04f46755f8af 124 int16_t temp_z16[3] = {0,};
jmhong 1:04f46755f8af 125
jmhong 1:04f46755f8af 126 int Comp1_x = 0, Comp2_x = 0;
jmhong 1:04f46755f8af 127 int Comp1_y = 0, Comp2_y = 0;
jmhong 1:04f46755f8af 128 int Comp1_z = 0, Comp2_z = 0;
jmhong 1:04f46755f8af 129
jmhong 1:04f46755f8af 130 float float_x = 0;
jmhong 1:04f46755f8af 131 float float_y = 0;
jmhong 1:04f46755f8af 132 float float_z = 0;
jmhong 1:04f46755f8af 133
jmhong 1:04f46755f8af 134 float G_x = 0;
jmhong 1:04f46755f8af 135 float G_y = 0;
jmhong 1:04f46755f8af 136 float G_z = 0;
jmhong 1:04f46755f8af 137
jmhong 1:04f46755f8af 138 float Output = 0;
jmhong 1:04f46755f8af 139
jmhong 1:04f46755f8af 140 double dVibOutputSqrt = 0;
jmhong 0:c2a57b2f934e 141
jmhong 0:c2a57b2f934e 142
jmhong 1:04f46755f8af 143 //온도
jmhong 1:04f46755f8af 144 char wReg[2] = {0,};
jmhong 1:04f46755f8af 145 char rReg[2] = {0,};
jmhong 1:04f46755f8af 146 int wACK = 0;
jmhong 1:04f46755f8af 147 int rACK = 0;
jmhong 1:04f46755f8af 148 int16_t Tem16;
jmhong 1:04f46755f8af 149 float TempData = 0;
jmhong 1:04f46755f8af 150
jmhong 1:04f46755f8af 151 #define busAddr 0x4F
jmhong 1:04f46755f8af 152
jmhong 1:04f46755f8af 153 #define ID_DATA_ADDR 0x00
jmhong 1:04f46755f8af 154 #define ID_CON_ADDR 0x01
jmhong 1:04f46755f8af 155 #define ID_REG_ADDR 0x07
jmhong 1:04f46755f8af 156
jmhong 1:04f46755f8af 157
jmhong 1:04f46755f8af 158 //RF->이거도 클래스 내부에 넣기
jmhong 1:04f46755f8af 159 static volatile bool bRxDoneFlag = false;
jmhong 1:04f46755f8af 160 static volatile bool bTxDoneFlag = false;
jmhong 1:04f46755f8af 161 static volatile bool bSendDataFlag = false;
jmhong 1:04f46755f8af 162
jmhong 1:04f46755f8af 163 //*************************************************************************************
jmhong 0:c2a57b2f934e 164
jmhong 0:c2a57b2f934e 165
jmhong 0:c2a57b2f934e 166
jmhong 0:c2a57b2f934e 167
jmhong 0:c2a57b2f934e 168
jmhong 0:c2a57b2f934e 169
jmhong 0:c2a57b2f934e 170
jmhong 0:c2a57b2f934e 171
jmhong 0:c2a57b2f934e 172
jmhong 1:04f46755f8af 173 //HJM : I2C PullUp 용.. RF IRQ 도 이 핀 이지만 사용안하기 때문에 괜찮음.
jmhong 1:04f46755f8af 174 DigitalOut TempSupply(P1_12);
jmhong 0:c2a57b2f934e 175
jmhong 1:04f46755f8af 176 bool iTempFlag = false;
jmhong 1:04f46755f8af 177 bool isTimerInterruptStarted = false;
jmhong 1:04f46755f8af 178 bool bIs1SecTimerSet = false;
jmhong 1:04f46755f8af 179 int iTempInitCount = 0;
jmhong 1:04f46755f8af 180 bool isTempInitOk = false;
jmhong 1:04f46755f8af 181 int main(void)
jmhong 1:04f46755f8af 182 {
jmhong 1:04f46755f8af 183 //*************************************************************************************
jmhong 1:04f46755f8af 184 //HJM SUDO code : 진동, 온도, RF 초기화
jmhong 1:04f46755f8af 185 //*************************************************************************************
jmhong 1:04f46755f8af 186
jmhong 1:04f46755f8af 187 //필수!!!
jmhong 1:04f46755f8af 188 TempSupply.write(1);
jmhong 1:04f46755f8af 189
jmhong 1:04f46755f8af 190
jmhong 1:04f46755f8af 191 //진동 init_시작
jmhong 1:04f46755f8af 192 // set up SPI interface
jmhong 1:04f46755f8af 193 adxl362.init_spi();
jmhong 1:04f46755f8af 194 // Set up accelerometer
jmhong 1:04f46755f8af 195 adxl362.init_adxl362();
jmhong 1:04f46755f8af 196
jmhong 1:04f46755f8af 197 wait_ms(25);
jmhong 1:04f46755f8af 198 //진동 init_끝
jmhong 1:04f46755f8af 199
jmhong 1:04f46755f8af 200
jmhong 1:04f46755f8af 201 //온도 init_시작
jmhong 1:04f46755f8af 202 //Power supply for the sensor is given from GPIO28(VDD_MCU_B).
jmhong 1:04f46755f8af 203
jmhong 1:04f46755f8af 204 #ifndef CUBEBITE_TEMPERATURE_DISABLE
jmhong 1:04f46755f8af 205 i2c.frequency(100000);
jmhong 1:04f46755f8af 206 #endif
jmhong 1:04f46755f8af 207
jmhong 1:04f46755f8af 208 // JMOD Init
jmhong 1:04f46755f8af 209 #ifndef CUBEBITE_TEMPERATURE_DISABLE
jmhong 1:04f46755f8af 210 wReg[0] = ID_CON_ADDR;
jmhong 1:04f46755f8af 211
jmhong 1:04f46755f8af 212 while(rReg[0] != 0x03)
jmhong 1:04f46755f8af 213 {
jmhong 1:04f46755f8af 214 //write 0x00(ID_CON_ADDR)
jmhong 1:04f46755f8af 215 wReg[1] = 0x00;
jmhong 1:04f46755f8af 216 wACK = i2c.write(busAddr, wReg, 2);
jmhong 0:c2a57b2f934e 217
jmhong 1:04f46755f8af 218 //read 0x00(ID_CON_ADDR)
jmhong 1:04f46755f8af 219 wACK = i2c.write(busAddr, wReg, 1);
jmhong 1:04f46755f8af 220 rACK = i2c.read(busAddr, rReg, 1);
jmhong 1:04f46755f8af 221
jmhong 1:04f46755f8af 222 wait_ms(250);
jmhong 1:04f46755f8af 223
jmhong 1:04f46755f8af 224 //write 0x03(ID_CON_ADDR)
jmhong 1:04f46755f8af 225 wReg[1] = 0x03;
jmhong 1:04f46755f8af 226 wACK = i2c.write(busAddr, wReg, 2);
jmhong 1:04f46755f8af 227
jmhong 1:04f46755f8af 228 //read 0x03(ID_CON_ADDR)
jmhong 1:04f46755f8af 229 wACK = i2c.write(busAddr, wReg, 1);
jmhong 1:04f46755f8af 230 rACK = i2c.read(busAddr, rReg, 1);
jmhong 1:04f46755f8af 231
jmhong 1:04f46755f8af 232 i2c.write(busAddr, wReg, 2);
jmhong 0:c2a57b2f934e 233
jmhong 1:04f46755f8af 234 if(rReg[0] == 0x03)
jmhong 1:04f46755f8af 235 {
jmhong 1:04f46755f8af 236 printf(" (Success!!)\n\n");
jmhong 0:c2a57b2f934e 237
jmhong 1:04f46755f8af 238 //write 0x00(ID_CON_ADDR)
jmhong 1:04f46755f8af 239 wReg[1] = 0x00;
jmhong 1:04f46755f8af 240 wACK = i2c.write(busAddr, wReg, 2);
jmhong 1:04f46755f8af 241 isTempInitOk = true;
jmhong 1:04f46755f8af 242 wait_ms(250);
jmhong 1:04f46755f8af 243 }
jmhong 1:04f46755f8af 244 else if (3 == iTempInitCount)
jmhong 1:04f46755f8af 245 {
jmhong 1:04f46755f8af 246 isTempInitOk = false;
jmhong 1:04f46755f8af 247 break;
jmhong 1:04f46755f8af 248 }
jmhong 1:04f46755f8af 249 else
jmhong 1:04f46755f8af 250 {
jmhong 1:04f46755f8af 251 printf(".");
jmhong 1:04f46755f8af 252 ++iTempInitCount;
jmhong 1:04f46755f8af 253 }
jmhong 1:04f46755f8af 254
jmhong 1:04f46755f8af 255 wait_ms(500);
jmhong 1:04f46755f8af 256 }
jmhong 1:04f46755f8af 257 #endif
jmhong 1:04f46755f8af 258 //온도 init_끝
jmhong 1:04f46755f8af 259
jmhong 1:04f46755f8af 260
jmhong 1:04f46755f8af 261
jmhong 1:04f46755f8af 262 //RF init_시작
jmhong 1:04f46755f8af 263 myspirit.attach_irq_callback(callback_func);
jmhong 1:04f46755f8af 264 if (myspirit.on())
jmhong 1:04f46755f8af 265 {
jmhong 1:04f46755f8af 266 printf("ERROR.\n");
jmhong 1:04f46755f8af 267 }
jmhong 1:04f46755f8af 268 else
jmhong 1:04f46755f8af 269 {
jmhong 1:04f46755f8af 270 printf("OK.\n");
jmhong 1:04f46755f8af 271 }
jmhong 1:04f46755f8af 272 //RF init_끝
jmhong 1:04f46755f8af 273 //*************************************************************************************
jmhong 1:04f46755f8af 274
jmhong 1:04f46755f8af 275
jmhong 1:04f46755f8af 276
jmhong 1:04f46755f8af 277 //*************************************************************************************
jmhong 1:04f46755f8af 278 //HJM SUDO code : 1초 타이머 인터럽트 생성, 1초 간격 호출 함수 : UserTimerInterrupt()
jmhong 1:04f46755f8af 279 //*************************************************************************************
jmhong 1:04f46755f8af 280 // Timeout timeoutUserInterrupt; //1번만 실행
jmhong 1:04f46755f8af 281 // Ticker timeoutUserInterrupt; //매번 실행
jmhong 1:04f46755f8af 282 // timeoutUserInterrupt.attach(&UserTimerInterrupt, 1.0); //1 sec
jmhong 1:04f46755f8af 283 // timeoutUserInterrupt.attach(&UserTimerInterrupt, 3.0); //3 sec
jmhong 1:04f46755f8af 284 //*************************************************************************************
jmhong 1:04f46755f8af 285
jmhong 1:04f46755f8af 286 wait(1);
jmhong 1:04f46755f8af 287
jmhong 1:04f46755f8af 288
jmhong 1:04f46755f8af 289 while(1)
jmhong 1:04f46755f8af 290 {
jmhong 1:04f46755f8af 291 __WFE(); //HJM : sleep 모드 ON
jmhong 1:04f46755f8af 292
jmhong 1:04f46755f8af 293 UserTimerInterrupt_Execution();
jmhong 1:04f46755f8af 294 if (true == isTimerInterruptStarted)
jmhong 1:04f46755f8af 295 {
jmhong 1:04f46755f8af 296 isTimerInterruptStarted = false;
jmhong 1:04f46755f8af 297 SendData(myspirit);
jmhong 1:04f46755f8af 298 }
jmhong 1:04f46755f8af 299 }
jmhong 0:c2a57b2f934e 300
jmhong 0:c2a57b2f934e 301
jmhong 1:04f46755f8af 302 // return 0; //unreachable
jmhong 1:04f46755f8af 303 }
jmhong 0:c2a57b2f934e 304
jmhong 0:c2a57b2f934e 305 static void callback_func(int event)
jmhong 0:c2a57b2f934e 306 {
jmhong 0:c2a57b2f934e 307 #ifdef CUBEBITE_DEBUG
jmhong 0:c2a57b2f934e 308 printf("[CUBEBITE] callback_func(int event) \n");
jmhong 0:c2a57b2f934e 309 #endif
jmhong 0:c2a57b2f934e 310
jmhong 0:c2a57b2f934e 311
jmhong 0:c2a57b2f934e 312 if(event == SimpleSpirit1::RX_DONE)
jmhong 0:c2a57b2f934e 313 {
jmhong 0:c2a57b2f934e 314 bRxDoneFlag = 1;
jmhong 0:c2a57b2f934e 315 }
jmhong 0:c2a57b2f934e 316 else if (event == SimpleSpirit1::TX_DONE)
jmhong 0:c2a57b2f934e 317 {
jmhong 0:c2a57b2f934e 318 bTxDoneFlag = 1;
jmhong 0:c2a57b2f934e 319 }
jmhong 0:c2a57b2f934e 320 }
jmhong 0:c2a57b2f934e 321
jmhong 0:c2a57b2f934e 322
jmhong 0:c2a57b2f934e 323
jmhong 1:04f46755f8af 324 void UserTimerInterrupt(void)
jmhong 0:c2a57b2f934e 325 {
jmhong 1:04f46755f8af 326 //*************************************************************************************
jmhong 1:04f46755f8af 327 //HJM : 타이머 인터럽트 작동 테스트
jmhong 1:04f46755f8af 328 //*************************************************************************************
jmhong 1:04f46755f8af 329 //180329 HJM : 작동 테스트 완료
jmhong 0:c2a57b2f934e 330 #ifdef CUBEBITE_DEBUG
jmhong 1:04f46755f8af 331 led1 = !led1;
jmhong 0:c2a57b2f934e 332 #endif
jmhong 0:c2a57b2f934e 333
jmhong 1:04f46755f8af 334 //*************************************************************************************
jmhong 1:04f46755f8af 335
jmhong 1:04f46755f8af 336 if (false == bIs1SecTimerSet)
jmhong 1:04f46755f8af 337 {
jmhong 1:04f46755f8af 338 bIs1SecTimerSet = true;
jmhong 0:c2a57b2f934e 339 }
jmhong 1:04f46755f8af 340
jmhong 1:04f46755f8af 341 return;
jmhong 0:c2a57b2f934e 342 }
jmhong 0:c2a57b2f934e 343
jmhong 0:c2a57b2f934e 344
jmhong 1:04f46755f8af 345 volatile int iFunctionCallCounting = 0;
jmhong 1:04f46755f8af 346 int UserTimerInterrupt_Execution(void)
jmhong 1:04f46755f8af 347 {
jmhong 1:04f46755f8af 348 // printf("UserTimerInterrupt_Execution 호출, dataCount : [%d]\n", dataCount);
jmhong 1:04f46755f8af 349 ++iFunctionCallCounting;
jmhong 0:c2a57b2f934e 350
jmhong 1:04f46755f8af 351 if (false == isTimerInterruptStarted)
jmhong 0:c2a57b2f934e 352 {
jmhong 1:04f46755f8af 353 //진동
jmhong 1:04f46755f8af 354 adxl362.ACC_GetXYZ8(&x8, &y8, &z8);
jmhong 1:04f46755f8af 355
jmhong 1:04f46755f8af 356 if (0 == x8)
jmhong 1:04f46755f8af 357 {
jmhong 1:04f46755f8af 358 uiSendBuf[dataCount++] = '0';
jmhong 1:04f46755f8af 359 uiSendBuf[dataCount++] = 'x';
jmhong 1:04f46755f8af 360 uiSendBuf[dataCount++] = '@';
jmhong 1:04f46755f8af 361 }
jmhong 1:04f46755f8af 362 else
jmhong 1:04f46755f8af 363 {
jmhong 1:04f46755f8af 364 int8tX8Result = x8;
jmhong 1:04f46755f8af 365
jmhong 1:04f46755f8af 366 uiSendBuf[dataCount++] = (uint8_t)int8tX8Result;
jmhong 1:04f46755f8af 367 }
jmhong 1:04f46755f8af 368
jmhong 1:04f46755f8af 369 if (0 == y8)
jmhong 1:04f46755f8af 370 {
jmhong 1:04f46755f8af 371 uiSendBuf[dataCount++] = '0';
jmhong 1:04f46755f8af 372 uiSendBuf[dataCount++] = 'y';
jmhong 1:04f46755f8af 373 uiSendBuf[dataCount++] = '@';
jmhong 1:04f46755f8af 374 }
jmhong 1:04f46755f8af 375 else
jmhong 1:04f46755f8af 376 {
jmhong 1:04f46755f8af 377 int8tY8Result = y8;
jmhong 1:04f46755f8af 378
jmhong 1:04f46755f8af 379 uiSendBuf[dataCount++] = (uint8_t)int8tY8Result;
jmhong 1:04f46755f8af 380 }
jmhong 1:04f46755f8af 381
jmhong 1:04f46755f8af 382 if (0 == z8)
jmhong 1:04f46755f8af 383 {
jmhong 1:04f46755f8af 384 uiSendBuf[dataCount++] = '0';
jmhong 1:04f46755f8af 385 uiSendBuf[dataCount++] = 'z';
jmhong 1:04f46755f8af 386 uiSendBuf[dataCount++] = '@';
jmhong 1:04f46755f8af 387 }
jmhong 1:04f46755f8af 388 else
jmhong 1:04f46755f8af 389 {
jmhong 1:04f46755f8af 390 int8tZ8Result = z8;
jmhong 1:04f46755f8af 391
jmhong 1:04f46755f8af 392 uiSendBuf[dataCount++] = (uint8_t)int8tZ8Result;
jmhong 1:04f46755f8af 393 }
jmhong 1:04f46755f8af 394
jmhong 1:04f46755f8af 395 // printf("int8tX8Result : %d\n", (uint8_t)int8tX8Result);
jmhong 1:04f46755f8af 396
jmhong 1:04f46755f8af 397 // printf("int8tY8Result : %d\n", (uint8_t)int8tY8Result);
jmhong 1:04f46755f8af 398
jmhong 1:04f46755f8af 399 // printf("int8tZ8Result : %d\n", (uint8_t)int8tZ8Result);
jmhong 1:04f46755f8af 400
jmhong 1:04f46755f8af 401
jmhong 1:04f46755f8af 402
jmhong 0:c2a57b2f934e 403
jmhong 1:04f46755f8af 404 wait(0.025); // 25ms, Wait is required in this mode
jmhong 1:04f46755f8af 405
jmhong 1:04f46755f8af 406 //온도
jmhong 1:04f46755f8af 407 // temperature data receive
jmhong 1:04f46755f8af 408 #ifndef CUBEBITE_TEMPERATURE_DISABLE
jmhong 1:04f46755f8af 409 if (true == isTempInitOk)
jmhong 0:c2a57b2f934e 410 {
jmhong 1:04f46755f8af 411 wReg[0] = ID_DATA_ADDR;
jmhong 1:04f46755f8af 412
jmhong 1:04f46755f8af 413 i2c.write(busAddr, wReg, 1);
jmhong 1:04f46755f8af 414 i2c.read(busAddr, rReg, 2);
jmhong 0:c2a57b2f934e 415
jmhong 1:04f46755f8af 416 Tem16 = (rReg[0] << 8) | (rReg[1]);
jmhong 1:04f46755f8af 417 Tem16 >>= 5;
jmhong 1:04f46755f8af 418 TempData = Tem16;
jmhong 1:04f46755f8af 419
jmhong 1:04f46755f8af 420 TempData = TempData *0.125;
jmhong 1:04f46755f8af 421
jmhong 1:04f46755f8af 422 if (0 == rReg[0])
jmhong 1:04f46755f8af 423 {
jmhong 1:04f46755f8af 424 uiSendBuf[dataCount++] = '0';
jmhong 1:04f46755f8af 425 // uiSendBuf[dataCount++] = '1';
jmhong 1:04f46755f8af 426 }
jmhong 1:04f46755f8af 427 else
jmhong 1:04f46755f8af 428 {
jmhong 1:04f46755f8af 429 uiSendBuf[dataCount++] = (uint8_t)rReg[0];
jmhong 1:04f46755f8af 430 }
jmhong 1:04f46755f8af 431
jmhong 1:04f46755f8af 432 if (0 == rReg[1])
jmhong 1:04f46755f8af 433 {
jmhong 1:04f46755f8af 434 uiSendBuf[dataCount++] = '0';
jmhong 1:04f46755f8af 435 // uiSendBuf[dataCount++] = '2';
jmhong 1:04f46755f8af 436 }
jmhong 1:04f46755f8af 437 else
jmhong 1:04f46755f8af 438 {
jmhong 1:04f46755f8af 439 uiSendBuf[dataCount++] = (uint8_t)rReg[1];
jmhong 1:04f46755f8af 440 }
jmhong 1:04f46755f8af 441 }
jmhong 1:04f46755f8af 442 else
jmhong 1:04f46755f8af 443 {
jmhong 1:04f46755f8af 444 uiSendBuf[dataCount++] = '0';
jmhong 1:04f46755f8af 445 uiSendBuf[dataCount++] = '0';
jmhong 1:04f46755f8af 446 }
jmhong 1:04f46755f8af 447
jmhong 0:c2a57b2f934e 448
jmhong 1:04f46755f8af 449 #else //온도 안쓰면,
jmhong 1:04f46755f8af 450 uiSendBuf[dataCount++] = '0';
jmhong 1:04f46755f8af 451 uiSendBuf[dataCount++] = '0';
jmhong 1:04f46755f8af 452 #endif
jmhong 1:04f46755f8af 453
jmhong 1:04f46755f8af 454 #ifdef CUBEBITE_DEBUG
jmhong 1:04f46755f8af 455 printf("!!!!!!!!!!!!!! cFileWriteData : %d@%d@%d@%f\n", x8, y8, z8, TempData);
jmhong 1:04f46755f8af 456 #endif //CUBEBITE_DEBUG
jmhong 1:04f46755f8af 457
jmhong 1:04f46755f8af 458
jmhong 1:04f46755f8af 459 // printf("iFunctionCallCounting : [%d]\n", iFunctionCallCounting);
jmhong 1:04f46755f8af 460
jmhong 1:04f46755f8af 461 uiSendBuf[dataCount++] = '#';
jmhong 1:04f46755f8af 462 uiSendBuf[dataCount++] = '#';
jmhong 0:c2a57b2f934e 463
jmhong 1:04f46755f8af 464 wait(0.025); // 25ms, Wait is required in this mode
jmhong 1:04f46755f8af 465
jmhong 0:c2a57b2f934e 466 }
jmhong 1:04f46755f8af 467
jmhong 1:04f46755f8af 468 if (iFunctionCallCounting >= 10) //10번의 측정이 끝나면,
jmhong 1:04f46755f8af 469 {
jmhong 1:04f46755f8af 470 isTimerInterruptStarted = true;
jmhong 1:04f46755f8af 471 // printf("if in!!\n");
jmhong 1:04f46755f8af 472
jmhong 1:04f46755f8af 473 uiSendBuf[dataCount++] = '*';
jmhong 1:04f46755f8af 474 uiSendBuf[dataCount++] = '*';
jmhong 1:04f46755f8af 475
jmhong 1:04f46755f8af 476 uiSendBuf[dataCount] = CUBEBITE_SENSOR_UUID;
jmhong 1:04f46755f8af 477
jmhong 1:04f46755f8af 478 iFunctionCallCounting = 0;
jmhong 1:04f46755f8af 479 }
jmhong 1:04f46755f8af 480
jmhong 1:04f46755f8af 481 return 0;
jmhong 0:c2a57b2f934e 482 }
jmhong 0:c2a57b2f934e 483
jmhong 0:c2a57b2f934e 484
jmhong 0:c2a57b2f934e 485
jmhong 0:c2a57b2f934e 486
jmhong 0:c2a57b2f934e 487
jmhong 0:c2a57b2f934e 488
jmhong 1:04f46755f8af 489
jmhong 1:04f46755f8af 490
jmhong 1:04f46755f8af 491
jmhong 0:c2a57b2f934e 492
jmhong 0:c2a57b2f934e 493
jmhong 0:c2a57b2f934e 494
jmhong 0:c2a57b2f934e 495
jmhong 0:c2a57b2f934e 496
jmhong 0:c2a57b2f934e 497
jmhong 0:c2a57b2f934e 498 /**
jmhong 0:c2a57b2f934e 499 * @brief SendData
jmhong 0:c2a57b2f934e 500 * @param None
jmhong 0:c2a57b2f934e 501 * @retval None
jmhong 0:c2a57b2f934e 502 */
jmhong 0:c2a57b2f934e 503 static int SendData(SimpleSpirit1& myspirit)
jmhong 0:c2a57b2f934e 504 {
jmhong 1:04f46755f8af 505 #ifdef CUBEBITE_DEBUG
jmhong 1:04f46755f8af 506 printf("=========================================\n");
jmhong 1:04f46755f8af 507 #endif //CUBEBITE_DEBUG
jmhong 0:c2a57b2f934e 508
jmhong 1:04f46755f8af 509 #ifdef CUBEBITE_DEBUG
jmhong 1:04f46755f8af 510 printf("[CUBEBITE] SendData() 호출 됨.\n");
jmhong 1:04f46755f8af 511 #endif //CUBEBITE_DEBUG
jmhong 1:04f46755f8af 512
jmhong 1:04f46755f8af 513 int iRet;
jmhong 1:04f46755f8af 514 while(myspirit.is_receiving()); /* wait for ongoing RX ends 180110 HJM 아마 이 전에 보내던 거 마저 다 보내려고 하는 거 같다. */
jmhong 1:04f46755f8af 515
jmhong 0:c2a57b2f934e 516 size_t curr_len = strlen((const char*)uiSendBuf) + 1;
jmhong 1:04f46755f8af 517 // printf("curr_len : [%d]\n", curr_len);
jmhong 1:04f46755f8af 518
jmhong 1:04f46755f8af 519
jmhong 1:04f46755f8af 520 iRet = myspirit.send(uiSendBuf, curr_len);
jmhong 1:04f46755f8af 521
jmhong 1:04f46755f8af 522
jmhong 1:04f46755f8af 523 dataCount = 0;
jmhong 1:04f46755f8af 524 for (int iTemp = 0; iTemp < TEST_STR_LEN; ++iTemp)
jmhong 1:04f46755f8af 525 {
jmhong 1:04f46755f8af 526 uiSendBuf[iTemp] = 0;
jmhong 1:04f46755f8af 527 }
jmhong 1:04f46755f8af 528
jmhong 1:04f46755f8af 529 // static uint8_t uiRFSpeedTestSendBuf[MAX_BUFFER_LEN] = { 0, }; //70 Byte //성공
jmhong 0:c2a57b2f934e 530
jmhong 1:04f46755f8af 531 // sprintf((char *)uiRFSpeedTestSendBuf, "%f@%f@%f@%f@%f", G_x, G_y, G_z, Output, TempData); //HJM : 데이터 파싱 용
jmhong 1:04f46755f8af 532 // sprintf((char *)uiRFSpeedTestSendBuf, "%.2f@%.2f@%.2f@%.2lf@%.2f@%d", G_x, G_y, G_z, dVibOutputSqrt, TempData, CUBEBITE_SENSOR_UUID); //HJM : 데이터 파싱 용
jmhong 1:04f46755f8af 533 // printf("%.2f@%.2f@%.2f@%.2lf@%.2f@%d\n\n", G_x, G_y, G_z, dVibOutputSqrt, TempData, CUBEBITE_SENSOR_UUID);
jmhong 1:04f46755f8af 534
jmhong 1:04f46755f8af 535 //서버 에서 split 처리 시, 아래와 같음.
jmhong 1:04f46755f8af 536 //0 -> 진동 x 축 값
jmhong 1:04f46755f8af 537 //1 -> 진동 y 축 값
jmhong 1:04f46755f8af 538 //2 -> 진동 z 축 값
jmhong 1:04f46755f8af 539 //3 -> 온도 값
jmhong 1:04f46755f8af 540 //
jmhong 1:04f46755f8af 541
jmhong 1:04f46755f8af 542 // iRet = myspirit.send(uiSendBuf, curr_len);
jmhong 0:c2a57b2f934e 543 if (iRet == RADIO_TX_OK)
jmhong 0:c2a57b2f934e 544 {
jmhong 1:04f46755f8af 545 return RADIO_TX_OK;
jmhong 0:c2a57b2f934e 546 }
jmhong 0:c2a57b2f934e 547 else if (iRet == RADIO_TX_ERR)
jmhong 0:c2a57b2f934e 548 {
jmhong 1:04f46755f8af 549 return RADIO_TX_ERR;
jmhong 0:c2a57b2f934e 550 }
jmhong 0:c2a57b2f934e 551 else if (iRet == RADIO_TX_COLLISION)
jmhong 1:04f46755f8af 552 {
jmhong 1:04f46755f8af 553 return RADIO_TX_COLLISION;
jmhong 0:c2a57b2f934e 554 }
jmhong 0:c2a57b2f934e 555 else if (iRet == RADIO_TX_NOACK)
jmhong 0:c2a57b2f934e 556 {
jmhong 1:04f46755f8af 557 return RADIO_TX_NOACK;
jmhong 0:c2a57b2f934e 558 }
jmhong 1:04f46755f8af 559 else if (iRet == RADIO_TX_ERR_RESET)
jmhong 1:04f46755f8af 560 {
jmhong 1:04f46755f8af 561 printf("RADIO_TX_ERR_RESET return.\n");
jmhong 1:04f46755f8af 562 // myspirit.off();
jmhong 1:04f46755f8af 563 myspirit.reset_board();
jmhong 1:04f46755f8af 564 myspirit.off();
jmhong 1:04f46755f8af 565 myspirit.on();
jmhong 1:04f46755f8af 566 }
jmhong 1:04f46755f8af 567
jmhong 1:04f46755f8af 568 dataCount = 0;
jmhong 1:04f46755f8af 569
jmhong 1:04f46755f8af 570 for (int iTemp = 0; iTemp < TEST_STR_LEN; ++iTemp)
jmhong 1:04f46755f8af 571 {
jmhong 1:04f46755f8af 572 uiSendBuf[iTemp] = 0;
jmhong 1:04f46755f8af 573 }
jmhong 1:04f46755f8af 574
jmhong 0:c2a57b2f934e 575
jmhong 0:c2a57b2f934e 576 #ifdef CUBEBITE_DEBUG
jmhong 0:c2a57b2f934e 577 printf("[CUBEBITE] SendData() 호출 끝.\n");
jmhong 0:c2a57b2f934e 578 #endif
jmhong 0:c2a57b2f934e 579
jmhong 1:04f46755f8af 580 return -10;
jmhong 0:c2a57b2f934e 581 }
jmhong 0:c2a57b2f934e 582
jmhong 0:c2a57b2f934e 583
jmhong 0:c2a57b2f934e 584