ユースケース変更後に試験を行いましたが,レビュー後に再び変更する可能性があります
bundle_photo_data_downlink.cpp@0:393297a738c5, 2017-09-03 (annotated)
- Committer:
- yousei
- Date:
- Sun Sep 03 01:05:38 2017 +0000
- Revision:
- 0:393297a738c5
?????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yousei | 0:393297a738c5 | 1 | #include "mbed.h" |
yousei | 0:393297a738c5 | 2 | #include "type_define.h" |
yousei | 0:393297a738c5 | 3 | #include "bundle_photo_data_downlink.h" |
yousei | 0:393297a738c5 | 4 | #include "fm_dd.h" |
yousei | 0:393297a738c5 | 5 | #include "missionDR.h" |
yousei | 0:393297a738c5 | 6 | |
yousei | 0:393297a738c5 | 7 | #pragma diag_suppress 870 |
yousei | 0:393297a738c5 | 8 | |
yousei | 0:393297a738c5 | 9 | Timer BPDDtimer; |
yousei | 0:393297a738c5 | 10 | |
yousei | 0:393297a738c5 | 11 | Fm transmitter; |
yousei | 0:393297a738c5 | 12 | MissionDR dr; |
yousei | 0:393297a738c5 | 13 | |
yousei | 0:393297a738c5 | 14 | BPDD::BPDD()//コンストラクタ |
yousei | 0:393297a738c5 | 15 | { |
yousei | 0:393297a738c5 | 16 | flag_BPDD=0; |
yousei | 0:393297a738c5 | 17 | permit[0]=0; |
yousei | 0:393297a738c5 | 18 | permit[1]=0; |
yousei | 0:393297a738c5 | 19 | permit[2]=0; |
yousei | 0:393297a738c5 | 20 | permit[3]=0; |
yousei | 0:393297a738c5 | 21 | camera_id=0; |
yousei | 0:393297a738c5 | 22 | downlink_num=1;//最低1回は送信するので |
yousei | 0:393297a738c5 | 23 | downlink_cnt=0; |
yousei | 0:393297a738c5 | 24 | com_style=0; |
yousei | 0:393297a738c5 | 25 | save_data_id=1; |
yousei | 0:393297a738c5 | 26 | readout_block_num=0; |
yousei | 0:393297a738c5 | 27 | send_cnt=0; |
yousei | 0:393297a738c5 | 28 | num_repeat=0; |
yousei | 0:393297a738c5 | 29 | total_cnt=0; |
yousei | 0:393297a738c5 | 30 | size=1;//デバッグ |
yousei | 0:393297a738c5 | 31 | block_num=0; |
yousei | 0:393297a738c5 | 32 | |
yousei | 0:393297a738c5 | 33 | } |
yousei | 0:393297a738c5 | 34 | |
yousei | 0:393297a738c5 | 35 | void BPDD::photo_info_sending(void) |
yousei | 0:393297a738c5 | 36 | { |
yousei | 0:393297a738c5 | 37 | uint8_t photo_info[512]= {0}; |
yousei | 0:393297a738c5 | 38 | uint8_t first_telemetry[128]= {0}; |
yousei | 0:393297a738c5 | 39 | |
yousei | 0:393297a738c5 | 40 | bpdd_debug_printf("photo info readout process\r\n"); |
yousei | 0:393297a738c5 | 41 | bpdd_debug_printf("save_data_id(in photo info sending func):%d\r\n",save_data_id); |
yousei | 0:393297a738c5 | 42 | block_num = 1 + save_data_id*321; |
yousei | 0:393297a738c5 | 43 | bpdd_debug_printf("block num for photo info:%d\r\n",block_num); |
yousei | 0:393297a738c5 | 44 | //dr.read(photo_info,block_num,1); |
yousei | 0:393297a738c5 | 45 | bpdd_debug_printf("photo info reading...\r\n"); |
yousei | 0:393297a738c5 | 46 | |
yousei | 0:393297a738c5 | 47 | size = photo_info[4+camera_id];//DRマップ参照のこと |
yousei | 0:393297a738c5 | 48 | size=2;//SDに0しか書かれていなくて困るので、今だけ |
yousei | 0:393297a738c5 | 49 | |
yousei | 0:393297a738c5 | 50 | //bpdd_debug_printf("画像サイズ(ブロック):%d\r\n",size); |
yousei | 0:393297a738c5 | 51 | |
yousei | 0:393297a738c5 | 52 | first_telemetry[0] = 3;//テレメトリID |
yousei | 0:393297a738c5 | 53 | first_telemetry[1] = camera_id+1;//カメラ番号(1~4) |
yousei | 0:393297a738c5 | 54 | first_telemetry[2] = save_data_id+1;//画像保存データID(1~10) |
yousei | 0:393297a738c5 | 55 | for(int i=3; i<34; i++) { |
yousei | 0:393297a738c5 | 56 | first_telemetry[i]=photo_info[i-3];//RTC時刻(4byte)画像容量(4byte),姿勢データ(24byte)を保存 |
yousei | 0:393297a738c5 | 57 | } |
yousei | 0:393297a738c5 | 58 | bpdd_debug_printf("first telemetly has formed\r\n"); |
yousei | 0:393297a738c5 | 59 | |
yousei | 0:393297a738c5 | 60 | /*printf("first telemetry of photo data\r\n"); |
yousei | 0:393297a738c5 | 61 | for(int i=0;i<128;i++){ |
yousei | 0:393297a738c5 | 62 | printf("%d,",first_telemetry[i]); |
yousei | 0:393297a738c5 | 63 | }*/ |
yousei | 0:393297a738c5 | 64 | |
yousei | 0:393297a738c5 | 65 | transmitter.baud(com_style); |
yousei | 0:393297a738c5 | 66 | //transmitter.send(first_telemetry,128); |
yousei | 0:393297a738c5 | 67 | printf("first telemetly sended\r\n"); |
yousei | 0:393297a738c5 | 68 | block_num=block_num+1+80*camera_id;//画像データ保存先へ移動 |
yousei | 0:393297a738c5 | 69 | printf("block_num:%d\r\n",block_num); |
yousei | 0:393297a738c5 | 70 | num_repeat++; |
yousei | 0:393297a738c5 | 71 | //printf("photo info processing time:%d\r\n",BPDDtimer.read_ms()); |
yousei | 0:393297a738c5 | 72 | } |
yousei | 0:393297a738c5 | 73 | |
yousei | 0:393297a738c5 | 74 | void BPDD::photo_data_AFSK_sending(void) |
yousei | 0:393297a738c5 | 75 | { |
yousei | 0:393297a738c5 | 76 | bpdd_debug_printf("send_cnt:%d\r\n",send_cnt); |
yousei | 0:393297a738c5 | 77 | uint8_t photo_data_AFSK[512]= {0}; |
yousei | 0:393297a738c5 | 78 | uint8_t photo_packet_afsk[128]= {0}; |
yousei | 0:393297a738c5 | 79 | printf("block_num : %d\r\n",block_num); |
yousei | 0:393297a738c5 | 80 | if(send_cnt<=4) { |
yousei | 0:393297a738c5 | 81 | if(send_cnt==0) { |
yousei | 0:393297a738c5 | 82 | //dr.read(photo_data_AFSK,block_num,1); |
yousei | 0:393297a738c5 | 83 | bpdd_debug_printf("photo data reading...\r\n"); |
yousei | 0:393297a738c5 | 84 | } |
yousei | 0:393297a738c5 | 85 | /*printf("photo data\r\n"); |
yousei | 0:393297a738c5 | 86 | for(int i=0;i<512;i++){ |
yousei | 0:393297a738c5 | 87 | printf("%d,",photo_data[i]); |
yousei | 0:393297a738c5 | 88 | }*/ |
yousei | 0:393297a738c5 | 89 | for(int i=0; i<128; i++) { |
yousei | 0:393297a738c5 | 90 | photo_packet_afsk[i]=photo_data_AFSK[i+128*send_cnt]; |
yousei | 0:393297a738c5 | 91 | } |
yousei | 0:393297a738c5 | 92 | //transmitter.baud(com_style); |
yousei | 0:393297a738c5 | 93 | //transmitter.send(photo_packet_afsk,128); |
yousei | 0:393297a738c5 | 94 | bpdd_debug_printf("photo data sending...\r\n"); |
yousei | 0:393297a738c5 | 95 | send_cnt++; |
yousei | 0:393297a738c5 | 96 | //printf("%dブロック目、%dパケット目送信完了\r\n",block_num,send_cnt); |
yousei | 0:393297a738c5 | 97 | num_repeat++; |
yousei | 0:393297a738c5 | 98 | //printf("AFSK photo data send processing time:%d\r\n",BPDDtimer.read_ms()); |
yousei | 0:393297a738c5 | 99 | if(send_cnt>=4) { |
yousei | 0:393297a738c5 | 100 | printf("%dblock sended\r\n",block_num); |
yousei | 0:393297a738c5 | 101 | send_cnt=0; |
yousei | 0:393297a738c5 | 102 | readout_block_num++; |
yousei | 0:393297a738c5 | 103 | block_num++; |
yousei | 0:393297a738c5 | 104 | //printf("block number send processing time:%d\r\n",BPDDtimer.read_ms()); |
yousei | 0:393297a738c5 | 105 | |
yousei | 0:393297a738c5 | 106 | //bpdd_debug_printf("readout_block_num:%d\r\n",readout_block_num); |
yousei | 0:393297a738c5 | 107 | //printf("num_repeat:%d\r\n",num_repeat); |
yousei | 0:393297a738c5 | 108 | } |
yousei | 0:393297a738c5 | 109 | } |
yousei | 0:393297a738c5 | 110 | } |
yousei | 0:393297a738c5 | 111 | |
yousei | 0:393297a738c5 | 112 | void BPDD::photo_data_GFSK_sending(void) |
yousei | 0:393297a738c5 | 113 | { |
yousei | 0:393297a738c5 | 114 | bpdd_debug_printf("GMSK or rapid communication process\r\n"); |
yousei | 0:393297a738c5 | 115 | |
yousei | 0:393297a738c5 | 116 | uint8_t photo_data_GFSK[512]= {0}; |
yousei | 0:393297a738c5 | 117 | uint8_t photo_packet1[256]= {0}; |
yousei | 0:393297a738c5 | 118 | uint8_t photo_packet2[256]= {0}; |
yousei | 0:393297a738c5 | 119 | ///dr.read(photo_data_GFSK,block_num,1); |
yousei | 0:393297a738c5 | 120 | for(int i = 0; i<256; i++) { |
yousei | 0:393297a738c5 | 121 | photo_packet1[i] = photo_data_GFSK[i]; |
yousei | 0:393297a738c5 | 122 | photo_packet2[i] = photo_data_GFSK[i+256]; |
yousei | 0:393297a738c5 | 123 | } |
yousei | 0:393297a738c5 | 124 | transmitter.baud(com_style); |
yousei | 0:393297a738c5 | 125 | transmitter.send(photo_packet1,256); |
yousei | 0:393297a738c5 | 126 | transmitter.send(photo_packet2,256); |
yousei | 0:393297a738c5 | 127 | |
yousei | 0:393297a738c5 | 128 | printf("%d sending complete\r\n",block_num); |
yousei | 0:393297a738c5 | 129 | num_repeat++; |
yousei | 0:393297a738c5 | 130 | readout_block_num++; |
yousei | 0:393297a738c5 | 131 | block_num++; |
yousei | 0:393297a738c5 | 132 | //printf("GFSK photo data send processing time:%d\r\n",BPDDtimer.read_ms()); |
yousei | 0:393297a738c5 | 133 | } |
yousei | 0:393297a738c5 | 134 | |
yousei | 0:393297a738c5 | 135 | |
yousei | 0:393297a738c5 | 136 | bool BPDD::bundle_photo_data_downlink(u8* uart_data) |
yousei | 0:393297a738c5 | 137 | { |
yousei | 0:393297a738c5 | 138 | BPDDtimer.reset(); |
yousei | 0:393297a738c5 | 139 | BPDDtimer.start(); |
yousei | 0:393297a738c5 | 140 | |
yousei | 0:393297a738c5 | 141 | //printf("%dループ目\r\n",num_repeat+1); |
yousei | 0:393297a738c5 | 142 | |
yousei | 0:393297a738c5 | 143 | if(total_cnt==0) { |
yousei | 0:393297a738c5 | 144 | uint8_t p=0; |
yousei | 0:393297a738c5 | 145 | for(int i=0; i<4; i++) { |
yousei | 0:393297a738c5 | 146 | p=uart_data[6]<<(7-i); |
yousei | 0:393297a738c5 | 147 | permit[i]=p>>7; |
yousei | 0:393297a738c5 | 148 | } |
yousei | 0:393297a738c5 | 149 | |
yousei | 0:393297a738c5 | 150 | save_data_id = uart_data[3]; |
yousei | 0:393297a738c5 | 151 | com_style = uart_data[4]<<5; |
yousei | 0:393297a738c5 | 152 | com_style = com_style>>5; |
yousei | 0:393297a738c5 | 153 | downlink_num = uart_data[4]>>6; |
yousei | 0:393297a738c5 | 154 | |
yousei | 0:393297a738c5 | 155 | printf("%d,%d,%d,%d\r\n",permit[0],permit[1],permit[2],permit[3]);//test |
yousei | 0:393297a738c5 | 156 | printf("save_data_ID:%d\r\n",save_data_id);//test |
yousei | 0:393297a738c5 | 157 | printf("com_style%d\r\n",com_style);//test |
yousei | 0:393297a738c5 | 158 | printf("downlink_num:%d\r\n",downlink_num);//test |
yousei | 0:393297a738c5 | 159 | } |
yousei | 0:393297a738c5 | 160 | |
yousei | 0:393297a738c5 | 161 | total_cnt++; |
yousei | 0:393297a738c5 | 162 | |
yousei | 0:393297a738c5 | 163 | for(int i=0; i<4; i++) { |
yousei | 0:393297a738c5 | 164 | if(permit[3-i]==1) { |
yousei | 0:393297a738c5 | 165 | camera_id=3-i; |
yousei | 0:393297a738c5 | 166 | } |
yousei | 0:393297a738c5 | 167 | } |
yousei | 0:393297a738c5 | 168 | bpdd_debug_printf("camera_id is %d\r\n",camera_id); |
yousei | 0:393297a738c5 | 169 | //printf("カメラID:%d\r\n",camera_id);//test |
yousei | 0:393297a738c5 | 170 | bpdd_debug_printf("num_repeat is %d\r\n",num_repeat); |
yousei | 0:393297a738c5 | 171 | if(num_repeat == 0) { |
yousei | 0:393297a738c5 | 172 | bpdd_debug_printf("photo info sending process\r\n"); |
yousei | 0:393297a738c5 | 173 | photo_info_sending(); |
yousei | 0:393297a738c5 | 174 | } else { |
yousei | 0:393297a738c5 | 175 | bpdd_debug_printf("photo data sending process\r\n"); |
yousei | 0:393297a738c5 | 176 | printf("downlink_cnt :%d,downlink_num :%d\r\n",downlink_cnt,downlink_num); |
yousei | 0:393297a738c5 | 177 | printf("com_style is %d\r\n",com_style); |
yousei | 0:393297a738c5 | 178 | if(downlink_cnt<downlink_num) { //分割データ送信回数回データを送る |
yousei | 0:393297a738c5 | 179 | if(com_style == 0) { |
yousei | 0:393297a738c5 | 180 | printf("AFSK sending process\r\n"); |
yousei | 0:393297a738c5 | 181 | photo_data_AFSK_sending(); |
yousei | 0:393297a738c5 | 182 | } else { |
yousei | 0:393297a738c5 | 183 | photo_data_GFSK_sending(); |
yousei | 0:393297a738c5 | 184 | } |
yousei | 0:393297a738c5 | 185 | }else{ |
yousei | 0:393297a738c5 | 186 | printf("downlink count is not inputed\r\n"); |
yousei | 0:393297a738c5 | 187 | return 1;//ダウンリンクする回数が指定されていなかったとき用の例外処理 |
yousei | 0:393297a738c5 | 188 | } |
yousei | 0:393297a738c5 | 189 | } |
yousei | 0:393297a738c5 | 190 | |
yousei | 0:393297a738c5 | 191 | if(readout_block_num == size) { //読み出したブロックの数と画像のブロックサイズが一致している |
yousei | 0:393297a738c5 | 192 | downlink_cnt++; |
yousei | 0:393297a738c5 | 193 | readout_block_num=0; |
yousei | 0:393297a738c5 | 194 | //if(num_repeat-1==downlink_num*4*readout_block_num||downlink_num*readout_block_num == num_repeat-1) { //画像を実際送信した回数と指定した送信回数が一致している(cnt実装前)} |
yousei | 0:393297a738c5 | 195 | if(downlink_cnt>=downlink_num) { |
yousei | 0:393297a738c5 | 196 | permit[camera_id]=0; |
yousei | 0:393297a738c5 | 197 | downlink_cnt=0; |
yousei | 0:393297a738c5 | 198 | num_repeat=0; |
yousei | 0:393297a738c5 | 199 | if((permit[0]|permit[1]|permit[2]|permit[3])==0) { |
yousei | 0:393297a738c5 | 200 | printf("permit=%d\r\n",permit[0]|permit[1]|permit[2]|permit[3]); |
yousei | 0:393297a738c5 | 201 | total_cnt=0; |
yousei | 0:393297a738c5 | 202 | printf("mission complete!\r\n"); |
yousei | 0:393297a738c5 | 203 | flag_BPDD = 1; |
yousei | 0:393297a738c5 | 204 | } else { |
yousei | 0:393297a738c5 | 205 | flag_BPDD = 0; |
yousei | 0:393297a738c5 | 206 | } |
yousei | 0:393297a738c5 | 207 | } else { |
yousei | 0:393297a738c5 | 208 | flag_BPDD = 0; |
yousei | 0:393297a738c5 | 209 | } |
yousei | 0:393297a738c5 | 210 | } else { |
yousei | 0:393297a738c5 | 211 | flag_BPDD = 0; |
yousei | 0:393297a738c5 | 212 | } |
yousei | 0:393297a738c5 | 213 | |
yousei | 0:393297a738c5 | 214 | return flag_BPDD; |
yousei | 0:393297a738c5 | 215 | } |