Exemple #1
0
void wpQfReadAlarm(unsigned char id) {
    DEFINE_CAN_WP_FRAME(frame);
    frame.funcode = CAN_WP_FUNCODE_QF_READALARM;
    frame.desid = QIFA_ID(id);
    frame.dlc = 0;
    CANSend_noblock(MODULE_ID_DCAN0, (CAN_FRAME *)&frame);
}
Exemple #2
0
void Can_Cmd_Lockcurrent_Set(CAN_WP *wp) {
    if (wp->dlc % 2 != 0) {
        return;
    }
    unsigned int num = wp->dlc / 2;
    uint8_t Current_value;
    for (int i = 0; i < num; i++) {
        uint32 imotor = wp->data[i * 2];
        if (imotor >= MIDUMOTOBEGINHZ) {
            continue;
        }
        Current_value = MAX(wp->data[i * 2 + 1], Max_Current_Num);
        if (Current_value > 0) {
            HalfPulseNum[imotor] = Current_value - 1;
            //若当前是半流锁定强制改变锁定电流
            if (MiduMotoCtrPra[imotor].MotoRunState == MOTOSTOPHALF) {
                MiduMotoRefCtr(imotor, ENABLE);
            }
        }
    }
    DEFINE_CAN_WP_FRAME(twp);
    twp.funcode = CANCMD_LOCKCURRENT_SET;
    twp.desid = wp->srcid;
    twp.dlc = 0;
    wpSend(&twp);
}
Exemple #3
0
void wpQfSetDuty(unsigned char id, unsigned char duty) {
    DEFINE_CAN_WP_FRAME(frame);
    frame.funcode = CAN_WP_FUNCODE_QF_SETDUTY;
    frame.desid = QIFA_ID(id);
    frame.data[0] = (unsigned char)duty;
    frame.dlc = 1;
    CANSend_noblock(MODULE_ID_DCAN0, (CAN_FRAME *)&frame);
}
Exemple #4
0
void wpQfRst(unsigned char id, bool rst) {
    DEFINE_CAN_WP_FRAME(frame);
    frame.funcode = CAN_WP_FUNCODE_QF_RESET;
    frame.desid = QIFA_ID(id);
    frame.data[0] = (unsigned char)(!!rst);
    frame.dlc = 1;
    CANSend_noblock(MODULE_ID_DCAN0, (CAN_FRAME *)&frame);
}
Exemple #5
0
void wpQfEn(unsigned char id, bool on) {
    DEFINE_CAN_WP_FRAME(frame);
    frame.funcode = CAN_WP_FUNCODE_QF_EN;
    frame.desid = QIFA_ID(id);
    frame.data[0] = (unsigned char)on;
    frame.dlc = 1;
    CANSend_noblock(MODULE_ID_DCAN0, (CAN_FRAME *)&frame);
}
Exemple #6
0
void wpQfSetAlarmMask(unsigned char id, unsigned char mask) {
    DEFINE_CAN_WP_FRAME(frame);
    frame.funcode = CAN_WP_FUNCODE_QF_SETALARMMASK;
    frame.desid = QIFA_ID(id);
    frame.data[0] = mask;
    frame.dlc = 1;
    CANSend_noblock(MODULE_ID_DCAN0, (CAN_FRAME *)&frame);
}
Exemple #7
0
void CanCmd_ReadAlarm(CAN_WP *wp) {
    uint8 val = Scan_Input_state();
    DEFINE_CAN_WP_FRAME(twp);
    twp.funcode = wp->funcode;
    twp.desid = wp->srcid;
    twp.dlc = 1;
    twp.data[0] = val;
    wpSend(&twp);
}
Exemple #8
0
void wpQfWrite(unsigned char id, unsigned char *val, unsigned char count) {
    ASSERT(count < 9);
    DEFINE_CAN_WP_FRAME(frame);
    frame.funcode = CAN_WP_FUNCODE_QF_WRITE;
    frame.desid = QIFA_ID(id);
    memcpy(frame.data, val, count);
    frame.dlc = count;
    CANSend_noblock(MODULE_ID_DCAN0, (CAN_FRAME *)&frame);
}
Exemple #9
0
//向主板发送气阀的阻值
void CanCmd_ReturnQIfa_Res_value(uint8_t num, uint16_t res_value) {
    DEFINE_CAN_WP_FRAME(twp);
    twp.funcode = CANCMD_SINGAL_QIFA;
    twp.desid = 0; //todo
    twp.dlc = 3;
    twp.data[0] = num;
    twp.data[1] = res_value & 0xff;
    twp.data[2] = (res_value / 256) & 0xff;
    wpSend(&twp);
}
Exemple #10
0
// 读取气阀1~16号 当前状态
void CanCmd_ReadQifa1to16(CAN_WP *wp) {

    DEFINE_CAN_WP_FRAME(twp);
    twp.funcode = wp->funcode;
    twp.desid = wp->srcid;
    twp.dlc = 2;
    twp.data[0] = Qifa_state.fg_qifa_out & 0xff;
    twp.data[1] = (Qifa_state.fg_qifa_out / 256) & 0xff;
    wpSend(&twp);
}
Exemple #11
0
void ScanAlarm(void) {
    if (DeviceCanAddr==0) {
        return;
    }
    uint32 val = Scan_Input_state();
    if (val != (1UL << Max_Input_Single)-1) {
        DEFINE_CAN_WP_FRAME(twp);
        twp.funcode = CANCMD_SENDALARM;
        twp.desid = CAN_WP_ID_GROUP_BROADCAST(CAN_WP_DEV_TYPE_MAIN);
        twp.dlc = 1;
        twp.data[0] = val;
        wpSend(&twp);
    }
}
Exemple #12
0
bool wpQfRead(unsigned char id, unsigned int timeout, unsigned int *status) {
    DEFINE_CAN_WP_FRAME(frame);
    frame.funcode = CAN_WP_FUNCODE_QF_READ;
    frame.desid = QIFA_ID(id);
    frame.dlc = 0;
    CANSend_noblock(MODULE_ID_DCAN0, (CAN_FRAME *)&frame);
    atomicClear(&wp_read_qf_flag);
    withintimedo(timeout) {
        if (atomicTestClear(&wp_read_qf_flag)) {
            *status = Sw_Qf_Status;
            return true;
        }
    }
    return false;
}
Exemple #13
0
void scanMotorCmd(void) {
    MOTOR_CMD *cmd;
    for (int i = 0; i < MiDuMotoNum; i++) {
        if (ringBufRead(&motorcmdbuf[i], (void **)&cmd)) {
            switch (cmd->stat) {
            case MOTOR_CMD_STAT_WAITE:
                if ((cmd->speedHz >= DUMUMOTOSTOPHZ) && (cmd->puls <= 15000)) {
                    cmd->stat = MOTOR_CMD_STAT_BUSY;
                    cmd->flag |= 0x10; //force return
                    MotoDumuRun(i, cmd->flag | 0x80,
                                cmd->puls, cmd->speedHz, cmd->stopData);
                    cmd->timertick = timerTick1ms;
                } else {
                    ringBufPop_noread(&motorcmdbuf[i]);
                }
                break;
            case MOTOR_CMD_STAT_BUSY:
                if (MiduMotoCtrPra[i].MotoRunState == MOTOSTOPHALF
                    || MiduMotoCtrPra[i].MotoRunState == MOTOSTOPFREE) {
                    ringBufPop_noread(&motorcmdbuf[i]);
                    if (cmd->flag & MOTOR_CMDGO_RETURN_FLAG_RETURN) {
                        //unsigned char stopflag = MiduMotoCtrPra[i].MotoStopData;
                        uint16_t timedif = timerTick1ms - cmd->timertick;
                        DEFINE_CAN_WP_FRAME(wpt);
                        wpt.funcode = CANCMD_DUMUMOTOGO_LOW;
                        wpt.dlc = 8;
                        wpt.data[0] = i;
                        wpt.data[1] = (uint8_t)MiduMotoCtrPra[i].MotoDumuDangqian;
                        wpt.data[2] = (uint8_t)(MiduMotoCtrPra[i].MotoDumuDangqian >> 8);
                        wpt.data[3] = (uint8_t)timedif;
                        wpt.data[4] = (uint8_t)(timedif >> 8);
                        uint8_t flag = 0;
                        flag |= MiduMotoCtrPra[i].MotoRunState << MOTOR_CMDGO_RETURN_FLAG_STAT_SHIFT;
                        flag |= MiduMotoCtrPra[i].MotoRunDir << MOTOR_CMDGO_RETURN_FLAG_DIR_SHIFT;
                        flag |= GetMiduMotoZero(i) << MOTOR_CMDGO_RETURN_FLAG_PROBE_SHIFT;
                        flag |= MiduMotoCtrPra[i].clearPosFlag << MOTOR_CMDGO_FLAG_CLEAR_POS_SHIFT;
                        flag |= MiduMotoCtrPra[i].stopFlag;
                        wpt.data[5] = flag;
                        wpt.data[6] = cmd->stopData;
                        wpt.data[7] = cmd->cmdcode;
                        wpSend(&wpt);
                    }
                }
                break;
            default:
                break;
            }
        }
Exemple #14
0
void Can_Cmd_Workcurrent_Set(CAN_WP *wp) {

    uint8_t val;
    for (int i = 0; i < MIN(4, wp->dlc); i++) {
        val = wp->data[i];
        //电机号 1~4  电流档位1~25 才为有效数据
        if ((val > 0) && (val < (Max_Current_Num + 1))) {
            ChannelNum[i] = val - 1;
        }
    }
    DEFINE_CAN_WP_FRAME(twp);
    twp.funcode = CANCMD_WORKCURRENT_SET;
    twp.desid = wp->srcid;
    twp.dlc = 0;
    wpSend(&twp);
}
Exemple #15
0
//读取度目马达状态
void CanCmd_GetDumuMotoState(CAN_WP *wp) {
    uint32 moto = wp->data[0];
    if (moto >= MiDuMotoNum) {
        return;
    }
    //MiduMotoCtrPra[moto].shiji_zero_zhuangtai = GetMiduMotoZero(moto);
    DEFINE_CAN_WP_FRAME(twp);
    twp.funcode = CANCMD_GETDUMUMOTOSTATE;
    twp.desid = wp->srcid;
    twp.dlc = 4;
    twp.data[0] = moto;
    twp.data[1] = MiduMotoCtrPra[moto].MotoDumuDangqian & 0xff;
    twp.data[2] = MiduMotoCtrPra[moto].MotoDumuDangqian >> 8;
    uint8_t stat = MiduMotoCtrPra[moto].MotoRunState << 6 |
                   MiduMotoCtrPra[moto].MotoRunDir << 5 |
                   GetMiduMotoZero(moto) << 3;
    twp.data[3] = stat;
    wpSend(&twp);
}
Exemple #16
0
bool wpQfReadOhm(unsigned char id, unsigned char qifaId, unsigned short timeout, unsigned short *Ohm) {
    QIFA *qifa = qifaSys.QiFa_Reg_Table[id - 1][qifaId];
    if (qifa == NULL) {
        return false;
    }
    DEFINE_CAN_WP_FRAME(frame);
    frame.funcode = CAN_WP_FUNCODE_QF_READOHM;
    frame.desid = QIFA_ID(id);
    frame.data[0] = qifaId | (1 << 7);
    frame.dlc = 1;
    CANSend_noblock(MODULE_ID_DCAN0, (CAN_FRAME *)&frame);
    atomicClear(&wp_qf_resdata);
    withintimedo(timeout) {
        if (atomicTestClear(&wp_qf_resdata)) {
            *Ohm = qifa->Ohm;
            return true;
        }
    }
    return false;
}