�༭�ƽ�: |
������ҫ����ƕ��ʽ�豸�ij�����������ܣ��۲���ģʽ�լ�ְ����ģʽ���龰ʵ���լ�ʾ����ϣ��������ѧϰ����������
����������
�ǹ�autosar
���ɻ���������alice�༭���ƽ��� |
|
ƕ��ʽ�ı�ǩ��ϊ�� ���䣬ƫӳ�����ײ㣬��դ���ţ��������c���ԣ����ϊ��������ӧ������ ������aiotʱ���ĵ�������������ı䡣 оƭ��������դ��������ҵ����ҳ��ø��ӣ�����ڴ����ч�ʶ��ԣ�����ĸ��ÿ���ֲ��ҫ��խ��խ�ߣ��ի�ø��̵���ŀ���� ���ߵŀ�ά���ԡ� ������aiotʱ��ƕ��ʽ�豸�ij�����������ܡ�

���ģʽ
���ģʽ�ı�ǩ�������� ���߶ˣ��ܹ��ȡ���aiotʱ�������ģʽ��ƕ��ʽ�ܲ��������ļ����ģʽ������ϊ������ij�����ƶ����⣬����ǰ�˵ij��ϳ��ԣ��ܽ���˴������������ ���� �� ��ч ����취��
ƕ��ʽ��ҫ��c���կ�������������̣������ģʽ�����ڸ����ԣ��������ŀǰ�������������ģʽ���鼮����ʹ��java ���ԣ�c������ʵ�����ģʽ�����ģʽ�������أ����ǽ������ķ�����java����ʵ�֣�c����ͬ������ʵ�֡�ͬ���ģ�java����ա��������ҫ��ģʽ�����������⣬c����աҳ����������������ģʽ�ǻ��б�ҫѧϰ�ġ�
ģʽ���壺���ģʽ����ծ����ijщ���������ч����취���������е����ⶼ��ƥ�䵽��ӧ�����ģʽ����ˣ�����һζ�������ģʽ����ʱ���ֱ�ӵĵ�����������ч���е�����û�к��ʵ�ģʽ�����ծ�������һщ���ԭ���翪��ԭ����չ���ţ����ĺرգ�
�۲���ģʽ
�龰
�ڶ���֮�䶨��һ��һ�զ����������һ������״̬�ı��ʱ�����������ķ����զ��յ�֪ͨ��

ʵ��
��������ṩͳһ��ע��ӿڣ��լ�ע�ắ�� ���ɹ۲��߱���ʵ����observer_intf �ӿڣ�ȼ��ʹ��ע�ắ�������ӵ���ӧ�������б��у�����״̬�����ı䣬����֪ͨ�б��е����ж���

������״̬�����ı䣬��֪ͨ�����й۲��ߣ��۲��߱���ҳ���������������ƿ�ѡ�����֪ͨ

ʵ����ƕ��ʽ������ŀ��

������·��ģ���դ��·�����������ƣ��ʲ����ۡ��������裬�紫��������ͨ��ij���������ý������ģʽ���ֻ���ӳ����֧�ֿ��������դ�����ƹ��ġ�ƭ�����裬��оƭ�ڲ������裬ͨ��ж������������ر�ʱ�����ù���ģʽ�����ƹ��ġ�
- �豸���ѷ�ʽ
- ��������ϵͳij����ʱ�¼�����ʱ��ϵͳ���������ѵ����¼�
- ��������ϵͳ����˯�ߣ����ⲿ�¼����ѣ��紮�ڽ��յ�һ�����ݣ����������仯��ͨ������֪ͨоƭ
- ϵͳ����˯�ߵ�����
- �����������շ�������
- ��������ҫ����������
- ӧ�ò�״̬���ڿ��у�����ҫ�������¼���
- ���ڹ۲���ģʽ��pm���ʵ��
pm����ṩ�ľӿ�
-
struct pm
-
{
-
struct pm * next;
-
const char * name;
-
void (*init)( void );
-
void (* deinit ( void );
-
void * condition;
-
};
-
static struct pm pm_list;
-
static uint8_t pm_num;
-
static uint8_t pm_status;
-
-
int pm_register ( const struct pm* pm , const char * name)
-
{
-
struct pm* cur_pm = &pm_list;
-
while (cur_pm->next)
-
{
-
cur_pm = cur_pm->next;
-
}
-
cur_pm->next = pm;
-
pm->next = null ;
-
pm->name = name;
-
pm_num ;
-
}
-
-
void pm_loop ( void )
-
{
-
uint32_t pm_condition = 0 ;
-
struct pm* cur_pm = pm_list.next;
-
static uint8_t cnt;
-
-
/*check all condition*/
-
while (cur_pm)
-
{
-
if (cur_pm->condition){
-
pm_condition |= *(( uint32_t *)(cur_pm->condition));
-
}
-
cur_pm = cur_pm->next;
-
}
-
if (pm_condition == 0 )
-
{
-
cnt ;
-
if (cnt>= 5 )
-
{
-
pm_status = ready_sleep;
-
}
-
}
-
else
-
{
-
cnt = 0 ;
-
}
-
if ( pm_status == ready_sleep)
-
{
-
cur_pm = pm_list.next;
-
while (cur_pm)
-
{
-
if (cur_pm->deinit){
-
cur_pm-> deinit ();
-
}
-
cur_pm = cur_pm->next;
-
}
-
pm_status = sleep;
-
enter_sleep_mode ();
-
}
-
/*sleep--->wakeup*/
-
if (pm_status == sleep)
-
{
-
pm_status = normal;
-
cur_pm = pm_list.next;
-
while (cur_pm)
-
{
-
if (cur_pm->init){
-
cur_pm-> init ();
-
}
-
cur_pm = cur_pm->next;
-
}
-
}
-
}
|
����ʹ��pm�ӿ�

����
- pm ��դ�������ե����γ�ģ�飬��������������ʱ��ֻ��ʵ�ֽӿڣ�ע�ἴ��
- ͨ������ε������������ը��ӽ�ӧ�ò�������ע����
- ������ԣ����ժܷ����ӡ��ϵͳ��ǰϊ����˯��������ģ��
- ͨ�������ֶλ��֣�ӧ�ÿ���ʵ��ϵͳ����˯��
ְ����ģʽ
�龰
����ʵ�����у�һ���¼�(����)��ҫ��������������ǻܳ����ij������籨�����̣���˾ա�������� ����ա���������������˶ա���������������˶�������ֱ�������������ݽ����������ž��к˶ԣ��˶�������жͻ����������с��һ����������ſ�ֱ����������������χ���������������ܾ������õ������������������������ƶ��龰���кܶ࣬������һ��wifiģ�飬ͨ��atָ�ҫ��ģ����ȷ����wifi �� ��ҫ��һ����˳�����η�������ָ�� �� ����������ģʽ ������ ��ҫ���ӵ�wifi�������룬ÿ����һ������ָ�ģ�鶼���������ý��������������ҫ�жͻ������ȷ�ԣ���ѡ���ƿ�����һ��ָ����߽����ش���
�ܽ������ǣ�һϵ��������ҫ�ϸ���ʱ�������δ�����˳����������ͼ��ʾ ��

�ڴ���ϵͳ������£����������ժ�������������ʱ��ʵ�֣�ʵ�����£�

�����������£�ϊ�˱�֤ϵͳ��ʵʱ�ԣ���ʹ��������ʱ��һ��ʹ�ö�ʱ�¼����״̬����ʵ�֣�

��ϵͳʵ����ȣ������ʵ�ָ��ӹ��ӣ�ϊ�˱���������ֻ��ͨ��״̬�ͷ�ʱ����ʵ��˳����ʱ���������կ�����ʵ�ֹ����൱��ɢ�����ڵ�������ĵ�����ɢ����3�������д������������µĺ���ǣ��ģ���ֲ�ij��㡣��ʵ�ʵ�ӧ���у����ƶ����൱�࣬�����������ķ���ȥʵ�֣����ᵼ��ӧ�ó����ǿ��ϡ�
ʵ��
���է��֣�������龰�������ص㣺
- ����˳��ִ�у�ֻ�е�ǰ����ִ������(�н��ۣ��ɹ�����ʧ��)������ִ����һ������
- ǰһ�������ִ�н����ӱ�쵽��һ�������ִ�����
- ������һщ���ԣ��糬ʱʱ�䣬��ʱʱ�䣬���դ���
ͨ��������ϣ�����ǿ��գ��������һ��ģ�ͣ�������ϊ�ڵ㣬 ÿһ������ڵ��������ԣ��糬ʱ����ʱ�����ԣ�����������������ִ�н��������ҫ����˳��ִ��һϵ������ʱ�����ν�����ڵ㴮��һ���������������у�����������ĵ�һ���ڵ㿪ʼ���у����еľ�������� ok , busy ,error ������ok, ��ʾ�ڵ��ѵ���������������ɾ����error ��ʾ���г�������������ֹͣ���у����д���ص����������û������ƿ����������ȥ��busy��ʾ���������ڵȴ�ӧ�𣬻��ߵȴ���ʱ��������������������ϵľڵ㶼ִ���꣬���гɹ��ص���

node���ݽṹ����

node�ڴ��
ʹ���ڴ�صı�ҫ�ԣ�ʵ������£�ͬһʱ�䣬���������������լ��������ľڵ����ƚ����ޣ����������൱��ġ�����һ��֧��atָ���ģ�飬����֧�ּ�ʮ��atָ���ִ��һ�����ò��������ܾ�ֻ��ʹ��3-5��ָ���ȫ����̬����ڵ㣬�������ĵ����ڴ���դ����˶�̬�����dz�ҫ�ġ�

��ʼ��node�ڴ�أ��ڴ�������нڵ㶼�����ӵ�free_list��������ڵ�ʱ����ȡ����һ�����нڵ㣬���뵽used_list , ���ҽ��뵽����������������ijһ���ڵ�ִ���꣬���ᱻ�զ����գ�����������ɾ��������used_list��ɾ����ȼ�����ӵ�free_list��
ְ�������ݽṹ����

ְ������ʼ��

ְ�������ӽڵ�

ְ����������

ְ������ӧ��

ְ����������
-
int resp_chain_run ( resp_chain_t * chain)
-
{
-
resp_assert (chain);
-
if (chain->enable)
-
{
-
shadow_resp_chain_node_t * cur_node = chain->node.next;
-
/*maybe ans occur in handle,so cannot change state direct when ans comming*/
-
if (chain->is_ans)
-
{
-
chain->is_ans = false ;
-
chain->state = resp_status_ans;
-
}
-
switch (chain->state)
-
{
-
case resp_status_idle:
-
{
-
if (cur_node)
-
{
-
uint16_t retry = cur_node->init_retry;
-
if (cur_node->handle)
-
{
-
cur_node->param_type = resp_param_input;
-
chain->state = cur_node-> handle (( resp_chain_node_t *)cur_node ,cur_node->param);
-
}
-
else
-
{
-
resp_log ( "node handle is null ,goto next node" );
-
chain->state = resp_status_ok;
-
}
-
if (retry != cur_node->init_retry)
-
{
-
cur_node->retry = cur_node->init_retry> 0 ?(cur_node- >init_retry -1 ): 0 ;
-
}
-
}
-
else
-
{
-
if (chain->resp_done)
-
{
-
chain-> resp_done (( void *)resp_result_ok);
-
}
-
chain->enable = 0 ;
-
chain->state = resp_status_idle;
-
timerstop (&chain->timer);
-
chain->timer_is_running = false ;
-
}
-
break ;
-
}
-
case resp_status_delay:
-
{
-
if (chain->timer_is_running == false )
-
{
-
chain->timer_is_running = true ;
-
timersetvaluestart (&chain->timer , cur_node->duration);
-
}
-
if ( timergetflag (&chain->timer) == true )
-
{
-
chain->state = resp_status_ok;
-
chain->timer_is_running = false ;
-
}
-
break ;
-
}
-
case resp_status_busy:
-
{
-
/*waiting for ans or timeout*/
-
if (chain->timer_is_running == false )
-
{
-
chain->timer_is_running = true ;
-
timersetvaluestart (&chain->timer , cur_node->timeout);
-
}
-
if ( timergetflag (&chain->timer) == true )
-
{
-
chain->state = resp_status_timeout;
-
chain->timer_is_running = false ;
-
}
-
break ;
-
}
-
case resp_status_ans:
-
{
-
/*already got the ans,put the param back to the request handle*/
-
timerstop (&chain->timer);
-
chain->timer_is_running = false ;
-
if (cur_node->handle)
-
{
-
cur_node->param_type = resp_param_ans;
-
chain->state = cur_node-> handle (( resp_chain_node_t *)cur_node , chain->param);
-
}
-
else
-
{
-
resp_log ( "node handle is null ,goto next node" );
-
chain->state = resp_status_ok;
-
}
-
break ;
-
}
-
case resp_status_timeout:
-
{
-
if (cur_node->retry)
-
{
-
cur_node->retry--;
-
/*retry to request until cnt is 0*/
-
chain->state = resp_status_idle;
-
}
-
else
-
{
-
chain->state = resp_status_error;
-
}
-
break ;
-
}
-
case resp_status_error:
-
{
-
if (chain->resp_done)
-
{
-
chain-> resp_done (( void *)resp_result_error);
-
}
-
chain->enable = 0 ;
-
chain->state = resp_status_idle;
-
timerstop (&chain->timer);
-
chain->timer_is_running = false ;
-
cur_node->retry = cur_node->init_retry> 0 ?(cur_node->init_retry -1 ): 0 ;
-
chain_node_free_all (chain);
-
break ;
-
}
-
case resp_status_ok:
-
{
-
/*get the next node*/
-
cur_node->retry = cur_node->init_retry> 0 ?(cur_node->init_retry -1 ): 0 ;
-
chain_node_free (cur_node);
-
chain->node.next = chain->node.next->next;
-
chain->state = resp_status_idle;
-
break ;
-
}
-
default :
-
break ;
-
}
-
}
-
return chain->enable;
-
}
|
��������
- ���岢��ʼ��������

- �������к���������ѭ���е���

- ���խڵ����ӳ�������������

- �ֱ�ʵ�ֽڵ�������

����
- ʵ����������� ˳����ʱ����
- �θ�̶ȵļ���ӧ�ó̵�ʵ�֣��û�ֻ��ҫʵ����ӧ�ĵ������� �� ���ýӿ����ӣ����ɰ�ʱ��ҫ��ִ��
- ����ϊ�գ�����ϊ���� ������ϊӧ�𡣣���ijщ���ϣ��������ҳ�����������������˵��lapэ�飬��ʱ��ҫͨ���жϲ��������ͣ�
|