return 0;
}
-static void motorola_common_packet(uint8_t addr, uint8_t aux, uint8_t value)
+static OutputPacket *motorola_common_packet(uint8_t addr, uint8_t aux, uint8_t value)
{
uint8_t i;
- clear_packet();
+ OutputPacket *packet = output_create_packet();
- packet.bit_duration = 2;
- packet.length = 18*8;
+ packet->bit_duration = 2;
+ packet->length = 18*8;
for(i=0; i<4; ++i)
{
uint8_t d = addr%3;
addr /= 3;
- packet.data[i*2] = (d==0 ? 0x01 : 0x7F);
- packet.data[i*2+1] = (d==1 ? 0x7F : 0x01);
+ packet->data[i*2] = (d==0 ? 0x01 : 0x7F);
+ packet->data[i*2+1] = (d==1 ? 0x7F : 0x01);
}
- packet.data[8] = (aux ? 0x7F : 0x01);
- packet.data[9] = packet.data[8];
+ packet->data[8] = (aux ? 0x7F : 0x01);
+ packet->data[9] = packet->data[8];
for(i=0; i<4; ++i)
{
- packet.data[10+i*2] = ((value&1) ? 0x7F : 0x01);
+ packet->data[10+i*2] = ((value&1) ? 0x7F : 0x01);
value >>= 1;
}
- packet.repeat_count = 2;
+ packet->repeat_count = 2;
// Duration of three trits
- packet.repeat_delay = 96;
- packet.final_delay = 224;
+ packet->repeat_delay = 96;
+ packet->final_delay = 224;
+
+ return packet;
}
-static void motorola_old_packet(uint8_t addr, uint8_t aux, uint8_t value)
+static OutputPacket *motorola_old_packet(uint8_t addr, uint8_t aux, uint8_t value)
{
uint8_t i;
- motorola_common_packet(addr, aux, value);
+ OutputPacket *packet = motorola_common_packet(addr, aux, value);
for(i=0; i<4; ++i)
- packet.data[11+i*2] = packet.data[10+i*2];
+ packet->data[11+i*2] = packet->data[10+i*2];
+
+ return packet;
}
void motorola_locomotive_speed_packet(uint8_t addr, uint8_t aux, uint8_t speed)
{
motorola_old_packet(addr, aux, motorola_speed_to_value(speed));
-
- packet.ready = 1;
+ output_send_packet();
}
void motorola_locomotive_reverse_packet(uint8_t addr, uint8_t aux)
{
motorola_old_packet(addr, aux, 1);
-
- packet.ready = 1;
+ output_send_packet();
}
void motorola_locomotive_speed_direction_packet(uint8_t addr, uint8_t aux, uint8_t speed, uint8_t dir)
{
- motorola_common_packet(addr, aux, motorola_speed_to_value(speed));
+ OutputPacket *packet = motorola_common_packet(addr, aux, motorola_speed_to_value(speed));
- packet.data[11] = (dir ? 0x01 : 0x7F);
- packet.data[13] = (dir ? 0x7F : 0x01);
- packet.data[15] = (dir ? 0x01 : 0x7F);
- packet.data[17] = 0x80-packet.data[16];
+ packet->data[11] = (dir ? 0x01 : 0x7F);
+ packet->data[13] = (dir ? 0x7F : 0x01);
+ packet->data[15] = (dir ? 0x01 : 0x7F);
+ packet->data[17] = 0x80-packet->data[16];
- packet.ready = 1;
+ output_send_packet();
}
void motorola_locomotive_speed_function_packet(uint8_t addr, uint8_t aux, uint8_t speed, uint8_t func, uint8_t state)
{
uint8_t i;
uint8_t value;
+ OutputPacket *packet;
value = motorola_speed_to_value(speed);
- motorola_common_packet(addr, aux, value);
+ packet = motorola_common_packet(addr, aux, value);
/*
001 -> 011
for(i=0; i<4; ++i)
{
- packet.data[11+i*2] = ((func&1) ? 0x7F : 0x01);
+ packet->data[11+i*2] = ((func&1) ? 0x7F : 0x01);
func >>= 1;
}
- packet.ready = 1;
+ output_send_packet();
}
void motorola_solenoid_packet(uint8_t addr, uint8_t output, uint8_t state)
if(state)
value |= 8;
- motorola_old_packet(addr, 0, value);
- packet.repeat_delay >>= 1;
- packet.bit_duration = 1;
+ OutputPacket *packet = motorola_old_packet(addr, 0, value);
+ packet->repeat_delay >>= 1;
+ packet->bit_duration = 1;
- packet.ready = 1;
+ output_send_packet();
}
uint8_t motorola_command(const uint8_t *cmd_buf, uint8_t cmd_length)
uint8_t dir = !(cmd_buf[3]&0x80);
- while(packet.ready && !packet.done) ;
-
if(cmd_buf[0]==MOTOROLA_SPEED)
motorola_locomotive_speed_packet(addr, aux, speed);
else if(cmd_buf[0]==MOTOROLA_SPEED_DIRECTION)
return INVALID_VALUE;
uint8_t aux = cmd_buf[2]&0x01;
- while(packet.ready && !packet.done) ;
-
motorola_locomotive_reverse_packet(addr, aux);
}
else if(cmd_buf[0]==MOTOROLA_SOLENOID)
uint8_t output = (cmd_buf[2]&0x70)>>4;
uint8_t state = cmd_buf[2]&1;
- while(packet.ready && !packet.done) ;
-
motorola_solenoid_packet(addr, output, state);
}
else