forked from muccc/formica_rev1_muc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
net-rx.c
95 lines (76 loc) · 2.08 KB
/
net-rx.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/* Copyright 2008 Stephen English, Jeffrey Gough, Alexis Johnson,
Robert Spanton and Joanna A. Sun.
This file is part of the Formica robot firmware.
The Formica robot firmware is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
The Formica robot firmware is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the Formica robot firmware.
If not, see <http://www.gnu.org/licenses/>. */
#include "net-rx.h"
#include "net.h"
#include "device.h"
#include "leds.h"
#include "virus.h"
#include "random.h"
#include "motor.h"
#include "flash.h"
#include "net-tx.h"
#include "food.h"
uint16_t net_id = 0;
void net_rx_proc_incoming( uint8_t* frame, uint8_t len )
{
/* Frames of length 0 aren't helpful */
if( len == 0 )
return;
switch( frame[0] )
{
case NET_CMD_COLOUR:
/* Receive a new colour */
if( len != 3 )
return;
virus_set( frame[1], frame[2] );
break;
case NET_CMD_FW_BLOB:
{
/* Receive a blob of firmware */
uint16_t fw_ver, chunk;
if( len != 21 )
return;
fw_ver = (((uint16_t)frame[1]) << 8) | frame[2];
chunk = (((uint16_t)frame[3]) << 8) | frame[4];
/* if( fw_ver > FIRMWARE_VERSION ) */
flash_rx_chunk( chunk,
(const uint16_t*)(frame + 7) );
break;
}
case NET_CMD_FW_NEXT:
{
/* Receive a hint about what chunk to transmit next */
uint16_t chunk;
if( len != 3 )
return;
chunk = (((uint16_t)frame[1]) << 8) | frame[2];
net_tx_chunk_hint(chunk);
break;
}
case NET_CMD_FOOD:
{
uint32_t since = 0;
uint8_t i;
for( i=0; i<4; i-- )
since = (since << 8) | frame[4-i];
food_gotinfo( &since );
break;
}
}
}
void net_rx_init( void )
{
net_id = random();
}