// 充电-CCS-充电机充电状态 int gen_packet_PGN4608(struct charge_job * thiz, struct bms_event_struct* param) { struct can_pack_generator *gen = gen_search(thiz->bms.generator, thiz->bms.can_pack_gen_nr, PGN_CCS); struct pgn4608_CCS ccs; struct charge_task *tsk = thiz->tsk; if ( thiz->job_gun_sn == GUN_SN0 ) { ccs.spn3081_output_voltage = b2l(tsk->measure[0]->measure.VinKM0); ccs.spn3082_output_current = thiz->bms.bms_all_battery_status.spn3076_charge_current; //ccs.spn3082_output_current = (b2l(tsk->measure[0]->measure.IoutBAT0)-400)*10; } else if ( thiz->job_gun_sn == GUN_SN1 ) { ccs.spn3081_output_voltage = b2l(tsk->measure[0]->measure.VinKM1); ccs.spn3082_output_current = (b2l(tsk->measure[0]->measure.IoutBAT1)-400)*10; } ccs.spn3083_charge_time = (thiz->charged_seconds + thiz->section_seconds)/60; log_printf(INF, "BMS.CCS: %.1f V, %.1f(%X) A", (double)ccs.spn3081_output_voltage/10, (ccs.spn3082_output_current-4000)/-10.0, ccs.spn3082_output_current); memset(param->buff.tx_buff, 0xFF, 8); memcpy((void * __restrict__)param->buff.tx_buff, &ccs, sizeof(struct pgn4608_CCS)); param->buff_payload = gen->datalen; param->can_id = gen->prioriy << 26 | gen->can_pgn << 8 | CAN_TX_ID_MASK | CAN_EFF_FLAG; param->evt_param = EVT_RET_OK; gen->can_counter ++; return 0; }
// 充电-CCS-充电机充电状态 int gen_packet_PGN4608(struct charge_job * thiz, struct bms_event_struct* param) { struct can_pack_generator *gen = gen_search(thiz->bms.generator, thiz->bms.can_pack_gen_nr, PGN_CCS); struct pgn4608_CCS ccs; struct charge_task *tsk = thiz->tsk; memset(&ccs, 0, sizeof(ccs)); if ( thiz->job_gun_sn == GUN_SN0 ) { if ( tsk->measure[0] ) { ccs.spn3081_output_voltage = b2l(tsk->measure[0]->measure.VinKM0); ccs.spn3082_output_current = (400-b2l(tsk->measure[0]->measure.IoutBAT0))*10; } else { log_printf(ERR, "crash %d", __LINE__); } } else if ( thiz->job_gun_sn == GUN_SN1 ) { if ( tsk->measure[0] ) { ccs.spn3081_output_voltage = b2l(tsk->measure[0]->measure.VinKM1); ccs.spn3082_output_current = (400-b2l(tsk->measure[0]->measure.IoutBAT1))*10; } else { log_printf(ERR, "crash %d", __LINE__); } } ccs.spn3083_charge_time = (thiz->charged_seconds + thiz->section_seconds)/60; log_printf(DBG_LV3, "BMS.CCS: %.1f V, %.1f(%X) A", (double)ccs.spn3081_output_voltage/10, (ccs.spn3082_output_current-4000)/-10.0, ccs.spn3082_output_current); memset(param->buff.tx_buff, 0xFF, 8); memcpy((void * __restrict__)param->buff.tx_buff, &ccs, sizeof(struct pgn4608_CCS)); param->buff_payload = gen->datalen; param->can_id = gen->prioriy << 26 | gen->can_pgn << 8 | CAN_TX_ID_MASK | CAN_EFF_FLAG; if ( !bit_read(thiz, JF_CHG_TRM_CHARGE) && !bit_read(thiz, JF_BMS_TRM_CHARGE) ) { if ( bit_read(thiz, JF_BMS_RX_BCS) && bit_read(thiz, JF_BMS_RX_BCL) ) { param->evt_param = EVT_RET_OK; gen->can_counter ++; bit_set(thiz, JF_BMS_TX_CCS); } else { param->evt_param = EVT_RET_INVALID; } } else { param->evt_param = EVT_RET_INVALID; } return 0; }
/* fixed xor: xor two equal-length buffers together and print output */ std::string problem02() { BinaryBlob b2l("1c0111001f010100061a024b53535009181c", 16); BinaryBlob b2r("686974207468652062756c6c277320657965", 16); BinaryBlob b2 = b2l ^ b2r; return b2.hex(); }
int32_t collectAtoms(FILE *fp, size_t parentAtomSize, size_t child) { uint32_t i; size_t atomSize, totalAtomSize = 0; uint32_t timeScale = 0, duration = 0; FILE fp_tmp; uint8_t atombuf[512]; do{ memset(atombuf, '\0', sizeof(atombuf)); atomSize = getSampleSize(atombuf, 8, fp); // 4B Size 4B Atoma printf("\r\n"); for(i = child;i > 0;i--){ printf(" "); } printf("%s %d", (char*)&atombuf[4], atomSize); for(i = 0;i < ATOM_ITEMS;i++){ if(strncmp((char*)&atombuf[4], (char*)&atomTypeString[i][0], 4) == 0) { if(atomHasChild[i]){printf(" +"); } break; } } if(i >= ATOM_ITEMS){ // unrecognized atom if(atomSize == 0){ return -1; } goto NEXT; } memcpy((void*)&fp_tmp, (void*)fp, sizeof(FILE)); switch(i){ case MDHD: f_lseek(fp,fp->fptr+12); // skip ver/flag creationtime modificationtime timeScale = getSampleSize(atombuf, 4, fp); // time scale duration = getSampleSize(atombuf, 4, fp); // duration break; case HDLR: f_lseek(fp,fp->fptr+4); // skip flag ver read_file (fp, (uint8_t*)atombuf,4);// Component type read_file(fp, (uint8_t*)atombuf,4); // Component subtype if(!strncmp((char*)atombuf, (const char*)"soun", 4)){ media.sound.flag.process = 1; media.sound.timeScale = timeScale; media.sound.duration = duration; } if(!strncmp((char*)atombuf, (const char*)"vide", 4)){ media.video.flag.process = 1; media.video.timeScale = timeScale; media.video.duration = duration; } break; case TKHD: f_lseek(fp,fp->fptr+74); // skip till width, height data read_file(fp, (uint8_t*)atombuf,4); // width if(getAtomSize(atombuf)){ media.video.width = getAtomSize(atombuf); } read_file(fp, (uint8_t*)atombuf,4); // height if(getAtomSize(atombuf)){ media.video.height = getAtomSize(atombuf); } break; case STSD: f_lseek(fp,fp->fptr+8); // skip Reserved(6bytes)/Data Reference Index read_file(fp, (uint8_t*)atombuf,4); // next atom size read_file(fp, (uint8_t*)atombuf, getAtomSize(atombuf) - 4); if(media.video.flag.process && !media.video.flag.complete){ memset((void*)media.video.videoFmtString, '\0', sizeof(media.video.videoFmtString)); memset((void*)media.video.videoCmpString, '\0', sizeof(media.video.videoCmpString)); memcpy((void*)media.video.videoFmtString, (void*)atombuf, 4); memcpy((void*)media.video.videoCmpString, (void*)&atombuf[47], atombuf[46]); if(strncmp((char*)media.video.videoFmtString, "jpeg", 4) == 0) { media.video.playJpeg = 1; // JPEG } else { media.video.playJpeg = 0; // Uncompression } } if(media.sound.flag.process && !media.sound.flag.complete){ memcpy((void*)&media.sound.format, (void*)atombuf, sizeof(sound_format)); media.sound.format.version = (uint16_t)b2l((void*)&media.sound.format.version, sizeof(uint16_t)); media.sound.format.revision = (uint16_t)b2l((void*)&media.sound.format.revision, sizeof(media.sound.format.revision)); media.sound.format.vendor = (uint16_t)b2l((void*)&media.sound.format.vendor, sizeof(media.sound.format.vendor)); media.sound.format.numChannel = (uint16_t)b2l((void*)&media.sound.format.numChannel, sizeof(media.sound.format.numChannel)); media.sound.format.sampleSize = (uint16_t)b2l((void*)&media.sound.format.sampleSize, sizeof(media.sound.format.sampleSize)); media.sound.format.complesionID = (uint16_t)b2l((void*)&media.sound.format.complesionID, sizeof(media.sound.format.complesionID)); media.sound.format.packetSize = (uint16_t)b2l((void*)&media.sound.format.packetSize, sizeof(media.sound.format.packetSize)); media.sound.format.sampleRate = (uint16_t)b2l((void*)&media.sound.format.sampleRate, sizeof(uint16_t)); } break; case STTS: f_lseek(fp,fp->fptr+ 4); // skip flag ver if(media.video.flag.process && !media.video.flag.complete){ video_stts.numEntry = getSampleSize(atombuf, 4, fp); memcpy((void*)&video_stts.fp, (void*)fp, sizeof(FILE)); } if(media.sound.flag.process && !media.sound.flag.complete){ sound_stts.numEntry = getSampleSize(atombuf, 4, fp); memcpy((void*)&sound_stts.fp, (void*)fp, sizeof(FILE)); } break; case STSC: f_lseek(fp,fp->fptr+ 4); // skip flag ver if(media.video.flag.process && !media.video.flag.complete){ video_stsc.numEntry = getSampleSize(atombuf, 4, fp); memcpy((void*)&video_stsc.fp, (void*)fp, sizeof(FILE)); } if(media.sound.flag.process && !media.sound.flag.complete){ sound_stsc.numEntry = getSampleSize(atombuf, 4, fp); memcpy((void*)&sound_stsc.fp, (void*)fp, sizeof(FILE)); } break; case STSZ: f_lseek(fp,fp->fptr+ 4); // skip flag ver if(media.video.flag.process && !media.video.flag.complete){ video_stsz.sampleSize = getSampleSize(atombuf, 4, fp); video_stsz.numEntry = getSampleSize(atombuf, 4, fp); memcpy((void*)&video_stsz.fp, (void*)fp, sizeof(FILE)); } if(media.sound.flag.process && !media.sound.flag.complete){ sound_stsz.sampleSize = getSampleSize(atombuf, 4, fp); memcpy((void*)&sound_stsz.fp, (void*)fp, sizeof(FILE)); sound_stsz.numEntry = getSampleSize(atombuf, 4, fp); memcpy((void*)&sound_stsz.fp, (void*)fp, sizeof(FILE)); } break; case STCO: f_lseek(fp,fp->fptr+ 4); // skip flag ver if(media.video.flag.process && !media.video.flag.complete){ video_stco.numEntry = getSampleSize(atombuf, 4, fp); memcpy((void*)&video_stco.fp, (void*)fp, sizeof(FILE)); media.video.flag.process = 0; media.video.flag.complete = 1; } if(media.sound.flag.process && !media.sound.flag.complete){ sound_stco.numEntry = getSampleSize(atombuf, 4, fp); memcpy((void*)&sound_stco.fp, (void*)fp, sizeof(FILE)); media.sound.flag.process = 0; media.sound.flag.complete = 1; } break; default: break; } memcpy((void*)fp, (void*)&fp_tmp, sizeof(FILE)); if(i < ATOM_ITEMS && atomHasChild[i]){ // memcpy((void*)&fp_tmp, (void*)fp, sizeof(MY_FILE)); if(collectAtoms(fp, atomSize-8, child + 1) != 0){ // Re entrant return -1; } memcpy((void*)fp, (void*)&fp_tmp, sizeof(FILE)); } NEXT: f_lseek(fp,(fp->fptr+atomSize)-8); totalAtomSize += atomSize; }while(parentAtomSize > (totalAtomSize + 8)); return 0; }