11 changed files with 227 additions and 23 deletions
-
10components/mini_servo_motor/mini_servo_motor_ctrl_module.cpp
-
85components/motor_laser_code_scanner/motor_laser_code_scanne.cpp
-
37components/motor_laser_code_scanner/motor_laser_code_scanne.hpp
-
12components/sensors/smtp2/smtp2.cpp
-
10components/step_motor_ctrl_module/step_motor_ctrl_module.cpp
-
8components/xy_robot_ctrl_module/xy_robot_ctrl_module.cpp
-
2components/zcancmder/zcanreceiver.hpp
-
63components/zcancmder_module/zcan_motor_laser_code_scanner_scan_module.cpp
-
19components/zcancmder_module/zcan_motor_laser_code_scanner_scan_module.hpp
-
2components/zprotocols/errorcode
-
2components/zprotocols/zcancmder
@ -0,0 +1,85 @@ |
|||||
|
#include "motor_laser_code_scanne.hpp"
|
||||
|
|
||||
|
#include <stdio.h>
|
||||
|
#include <string.h>
|
||||
|
|
||||
|
#include "sdk\components\zprotocols\errorcode\errorcode.hpp"
|
||||
|
using namespace iflytop; |
||||
|
using namespace std; |
||||
|
#define TAG "MotorLaserCodeScanner"
|
||||
|
|
||||
|
#define DO(infostr, ACTION) \
|
||||
|
{ \ |
||||
|
int exec_ret = ACTION; \ |
||||
|
if (exec_ret != 0) { \ |
||||
|
ZLOGE(TAG, "do " infostr "(line:%d) fail, ret = %d", __LINE__, exec_ret); \ |
||||
|
m_lastexecstatus = exec_ret; \ |
||||
|
if (status_cb) status_cb(exec_ret); \ |
||||
|
return; \ |
||||
|
} \ |
||||
|
} |
||||
|
|
||||
|
void MotorLaserCodeScanner::initialize(int id, I_StepMotorCtrlModule* stepM, int max_scan_result_num) { |
||||
|
m_id = id; |
||||
|
m_stepM1 = stepM; |
||||
|
|
||||
|
m_mallocsize = sizeof(scan_result_t) + 2 * max_scan_result_num; |
||||
|
m_scan_result = (scan_result_t*)malloc(m_mallocsize); |
||||
|
ZASSERT(m_scan_result != nullptr); |
||||
|
memset(m_scan_result, 0, m_mallocsize); |
||||
|
m_max_scan_result_num = max_scan_result_num; |
||||
|
|
||||
|
m_lock.init(); |
||||
|
m_thread.init(TAG, 1024, osPriorityNormal); |
||||
|
} |
||||
|
|
||||
|
int32_t MotorLaserCodeScanner::start_scan(s32 moveby_distance, //
|
||||
|
s32 scan_interval_distance, //
|
||||
|
s32 each_sample_times, //
|
||||
|
s32 transmitting_tube_amplification, //
|
||||
|
s32 receiving_tube_amplification, //
|
||||
|
//
|
||||
|
action_cb_status_t status_cb) { |
||||
|
zlock_guard lock(m_lock); |
||||
|
ZLOGI(TAG, "start_scan %d %d %d %d %d", moveby_distance, scan_interval_distance, each_sample_times, transmitting_tube_amplification, receiving_tube_amplification); |
||||
|
|
||||
|
m_thread.stop(); |
||||
|
memset(m_scan_result, 0, m_mallocsize); |
||||
|
m_thread.start([this, //
|
||||
|
moveby_distance, //
|
||||
|
scan_interval_distance, //
|
||||
|
each_sample_times, //
|
||||
|
transmitting_tube_amplification, //
|
||||
|
receiving_tube_amplification, //
|
||||
|
status_cb]() { |
||||
|
int32_t count = moveby_distance / scan_interval_distance; |
||||
|
int32_t each_move_by_distance = moveby_distance > 0 ? abs(scan_interval_distance) : -abs(scan_interval_distance); |
||||
|
|
||||
|
for (int32_t i = 0; i < count; i++) { |
||||
|
ZLOGI(TAG, "move to %d", each_move_by_distance); |
||||
|
DO("move_by", m_stepM1->move_by_block(each_move_by_distance)); |
||||
|
// read adc
|
||||
|
} |
||||
|
m_scan_result->each_scan_result_len = 2; |
||||
|
m_scan_result->scan_reult_nums = count; |
||||
|
call_action_cb(status_cb, 0); |
||||
|
}); |
||||
|
return 0; |
||||
|
} |
||||
|
int32_t MotorLaserCodeScanner::stop_scan() { |
||||
|
zlock_guard lock(m_lock); |
||||
|
ZLOGI(TAG, "stop_scan"); |
||||
|
m_thread.stop(); |
||||
|
return 0; |
||||
|
}; |
||||
|
|
||||
|
int32_t MotorLaserCodeScanner::get_scan_result(scan_result_t** result) { |
||||
|
if (m_thread.isworking()) return err::kce_device_is_busy; |
||||
|
*result = m_scan_result; |
||||
|
return 0; |
||||
|
} |
||||
|
|
||||
|
void MotorLaserCodeScanner::call_action_cb(action_cb_status_t status_cb, int32_t status) { |
||||
|
m_lastexecstatus = status; |
||||
|
if (status_cb) status_cb(status); |
||||
|
} |
@ -0,0 +1,37 @@ |
|||||
|
#pragma once
|
||||
|
//
|
||||
|
#include "sdk/os/zos.hpp"
|
||||
|
#include "sdk\components\zprotocols\zcancmder\api\i_motor_laser_code_scanner.hpp"
|
||||
|
#include "sdk\components\zprotocols\zcancmder\api\i_step_motor_ctrl_module.hpp"
|
||||
|
namespace iflytop { |
||||
|
class MotorLaserCodeScanner : public I_MotorLaserCodeScanner { |
||||
|
ZThread m_thread; |
||||
|
int m_id = 0; |
||||
|
I_StepMotorCtrlModule* m_stepM1 = nullptr; |
||||
|
zmutex m_lock; |
||||
|
|
||||
|
scan_result_t* m_scan_result = nullptr; |
||||
|
int m_max_scan_result_num = 0; |
||||
|
int m_mallocsize = 0; |
||||
|
|
||||
|
int32_t m_lastexecstatus = 0; |
||||
|
|
||||
|
public: |
||||
|
void initialize(int id, I_StepMotorCtrlModule* stepM, int max_scan_result_num); |
||||
|
|
||||
|
virtual int32_t start_scan(s32 moveby_distance, //
|
||||
|
s32 scan_interval_distance, //
|
||||
|
s32 each_sample_times, //
|
||||
|
s32 transmitting_tube_amplification, //
|
||||
|
s32 receiving_tube_amplification, //
|
||||
|
//
|
||||
|
action_cb_status_t status_cb) override; |
||||
|
//
|
||||
|
virtual int32_t stop_scan() override; |
||||
|
//
|
||||
|
virtual int32_t get_scan_result(scan_result_t** result) override; |
||||
|
|
||||
|
private: |
||||
|
void call_action_cb(action_cb_status_t status_cb, int32_t status); |
||||
|
}; |
||||
|
}; // namespace iflytop
|
@ -0,0 +1,63 @@ |
|||||
|
#include "zcan_motor_laser_code_scanner_scan_module.hpp"
|
||||
|
using namespace iflytop; |
||||
|
|
||||
|
#define TAG "ZcanMotorLaserCodeScannerScanModule"
|
||||
|
#if 1
|
||||
|
void ZcanMotorLaserCodeScannerScanModule::initialize(ZCanCmder* cancmder, int id, I_MotorLaserCodeScanner* module) { |
||||
|
m_cancmder = cancmder; |
||||
|
m_id = id; |
||||
|
m_module = module; |
||||
|
cancmder->registerListener(this); |
||||
|
} |
||||
|
void ZcanMotorLaserCodeScannerScanModule::onRceivePacket(CanPacketRxBuffer* rxcmd) { |
||||
|
#if 0
|
||||
|
ZPACKET_CMD_ACK_AND_REPORT(kcmd_motor_laser_code_scanner_scan, |
||||
|
CMD(u8 id; //
|
||||
|
s32 moveby_distance; //
|
||||
|
s32 scan_interval_distance; //
|
||||
|
s32 each_sample_times; //
|
||||
|
s32 transmitting_tube_amplification; // 0.001
|
||||
|
s32 receiving_tube_amplification; // 0.001
|
||||
|
), |
||||
|
ACK(u8 id;), REPORT(u8 id; int32_t exec_status;)); |
||||
|
ZPACKET_CMD_ACK(kcmd_motor_laser_code_scanner_stop_scan, CMD(u8 id;), ACK(u8 id;)); |
||||
|
ZPACKET_CMD_ACK(kcmd_motor_laser_code_scanner_get_scan_result, CMD(u8 id; u16 packetoff;), ACK(u8 id; u8 endpacket; u8 packetlen; u8 packet[];)); |
||||
|
#endif
|
||||
|
|
||||
|
PROCESS_PACKET(kcmd_motor_laser_code_scanner_scan, m_id) { |
||||
|
errorcode = m_module->start_scan( //
|
||||
|
cmd->moveby_distance, cmd->scan_interval_distance, cmd->each_sample_times, cmd->transmitting_tube_amplification, cmd->receiving_tube_amplification, //
|
||||
|
[this, cmdheader](int32_t status) { PROCESS_REPORT(kcmd_motor_laser_code_scanner_scan); }); |
||||
|
} |
||||
|
END_PP(); |
||||
|
|
||||
|
PROCESS_PACKET(kcmd_motor_laser_code_scanner_stop_scan, m_id) { errorcode = m_module->stop_scan(); } |
||||
|
END_PP(); |
||||
|
|
||||
|
if (rxcmd->iscmd(kcmd_motor_laser_code_scanner_get_scan_result)) { |
||||
|
#if 0
|
||||
|
auto* cmd = rxcmd->get_data_as<kcmd_motor_laser_code_scanner_get_scan_result_cmd_t>(); |
||||
|
auto cmdheader = rxcmd->get_cmdheader(); |
||||
|
uint32_t errorcode = 0; |
||||
|
if (cmd->id == m_id) { |
||||
|
|
||||
|
I_MotorLaserCodeScanner::scan_result_t* result = nullptr; |
||||
|
u8 packetoff = cmd->packetoff; |
||||
|
errorcode = m_module->get_scan_result(&result); |
||||
|
|
||||
|
|
||||
|
if (errorcode == 0) { |
||||
|
} |
||||
|
// scan_result_t* result;
|
||||
|
if (errorcode == 0) { |
||||
|
m_cancmder->sendAck(rxcmd->get_cmdheader(), m_txbuf, sizeof(*ack)); |
||||
|
} else { |
||||
|
m_cancmder->sendErrorAck(rxcmd->get_cmdheader(), errorcode); |
||||
|
} |
||||
|
return; |
||||
|
|
||||
|
} |
||||
|
#endif
|
||||
|
} |
||||
|
} |
||||
|
#endif
|
@ -0,0 +1,19 @@ |
|||||
|
#pragma once
|
||||
|
// #include "sdk/components/zprotocols/zcancmder/api/i_step_motor_ctrl_module.hpp"
|
||||
|
// #include "sdk/components/zprotocols/zcancmder/api/i_pipette_module.hpp"
|
||||
|
#include "sdk/components/zprotocols/zcancmder/api/i_motor_laser_code_scanner.hpp"
|
||||
|
#include "sdk\components\zcancmder\zcanreceiver.hpp"
|
||||
|
namespace iflytop { |
||||
|
|
||||
|
class ZcanMotorLaserCodeScannerScanModule : public ZCanCmderListener { |
||||
|
ZCanCmder* m_cancmder = nullptr; |
||||
|
int m_id = 0; |
||||
|
I_MotorLaserCodeScanner* m_module; |
||||
|
|
||||
|
uint8_t m_txbuf[512] = {0}; |
||||
|
|
||||
|
public: |
||||
|
void initialize(ZCanCmder* cancmder, int id, I_MotorLaserCodeScanner* module); |
||||
|
virtual void onRceivePacket(CanPacketRxBuffer* rxcmd); |
||||
|
}; |
||||
|
} // namespace iflytop
|
@ -1 +1 @@ |
|||||
Subproject commit fd9bffbcf3c637591eca6b5b72f7a5f9fe5670b3 |
|
||||
|
Subproject commit 3ea10620670f4d40e220ed2ac75df734065fe3a6 |
@ -1 +1 @@ |
|||||
Subproject commit b59413a0e50fa100ab191dd0b2f7c9eb549e259c |
|
||||
|
Subproject commit 6ee22571832bbd90cdd5f4edb16e7a6d570e8baf |
Write
Preview
Loading…
Cancel
Save
Reference in new issue