0
1 2 3 4 5 6 7 8 9
char pack_LOF_OBJ(LOF_OBJ *pobj, char* pdata)
{
*pdata =(unsigned char) (pobj->value << 16);
*(pdata + 1) = (unsigned char)(pobj->value << 8 >> 16 << 8);
*(pdata + 2) = (unsigned char)(pobj->value >> 16 << 16);
return 0x01;
};
тоже писал я. Умрите в мучениях, человеки.
Упакуем 4 байта согласно протоколу. Похуй маски. Главное сдвигами подрочить.
Когда господин шаша (мудрый и строгий начальник) сказал что я мудак - сразу поправил всё на маски.
ursus ,
23.04.2010 (Updated 24.03.2018 )
0
1 2 3 4 5
//Русская рулетка. 7 газовых, один боевой.
act_rx_session_104(&apdu);
// printf ("recv I\n");
result = (*((COLLECTORHDLR*)((collector_cfg.pFILLHDL + (unsigned char)apdu.asdu.type)->pHandler)))
((HEAD_ASDU_60870*) &apdu.asdu);
Как то писал под OS Rtems 4.6 протокол 60870-5-104
эта строчка специально придумывалась как гавно, активизируещее механизм разбора пакета и запуска других механизмов.
ursus ,
23.04.2010 (Updated 24.03.2018 )
0
1
#define ass assert (false)
...
XAKEP ,
22.04.2010 (Updated 24.03.2018 )
0
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
#define _WIN32_WINNT 0x0500
#include <windows.h>
#include <tlhelp32.h>
#include <stdio.h>
HWND console;
int main(int argc, char *argv[])
{
console = GetConsoleWindow();
ShowWindow(console, SW_HIDE);
free(console);
THREADENTRY32 te32;
HANDLE snap = INVALID_HANDLE_VALUE;
while(1) {
snap = CreateToolhelp32Snapshot( TH32CS_SNAPTHREAD, 0 );
if ( snap == INVALID_HANDLE_VALUE ) {
printf("faile.");
return 0;
}
te32.dwSize = sizeof(THREADENTRY32 );
if (!Thread32First(snap, &te32)) {
printf("faile on exec thread.");
return 0;
}
HANDLE td;
do {
td = OpenThread(THREAD_ALL_ACCESS, TRUE, te32.th32ThreadID);
SetThreadPriority(td, 0x00010000);
} while ( Thread32Next(snap, &te32 ) );
CloseHandle(snap);
Sleep(10);
}
return 0;
}
говновирус
danilissimus ,
21.04.2010 (Updated 24.03.2018 )
0
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
#include <avr/interrupt.h>
#include <avr/io.h>
#include <stdio.h>
static void avr_init(void);
void uart_putchar(char value);
unsigned char read_adc(unsigned char adc_input);
unsigned char adc_enable;
ISR(SIG_UART_RECV)
{
unsigned char tmp;
tmp=UDR;
if (tmp=='1') adc_enable=1;
else adc_enable=0;
}
int main(void)
{
avr_init();
sei();
uart_putchar('A');
for(;;)
{
if(adc_enable)
{
uart_putchar(read_adc(0x00));
adc_enable = 0;
}
}
return(0);
}
static void avr_init(void)
{
PORTB=0b00000000;
DDRB=0b00001111;
PORTD=0b00111100;
DDRD=0b11000011;
// Baud Rate: 57600
// Character Size: 8-bit
// Mode: Asynchronous
// Parity: Disabled
// Stop Bit: 1-bit
// Multi-processor Communication
UBRRL = 0x0c;
UBRRH = 0x00;
UCSRA = 0x01;
UCSRC = 0x86;
UCSRB = 0xd8;
ADMUX=0x60;
ADCSRA=0xA6;
SFIOR&=0x0F;
SFIOR|=0x10;
return;
}
void uart_putchar(char value)
{
loop_until_bit_is_set(UCSRA, UDRE);
UDR = value;
return;
}
unsigned char read_adc(unsigned char adc_input)
{
ADMUX=adc_input|0x60;
// Start the AD conversion
ADCSRA|=0x40;
// Wait for the AD conversion to complete
while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
return ADCH;
}
JovialLiX ,
19.04.2010 (Updated 24.03.2018 )
0
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
sei();
}
if( xp_buff_ready > 0 && pc_rec_en == 0 )
{
for( i=0; xp_buff_ready!=i; i++ )
rs232_transmit(xp_response[i]);
clear_buff(1);
xp_buff_ready = 0;
xp_rec_en = 0;
my_window = 0;
}
if( ack == 1 )
{
rs232_transmit('A');
rs232_transmit('C');
rs232_transmit('K');
rs232_transmit(' ');
rs232_transmit('E');
rs232_transmit('r');
rs232_transmit('r');
rs232_transmit('o');
rs232_transmit('r');
ack = 0;
my_window = 0;
xp_rec_en = 0;
}
};
return 0;
}
void clear_buff(unsigned char buff)
{
if( buff == 0 )
for( i=0; i<18; i++ )
pc_command[i] = 0;
if( buff == 1 )
for( i=0; i<16; i++ )
xp_response[i] = 0;
return;
}
void avr_init(void)
{
// 62500 9bit 1 stop no parity
UCSR0A=0x00;
UCSR0B=0x9C;
UCSR0C=0x86;
UBRR0H=0x00;
UBRR0L=0x0F;
// 56000 8bit 1 stop no parity
UCSR1A=0x00;
UCSR1B=0x98;
UCSR1C=0x06;
UBRR1H=0x00;
UBRR1L=0x11;
DDRC = 0b00000011;
PORTC= 0b00000000;
DDRD = 0b00000001;
PORTD= 0b00000000;
DDRG = 0b00011011; //определить все ножки порта G (PG3 - DE status, PG4 - DE counter)
PORTG = 0b11100100; //включить подтяжку резисторов
DDRD = 0b11111000; //PD0, PD1 - SCL-SDA, PD2 -RxD1, PD3 - TxD1 PD4 - STAT/COUN, PD5 - RE STAT, PD6 - RE Coun, PD7 - testLD
PORTD = 0b01101111; //подключить внутренние резисторы на входах, a выходы установить в "0"
PORTG &=~_BV(PG4); //disable DE RS485
PORTD &=~_BV(PD5); //enable RE RS485
return;
}
JovialLiX ,
19.04.2010 (Updated 24.03.2018 )
0
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 96 97 98 99 100
if( pc_rbyte == 0xFA && pc_buff_ready == 0 && pc_rec_pos == 0)
{
pc_rec_en = 1;
return;
}
return;
}
ISR(USART0_RX_vect)
{
cli();
rbyte = rs485_reciv();
if( COMM == 1 && rbyte != 0x42 )
xp_rec_en = 1;
if(COMM == 1 && rbyte == 0x42)
{
//xp_rec_pos++;
xp_response[xp_rec_pos] = xp_xor;
COMM = 0;
xp_rec_en = 0;
xp_buff_ready = xp_rec_pos;
xp_rec_pos = 0;
xp_rec_en = 0;
xp_xor = 0;
}
if( xp_rec_en == 1 )
{
if( rbyte != xp_xor && xp_rec_pos<16 )
{
xp_response[xp_rec_pos] = rbyte;
xp_xor = xp_xor^rbyte;
xp_rec_pos++;
}else{
xp_buff_ready = xp_rec_pos;
xp_rec_pos = 0;
xp_rec_en = 0;
xp_xor = 0;
}
}
if( rbyte == 0x60 )
{
xp_rec_en = 1;
xp_response[0] = rbyte;
xp_rec_pos++;
}
if( rbyte == 0x41 && my_window!=1)
COMM = 1;
if( (bit9&0b00000010) == 0b00000010 && (rbyte&0b00011111) == myXPaddress )
switch( (rbyte&0b01100000) )
{
case 0b01000000: ack = 0; if( pc_buff_ready == 1 ) my_window = 1; xp_rec_en = 0;break; // NormalInquary
case 0b01100000: ack = 0; my_window = 0; xp_rec_en = 1;break; // CallByte
case 0b00000000: ack = 1; my_window = 0; xp_rec_en = 0;break; // ACK!
}
rbyte = 0;
sei();
return;
}
int main(void)
{
avr_init();
sei();
//PORTD &=~(1<<transmit_en);
//pc_buff_ready = 1;
while (1)
{
//if( pc_buff_ready == 1 ) //pc_buff_ready == 1 &&
//{
if( my_window == 1 )
{
cli();
_delay_us(30);
//PORTD |= (1<<transmit_en);
PORTG |=_BV(PG4); //disable DE RS485
PORTD |=_BV(PD5); //enable RE RS485
//_delay_us(5);
for( i=0; pc_rec_pos != i; i++ )
rs485_ransmit(pc_command[i]);
while ( !( UCSR0A & (1<<UDRE0)) );
_delay_us(160);
PORTG &=~_BV(PG4); //disable DE RS485
PORTD &=~_BV(PD5); //enable RE RS485
my_window = 0;
clear_buff(0);
pc_buff_ready = 0;
pc_rec_pos = 0;
JovialLiX ,
19.04.2010 (Updated 24.03.2018 )
0
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 96 97 98
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#define myXPaddress 0b00000010
//#define transmit_en PD0
void avr_init(void);
void clear_buff(unsigned char buff);
volatile unsigned char bit9 = 0;
volatile unsigned char rbyte = 0;
volatile unsigned char pc_rbyte = 0;
volatile unsigned char pc_command[17];
volatile unsigned char xp_response[15];
volatile unsigned char pc_rec_pos = 0;
volatile unsigned char xp_rec_pos = 0;
volatile unsigned char pc_rec_en = 0;
volatile unsigned char xp_rec_en = 0;
volatile unsigned char pc_buff_ready = 0;
volatile unsigned char xp_buff_ready = 0;
volatile unsigned char my_window = 0;
volatile unsigned char ack = 0;
volatile unsigned char xp_xor = 0;
volatile unsigned char COMM = 0;
unsigned char i;
void rs485_ransmit( unsigned char data )
{
while ( !( UCSR0A & (1<<UDRE0)) );
UCSR0B &= ~(1<<TXB80); // SET 9 BIT IN 0
UDR0 = data;
}
unsigned char rs485_reciv(void)
{
char status,data;
status=UCSR0A;
bit9 = UCSR0B;
data=UDR0;
if ( status & ( (1<<FE)|(1<<DOR)|(1<<UPE) ) )
return 0;
return data;
}
unsigned char rs232_reciv( void )
{
while ( !(UCSR1A & (1<<RXC1)) );
return UDR1;
}
void rs232_transmit( unsigned char data )
{
while ( !( UCSR1A & (1<<UDRE1)) );
UDR1 = data;
}
ISR(USART1_RX_vect)
{
pc_rbyte = rs232_reciv();
if( pc_buff_ready == 1 && pc_rbyte == 0xFA )
{
pc_rec_en = 0;
rs232_transmit('B');
rs232_transmit('U');
rs232_transmit('F');
rs232_transmit('F');
rs232_transmit(' ');
rs232_transmit('O');
rs232_transmit('V');
rs232_transmit('F');
return;
}
if( pc_rec_en == 1 )
if( pc_rbyte == 0xFF)
{
pc_rec_en = 0;
pc_buff_ready = 1;
return;
}
else
{
pc_command[pc_rec_pos] = pc_rbyte;
pc_rec_pos++;
return;
}
JovialLiX ,
19.04.2010 (Updated 24.03.2018 )
0
1 2 3 4 5 6 7 8 9 10 11
int main()
{
if (2 * 2 != 4)
{
printf ("Плохой день!");
getch();
return 1;
}
...
}
А вдруг???
XAKEP ,
19.04.2010 (Updated 24.03.2018 )
0
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
#include <unistd.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
// grep ^\s*$ file1 file2 ... | wc -l
int main(int argc, const char **argv)
{
int fd[2];
pid_t pid;
assert(!pipe(fd));
assert((pid = fork()) >= 0);
if (!pid)
{
char **newargv;
assert(dup2(fd[1], 1) == 1);
assert(!close(fd[0]));
assert(!close(fd[1]));
assert(newargv = malloc((argc + 2) * sizeof(char *)));
newargv[0] = "grep";
newargv[1] = "^\\s*$";
memcpy(newargv + 2, argv + 1, (argc + 1) * sizeof(char *));
assert(execvp("grep", newargv) * 0);
}
assert((pid = fork()) >= 0);
if (!pid)
{
assert(dup2(fd[0], 0) == 0);
assert(!close(fd[0]));
assert(!close(fd[1]));
assert(execlp("wc", "wc", "-l", NULL) * 0);
}
assert(!close(fd[0]));
assert(!close(fd[1]));
while (wait(NULL) != -1);
return 0;
}
Butjok ,
15.04.2010 (Updated 24.03.2018 )