最新分享黑马C C++ 13期全套教程(完整)
作者:互联网
#!/usr/bin/env python
import time
from appium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
cap = {
"platformName": "Android",
"platformVersion": "4.4.2",
"deviceName": "127.0.0.1:62001",
"appPackage": "com.ss.android.ugc.aweme",
"appActivity": "com.ss.android.ugc.aweme.main.MainActivity",
"noReset": True,
"unicodeKeyboard":True,
"resetkeyboard":True
}
driver = webdriver.Remote("http://localhost:4723/wd/hub",cap)
def get_size():
x = driver.get_window_size()['width']
y = driver.get_window_size()['height']
return(x,y)
#!/usr/bin/env python
import time
from appium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
cap = {
"platformName": "Android",
"platformVersion": "4.4.2",
"deviceName": "127.0.0.1:62001",
"appPackage": "com.ss.android.ugc.aweme",
"appActivity": "com.ss.android.ugc.aweme.main.MainActivity",
"noReset": True,
"unicodeKeyboard":True,
"resetkeyboard":True
}
driver = webdriver.Remote("http://localhost:4723/wd/hub",cap)
def get_size():
x = driver.get_window_size()['width']
y = driver.get_window_size()['height']
return(x,y)
try:
#点击搜索
print('点击搜索')
if WebDriverWait(driver,60).until(lambda x:x.find_element_by_xpath("//android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.support.v4.view.ViewPager[1]/android.widget.FrameLayout[1]/android.support.v4.view.ViewPager[1]/android.widget.TabHost[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.view.View[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.widget.LinearLayout[2]/android.widget.FrameLayout[1]/android.widget.ImageView[1]")):
driver.find_element_by_xpath("//android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.support.v4.view.ViewPager[1]/android.widget.FrameLayout[1]/android.support.v4.view.ViewPager[1]/android.widget.TabHost[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.view.View[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.widget.LinearLayout[2]/android.widget.FrameLayout[1]/android.widget.ImageView[1]").click()
except:
#[26,76][115,165]
driver.tap([(26,76),(115,165)],500)
#定位搜索框
if WebDriverWait(driver,60).until(lambda x:x.find_element_by_xpath("//android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[2]/android.widget.EditText[1]")):
#获取douyin_id进行搜索
driver.find_element_by_xpath("//android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[2]/android.widget.EditText[1]").send_keys('191433445')
while driver.find_element_by_xpath("//android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[2]/android.widget.EditText[1]").text != '191433445':
driver.find_element_by_xpath("//android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[2]/android.widget.EditText[1]").send_keys('191433445')
time.sleep(0.1)
#点击搜索
driver.find_element_by_xpath("//android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.widget.LinearLayout[1]/android.widget.TextView[1]").click()
#点击用户标签
if WebDriverWait(driver,10).until(lambda x:x.find_element_by_xpath("//android.widget.TextView[@text='用户']")):
driver.find_element_by_xpath("//android.widget.TextView[@text='用户']").click()
#点击头像
if WebDriverWait(driver,10).until(lambda x:x.find_element_by_xpath("//android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.support.v4.view.ViewPager[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[2]/android.view.View[1]/android.support.v7.widget.RecyclerView[1]/android.widget.RelativeLayout[1]/android.widget.RelativeLayout[1]/android.widget.ImageView[1]")):
driver.find_element_by_xpath("//android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.support.v4.view.ViewPager[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[2]/android.view.View[1]/android.support.v7.widget.RecyclerView[1]/android.widget.RelativeLayout[1]/android.widget.RelativeLayout[1]/android.widget.ImageView[1]").click()
#点击粉丝按钮
if WebDriverWait(driver,10).until(lambda x:x.find_element_by_xpath("//android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.HorizontalScrollView[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.view.View[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[5]/android.widget.LinearLayout[3]/android.widget.TextView[2]")):
driver.find_element_by_xpath("//android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.HorizontalScrollView[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.view.View[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[5]/android.widget.LinearLayout[3]/android.widget.TextView[2]").click()
x1 = int(driver.get_window_size()['width']*0.5)
y1 = int(driver.get_window_size()['height']*0.75)
y2 = int(driver.get_window_size()['height']*0.25)
while True:
if '没有更多了' in driver.page_source:
break
driver.swipe(x1,y1,x1,y2)
time.sleep(0.5)
import React, { Component } from "react";
import { Button, FlatList, StyleSheet, Text, View, TextInput } from "react-native";
import Swiper from 'react-native-swiper';
import { PullView } from 'react-native-pull';
import ToastExample from "../toast/ToastExample";
/**
* 列表的数据源
*
* @type {*[]}
*/
const dataList = [
{
key: 'Banner',
type: 1,
content: 'THIS IS BANNER'
},
{
key: 'LIST',
type: 2,
content: 'its my reactnative app item1'
},
{
key: 'LIST',
type: 2,
content: 'its my reactnative app item2'
},
{
key: 'LIST',
type: 2,
content: 'its my reactnative app item3'
},
{
key: 'LIST',
type: 2,
content: 'its my reactnative app item4'
},
{
key: 'LIST',
type: 2,
content: 'its my reactnative app item5'
},
{
key: 'LIST',
type: 2,
content: 'its my reactnative app item6'
},
{
key: 'LIST',
type: 2,
content: 'its my reactnative app item7'
},
{
key: 'Button',
type: 3,
content: 'THIS IS BUTTON'
},
];
export default class home extends React.Component {
constructor(props) {
super(props)
this.state = {
}
}
onPullRelease(resolve) {
//do something
setTimeout(() => {
resolve();
}, 1500);
}
onPressItem(item) {
ToastExample.show(item.content, ToastExample.SHORT)
}
render() {
return (
// <View style={{justifyContent:"center"}}></View>
<View style={styles.container}>
<View style={styles.headSearch}>
<TextInput inlineImageLeft="icon_search" inlineImagePadding={10}
placeholder="搜索你要输入的内容" textAlignVertical="center" placeholderTextColor="gray" style={styles.textInput} />
</View>
<PullView onPullRelease={this.onPullRelease}>
<FlatList
data={dataList}
renderItem={this.renderItem.bind(this)}
keyExtractor={(item) => item}
/>
</PullView>
</View>
)
}
renderItem({ item }) {
if (item.type === 1) {
return (
<View style={styles.banner}>
<Swiper showsButtons={true}>
<View style={styles.slide1}>
<Text style={styles.text}>Hello Swiper</Text>
</View>
<View style={styles.slide2}>
<Text style={styles.text}>Beautiful</Text>
</View>
<View style={styles.slide3}>
<Text style={styles.text}>And simple</Text>
</View>
</Swiper>
</View>
)
} else if (item.type === 2) {
return (
<Text style={{ height: 60, textAlignVertical: "center", paddingLeft: 15 }} onPress={()=>{this.onPressItem(item)}}>{item.content}</Text>
)
} else if (item.type === 3) {
return (
<Text>type3</Text>
)
}
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: 'column',
},
headSearch: {
justifyContent: "center",
backgroundColor: 'blue',
paddingLeft: 15,
paddingRight: 15,
height: 50,
},
text: {
fontSize: 15,
color: '#2A2A2A'
},
textInput: {
paddingLeft: 5,
height: 35,
borderRadius: 20,
marginLeft: 5,
marginRight: 5,
backgroundColor: 'white',
fontSize: 12,
color: 'gray',
},
banner: {
height: 200,
},
slide1: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#9DD6EB',
},
slide2: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#97CAE5',
},
slide3: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#92BBD9',
},
text: {
color: '#fff',
fontSize: 30,
fontWeight: 'bold',
}
})
#ifndef __GENEARTED_DBC_PARSER
#define __GENERATED_DBC_PARSER
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
/// Extern function needed for dbc_encode_and_send()
extern bool dbc_app_send_can_msg(uint32_t mid, uint8_t dlc, uint8_t bytes[8]);
/// Missing in Action structure
typedef struct {
uint32_t is_mia : 1; ///< Missing in action flag
uint32_t mia_counter_ms : 31; ///< Missing in action counter
} dbc_mia_info_t;
/// CAN message header structure
typedef struct {
uint32_t mid; ///< Message ID of the message
uint8_t dlc; ///< Data length of the message
} dbc_msg_hdr_t;
static const dbc_msg_hdr_t DBC_TEST1_HDR = { 0x1f4, 8 };
static const dbc_msg_hdr_t DBC_TEST2_HDR = { 0x1f5, 8 };
static const dbc_msg_hdr_t DBC_TEST3_HDR = { 0x1f6, 8 };
// static const dbc_msg_hdr_t DRIVER_HEARTBEAT_HDR = { 0x64, 1 };
// static const dbc_msg_hdr_t MOTOR_CMD_HDR = { 0x65, 1 };
static const dbc_msg_hdr_t MOTOR_STATUS_HDR = { 0x190, 3 };
static const dbc_msg_hdr_t SENSOR_SONARS_HDR = { 0xc8, 8 };
static const dbc_msg_hdr_t DBC_TEST4_HDR = { 0x1f7, 8 };
/// Message: DBC_TEST1 from 'IO', DLC: 8 byte(s), MID: 0x1f4
typedef struct {
uint32_t DBC_TEST1_unsigned1 : 8; ///< B7:0 Destination: DBG
uint32_t DBC_TEST1_unsigned_minmax : 8; ///< B15:8 Min: 0 Max: 100 Destination: DBG
uint32_t DBC_TEST1_enum : 8; ///< B39:32 Destination: DBG
uint32_t DBC_TEST1_float : 8; ///< B47:40 Destination: DBG
uint32_t DBC_TEST1_float_signed : 16; ///< B63:48 Min: 0 Max: 65.535 Destination: DBG
// No dbc_mia_info_t for a message that we will send
} DBC_TEST1_t;
/// Message: DBC_TEST2 from 'IO', DLC: 8 byte(s), MID: 0x1f5
typedef struct {
uint32_t DBC_TEST2_real_signed1 : 12; ///< B17:6 Destination: DBG
uint32_t DBC_TEST2_real_signed2 : 18; ///< B35:18 Destination: DBG
uint32_t DBC_TEST2_signed : 8; ///< B43:36 Destination: DBG
uint32_t DBC_TEST2_signed_minmax : 16; ///< B59:44 Min: -32768 Max: 32767 Destination: DBG
// No dbc_mia_info_t for a message that we will send
} DBC_TEST2_t;
/// Message: DBC_TEST3 from 'IO', DLC: 8 byte(s), MID: 0x1f6
typedef struct {
uint32_t DBC_TEST3_real_signed1 : 4; ///< B5:2 Destination: DBG
uint32_t DBC_TEST3_real_signed2 : 8; ///< B15:8 Destination: DBG
// No dbc_mia_info_t for a message that we will send
} DBC_TEST3_t;
/// Message: MOTOR_STATUS from 'MOTOR', DLC: 3 byte(s), MID: 0x190
typedef struct {
uint32_t MOTOR_STATUS_wheel_error : 1; ///< B0:0 Destination: DRIVER,IO
uint32_t MOTOR_STATUS_speed_kph : 16; ///< B23:8 Destination: DRIVER,IO
dbc_mia_info_t mia_info;
} MOTOR_STATUS_t;
/// @{ MUX'd message: SENSOR_SONARS
/// Struct for MUX: m0 (used for transmitting)
typedef struct {
uint32_t SENSOR_SONARS_err_count : 12; ///< B15:4 Destination: DRIVER,IO
uint32_t SENSOR_SONARS_left : 12; ///< B27:16 Destination: DRIVER,IO
uint32_t SENSOR_SONARS_middle : 12; ///< B39:28 Destination: DRIVER,IO
uint32_t SENSOR_SONARS_right : 12; ///< B51:40 Destination: DRIVER,IO
uint32_t SENSOR_SONARS_rear : 12; ///< B63:52 Destination: DRIVER,IO
dbc_mia_info_t mia_info;
} SENSOR_SONARS_m0_t;
/// Struct for MUX: m1 (used for transmitting)
typedef struct {
uint32_t SENSOR_SONARS_err_count : 12; ///< B15:4 Destination: DRIVER,IO
uint32_t SENSOR_SONARS_no_filt_left : 12; ///< B27:16 Destination: DBG
uint32_t SENSOR_SONARS_no_filt_middle : 12; ///< B39:28 Destination: DBG
uint32_t SENSOR_SONARS_no_filt_right : 12; ///< B51:40 Destination: DBG
uint32_t SENSOR_SONARS_no_filt_rear : 12; ///< B63:52 Destination: DBG
dbc_mia_info_t mia_info;
} SENSOR_SONARS_m1_t;
/// Struct with all the child MUX'd signals (Used for receiving)
typedef struct {
SENSOR_SONARS_m0_t m0; ///< MUX'd structure
SENSOR_SONARS_m1_t m1; ///< MUX'd structure
} SENSOR_SONARS_t;
/// @} MUX'd message
/// Message: DBC_TEST4 from 'IO', DLC: 8 byte(s), MID: 0x1f7
typedef struct {
uint32_t DBC_TEST4_real_signed1 : 32; ///< B31:0 Destination: DBG
uint32_t DBC_TEST4_real_signed2 : 16; ///< B47:32 Min: -32768 Max: 32767 Destination: DBG
uint32_t DBC_TEST4_real_overflow : 16; ///< B63:48 Destination: DBG
// No dbc_mia_info_t for a message that we will send
} DBC_TEST4_t;
/// @{ These 'externs' need to be defined in a source file of your project
extern const uint32_t MOTOR_STATUS__MIA_MS;
extern const MOTOR_STATUS_t MOTOR_STATUS__MIA_MSG;
extern const uint32_t SENSOR_SONARS_m0__MIA_MS;
extern const SENSOR_SONARS_m0_t SENSOR_SONARS_m0__MIA_MSG;
extern const uint32_t SENSOR_SONARS_m1__MIA_MS;
extern const SENSOR_SONARS_m1_t SENSOR_SONARS_m1__MIA_MSG;
/// @}
/// Encode IO's 'DBC_TEST1' message
/// @returns the message header of this message
static inline dbc_msg_hdr_t dbc_encode_DBC_TEST1(uint8_t frame[8], DBC_TEST1_t *msg)
{
uint32_t raw;
frame[0]=frame[1]=frame[2]=frame[3]=frame[4]=frame[5]=frame[6]=frame[7]=0;
// Stuff a SIG into the DBC 8-bit signal
///< bit(s) starting from BBitStart:0BitSize:8
set_frame_data(frame, MOTOROLA_MSB, 0, 8, msg->DBC_TEST1_unsigned1);
// Stuff a SIG into the DBC 8-bit signal
///< bit(s) starting from BBitStart:8BitSize:8
set_frame_data(frame, MOTOROLA_MSB, 8, 8, msg->DBC_TEST1_unsigned_minmax);
// Stuff a SIG into the DBC 8-bit signal
///< bit(s) starting from BBitStart:32BitSize:8
set_frame_data(frame, MOTOROLA_MSB, 32, 8, msg->DBC_TEST1_enum);
// Stuff a SIG into the DBC 8-bit signal
///< bit(s) starting from BBitStart:40BitSize:8
set_frame_data(frame, MOTOROLA_MSB, 40, 8, msg->DBC_TEST1_float);
// Stuff a SIG into the DBC 16-bit signal
///< bit(s) starting from BBitStart:48BitSize:16
set_frame_data(frame, MOTOROLA_MSB, 48, 16, msg->DBC_TEST1_float_signed);
return DBC_TEST1_HDR;
}
/// Encode and send for dbc_encode_DBC_TEST1() message
static inline bool dbc_encode_and_send_DBC_TEST1(DBC_TEST1_t *from)
{
uint8_t bytes[8];
const dbc_msg_hdr_t hdr = dbc_encode_DBC_TEST1(bytes, from);
return dbc_app_send_can_msg(hdr.mid, hdr.dlc, bytes);
}
/// Encode IO's 'DBC_TEST2' message
/// @returns the message header of this message
static inline dbc_msg_hdr_t dbc_encode_DBC_TEST2(uint8_t frame[8], DBC_TEST2_t *msg)
{
uint32_t raw;
frame[0]=frame[1]=frame[2]=frame[3]=frame[4]=frame[5]=frame[6]=frame[7]=0;
// Stuff a SIG into the DBC 12-bit signal
///< bit(s) starting from BBitStart:6BitSize:12
set_frame_data(frame, MOTOROLA_MSB, 6, 12, msg->DBC_TEST2_real_signed1);
// Stuff a SIG into the DBC 18-bit signal
///< bit(s) starting from BBitStart:18BitSize:18
set_frame_data(frame, MOTOROLA_MSB, 18, 18, msg->DBC_TEST2_real_signed2);
// Stuff a SIG into the DBC 8-bit signal
///< bit(s) starting from BBitStart:36BitSize:8
set_frame_data(frame, MOTOROLA_MSB, 36, 8, msg->DBC_TEST2_signed);
// Stuff a SIG into the DBC 16-bit signal
///< bit(s) starting from BBitStart:44BitSize:16
set_frame_data(frame, MOTOROLA_MSB, 44, 16, msg->DBC_TEST2_signed_minmax);
return DBC_TEST2_HDR;
}
/// Encode and send for dbc_encode_DBC_TEST2() message
static inline bool dbc_encode_and_send_DBC_TEST2(DBC_TEST2_t *from)
{
uint8_t bytes[8];
const dbc_msg_hdr_t hdr = dbc_encode_DBC_TEST2(bytes, from);
return dbc_app_send_can_msg(hdr.mid, hdr.dlc, bytes);
}
/// Encode IO's 'DBC_TEST3' message
/// @returns the message header of this message
static inline dbc_msg_hdr_t dbc_encode_DBC_TEST3(uint8_t frame[8], DBC_TEST3_t *msg)
{
uint32_t raw;
frame[0]=frame[1]=frame[2]=frame[3]=frame[4]=frame[5]=frame[6]=frame[7]=0;
// Stuff a SIG into the DBC 4-bit signal
///< bit(s) starting from BBitStart:2BitSize:4
set_frame_data(frame, MOTOROLA_MSB, 2, 4, msg->DBC_TEST3_real_signed1);
// Stuff a SIG into the DBC 8-bit signal
///< bit(s) starting from BBitStart:8BitSize:8
set_frame_data(frame, MOTOROLA_MSB, 8, 8, msg->DBC_TEST3_real_signed2);
return DBC_TEST3_HDR;
}
/// Encode and send for dbc_encode_DBC_TEST3() message
static inline bool dbc_encode_and_send_DBC_TEST3(DBC_TEST3_t *from)
{
uint8_t bytes[8];
const dbc_msg_hdr_t hdr = dbc_encode_DBC_TEST3(bytes, from);
return dbc_app_send_can_msg(hdr.mid, hdr.dlc, bytes);
}
/// Not generating code for dbc_encode_DRIVER_HEARTBEAT() since the sender is DRIVER and we are IO
/// Not generating code for dbc_encode_MOTOR_CMD() since the sender is DRIVER and we are IO
/// Not generating code for dbc_encode_MOTOR_STATUS() since the sender is MOTOR and we are IO
/// Not generating code for dbc_encode_SENSOR_SONARS() since the sender is SENSOR and we are IO
/// Encode IO's 'DBC_TEST4' message
/// @returns the message header of this message
static inline dbc_msg_hdr_t dbc_encode_DBC_TEST4(uint8_t frame[8], DBC_TEST4_t *msg)
{
uint32_t raw;
frame[0]=frame[1]=frame[2]=frame[3]=frame[4]=frame[5]=frame[6]=frame[7]=0;
// Stuff a SIG into the DBC 32-bit signal
///< bit(s) starting from BBitStart:0BitSize:32
set_frame_data(frame, MOTOROLA_MSB, 0, 32, msg->DBC_TEST4_real_signed1);
// Stuff a SIG into the DBC 16-bit signal
///< bit(s) starting from BBitStart:32BitSize:16
set_frame_data(frame, MOTOROLA_MSB, 32, 16, msg->DBC_TEST4_real_signed2);
// Stuff a SIG into the DBC 16-bit signal
///< bit(s) starting from BBitStart:48BitSize:16
set_frame_data(frame, MOTOROLA_MSB, 48, 16, msg->DBC_TEST4_real_overflow);
return DBC_TEST4_HDR;
}
/// Encode and send for dbc_encode_DBC_TEST4() message
static inline bool dbc_encode_and_send_DBC_TEST4(DBC_TEST4_t *from)
{
uint8_t bytes[8];
const dbc_msg_hdr_t hdr = dbc_encode_DBC_TEST4(bytes, from);
return dbc_app_send_can_msg(hdr.mid, hdr.dlc, bytes);
}
/// Not generating code for dbc_decode_DBC_TEST1() since 'IO' is not the recipient of any of the signals
/// Not generating code for dbc_decode_DBC_TEST2() since 'IO' is not the recipient of any of the signals
/// Not generating code for dbc_decode_DBC_TEST3() since 'IO' is not the recipient of any of the signals
/// Not generating code for dbc_decode_DRIVER_HEARTBEAT() since 'IO' is not the recipient of any of the signals
/// Not generating code for dbc_decode_MOTOR_CMD() since 'IO' is not the recipient of any of the signals
/// Decode MOTOR's 'MOTOR_STATUS' message
/// @param hdr The header of the message to validate its DLC and MID; this can be NULL to skip this check
static inline bool dbc_decode_MOTOR_STATUS(MOTOR_STATUS_t *msg, const uint8_t frame[8], const dbc_msg_hdr_t *hdr)
{
const bool success = true;
// If msg header is provided, check if the DLC and the MID match
if (NULL != hdr && (hdr->dlc != MOTOR_STATUS_HDR.dlc || hdr->mid != MOTOR_STATUS_HDR.mid)) {
return !success;
}
uint32_t raw;
// Stuff a SIG from the DBC 1-bit signal
///< bit(s) starting from BBitStart:0BitSize:1
get_frame_data(frame, MOTOROLA_MSB, 0, 1, msg->MOTOR_STATUS_wheel_error);
// Stuff a SIG from the DBC 16-bit signal
///< bit(s) starting from BBitStart:8BitSize:16
get_frame_data(frame, MOTOROLA_MSB, 8, 16, msg->MOTOR_STATUS_speed_kph);
msg->mia_info.mia_counter_ms = 0; ///< Reset the MIA counter
return success;
}
/// Decode SENSOR's 'SENSOR_SONARS' message
/// @param hdr The header of the message to validate its DLC and MID; this can be NULL to skip this check
static inline bool dbc_decode_SENSOR_SONARS(SENSOR_SONARS_t *msg, const uint8_t frame[8], const dbc_msg_hdr_t *hdr)
{
const bool success = true;
// If msg header is provided, check if the DLC and the MID match
if (NULL != hdr && (hdr->dlc != SENSOR_SONARS_HDR.dlc || hdr->mid != SENSOR_SONARS_HDR.mid)) {
return !success;
}
uint32_t raw;
// Decode the MUX
uint8_t MUX = 0; // Stuff a SIG from the DBC 4-bit signal
///< bit(s) starting from BBitStart:0BitSize:4
get_frame_data(frame, MOTOROLA_MSB, 0, 4, &MUX);
if (0 == MUX) {
// Non Muxed signals (part of all MUX'd structures)
// Stuff a SIG from the DBC 12-bit signal
///< bit(s) starting from BBitStart:4BitSize:12
get_frame_data(frame, MOTOROLA_MSB, 4, 12, &msg->m0.SENSOR_SONARS_err_count);
// Stuff a SIG from the DBC 12-bit signal
///< bit(s) starting from BBitStart:16BitSize:12
get_frame_data(frame, MOTOROLA_MSB, 16, 12, &msg->m0.SENSOR_SONARS_left);
// Stuff a SIG from the DBC 12-bit signal
///< bit(s) starting from BBitStart:28BitSize:12
get_frame_data(frame, MOTOROLA_MSB, 28, 12, &msg->m0.SENSOR_SONARS_middle);
// Stuff a SIG from the DBC 12-bit signal
///< bit(s) starting from BBitStart:40BitSize:12
get_frame_data(frame, MOTOROLA_MSB, 40, 12, &msg->m0.SENSOR_SONARS_right);
// Stuff a SIG from the DBC 12-bit signal
///< bit(s) starting from BBitStart:52BitSize:12
get_frame_data(frame, MOTOROLA_MSB, 52, 12, &msg->m0.SENSOR_SONARS_rear);
msg->m0.mia_info.mia_counter_ms = 0; ///< Reset the MIA counter
}
else if (1 == MUX) {
// Non Muxed signals (part of all MUX'd structures)
// Stuff a SIG from the DBC 12-bit signal
///< bit(s) starting from BBitStart:4BitSize:12
get_frame_data(frame, MOTOROLA_MSB, 4, 12, &msg->m1.SENSOR_SONARS_err_count);
// Stuff a SIG from the DBC 12-bit signal
///< bit(s) starting from BBitStart:16BitSize:12
get_frame_data(frame, MOTOROLA_MSB, 16, 12, &msg->m1.SENSOR_SONARS_no_filt_left);
// Stuff a SIG from the DBC 12-bit signal
///< bit(s) starting from BBitStart:28BitSize:12
get_frame_data(frame, MOTOROLA_MSB, 28, 12, &msg->m1.SENSOR_SONARS_no_filt_middle);
// Stuff a SIG from the DBC 12-bit signal
///< bit(s) starting from BBitStart:40BitSize:12
get_frame_data(frame, MOTOROLA_MSB, 40, 12, &msg->m1.SENSOR_SONARS_no_filt_right);
// Stuff a SIG from the DBC 12-bit signal
///< bit(s) starting from BBitStart:52BitSize:12
get_frame_data(frame, MOTOROLA_MSB, 52, 12, &msg->m1.SENSOR_SONARS_no_filt_rear);
msg->m1.mia_info.mia_counter_ms = 0; ///< Reset the MIA counter
}
else {
return !success;
}
return success;
}
/// Not generating code for dbc_decode_DBC_TEST4() since 'IO' is not the recipient of any of the signals
/// Handle the MIA for MOTOR's MOTOR_STATUS message
/// @param time_incr_ms The time to increment the MIA counter with
/// @returns true if the MIA just occurred
/// @post If the MIA counter reaches the MIA threshold, MIA struct will be copied to *msg
static inline bool dbc_handle_mia_MOTOR_STATUS(MOTOR_STATUS_t *msg, uint32_t time_incr_ms)
{
bool mia_occurred = false;
const dbc_mia_info_t old_mia = msg->mia_info;
msg->mia_info.is_mia = (msg->mia_info.mia_counter_ms >= MOTOR_STATUS__MIA_MS);
if (!msg->mia_info.is_mia) { // Not MIA yet, so keep incrementing the MIA counter
msg->mia_info.mia_counter_ms += time_incr_ms;
}
else if(!old_mia.is_mia) { // Previously not MIA, but it is MIA now
// Copy MIA struct, then re-write the MIA counter and is_mia that is overwriten
*msg = MOTOR_STATUS__MIA_MSG;
msg->mia_info.mia_counter_ms = MOTOR_STATUS__MIA_MS;
msg->mia_info.is_mia = true;
mia_occurred = true;
}
return mia_occurred;
}
/// Handle the MIA for SENSOR's SENSOR_SONARS for MUX "m0" message
/// @param time_incr_ms The time to increment the MIA counter with
/// @returns true if the MIA just occurred
/// @post If the MIA counter reaches the MIA threshold, MIA struct will be copied to *msg
static inline bool dbc_handle_mia_SENSOR_SONARS_m0(SENSOR_SONARS_m0_t *msg, uint32_t time_incr_ms)
{
bool mia_occurred = false;
const dbc_mia_info_t old_mia = msg->mia_info;
msg->mia_info.is_mia = (msg->mia_info.mia_counter_ms >= SENSOR_SONARS_m0__MIA_MS);
if (!msg->mia_info.is_mia) { // Not MIA yet, so keep incrementing the MIA counter
msg->mia_info.mia_counter_ms += time_incr_ms;
}
else if(!old_mia.is_mia) { // Previously not MIA, but it is MIA now
// Copy MIA struct, then re-write the MIA counter and is_mia that is overwriten
*msg = SENSOR_SONARS_m0__MIA_MSG;
msg->mia_info.mia_counter_ms = SENSOR_SONARS_m0__MIA_MS;
msg->mia_info.is_mia = true;
mia_occurred = true;
}
return mia_occurred;
}
/// Handle the MIA for SENSOR's SENSOR_SONARS for MUX "m1" message
/
标签:widget,教程,DBC,13,C++,dbc,msg,android,frame 来源: https://blog.csdn.net/weixin_44937580/article/details/90028100