#include "Module_EvComm.h" #include #include #include #include /*標準輸入輸出定義*/ #include /*標準函數庫定義*/ #include /*Unix 標準函數定義*/ #include /*檔控制定義*/ #include /*PPSIX 終端控制定義*/ #include /*錯誤號定義*/ //================================================ //================================================ // CANBUS send cmd //================================================ //================================================ int PackageIdCmd(int cmd) { return cmd | 0x80000000; } void SendCmdToEvboard(int cmd, byte *data, byte dataLen) { struct can_frame frame; frame.can_id = cmd; frame.can_dlc = dataLen; memcpy(frame.data, data, sizeof(frame.data)); write(CanFd, &frame, sizeof(struct can_frame)); } void SetTargetAddr(byte *target_number, byte index) { int id = PackageIdCmd(Ev_Cmd.address_assignment + index); //printf("intCmd = %x \n", cmd & CAN_EFF_MASK); //cmd = cmd & CAN_EFF_MASK; byte data[8]; data[0] = *target_number; data[1] = *(target_number + 1); data[2] = *(target_number + 2); data[3] = *(target_number + 3); data[4] = index; SendCmdToEvboard(id, data, 5); } void GetFirmwareVersion(byte gun_index, byte toId) { int id = PackageIdCmd(Ev_Cmd.get_firmware_ver + toId); byte data[8]; SendCmdToEvboard(id, data, 0); } void SyncRtcInfo(byte gun_index, byte toId, int epoch) { int id = PackageIdCmd(Ev_Cmd.sync_rtc_info + toId); byte data[8]; data[0] = epoch & 0xff; data[1] = (epoch >> 8) & 0xff; data[2] = (epoch >> 16) & 0xff; data[3] = (epoch >> 24) & 0xff; SendCmdToEvboard(id, data, 4); } void GetHardwareVersion(byte gun_index, byte toId) { int id = PackageIdCmd(Ev_Cmd.get_hardware_ver + toId); byte data[8]; SendCmdToEvboard(id, data, 0); } void SetChargingPermission(byte gun_index, byte permissionStatus, short aOutputPw, short aOutputCur, short aOutputVol, byte toId) { int id = PackageIdCmd(Ev_Cmd.charging_permission + toId); byte data[8]; data[0] = permissionStatus; data[1] = aOutputPw & 0xff; data[2] = (aOutputPw >> 8) & 0xff; data[3] = aOutputCur & 0xff; data[4] = (aOutputCur >> 8) & 0xff; data[5] = aOutputVol & 0xff; data[6] = (aOutputVol >> 8) & 0xff; data[7] = 0xff; SendCmdToEvboard(id, data, sizeof(data)); } void SetPresentOutputPower(short outputVol_b1, short outputCur_b1, short outputVol_b2, short outputCur_b2) { int id = PackageIdCmd(Ev_Cmd.present_output_power); byte data[8]; data[0] = outputVol_b1 & 0xff; data[1] = (outputVol_b1 >> 8) & 0xff; data[2] = outputCur_b1 & 0xff; data[3] = (outputCur_b1 >> 8) & 0xff; data[4] = outputVol_b2 & 0xff; data[5] = (outputVol_b2 >> 8) & 0xff; data[6] = outputCur_b2 & 0xff; data[7] = (outputCur_b2 >> 8) & 0xff; SendCmdToEvboard(id, data, 8); } void SetPresentOutputCapacity(short aOutputPw_b1, short aOutputCur_b1, short aOutputPw_b2, short aOutputCur_b2) { int id = PackageIdCmd(Ev_Cmd.present_output_cap); byte data[8]; data[0] = aOutputPw_b1 & 0xff; data[1] = (aOutputPw_b1 >> 8) & 0xff; data[2] = aOutputCur_b1 & 0xff; data[3] = (aOutputCur_b1 >> 8) & 0xff; data[4] = aOutputPw_b2 & 0xff; data[5] = (aOutputPw_b2 >> 8) & 0xff; data[6] = aOutputCur_b2 & 0xff; data[7] = (aOutputCur_b2 >> 8) & 0xff; SendCmdToEvboard(id, data, 8); } void GetOutputReq(byte gun_index, byte toId) { int id = PackageIdCmd(Ev_Cmd.get_output_req + toId); byte data[8]; SendCmdToEvboard(id, data, 0); } void GetEvBatteryInfo(byte gun_index, byte toId) { int id = PackageIdCmd(Ev_Cmd.get_battery_info + toId); byte data[8]; SendCmdToEvboard(id, data, 0); } void EvseStopChargingEvent(byte stopResult, byte *stopReason, byte toId) { int id = PackageIdCmd(Ev_Cmd.evse_stop_charging + toId); byte data[8]; data[0] = stopResult; data[1] = *stopReason; data[2] = *(stopReason + 1); data[3] = *(stopReason + 2); data[4] = *(stopReason + 3); data[5] = *(stopReason + 4); data[6] = *(stopReason + 5); SendCmdToEvboard(id, data, 7); } void GetMiscellaneousInfo(byte gun_index, byte toId) { int id = PackageIdCmd(Ev_Cmd.get_miscellaneous_info + toId); byte data[8]; SendCmdToEvboard(id, data, 0); } void SetIsolationStatus(byte gun_index, byte result, byte toId) { int id = PackageIdCmd(Ev_Cmd.isolation_status + toId); byte data[8]; data[0] = result; SendCmdToEvboard(id, data, 1); } void SetEvsePrechargeInfo(byte gun_index, byte result, byte toId) { int id = PackageIdCmd(Ev_Cmd.evse_precharge_info + toId); byte data[8]; data[0] = result; SendCmdToEvboard(id, data, 1); }